portable-file-dialogs icon indicating copy to clipboard operation
portable-file-dialogs copied to clipboard

Open file(s) in file-explorer

Open cdcseacave opened this issue 5 years ago • 5 comments

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?

cdcseacave avatar Jun 01 '20 06:06 cdcseacave

Thanks for the suggestion, this sounds like a good idea.

samhocevar avatar Jun 01 '20 06:06 samhocevar

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.

cdcseacave avatar Jun 01 '20 07:06 cdcseacave

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.

funbiscuit avatar Jun 01 '20 08:06 funbiscuit

FYI I have started implementing this in the feature/explorer branch. Thanks to both of you for the sample code!

samhocevar avatar Jul 16 '20 13:07 samhocevar

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.

merwok avatar Jul 17 '20 19:07 merwok