Browse Source

Merge pull request #15261 from sersoong/2.1-addsettingsopen

Add open feature to editor autoload settings For 2.1
Rémi Verschelde 7 years ago
parent
commit
e0b20449ad
2 changed files with 30 additions and 4 deletions
  1. 25 4
      editor/editor_autoload_settings.cpp
  2. 5 0
      editor/editor_autoload_settings.h

+ 25 - 4
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);
 }

+ 5 - 0
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);