Context menu current directory wrong

Ask any support questions here
Post Reply
twinsen
Posts: 109
Joined: Mon Dec 27, 2010 3:17 pm

Context menu current directory wrong

Post by twinsen »

My existing windows explorer context menu extensions assume the current directory is set to the "current folder" in explorer when a context menu extension is executed.
I have to change them to work with explorer++ which is a bit annoying.
Currently a workaround is to use another bat file.

Eg Instead of:
"cmd.exe /k custombuild" (to execute custombuild on selected xml file)
Use:
"cmd.exe /k cd_dir_of_file.bat "%1" & custombuild"

Where cd_dir_of_file.bat contains:
@%~d1
@cd %~d1%~p1

And cd_dir_of_file.bat is in the path.

Maintaining another bat file just for explorer++ is a bit annoying.
Could we make it so when you right click a file the current directory is set to the path of the file? This should make existing context menu extensions compatible with explorer++. At the moment the current directory is the explorer++ installation directory, which does not seem all that useful (unless something relies on this?).
sun
Posts: 25
Joined: Tue Apr 05, 2011 5:02 am
Contact:

Re: Context menu current directory wrong

Post by sun »

Could you clarify the exact steps/things/scripts you're doing and what goes wrong?

I've just tested right-clicking a file and selecting a context menu entry that invokes a batch script on the file, which generates a new file (.patch) in E++ 1.2, Win7 64bit -- and that worked like it should.
twinsen
Posts: 109
Joined: Mon Dec 27, 2010 3:17 pm

Re: Context menu current directory wrong

Post by twinsen »

Here is a simple example (currently testing 1.2 on WinXP 32bit, but the same happens on Win7 32bit):

Warning: Knowledge of how to backup/restore registry keys required (or at least to delete a key).

Put this in "ListCurrentDirectory.reg" and double click it.

Code: Select all

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\List Current Directory]
@="List Current Directory"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\List Current Directory\command]
@="c:\\tmp\\ListCurrentDirectory \"%1\""
Put this in c:\tmp\ListCurrentDirectory.bat

Code: Select all

echo File is correct: %1
echo Current directory is different to windows explorer:
dir
pause
Now right click on a file in windows explorer, the directory where dir is executed is the expected directory (its the directory containing the file you right clicked). It is this no matter how you launch windows explorer.
Now right click on a file in explorer++, the directory where dir is executed on this particular computer using 1.2 is the directory where explorer++.exe resides, which breaks any context menu that relied on it.
Try it out on different computers with different windows operating systems. Try it by running explorer++.exe from the command line, eg change to c:\, then run "PATH_TO_EXPLORER\explorer++.exe", note that now the directory that is listed is always c:\, compared to windows explorer that displays the expected directory every time. Try launching via some other mechanisms. If you select "Replace explorer for file system folders" in options then launch by right clicking the start menu and choosing "Open in Explorer++" you get yet another different directory, on this computer its "C:\Documents and Settings\<username>". The current directory supplied by explorer++ is not consistent or useful to context menu extensions (hence why I need the "cd_dir_of_file.bat" workaround).

After finished testing, delete the registry key.
Attachments
ListCurrentDirectoryExample.7z
(400 Bytes) Downloaded 502 times
David Erceg
Site Admin
Posts: 933
Joined: Sat Apr 18, 2009 1:46 am

Re: Context menu current directory wrong

Post by David Erceg »

Ok, I see the problem. SetCurrentDirectory() is actually never called within the code, which is why the path always ends up been set to the directory E++ resides in. I'll have SetCurrentDirectory() called when either the tab selection/directory changes.

Edit: I assume this would be consistent with Windows Explorer. The current directory could be set when right-clicking a file, but this would only seem to be useful if files in a folder resided in different directories. There are two cases I can think of where this could be true (within Windows Explorer on Win 7):

1. Libraries - List Current Directory acts as if the files are within one directory.
2. Search results - Current directory set to path of cmd.exe (e.g. C:\Windows\System32).

So, setting the path once when the directory/tab changes should suffice.
sun
Posts: 25
Joined: Tue Apr 05, 2011 5:02 am
Contact:

Re: Context menu current directory wrong

Post by sun »

However, it looks like Windows Explorer in Windows 7 behaves differently than in older Windows versions then. Almost all of my custom shell scripts - which were originally written for Windows XP - contain a

Code: Select all

cd /D "%~dp1"
(or similar) line, as the working directory definitely was not the directory containing the file in Windows XP.

In turn, for maximum compatibility, Explorer++ would have to initialize a different working directory depending on the OS version it's running on.
David Erceg
Site Admin
Posts: 933
Joined: Sat Apr 18, 2009 1:46 am

Re: Context menu current directory wrong

Post by David Erceg »

How are the batch scripts invoked? Using the list current directory script + context menu entry, I get the same results on XP as I do on Win 7 (that is, the current directory is the directory that the file is in).
sun
Posts: 25
Joined: Tue Apr 05, 2011 5:02 am
Contact:

Re: Context menu current directory wrong

Post by sun »

Odd - you're right. Just double-checked on my old XP machine. Now I'm no longer sure why my shell scripts contain the cd lines. :P

The only time when CD is not the directory is when right-clicking a folder in the directory listing (i.e., not in the tree/navigation pane), in which case

Code: Select all

%1 == C:\parent\folder
%CD% == C:\parent
...but I guess that would be in line with your proposal of setting CD to the current directory view. It's perfectly possible that this is the reason for the cd in my scripts.
David Erceg
Site Admin
Posts: 933
Joined: Sat Apr 18, 2009 1:46 am

Re: Context menu current directory wrong

Post by David Erceg »

I've committed the changes I mentioned above, and they'll be in tonight's nightly.
Post Reply