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

Select the file after opening system file explorer #3251

Closed
KoBeWi opened this issue Sep 3, 2021 · 4 comments
Closed

Select the file after opening system file explorer #3251

KoBeWi opened this issue Sep 3, 2021 · 4 comments

Comments

@KoBeWi
Copy link
Member

KoBeWi commented Sep 3, 2021

Describe the project you are working on

A big project with many folders and files.

Describe the problem or limitation you are having in your project

It happens quite often that I need to open some directory looking for specific file. However when I use the Show in File Manager option, it only opens the directory. I have to find the file again, which often is more difficult than from within the editor due to the *.import litter.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

When I click the Show in File Manager option in filesystem dock, it should not only open the directory, but also select the file.

See also godotengine/godot#26364

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

image
It needs some platform-specific code.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Not really.

Is there a reason why this should be core and not an add-on in the asset library?

It's about editor filesystem dock usability.

@Calinou
Copy link
Member

Calinou commented Sep 3, 2021

Note that this requires OS-specific code to be implemented:
https://forum.qt.io/topic/18157/solved-open-folder-explorer-with-pre-selected-file

On Windows, a \select <filename> parameter can be passed to explorer.exe, but there is no CLI equivalent on other platforms.

@EricEzaM
Copy link

EricEzaM commented Sep 20, 2021

How jank is this? Acceptable?

Error OS_Windows::shell_open(String p_uri) {
	if (p_uri.begins_with("file://")) {
		String explorer_param = "/select," + p_uri;
		ShellExecute(nullptr, nullptr, "explorer.exe", (LPCSTR)(explorer_param.utf8().get_data()), nullptr, SW_SHOWNORMAL);
	} else {
		ShellExecuteW(nullptr, nullptr, (LPCWSTR)(p_uri.utf16().get_data()), nullptr, nullptr, SW_SHOWNORMAL);
	}
	return OK;
}

I also had to comment out this part to get it to work, otherwise it just kept opening to select the folder. This may impact other platforms...?

		case FILE_SHOW_IN_EXPLORER: {
			// Show the file/folder in the OS explorer.
			String fpath = path;
			if (path == "Favorites") {
				fpath = p_selected[0];
			}

			/*if (!fpath.ends_with("/")) {
				fpath = fpath.get_base_dir();
			}*/
			String dir = ProjectSettings::get_singleton()->globalize_path(fpath);
			OS::get_singleton()->shell_open(String("file://") + dir);
		} break;

@lexum0
Copy link

lexum0 commented Mar 11, 2022

Note that this requires OS-specific code to be implemented

The API to use in macOS is NSWorkspace.shared.activateFileViewerSelecting(url)

@KoBeWi
Copy link
Member Author

KoBeWi commented Aug 13, 2024

Implemented by godotengine/godot#69698

@KoBeWi KoBeWi closed this as completed Aug 13, 2024
@KoBeWi KoBeWi added this to the 4.1 milestone Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants