Browse Source

Make shortcut for focusing searchbar in filesystem dock

(cherry picked from commit 22e2e4334ef4c2e0b085fafe74f899e52d1577d4)
fox 4 years ago
parent
commit
533d3e7800
2 changed files with 19 additions and 0 deletions
  1. 18 0
      editor/filesystem_dock.cpp
  2. 1 0
      editor/filesystem_dock.h

+ 18 - 0
editor/filesystem_dock.cpp

@@ -1867,6 +1867,20 @@ void FileSystemDock::_resource_created() const {
 	editor->save_resource_as(RES(r), fpath);
 	editor->save_resource_as(RES(r), fpath);
 }
 }
 
 
+void FileSystemDock::_focus_current_search_box() {
+	LineEdit *current_search_box = nullptr;
+	if (display_mode == DISPLAY_MODE_TREE_ONLY) {
+		current_search_box = tree_search_box;
+	} else if (display_mode == DISPLAY_MODE_SPLIT) {
+		current_search_box = file_list_search_box;
+	}
+
+	if (current_search_box) {
+		current_search_box->grab_focus();
+		current_search_box->select_all();
+	}
+}
+
 void FileSystemDock::_search_changed(const String &p_text, const Control *p_from) {
 void FileSystemDock::_search_changed(const String &p_text, const Control *p_from) {
 	if (searched_string.length() == 0) {
 	if (searched_string.length() == 0) {
 		// Register the uncollapsed paths before they change.
 		// Register the uncollapsed paths before they change.
@@ -2461,6 +2475,8 @@ void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) {
 			_tree_rmb_option(FILE_REMOVE);
 			_tree_rmb_option(FILE_REMOVE);
 		} else if (ED_IS_SHORTCUT("filesystem_dock/rename", p_event)) {
 		} else if (ED_IS_SHORTCUT("filesystem_dock/rename", p_event)) {
 			_tree_rmb_option(FILE_RENAME);
 			_tree_rmb_option(FILE_RENAME);
+		} else if (ED_IS_SHORTCUT("editor/open_search", p_event)) {
+			_focus_current_search_box();
 		} else {
 		} else {
 			return;
 			return;
 		}
 		}
@@ -2484,6 +2500,8 @@ void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) {
 			_file_list_rmb_option(FILE_REMOVE);
 			_file_list_rmb_option(FILE_REMOVE);
 		} else if (ED_IS_SHORTCUT("filesystem_dock/rename", p_event)) {
 		} else if (ED_IS_SHORTCUT("filesystem_dock/rename", p_event)) {
 			_file_list_rmb_option(FILE_RENAME);
 			_file_list_rmb_option(FILE_RENAME);
+		} else if (ED_IS_SHORTCUT("editor/open_search", p_event)) {
+			_focus_current_search_box();
 		} else {
 		} else {
 			return;
 			return;
 		}
 		}

+ 1 - 0
editor/filesystem_dock.h

@@ -238,6 +238,7 @@ private:
 
 
 	void _toggle_split_mode(bool p_active);
 	void _toggle_split_mode(bool p_active);
 
 
+	void _focus_current_search_box();
 	void _search_changed(const String &p_text, const Control *p_from);
 	void _search_changed(const String &p_text, const Control *p_from);
 
 
 	void _file_and_folders_fill_popup(PopupMenu *p_popup, Vector<String> p_paths, bool p_display_path_dependent_options = true);
 	void _file_and_folders_fill_popup(PopupMenu *p_popup, Vector<String> p_paths, bool p_display_path_dependent_options = true);