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 a context menu to quick open dialog #100679

Merged
merged 1 commit into from
Jan 3, 2025
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
34 changes: 31 additions & 3 deletions editor/gui/editor_quick_open_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@

#include "editor_quick_open_dialog.h"

#include "core/config/project_settings.h"
#include "core/string/fuzzy_search.h"
#include "editor/editor_file_system.h"
#include "editor/editor_node.h"
#include "editor/editor_resource_preview.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/filesystem_dock.h"
#include "editor/themes/editor_scale.h"
#include "scene/gui/center_container.h"
#include "scene/gui/check_button.h"
Expand Down Expand Up @@ -226,6 +228,13 @@ QuickOpenResultContainer::QuickOpenResultContainer() {
grid->add_theme_constant_override("h_separation", 4);
grid->hide();
scroll_container->add_child(grid);

file_context_menu = memnew(PopupMenu);
file_context_menu->add_item(TTR("Show in FileSystem"), FILE_SHOW_IN_FILESYSTEM);
file_context_menu->add_item(TTR("Show in File Manager"), FILE_SHOW_IN_FILE_MANAGER);
file_context_menu->connect(SceneStringName(id_pressed), callable_mp(this, &QuickOpenResultContainer::_menu_option));
file_context_menu->hide();
scroll_container->add_child(file_context_menu);
}
}

Expand Down Expand Up @@ -272,6 +281,18 @@ QuickOpenResultContainer::QuickOpenResultContainer() {
}
}

void QuickOpenResultContainer::_menu_option(int p_option) {
switch (p_option) {
case FILE_SHOW_IN_FILESYSTEM: {
FileSystemDock::get_singleton()->navigate_to_path(get_selected());
} break;
case FILE_SHOW_IN_FILE_MANAGER: {
String dir = ProjectSettings::get_singleton()->globalize_path(get_selected());
OS::get_singleton()->shell_show_in_file_manager(dir, true);
} break;
}
}

void QuickOpenResultContainer::_ensure_result_vector_capacity() {
int target_size = EDITOR_GET("filesystem/quick_open_dialog/max_results");
int initial_size = result_items.size();
Expand Down Expand Up @@ -572,9 +593,16 @@ void QuickOpenResultContainer::_select_item(int p_index) {
void QuickOpenResultContainer::_item_input(const Ref<InputEvent> &p_ev, int p_index) {
Ref<InputEventMouseButton> mb = p_ev;

if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
_select_item(p_index);
emit_signal(SNAME("result_clicked"));
if (mb.is_valid() && mb->is_pressed()) {
if (mb->get_button_index() == MouseButton::LEFT) {
_select_item(p_index);
emit_signal(SNAME("result_clicked"));
} else if (mb->get_button_index() == MouseButton::RIGHT) {
_select_item(p_index);
file_context_menu->set_position(result_items[p_index]->get_screen_position() + mb->get_position());
file_context_menu->reset_size();
file_context_menu->popup();
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions editor/gui/editor_quick_open_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class LineEdit;
class HFlowContainer;
class MarginContainer;
class PanelContainer;
class PopupMenu;
class ScrollContainer;
class StringName;
class Texture2D;
Expand Down Expand Up @@ -81,6 +82,11 @@ class HighlightedLabel : public Label {
class QuickOpenResultContainer : public VBoxContainer {
GDCLASS(QuickOpenResultContainer, VBoxContainer)

enum {
FILE_SHOW_IN_FILESYSTEM,
FILE_SHOW_IN_FILE_MANAGER
};

public:
void init(const Vector<StringName> &p_base_types);
void handle_search_box_input(const Ref<InputEvent> &p_ie);
Expand Down Expand Up @@ -124,6 +130,7 @@ class QuickOpenResultContainer : public VBoxContainer {
ScrollContainer *scroll_container = nullptr;
VBoxContainer *list = nullptr;
HFlowContainer *grid = nullptr;
PopupMenu *file_context_menu = nullptr;

PanelContainer *panel_container = nullptr;
CenterContainer *no_results_container = nullptr;
Expand Down Expand Up @@ -160,6 +167,7 @@ class QuickOpenResultContainer : public VBoxContainer {
void _toggle_display_mode();
void _toggle_include_addons(bool p_pressed);
void _toggle_fuzzy_search(bool p_pressed);
void _menu_option(int p_option);

static void _bind_methods();
};
Expand Down