Probably this could help: http://wiki.wxwidgets.org/Launching_The_Default_Browser
But I wasn't able to make it open the directory:
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.
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?
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;
}
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
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;
}
codeman: You can use this:
#if MACRO1
#elif MACRO2
#else
#endif
It will make the code more readable :)
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:
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?