Skip to content

Commit

Permalink
Add option to copy absolute path in file system dock popup
Browse files Browse the repository at this point in the history
  • Loading branch information
Krigu committed Apr 9, 2024
1 parent a7b8602 commit 5c1d1ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2531,6 +2531,14 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
}
} break;

case FILE_COPY_ABSOLUTE_PATH: {
if (!p_selected.is_empty()) {
const String &fpath = p_selected[0];
const String absolute_path = ProjectSettings::get_singleton()->globalize_path(fpath);
DisplayServer::get_singleton()->clipboard_set(absolute_path);
}
} break;

case FILE_COPY_UID: {
if (!p_selected.is_empty()) {
ResourceUID::ID uid = ResourceLoader::get_resource_uid(p_selected[0]);
Expand Down Expand Up @@ -3193,6 +3201,7 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, const Vect

if (p_paths.size() == 1) {
p_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("ActionCopy")), ED_GET_SHORTCUT("filesystem_dock/copy_path"), FILE_COPY_PATH);
p_popup->add_shortcut(ED_GET_SHORTCUT("filesystem_dock/copy_absolute_path"), FILE_COPY_ABSOLUTE_PATH);
if (ResourceLoader::get_resource_uid(p_paths[0]) != ResourceUID::INVALID_ID) {
p_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Instance")), ED_GET_SHORTCUT("filesystem_dock/copy_uid"), FILE_COPY_UID);
}
Expand Down Expand Up @@ -3481,6 +3490,8 @@ void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) {
_tree_rmb_option(FILE_DUPLICATE);
} else if (ED_IS_SHORTCUT("filesystem_dock/copy_path", p_event)) {
_tree_rmb_option(FILE_COPY_PATH);
} else if (ED_IS_SHORTCUT("filesystem_dock/copy_absolute_path", p_event)) {
_tree_rmb_option(FILE_COPY_ABSOLUTE_PATH);
} else if (ED_IS_SHORTCUT("filesystem_dock/copy_uid", p_event)) {
_tree_rmb_option(FILE_COPY_UID);
} else if (ED_IS_SHORTCUT("filesystem_dock/delete", p_event)) {
Expand Down Expand Up @@ -3553,6 +3564,8 @@ void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) {
_file_list_rmb_option(FILE_DUPLICATE);
} else if (ED_IS_SHORTCUT("filesystem_dock/copy_path", p_event)) {
_file_list_rmb_option(FILE_COPY_PATH);
} else if (ED_IS_SHORTCUT("filesystem_dock/copy_absolute_path", p_event)) {
_file_list_rmb_option(FILE_COPY_ABSOLUTE_PATH);
} else if (ED_IS_SHORTCUT("filesystem_dock/delete", p_event)) {
_file_list_rmb_option(FILE_REMOVE);
} else if (ED_IS_SHORTCUT("filesystem_dock/rename", p_event)) {
Expand Down Expand Up @@ -3856,6 +3869,7 @@ FileSystemDock::FileSystemDock() {

// `KeyModifierMask::CMD_OR_CTRL | Key::C` conflicts with other editor shortcuts.
ED_SHORTCUT("filesystem_dock/copy_path", TTR("Copy Path"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::C);
ED_SHORTCUT("filesystem_dock/copy_absolute_path", TTR("Copy Absolute Path"));
ED_SHORTCUT("filesystem_dock/copy_uid", TTR("Copy UID"));
ED_SHORTCUT("filesystem_dock/duplicate", TTR("Duplicate..."), KeyModifierMask::CMD_OR_CTRL | Key::D);
ED_SHORTCUT("filesystem_dock/delete", TTR("Delete"), Key::KEY_DELETE);
Expand Down
1 change: 1 addition & 0 deletions editor/filesystem_dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class FileSystemDock : public VBoxContainer {
FILE_OPEN_EXTERNAL,
FILE_OPEN_IN_TERMINAL,
FILE_COPY_PATH,
FILE_COPY_ABSOLUTE_PATH,
FILE_COPY_UID,
FOLDER_EXPAND_ALL,
FOLDER_COLLAPSE_ALL,
Expand Down

0 comments on commit 5c1d1ea

Please sign in to comment.