Browse Source

Focus the search box when pressing Ctrl+F in Project/Editor Settings

Hugo Locurcio 5 years ago
parent
commit
724b9bc0ce

+ 23 - 0
editor/project_settings_editor.cpp

@@ -74,6 +74,26 @@ static const char *_axis_names[JOY_AXIS_MAX * 2] = {
 	"", " (R2)"
 	"", " (R2)"
 };
 };
 
 
+void ProjectSettingsEditor::_unhandled_input(const Ref<InputEvent> &p_event) {
+
+	const Ref<InputEventKey> k = p_event;
+
+	if (k.is_valid() && is_window_modal_on_top() && k->is_pressed()) {
+
+		if (k->get_scancode_with_modifiers() == (KEY_MASK_CMD | KEY_F)) {
+			if (search_button->is_pressed()) {
+				search_box->grab_focus();
+				search_box->select_all();
+			} else {
+				// This toggles the search bar display while giving the button its "pressed" appearance
+				search_button->set_pressed(true);
+			}
+
+			accept_event();
+		}
+	}
+}
+
 void ProjectSettingsEditor::_notification(int p_what) {
 void ProjectSettingsEditor::_notification(int p_what) {
 
 
 	switch (p_what) {
 	switch (p_what) {
@@ -116,6 +136,7 @@ void ProjectSettingsEditor::_notification(int p_what) {
 		} break;
 		} break;
 		case NOTIFICATION_POPUP_HIDE: {
 		case NOTIFICATION_POPUP_HIDE: {
 			EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "project_settings", get_rect());
 			EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "project_settings", get_rect());
+			set_process_unhandled_input(false);
 		} break;
 		} break;
 		case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
 		case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
 			search_button->set_icon(get_icon("Search", "EditorIcons"));
 			search_button->set_icon(get_icon("Search", "EditorIcons"));
@@ -800,6 +821,7 @@ void ProjectSettingsEditor::popup_project_settings() {
 	_update_translations();
 	_update_translations();
 	autoload_settings->update_autoload();
 	autoload_settings->update_autoload();
 	plugin_settings->update_plugins();
 	plugin_settings->update_plugins();
+	set_process_unhandled_input(true);
 }
 }
 
 
 void ProjectSettingsEditor::update_plugins() {
 void ProjectSettingsEditor::update_plugins() {
@@ -1697,6 +1719,7 @@ void ProjectSettingsEditor::_editor_restart_close() {
 
 
 void ProjectSettingsEditor::_bind_methods() {
 void ProjectSettingsEditor::_bind_methods() {
 
 
+	ClassDB::bind_method(D_METHOD("_unhandled_input"), &ProjectSettingsEditor::_unhandled_input);
 	ClassDB::bind_method(D_METHOD("_item_selected"), &ProjectSettingsEditor::_item_selected);
 	ClassDB::bind_method(D_METHOD("_item_selected"), &ProjectSettingsEditor::_item_selected);
 	ClassDB::bind_method(D_METHOD("_item_add"), &ProjectSettingsEditor::_item_add);
 	ClassDB::bind_method(D_METHOD("_item_add"), &ProjectSettingsEditor::_item_add);
 	ClassDB::bind_method(D_METHOD("_item_adds"), &ProjectSettingsEditor::_item_adds);
 	ClassDB::bind_method(D_METHOD("_item_adds"), &ProjectSettingsEditor::_item_adds);

+ 1 - 0
editor/project_settings_editor.h

@@ -178,6 +178,7 @@ class ProjectSettingsEditor : public AcceptDialog {
 	void _editor_restart_close();
 	void _editor_restart_close();
 
 
 protected:
 protected:
+	void _unhandled_input(const Ref<InputEvent> &p_event);
 	void _notification(int p_what);
 	void _notification(int p_what);
 	static void _bind_methods();
 	static void _bind_methods();
 
 

+ 24 - 26
editor/settings_config_dialog.cpp

@@ -140,32 +140,35 @@ void EditorSettingsDialog::_notification(int p_what) {
 
 
 void EditorSettingsDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
 void EditorSettingsDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
 
 
-	Ref<InputEventKey> k = p_event;
+	const Ref<InputEventKey> k = p_event;
 
 
-	if (k.is_valid() && is_window_modal_on_top()) {
+	if (k.is_valid() && is_window_modal_on_top() && k->is_pressed()) {
 
 
-		if (k->is_pressed()) {
+		bool handled = false;
 
 
-			bool handled = false;
+		if (ED_IS_SHORTCUT("editor/undo", p_event)) {
+			String action = undo_redo->get_current_action_name();
+			if (action != "")
+				EditorNode::get_log()->add_message("Undo: " + action, EditorLog::MSG_TYPE_EDITOR);
+			undo_redo->undo();
+			handled = true;
+		}
 
 
-			if (ED_IS_SHORTCUT("editor/undo", p_event)) {
-				String action = undo_redo->get_current_action_name();
-				if (action != "")
-					EditorNode::get_log()->add_message("Undo: " + action, EditorLog::MSG_TYPE_EDITOR);
-				undo_redo->undo();
-				handled = true;
-			}
-			if (ED_IS_SHORTCUT("editor/redo", p_event)) {
-				undo_redo->redo();
-				String action = undo_redo->get_current_action_name();
-				if (action != "")
-					EditorNode::get_log()->add_message("Redo: " + action, EditorLog::MSG_TYPE_EDITOR);
-				handled = true;
-			}
+		if (ED_IS_SHORTCUT("editor/redo", p_event)) {
+			undo_redo->redo();
+			String action = undo_redo->get_current_action_name();
+			if (action != "")
+				EditorNode::get_log()->add_message("Redo: " + action, EditorLog::MSG_TYPE_EDITOR);
+			handled = true;
+		}
 
 
-			if (handled) {
-				accept_event();
-			}
+		if (k->get_scancode_with_modifiers() == (KEY_MASK_CMD | KEY_F)) {
+			_focus_current_search_box();
+			handled = true;
+		}
+
+		if (handled) {
+			accept_event();
 		}
 		}
 	}
 	}
 }
 }
@@ -408,7 +411,6 @@ EditorSettingsDialog::EditorSettingsDialog() {
 	tabs->set_tab_align(TabContainer::ALIGN_LEFT);
 	tabs->set_tab_align(TabContainer::ALIGN_LEFT);
 	tabs->connect("tab_changed", this, "_tabs_tab_changed");
 	tabs->connect("tab_changed", this, "_tabs_tab_changed");
 	add_child(tabs);
 	add_child(tabs);
-	//set_child_rect(tabs);
 
 
 	// General Tab
 	// General Tab
 
 
@@ -425,7 +427,6 @@ EditorSettingsDialog::EditorSettingsDialog() {
 	hbc->add_child(search_box);
 	hbc->add_child(search_box);
 
 
 	inspector = memnew(SectionedInspector);
 	inspector = memnew(SectionedInspector);
-	//inspector->hide_top_label();
 	inspector->get_inspector()->set_use_filter(true);
 	inspector->get_inspector()->set_use_filter(true);
 	inspector->register_search_box(search_box);
 	inspector->register_search_box(search_box);
 	inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
 	inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
@@ -474,7 +475,6 @@ EditorSettingsDialog::EditorSettingsDialog() {
 	shortcuts->set_v_size_flags(SIZE_EXPAND_FILL);
 	shortcuts->set_v_size_flags(SIZE_EXPAND_FILL);
 	shortcuts->set_columns(2);
 	shortcuts->set_columns(2);
 	shortcuts->set_hide_root(true);
 	shortcuts->set_hide_root(true);
-	//shortcuts->set_hide_folding(true);
 	shortcuts->set_column_titles_visible(true);
 	shortcuts->set_column_titles_visible(true);
 	shortcuts->set_column_title(0, TTR("Name"));
 	shortcuts->set_column_title(0, TTR("Name"));
 	shortcuts->set_column_title(1, TTR("Binding"));
 	shortcuts->set_column_title(1, TTR("Binding"));
@@ -495,9 +495,7 @@ EditorSettingsDialog::EditorSettingsDialog() {
 	press_a_key->connect("gui_input", this, "_wait_for_key");
 	press_a_key->connect("gui_input", this, "_wait_for_key");
 	press_a_key->connect("confirmed", this, "_press_a_key_confirm");
 	press_a_key->connect("confirmed", this, "_press_a_key_confirm");
 
 
-	//get_ok()->set_text("Apply");
 	set_hide_on_ok(true);
 	set_hide_on_ok(true);
-	//get_cancel()->set_text("Close");
 
 
 	timer = memnew(Timer);
 	timer = memnew(Timer);
 	timer->set_wait_time(1.5);
 	timer->set_wait_time(1.5);