portable-file-dialogs
portable-file-dialogs copied to clipboard
Open file(s) in file-explorer
This library looks great! It would be exactly what I was looking fore, if it had also a way to open a file explorer window at the selected file or files: ex. SHOpenFolderAndSelectItems() on Windows. Would you consider adding this functionality too?
Thanks for the suggestion, this sounds like a good idea.
This is a ex code for Windows, maybe it helps:
#ifdef _MSC_VER
CoInitialize(NULL);
LPITEMIDLIST pidlFolder(ILCreateFromPath(Util::getPath(fileName)));
LPITEMIDLIST pidlFile(ILCreateFromPath(fileName));
LPCITEMIDLIST pidlItems[1] = { pidlFile };
SHOpenFolderAndSelectItems(pidlFolder, 1, pidlItems, 0);
ILFree(pidlFile);
ILFree(pidlFolder);
CoUninitialize();
#else
//TODO: implement
#endif
No idea how to do the same on other platforms though.
I have some code to select files on linux platforms with some popular file managers (dolphin, nautilus and nemo) with a fallback to open parent directory (without selecting file) if file manager is not supported. Some of them seem to not have such feature (like thunar, I wasn't able to find in docs how to select file). You're free to grab code here:
https://github.com/funbiscuit/spacedisplay/blob/master/lib/src/platformutils-nix.cpp
You select file by calling show_file_in_file_manager(filepath)
Or you can write windows part with stubs for other platforms and I'll do a PR with linux support.
It gets default file manager desktop file by executing xdg-mime query default inode/directory, then it tries to find its .desktop file in possible locations and then tries to determine what file manager it is. Code is a bit messy, but it works. At least on platforms I tested (ubuntu, lubuntu, manjaro kde), it worked.
FYI I have started implementing this in the feature/explorer branch. Thanks to both of you for the sample code!
For free OSes, I think these days you can have a generic command that uses xdg-open (from xdg-utils package) to open a directory or file (or URL) with the user’s preferred application.