From 9f6a06b9922196923a60c16c824d70481ca96056 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 12 Nov 2017 14:21:09 -0500 Subject: add script list drag n drop --- editor/plugins/script_editor_plugin.cpp | 192 +++++++++++++++++++++++++++----- 1 file changed, 166 insertions(+), 26 deletions(-) (limited to 'editor') diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index e024c56a3d..a19e67417e 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -865,20 +865,7 @@ void ScriptEditor::_menu_option(int p_option) { } break; case SEARCH_CLASSES: { - String current; - - if (tab_container->get_tab_count() > 0) { - EditorHelp *eh = Object::cast_to(tab_container->get_child(tab_container->get_current_tab())); - if (eh) { - current = eh->get_class(); - } - } - help_index->popup(); - - if (current != "") { - help_index->call_deferred("select_class", current); - } } break; case SEARCH_WEBSITE: { @@ -1074,6 +1061,11 @@ void ScriptEditor::_menu_option(int p_option) { switch (p_option) { + case SEARCH_CLASSES: { + + help_index->popup(); + help_index->call_deferred("select_class", help->get_class()); + } break; case HELP_SEARCH_FIND: { help->popup_search(); } break; @@ -1940,26 +1932,170 @@ void ScriptEditor::_script_split_dragged(float) { _save_layout(); } -// void ScriptEditor::_script_list_dragged(float) { +Variant ScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { + + // return Variant(); // return this if drag disabled -// _save_layout(); -// } + Node *cur_node = tab_container->get_child(tab_container->get_current_tab()); -Variant ScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from){ - WARN_PRINT("get_drag_data_fw"); - return Variant(); + HBoxContainer *drag_preview = memnew(HBoxContainer); + String preview_name = ""; + Ref preview_icon; + + ScriptEditorBase *se = Object::cast_to(cur_node); + if (se) { + preview_name = se->get_name(); + preview_icon = se->get_icon(); + } + EditorHelp *eh = Object::cast_to(cur_node); + if (eh) { + preview_name = eh->get_class(); + preview_icon = get_icon("Help", "EditorIcons"); + } + + if (!preview_icon.is_null()) { + TextureRect *tf = memnew(TextureRect); + tf->set_texture(preview_icon); + drag_preview->add_child(tf); + } + Label *label = memnew(Label(preview_name)); + drag_preview->add_child(label); + set_drag_preview(drag_preview); + + Dictionary drag_data; + drag_data["type"] = "script_list_element"; // using a custom type because node caused problems when dragging to scene tree + drag_data["script_list_element"] = cur_node; + + return drag_data; } + bool ScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - WARN_PRINT("can_drop_data_fw"); + + Dictionary d = p_data; + if (!d.has("type")) + return false; + + if (String(d["type"]) == "script_list_element") { + + Node *node = d["script_list_element"]; + + ScriptEditorBase *se = Object::cast_to(node); + if (se) { + return true; + } + EditorHelp *eh = Object::cast_to(node); + if (eh) { + return true; + } + } + + if (String(d["type"]) == "nodes") { + + Array nodes = d["nodes"]; + if (nodes.size() == 0) + return false; + Node *node = get_node((nodes[0])); + + ScriptEditorBase *se = Object::cast_to(node); + if (se) { + return true; + } + EditorHelp *eh = Object::cast_to(node); + if (eh) { + return true; + } + } + + if (String(d["type"]) == "files") { + + Vector files = d["files"]; + + if (files.size() == 0) + return false; //weird + + for (int i = 0; i < files.size(); i++) { + String file = files[i]; + if (file == "" || !FileAccess::exists(file)) + continue; + Ref