Author Topic: Editor's right-click menu can open file's containing folder.  (Read 25505 times)

Offline codeman

  • Multiple posting newcomer
  • *
  • Posts: 15
My 2nd patch:
https://developer.berlios.de/patch/index.php?func=detailpatch&patch_id=3038&group_id=5358

I use this feature from Visual Studio all the time.

Unfortunately it is platform specific, so I could only make it work for WIN32.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Editor's right-click menu can open file's containing folder.
« Reply #1 on: July 24, 2010, 11:20:29 pm »
The correct macro to check for is __WXMSW__ not _WIN32.

On linux xdg-open can be used.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline codeman

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Editor's right-click menu can open file's containing folder.
« Reply #2 on: July 25, 2010, 12:48:09 am »
Thanks.

Ok Ive updated the patch to use the __WXMSW__ define.

I will try xdg-open when I get back to my linux box, unless someone else wants to do it.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Editor's right-click menu can open file's containing folder.
« Reply #3 on: July 25, 2010, 05:16:15 am »
My 2nd patch:
https://developer.berlios.de/patch/index.php?func=detailpatch&patch_id=3038&group_id=5358

I use this feature from Visual Studio all the time.

Unfortunately it is platform specific, so I could only make it work for WIN32.

Nice work.
But I can't apply your patch. (I just copy the patch, and create a a.patch file, then apply the patch by tortoiseSVN, then failed)
but it seems your patch was generated from "msys git" ? Can git used to access cb repo?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Editor's right-click menu can open file's containing folder.
« Reply #4 on: July 25, 2010, 09:49:14 am »
https://developer.berlios.de/patch/index.php?func=detailpatch&patch_id=3038&group_id=5358
That is a very nice idea, however, I wonder whether wxWidgets can do that, too (in a cross platform way). Implementing such functionality OS natively should be our last option usually. Did you have a look at wxWidgets API first / ask in a wx forum?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline codeman

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Editor's right-click menu can open file's containing folder.
« Reply #5 on: July 25, 2010, 11:27:35 am »
Nice work.
But I can't apply your patch. (I just copy the patch, and create a a.patch file, then apply the patch by tortoiseSVN, then failed)
but it seems your patch was generated from "msys git" ? Can git used to access cb repo?

I stored the 10.05 source into a local git repo, and used git to create patches. After some reading, you can apply them to your files using git-apply (you dont need a git repository). I should probably get SVN so that I can work with the latest tree and create compatible patches  :P

That is a very nice idea, however, I wonder whether wxWidgets can do that, too (in a cross platform way). Implementing such functionality OS natively should be our last option usually. Did you have a look at wxWidgets API first / ask in a wx forum?

I did a lot of searching to see if wx has builtin support for it, and I dont think it does. Well just have to do this for Windows, Mac and Linux seperately.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Editor's right-click menu can open file's containing folder.
« Reply #6 on: July 25, 2010, 11:34:01 am »
Probably this could help: http://wiki.wxwidgets.org/Launching_The_Default_Browser

But I wasn't able to make it open the directory:
Code
    wxMimeTypesManager manager;
    wxFileType * filetype = manager.GetFileTypeFromMimeType(wxT("application/x-directory"));
    if (filetype)
    {
        wxString command = filetype->GetOpenCommand(wxT("/home/obfuscated"));
        wxExecute(command);
    }


codeman: you could use git svn, but the generated patches couldn't be applied in a normal tree, last time I've tried. The git svn was not recognizing the "$Revision:" and similar tags.
« Last Edit: July 25, 2010, 05:38:33 pm by oBFusCATed »
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline codeman

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Editor's right-click menu can open file's containing folder.
« Reply #7 on: July 25, 2010, 02:03:40 pm »
Ok I just replaced the patch with one coming from tortoiseSVN from the latest tree (revision 6416). Hopefully that will work for everyone.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Editor's right-click menu can open file's containing folder.
« Reply #8 on: July 25, 2010, 08:19:47 pm »
Code
    wxMimeTypesManager manager;
    wxFileType * filetype = manager.GetFileTypeFromMimeType(wxT("application/x-directory"));
    if (filetype)
    {
        wxString command = filetype->GetOpenCommand(wxT("/home/obfuscated"));
        wxExecute(command);
    }
I think this only applies to a web browser. What I meant was really the platform's file explorer.

In this thread:
http://forums.wxwidgets.org/viewtopic.php?p=9441
...I found this:
http://forums.wxwidgets.org/viewtopic.php?p=9624#9624

