Skip to content

Commit

Permalink
Add Ctrl + L / Cmd + Shift + G shortcut to focus path bar in FileDialog
Browse files Browse the repository at this point in the history
This also tweaks EditorFileDialog to use the same shortcut,
while making it select the path text after focusing
(like in most file managers).

Ctrl + L / Cmd + Shift + G can also now be used to focus on the
property name in the project settings editor, as well in the
Input Map, Autoload, Shader Globals and Global Groups tabs.
  • Loading branch information
Calinou committed Mar 4, 2024
1 parent 01dc5c5 commit 4f8d7ca
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 2 deletions.
4 changes: 4 additions & 0 deletions editor/action_map_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ LineEdit *ActionMapEditor::get_search_box() const {
return action_list_search;
}

LineEdit *ActionMapEditor::get_path_box() const {
return add_edit;
}

InputEventConfigurationDialog *ActionMapEditor::get_configuration_dialog() {
return event_config_dialog;
}
Expand Down
1 change: 1 addition & 0 deletions editor/action_map_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class ActionMapEditor : public Control {

public:
LineEdit *get_search_box() const;
LineEdit *get_path_box() const;
InputEventConfigurationDialog *get_configuration_dialog();

// Dictionary represents an Action with "events" (Array) and "deadzone" (float) items. Pass with no param to update list from cached action map.
Expand Down
4 changes: 4 additions & 0 deletions editor/editor_autoload_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,10 @@ void EditorAutoloadSettings::_script_created(Ref<Script> p_script) {
_autoload_add();
}

LineEdit *EditorAutoloadSettings::get_path_box() const {
return autoload_add_path;
}

Variant EditorAutoloadSettings::get_drag_data_fw(const Point2 &p_point, Control *p_control) {
if (autoload_cache.size() <= 1) {
return false;
Expand Down
2 changes: 2 additions & 0 deletions editor/editor_autoload_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class EditorAutoloadSettings : public VBoxContainer {
bool autoload_add(const String &p_name, const String &p_path);
void autoload_remove(const String &p_name);

LineEdit *get_path_box() const;

EditorAutoloadSettings();
~EditorAutoloadSettings();
};
Expand Down
7 changes: 7 additions & 0 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2575,6 +2575,11 @@ void FileSystemDock::fix_dependencies(const String &p_for_file) {
deps_editor->edit(p_for_file);
}

void FileSystemDock::focus_on_path() {
current_path_line_edit->grab_focus();
current_path_line_edit->select_all();
}

void FileSystemDock::focus_on_filter() {
LineEdit *current_search_box = nullptr;
if (display_mode == DISPLAY_MODE_TREE_ONLY) {
Expand Down Expand Up @@ -3398,6 +3403,8 @@ void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) {
_tree_rmb_option(FILE_OPEN_EXTERNAL);
} else if (ED_IS_SHORTCUT("filesystem_dock/open_in_terminal", p_event)) {
_tree_rmb_option(FILE_OPEN_IN_TERMINAL);
} else if (ED_IS_SHORTCUT("file_dialog/focus_path", p_event)) {
focus_on_path();
} else if (ED_IS_SHORTCUT("editor/open_search", p_event)) {
focus_on_filter();
} else {
Expand Down
1 change: 1 addition & 0 deletions editor/filesystem_dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ class FileSystemDock : public VBoxContainer {
String get_current_directory() const;

void navigate_to_path(const String &p_path);
void focus_on_path();
void focus_on_filter();

ScriptCreateDialog *get_script_create_dialog() const;
Expand Down
4 changes: 4 additions & 0 deletions editor/group_settings_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,10 @@ void GroupSettingsEditor::_show_rename_dialog() {
rename_group->grab_focus();
}

LineEdit *GroupSettingsEditor::get_name_box() const {
return group_name;
}

GroupSettingsEditor::GroupSettingsEditor() {
ProjectSettings::get_singleton()->add_hidden_prefix("global_group/");

Expand Down
1 change: 1 addition & 0 deletions editor/group_settings_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class GroupSettingsEditor : public VBoxContainer {
static void _bind_methods();

public:
LineEdit *get_name_box() const;
void show_message(const String &p_message);

void remove_references(const StringName &p_name);
Expand Down
6 changes: 5 additions & 1 deletion editor/gui/editor_file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ void EditorFileDialog::shortcut_input(const Ref<InputEvent> &p_event) {
}
if (ED_IS_SHORTCUT("file_dialog/focus_path", p_event)) {
dir->grab_focus();
dir->select_all();
handled = true;
}
if (ED_IS_SHORTCUT("file_dialog/move_favorite_up", p_event)) {
Expand Down Expand Up @@ -1783,7 +1784,10 @@ EditorFileDialog::EditorFileDialog() {
ED_SHORTCUT("file_dialog/toggle_mode", TTR("Toggle Mode"), KeyModifierMask::ALT | Key::V);
ED_SHORTCUT("file_dialog/create_folder", TTR("Create Folder"), KeyModifierMask::CMD_OR_CTRL | Key::N);
ED_SHORTCUT("file_dialog/delete", TTR("Delete"), Key::KEY_DELETE);
ED_SHORTCUT("file_dialog/focus_path", TTR("Focus Path"), KeyModifierMask::CMD_OR_CTRL | Key::D);
ED_SHORTCUT("file_dialog/focus_path", TTR("Focus Path"), KeyModifierMask::CMD_OR_CTRL | Key::L);
// Allow both Cmd + L and Cmd + Shift + G to match Safari's and Finder's shortcuts respectively.
ED_SHORTCUT_OVERRIDE_ARRAY("file_dialog/focus_path", "macos",
{ int32_t(KeyModifierMask::META | Key::L), int32_t(KeyModifierMask::META | KeyModifierMask::SHIFT | Key::G) });
ED_SHORTCUT("file_dialog/move_favorite_up", TTR("Move Favorite Up"), KeyModifierMask::CMD_OR_CTRL | Key::UP);
ED_SHORTCUT("file_dialog/move_favorite_down", TTR("Move Favorite Down"), KeyModifierMask::CMD_OR_CTRL | Key::DOWN);

Expand Down
28 changes: 27 additions & 1 deletion editor/project_settings_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,16 @@ void ProjectSettingsEditor::shortcut_input(const Ref<InputEvent> &p_event) {
handled = true;
}

if (k->is_match(InputEventKey::create_reference(KeyModifierMask::CMD_OR_CTRL | Key::F))) {
if (ED_IS_SHORTCUT("editor/open_search", p_event)) {
_focus_current_search_box();
handled = true;
}

if (ED_IS_SHORTCUT("file_dialog/focus_path", p_event)) {
_focus_current_path_box();
handled = true;
}

if (handled) {
set_input_as_handled();
}
Expand Down Expand Up @@ -347,6 +352,27 @@ void ProjectSettingsEditor::_focus_current_search_box() {
}
}

void ProjectSettingsEditor::_focus_current_path_box() {
Control *tab = tab_container->get_current_tab_control();
LineEdit *current_path_box = nullptr;
if (tab == general_editor) {
current_path_box = property_box;
} else if (tab == action_map_editor) {
current_path_box = action_map_editor->get_path_box();
} else if (tab == autoload_settings) {
current_path_box = autoload_settings->get_path_box();
} else if (tab == shaders_global_shader_uniforms_editor) {
current_path_box = shaders_global_shader_uniforms_editor->get_name_box();
} else if (tab == group_settings) {
current_path_box = group_settings->get_name_box();
}

if (current_path_box) {
current_path_box->grab_focus();
current_path_box->select_all();
}
}

void ProjectSettingsEditor::_editor_restart() {
ProjectSettings::get_singleton()->save();
EditorNode::get_singleton()->save_all_scenes();
Expand Down
1 change: 1 addition & 0 deletions editor/project_settings_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class ProjectSettingsEditor : public AcceptDialog {

void _tabs_tab_changed(int p_tab);
void _focus_current_search_box();
void _focus_current_path_box();

void _editor_restart_request();
void _editor_restart();
Expand Down
4 changes: 4 additions & 0 deletions editor/shader_globals_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ String ShaderGlobalsEditor::_check_new_variable_name(const String &p_variable_na
return "";
}

LineEdit *ShaderGlobalsEditor::get_name_box() const {
return variable_name;
}

void ShaderGlobalsEditor::_variable_name_text_changed(const String &p_variable_name) {
const String &warning = _check_new_variable_name(p_variable_name.strip_edges());
variable_add->set_tooltip_text(warning);
Expand Down
2 changes: 2 additions & 0 deletions editor/shader_globals_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class ShaderGlobalsEditor : public VBoxContainer {
void _notification(int p_what);

public:
LineEdit *get_name_box() const;

ShaderGlobalsEditor();
~ShaderGlobalsEditor();
};
Expand Down
21 changes: 21 additions & 0 deletions scene/gui/file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,27 @@ void FileDialog::shortcut_input(const Ref<InputEvent> &p_event) {
case Key::BACKSPACE: {
_dir_submitted("..");
} break;
#ifdef MACOS_ENABLED
// Cmd + Shift + G (matches Finder's "Go To" shortcut).
case Key::G: {
if (k->is_command_or_control_pressed() && k->is_shift_pressed()) {
dir->grab_focus();
dir->select_all();
} else {
handled = false;
}
} break;
#endif
// Ctrl + L (matches most Windows/Linux file managers' "focus on path bar" shortcut,
// plus macOS Safari's "focus on address bar" shortcut).
case Key::L: {
if (k->is_command_or_control_pressed()) {
dir->grab_focus();
dir->select_all();
} else {
handled = false;
}
} break;
default: {
handled = false;
}
Expand Down

0 comments on commit 4f8d7ca

Please sign in to comment.