Add support for search shortcut to all docks

This commit is contained in:
passivestar 2024-01-15 04:47:47 +04:00
parent 0bcc0e92b3
commit 97a77c5193
6 changed files with 91 additions and 40 deletions

View file

@ -1203,15 +1203,24 @@ void ConnectionsDock::_slot_menu_about_to_popup() {
}
void ConnectionsDock::_tree_gui_input(const Ref<InputEvent> &p_event) {
// Handle Delete press.
if (ED_IS_SHORTCUT("connections_editor/disconnect", p_event)) {
TreeItem *item = tree->get_selected();
if (item && _get_item_type(*item) == TREE_ITEM_TYPE_CONNECTION) {
Connection connection = item->get_metadata(0);
_disconnect(connection);
update_tree();
const Ref<InputEventKey> &key = p_event;
if (key.is_valid() && key->is_pressed() && !key->is_echo()) {
if (ED_IS_SHORTCUT("connections_editor/disconnect", p_event)) {
TreeItem *item = tree->get_selected();
if (item && _get_item_type(*item) == TREE_ITEM_TYPE_CONNECTION) {
Connection connection = item->get_metadata(0);
_disconnect(connection);
update_tree();
// Stop the Delete input from propagating elsewhere.
accept_event();
return;
}
} else if (ED_IS_SHORTCUT("editor/open_search", p_event)) {
search_box->grab_focus();
search_box->select_all();
// Stop the Delete input from propagating elsewhere.
accept_event();
return;
}
@ -1219,42 +1228,41 @@ void ConnectionsDock::_tree_gui_input(const Ref<InputEvent> &p_event) {
// Handle RMB press.
const Ref<InputEventMouseButton> &mb_event = p_event;
if (mb_event.is_null() || !mb_event->is_pressed() || mb_event->get_button_index() != MouseButton::RIGHT) {
return;
}
TreeItem *item = tree->get_item_at_position(mb_event->get_position());
if (!item) {
return;
}
if (mb_event.is_valid() && mb_event->is_pressed() && mb_event->get_button_index() == MouseButton::RIGHT) {
TreeItem *item = tree->get_item_at_position(mb_event->get_position());
if (!item) {
return;
}
if (item->is_selectable(0)) {
// Update selection now, before `about_to_popup` signal. Needed for SIGNAL and CONNECTION context menus.
tree->set_selected(item);
}
if (item->is_selectable(0)) {
// Update selection now, before `about_to_popup` signal. Needed for SIGNAL and CONNECTION context menus.
tree->set_selected(item);
}
Vector2 screen_position = tree->get_screen_position() + mb_event->get_position();
Vector2 screen_position = tree->get_screen_position() + mb_event->get_position();
switch (_get_item_type(*item)) {
case TREE_ITEM_TYPE_ROOT:
break;
case TREE_ITEM_TYPE_CLASS:
class_menu_doc_class_name = item->get_metadata(0);
class_menu->set_position(screen_position);
class_menu->reset_size();
class_menu->popup();
accept_event(); // Don't collapse item.
break;
case TREE_ITEM_TYPE_SIGNAL:
signal_menu->set_position(screen_position);
signal_menu->reset_size();
signal_menu->popup();
break;
case TREE_ITEM_TYPE_CONNECTION:
slot_menu->set_position(screen_position);
slot_menu->reset_size();
slot_menu->popup();
break;
switch (_get_item_type(*item)) {
case TREE_ITEM_TYPE_ROOT:
break;
case TREE_ITEM_TYPE_CLASS:
class_menu_doc_class_name = item->get_metadata(0);
class_menu->set_position(screen_position);
class_menu->reset_size();
class_menu->popup();
accept_event(); // Don't collapse item.
break;
case TREE_ITEM_TYPE_SIGNAL:
signal_menu->set_position(screen_position);
signal_menu->reset_size();
signal_menu->popup();
break;
case TREE_ITEM_TYPE_CONNECTION:
slot_menu->set_position(screen_position);
slot_menu->reset_size();
slot_menu->popup();
break;
}
}
}

View file

@ -783,6 +783,9 @@ void GroupsEditor::_groups_gui_input(Ref<InputEvent> p_event) {
_menu_id_pressed(DELETE_GROUP);
} else if (ED_IS_SHORTCUT("groups_editor/rename", p_event)) {
_menu_id_pressed(RENAME_GROUP);
} else if (ED_IS_SHORTCUT("editor/open_search", p_event)) {
filter->grab_focus();
filter->select_all();
} else {
return;
}

View file

@ -614,6 +614,26 @@ void InspectorDock::apply_script_properties(Object *p_object) {
stored_properties.clear();
}
void InspectorDock::shortcut_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
Ref<InputEventKey> key = p_event;
if (key.is_null() || !key->is_pressed() || key->is_echo()) {
return;
}
if (!is_visible() || !inspector->get_rect().has_point(inspector->get_local_mouse_position())) {
return;
}
if (ED_IS_SHORTCUT("editor/open_search", p_event)) {
search->grab_focus();
search->select_all();
accept_event();
}
}
InspectorDock::InspectorDock(EditorData &p_editor_data) {
singleton = this;
set_name("Inspector");
@ -770,6 +790,8 @@ InspectorDock::InspectorDock(EditorData &p_editor_data) {
inspector->set_use_filter(true); // TODO: check me
inspector->connect("resource_selected", callable_mp(this, &InspectorDock::_resource_selected));
set_process_shortcut_input(true);
}
InspectorDock::~InspectorDock() {

View file

@ -133,6 +133,8 @@ class InspectorDock : public VBoxContainer {
void _select_history(int p_idx);
void _prepare_history();
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
private:
static InspectorDock *singleton;

View file

@ -162,6 +162,20 @@ void SceneTreeDock::shortcut_input(const Ref<InputEvent> &p_event) {
accept_event();
}
void SceneTreeDock::_scene_tree_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventKey> key = p_event;
if (key.is_null() || !key->is_pressed() || key->is_echo()) {
return;
}
if (ED_IS_SHORTCUT("editor/open_search", p_event)) {
filter->grab_focus();
filter->select_all();
accept_event();
}
}
void SceneTreeDock::instantiate(const String &p_file) {
Vector<String> scenes;
scenes.push_back(p_file);
@ -4226,6 +4240,7 @@ SceneTreeDock::SceneTreeDock(Node *p_scene_root, EditorSelection *p_editor_selec
scene_tree->connect("script_dropped", callable_mp(this, &SceneTreeDock::_script_dropped));
scene_tree->connect("nodes_dragged", callable_mp(this, &SceneTreeDock::_nodes_drag_begin));
scene_tree->get_scene_tree()->connect("gui_input", callable_mp(this, &SceneTreeDock::_scene_tree_gui_input));
scene_tree->get_scene_tree()->connect("item_icon_double_clicked", callable_mp(this, &SceneTreeDock::_focus_node));
editor_selection->connect("selection_changed", callable_mp(this, &SceneTreeDock::_selection_changed));

View file

@ -235,6 +235,7 @@ class SceneTreeDock : public VBoxContainer {
void _nodes_drag_begin();
virtual void input(const Ref<InputEvent> &p_event) override;
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
void _scene_tree_gui_input(Ref<InputEvent> p_event);
void _new_scene_from(String p_file);
void _set_node_owner_recursive(Node *p_node, Node *p_owner, const HashMap<const Node *, Node *> &p_inverse_duplimap);