This looks like cross-platform and in addition you can open up in a folder you like.

Strange that there is really no wx core function available. I wonder how it's done in Qt, maybe it can be done similar in wx, too.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline codeman

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Editor's right-click menu can open file's containing folder.
« Reply #9 on: July 25, 2010, 09:07:48 pm »
Ok here is my latest version that I have tested on Ubuntu - it works very well, except that it wont leave the file selected.

MortenMacFly: were you referring to the wxExecute() command when you said it was cross-platform? We still need to use different commands for the different platforms, like I have, correct?

Code
bool EditorManager::OpenContainingFolder()
{
cbEditor* ed = GetBuiltinEditor(GetActiveEditor());
if (!ed)
return false;

const wxString& fullpath = ed->GetFilename();

#ifdef __WXMSW__

WCHAR cmd[1024]; //CreateProcessW is allowed to modify this for internal processing.
wsprintf(cmd, _("explorer /select,%s"), fullpath.c_str()); //Build the command string to open an explorer window on the folder with the file selected

STARTUPINFOW si;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
PROCESS_INFORMATION po;
memset(&po, 0, sizeof(po));
CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &po); //Launch explorer
#else
//Extract the folder name from the file
wxString cmd;
wxFileName::SplitPath(fullpath, &cmd, NULL, NULL);

//Use the xdg-open command, and get the char* string
cmd.Prepend(_("xdg-open "));
wxCharBuffer mbcmd = cmd.mb_str();
system(mbcmd);
#endif

return true;
}

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Editor's right-click menu can open file's containing folder.
« Reply #10 on: July 25, 2010, 09:22:50 pm »
MortenMacFly: were you referring to the wxExecute() command when you said it was cross-platform? We still need to use different commands for the different platforms, like I have, correct?
Partially. In the post I was referring to it shows what to use for "explorer" on the other platforms. Basically you call wxExecute with the system's default file explorer as listed in this post (of Ryan Norton):
http://forums.wxwidgets.org/viewtopic.php?p=9624#9624
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline codeman

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Editor's right-click menu can open file's containing folder.
« Reply #11 on: July 25, 2010, 10:20:11 pm »
Ok shall I change my code to use wxExecute with the three different commands (explorer, xdg-open, open), and then we can put it into the codebase?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Editor's right-click menu can open file's containing folder.
« Reply #12 on: July 25, 2010, 10:29:33 pm »
I think this only applies to a web browser. What I meant was really the platform's file explorer.
No it doesn't, mime types can be used by all applications (the Enlightenment WM/shell is using them to recognize files for example).

Please make this configurable, even on windows, some people are not using the exploder, but total commander or something similar.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline codeman

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Editor's right-click menu can open file's containing folder.
« Reply #13 on: July 26, 2010, 02:44:13 am »
Now works with all three platforms, using wxExecute.

Im pretty sure the Mac version works, but if someone would like to test it. Ive updated the patch https://developer.berlios.de/patch/index.php?func=detailpatch&patch_id=3038&group_id=5358

Code
bool EditorManager::OpenContainingFolder()
{
cbEditor* ed = GetBuiltinEditor(GetActiveEditor());
if (!ed)
return false;

const wxString& fullpath = ed->GetFilename();

wxString cmd;

#ifdef __WXMSW__
cmd = _("explorer /select,") + fullpath; //Open folder with the file selected
#else
#ifdef __WXMAC__
cmd = _("open -R ") + fullpath; //Open folder with the file selected
#else
//Cant select the file on Linux, so just extract the folder name
wxFileName::SplitPath(fullpath, &cmd, NULL, NULL);

//Use the xdg-open command
cmd = _("xdg-open ") + cmd;
#endif
#endif

wxExecute(cmd);

return true;
}

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Editor's right-click menu can open file's containing folder.
« Reply #14 on: July 26, 2010, 06:59:59 am »
I would prefer not to hardcode the open-commands, but making them configurable.
The configuration-defaults should be platform specific, so the user can change the default command to his/her needs.
It would be a little bit like "Terminal to launch  console apps", but for all platforms and not only for non-windows platforms.

Should not be too hard to implement.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Editor's right-click menu can open file's containing folder.
« Reply #15 on: July 26, 2010, 09:11:37 am »
codeman: You can use this:

Code
#if MACRO1 
#elif MACRO2
#else
#endif

