Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open file(s) in file-explorer #36

Open
cdcseacave opened this issue Jun 1, 2020 · 5 comments
Open

Open file(s) in file-explorer #36

cdcseacave opened this issue Jun 1, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@cdcseacave
Copy link

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?

@samhocevar samhocevar added the enhancement New feature or request label Jun 1, 2020
@samhocevar
Copy link
Owner

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

@cdcseacave
Copy link
Author

cdcseacave commented Jun 1, 2020

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.

@funbiscuit
Copy link
Contributor

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.

@samhocevar
Copy link
Owner

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

@merwok
Copy link

merwok commented Jul 17, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants