From 36bdf789274ca5b8daf41fddf5f5d05471812c1e Mon Sep 17 00:00:00 2001 From: Jeremy Bullock Date: Tue, 9 Apr 2019 11:22:14 -0600 Subject: Allow Right Click in Empty Space on FileSystemDock --- editor/filesystem_dock.cpp | 14 ++++++++++++++ editor/filesystem_dock.h | 1 + scene/gui/tree.cpp | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 5a1383be6d..018ba47e57 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -2125,6 +2125,18 @@ void FileSystemDock::_tree_rmb_select(const Vector2 &p_pos) { } } +void FileSystemDock::_tree_rmb_empty(const Vector2 &p_pos) { + // Right click is pressed in the empty space of the tree + path = "res://"; + tree_popup->clear(); + tree_popup->set_size(Size2(1, 1)); + tree_popup->add_item(TTR("New Folder..."), FILE_NEW_FOLDER); + tree_popup->add_item(TTR("New Script..."), FILE_NEW_SCRIPT); + tree_popup->add_item(TTR("New Resource..."), FILE_NEW_RESOURCE); + tree_popup->set_position(tree->get_global_position() + p_pos); + tree_popup->popup(); +} + void FileSystemDock::_tree_empty_selected() { tree->deselect_all(); } @@ -2318,6 +2330,7 @@ void FileSystemDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_file_list_rmb_option", "option"), &FileSystemDock::_file_list_rmb_option); ClassDB::bind_method(D_METHOD("_file_list_rmb_select"), &FileSystemDock::_file_list_rmb_select); ClassDB::bind_method(D_METHOD("_file_list_rmb_pressed"), &FileSystemDock::_file_list_rmb_pressed); + ClassDB::bind_method(D_METHOD("_tree_rmb_empty"), &FileSystemDock::_tree_rmb_empty); ClassDB::bind_method(D_METHOD("_file_deleted"), &FileSystemDock::_file_deleted); ClassDB::bind_method(D_METHOD("_folder_deleted"), &FileSystemDock::_folder_deleted); @@ -2450,6 +2463,7 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { tree->connect("item_activated", this, "_tree_activate_file"); tree->connect("multi_selected", this, "_tree_multi_selected"); tree->connect("item_rmb_selected", this, "_tree_rmb_select"); + tree->connect("empty_rmb", this, "_tree_rmb_empty"); tree->connect("nothing_selected", this, "_tree_empty_selected"); tree->connect("gui_input", this, "_tree_gui_input"); diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h index 8b27938c8a..1878f589e1 100644 --- a/editor/filesystem_dock.h +++ b/editor/filesystem_dock.h @@ -235,6 +235,7 @@ private: void _file_and_folders_fill_popup(PopupMenu *p_popup, Vector p_paths, bool p_display_path_dependent_options = true); void _tree_rmb_select(const Vector2 &p_pos); + void _tree_rmb_empty(const Vector2 &p_pos); void _file_list_rmb_select(int p_item, const Vector2 &p_pos); void _file_list_rmb_pressed(const Vector2 &p_pos); void _tree_empty_selected(); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 7f00e7bd24..2821893a74 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1970,6 +1970,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool item_h += child_h; } } + if (p_item == root && p_button == BUTTON_RIGHT) { + emit_signal("empty_rmb", get_local_mouse_position()); + } } return item_h; // nothing found @@ -3850,6 +3853,7 @@ void Tree::_bind_methods() { ADD_SIGNAL(MethodInfo("cell_selected")); ADD_SIGNAL(MethodInfo("multi_selected", PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "TreeItem"), PropertyInfo(Variant::INT, "column"), PropertyInfo(Variant::BOOL, "selected"))); ADD_SIGNAL(MethodInfo("item_rmb_selected", PropertyInfo(Variant::VECTOR2, "position"))); + ADD_SIGNAL(MethodInfo("empty_rmb", PropertyInfo(Variant::VECTOR2, "position"))); ADD_SIGNAL(MethodInfo("empty_tree_rmb_selected", PropertyInfo(Variant::VECTOR2, "position"))); ADD_SIGNAL(MethodInfo("item_edited")); ADD_SIGNAL(MethodInfo("item_rmb_edited")); -- cgit v1.2.3