It will make the code more readable :)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline codeman

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Editor's right-click menu can open file's containing folder.
« Reply #16 on: July 27, 2010, 12:01:26 am »
I would prefer not to hardcode the open-commands, but making them configurable.
The configuration-defaults should be platform specific, so the user can change the default command to his/her needs.
It would be a little bit like "Terminal to launch  console apps", but for all platforms and not only for non-windows platforms.

Should not be too hard to implement.

Ok what about this: In ToolsManager::LoadTools(), we currently do:
Code
void ToolsManager::LoadTools()
{
    ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("tools"));
    wxArrayString list = cfg->EnumerateSubPaths(_("/"));
    for (unsigned int i = 0; i < list.GetCount(); ++i)
    {
...

If the list of saved tools returns zero, then we could create a default tool to open the containing folder. For windows this would by default point to explorer, and for linux it would be xdg-open, but then you could change the tool to whatever you wanted. This tool would then be saved and loaded up as normal the next time round.

Only issue is how do we allow that tool to appear in the context menu? - that could be a new custom tool option.

What do you think?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Editor's right-click menu can open file's containing folder.
« Reply #17 on: July 27, 2010, 07:25:11 am »
What do you think?
I think what Jens means is a configuration option like in Settings -> Environment -> General settings -> "Shell to run commands in" or "Terminal to launch console programs".

If there would be another option like "explorer to launch" which can be configured (with a checkbox to "use the file name", too for Linux) and the text box is pre-configured with the platform specific default explorer (as you did now) that would be fine and most flexible.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ptDev

  • Almost regular
  • **
  • Posts: 222
Re: Editor's right-click menu can open file's containing folder.
« Reply #18 on: July 27, 2010, 10:08:21 am »
I like the idea of having the option to call the system's file browser from "Tools". It makes sense to me. In fact, under Windows I added explorer to my tools, and passed arguments to make it open the directory of the active project by default.

It would be nice if a special, separated, menu option to browse the project directory would be present under "Tools" in addition to the context menu of the project manager.

Offline codeman

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Editor's right-click menu can open file's containing folder.
« Reply #19 on: July 27, 2010, 09:43:16 pm »
I like the idea of having the option to call the system's file browser from "Tools". It makes sense to me. In fact, under Windows I added explorer to my tools, and passed arguments to make it open the directory of the active project by default.

It would be nice if a special, separated, menu option to browse the project directory would be present under "Tools" in addition to the context menu of the project manager.

This is my current thinking too. The "Open containing folder" feature doesnt need its own dedicated setting field, as Morten suggested. All the functionality to do it is already available in the custom Tools menu. The correct way to do this would be to create default tools for the different platforms, and to allow cusomizing tools to be accessible from the context menu.

Maybe my code segment was not the correct way of creating pre-defined custom tools, but the idea is still sound.
« Last Edit: July 27, 2010, 09:45:07 pm by codeman »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Editor's right-click menu can open file's containing folder.
« Reply #20 on: July 28, 2010, 07:34:41 am »
This is my current thinking too. The "Open containing folder" feature doesnt need its own dedicated setting field, as Morten suggested. All the functionality to do it is already available in the custom Tools menu. The correct way to do this would be to create default tools for the different platforms, and to allow cusomizing tools to be accessible from the context menu.
I disagree. Assume you have a project with sub-folders. You can browse to any folder from the project managment pane if you attach the option there. However, from the tools menu you don-t have macros available to tell you the path to browse to. All you can do is e.g. open an Explorer in the path of you project or alike. But not in any sub-path. Try yourself or proof me wrong.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

mariocup

  • Guest
Re: Editor's right-click menu can open file's containing folder.
« Reply #21 on: July 28, 2010, 07:51:23 am »
Hi,

I think we should integrate another option. Since the Filemanager and Powershell plugin will be integrated in Code::Blocks it would make sense to have also a context menu like: Open in Filemanager. This would work under windows and linux and it is more convenient to browse within the Filemanager.

What do you think about?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Editor's right-click menu can open file's containing folder.
« Reply #22 on: July 28, 2010, 08:13:57 am »
What do you think about?
True. However, you might really want to browse with the explorer if you want to use Explorer shell extensions like TortoiseSVN or alike (as an example on Windows).
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: Editor's right-click menu can open file's containing folder.
« Reply #23 on: October 01, 2010, 08:41:35 am »
There are too many options in "General setting" panel.
Why not instead by wxAuiNotebook?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Editor's right-click menu can open file's containing folder.
« Reply #24 on: October 01, 2010, 05:34:05 pm »
Why not instead by wxAuiNotebook?
Probably splitting into another category would make more sense.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