From 64ceb0be5ba2d76626a9cc8a46fcbd7ca706484b Mon Sep 17 00:00:00 2001 From: sersoong Date: Tue, 2 Jan 2018 14:53:48 +0800 Subject: [PATCH] Add open feature to editor autoload settings --- editor/editor_autoload_settings.cpp | 29 +++++++++++++++++++++++++---- editor/editor_autoload_settings.h | 5 +++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp index 31038711701..7f4976f50bf 100644 --- a/editor/editor_autoload_settings.cpp +++ b/editor/editor_autoload_settings.cpp @@ -251,7 +251,9 @@ void EditorAutoloadSettings::_autoload_button_pressed(Object *p_item, int p_colu UndoRedo *undo_redo = EditorNode::get_undo_redo(); switch (p_button) { - + case BUTTON_OPEN: { + _autoload_open(ti->get_text(1)); + } break; case BUTTON_MOVE_UP: case BUTTON_MOVE_DOWN: { @@ -315,6 +317,22 @@ void EditorAutoloadSettings::_autoload_file_callback(const String &p_path) { autoload_add_name->set_text(p_path.get_file().basename()); } +void EditorAutoloadSettings::_autoload_activated() { + TreeItem *ti = tree->get_selected(); + if (!ti) + return; + _autoload_open(ti->get_text(1)); +} + +void EditorAutoloadSettings::_autoload_open(const String &fpath) { + if (ResourceLoader::get_resource_type(fpath) == "PackedScene") { + EditorNode::get_singleton()->open_request(fpath); + } else { + EditorNode::get_singleton()->load_resource(fpath); + } + ProjectSettings::get_singleton()->hide(); +} + void EditorAutoloadSettings::update_autoload() { if (updating_autoload) @@ -361,13 +379,13 @@ void EditorAutoloadSettings::update_autoload() { item->set_editable(0, true); item->set_text(1, path); - item->set_selectable(1, false); + item->set_selectable(1, true); item->set_cell_mode(2, TreeItem::CELL_MODE_CHECK); item->set_editable(2, true); item->set_text(2, TTR("Enable")); item->set_checked(2, global); - + item->add_button(3, get_icon("FileList", "EditorIcons"), BUTTON_OPEN); item->add_button(3, get_icon("MoveUp", "EditorIcons"), BUTTON_MOVE_UP); item->add_button(3, get_icon("MoveDown", "EditorIcons"), BUTTON_MOVE_DOWN); item->add_button(3, get_icon("Del", "EditorIcons"), BUTTON_DELETE); @@ -534,6 +552,8 @@ void EditorAutoloadSettings::_bind_methods() { ObjectTypeDB::bind_method("_autoload_edited", &EditorAutoloadSettings::_autoload_edited); ObjectTypeDB::bind_method("_autoload_button_pressed", &EditorAutoloadSettings::_autoload_button_pressed); ObjectTypeDB::bind_method("_autoload_file_callback", &EditorAutoloadSettings::_autoload_file_callback); + ObjectTypeDB::bind_method("_autoload_activated", &EditorAutoloadSettings::_autoload_activated); + ObjectTypeDB::bind_method("_autoload_open", &EditorAutoloadSettings::_autoload_open); ObjectTypeDB::bind_method("get_drag_data_fw", &EditorAutoloadSettings::get_drag_data_fw); ObjectTypeDB::bind_method("can_drop_data_fw", &EditorAutoloadSettings::can_drop_data_fw); @@ -606,11 +626,12 @@ EditorAutoloadSettings::EditorAutoloadSettings() { tree->set_column_min_width(2, 80); tree->set_column_expand(3, false); - tree->set_column_min_width(3, 80); + tree->set_column_min_width(3, 120); tree->connect("cell_selected", this, "_autoload_selected"); tree->connect("item_edited", this, "_autoload_edited"); tree->connect("button_pressed", this, "_autoload_button_pressed"); + tree->connect("item_activated", this, "_autoload_activated"); add_margin_child(TTR("List:"), tree, true); } diff --git a/editor/editor_autoload_settings.h b/editor/editor_autoload_settings.h index 76fcc77fc65..1b90de9a41e 100644 --- a/editor/editor_autoload_settings.h +++ b/editor/editor_autoload_settings.h @@ -40,6 +40,7 @@ class EditorAutoloadSettings : public VBoxContainer { OBJ_TYPE(EditorAutoloadSettings, VBoxContainer); enum { + BUTTON_OPEN, BUTTON_MOVE_UP, BUTTON_MOVE_DOWN, BUTTON_DELETE @@ -74,6 +75,10 @@ class EditorAutoloadSettings : public VBoxContainer { void _autoload_button_pressed(Object *p_item, int p_column, int p_button); void _autoload_file_callback(const String &p_path); + void _autoload_activated(); + + void _autoload_open(const String &fpath); + Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);