Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for search shortcut to all docks #87200

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 48 additions & 40 deletions editor/connections_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,58 +1203,66 @@ 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;
}
}

// 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;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions editor/groups_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
22 changes: 22 additions & 0 deletions editor/inspector_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions editor/inspector_dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 15 additions & 0 deletions editor/scene_tree_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions editor/scene_tree_dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading