Expose ScriptCreateDialog to EditorPlugin

This commit is contained in:
willnationsdev 2018-06-29 22:08:28 -05:00 committed by Will Nations
parent 0ffec7daf7
commit 2a6c591957
11 changed files with 91 additions and 4 deletions

View file

@ -235,6 +235,13 @@
<description>
</description>
</method>
<method name="get_script_create_dialog">
<return type="ScriptCreateDialog">
</return>
<description>
Gets the Editor's dialogue used for making scripts. Note that users can configure it before use.
</description>
</method>
<method name="get_state" qualifiers="virtual">
<return type="Dictionary">
</return>

View file

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="ScriptCreateDialog" inherits="ConfirmationDialog" category="Core" version="3.1">
<brief_description>
The Editor's popup dialog for creating new [Script] files.
</brief_description>
<description>
The ScriptCreateDialog creates script files according to a given template for a given scripting language. The standard use is to configure its fields prior to calling a [method popup]() method.
[codeblock]
func _ready():
dialog.config("Node", "res://new_node.gd") # for in-engine types
dialog.config("\"res://base_node.gd\"", "res://derived_node.gd") # for script types
dialog.popup_centered()
[/codeblock]
</description>
<tutorials>
</tutorials>
<demos>
</demos>
<methods>
<method name="config">
<return type="void">
</return>
<argument index="0" name="inherits" type="String">
The dialog's "Inherits" field content.
</argument>
<argument index="1" name="path" type="String">
The dialog's "Path" field content.
</argument>
<description>
Prefills required fields to configure the ScriptCreateDialog for use.
</description>
</method>
</methods>
<signals>
<signal name="script_created">
<argument index="0" name="script" type="Object">
</argument>
<description>
Emitted when the user clicks the OK button.
</description>
</signal>
</signals>
<constants>
</constants>
</class>

View file

@ -262,13 +262,17 @@ void CreateDialog::_update_search() {
if (base_type == "Node" && type.begins_with("Editor"))
continue; // do not show editor nodes
if (base_type == "Resource" && ClassDB::is_parent_class(type, "PluginScript"))
// PluginScript must be initialized before use, which is not possible here
continue;
if (!ClassDB::can_instance(type))
continue; // can't create what can't be instanced
bool skip = false;
for (Set<StringName>::Element *E = type_blacklist.front(); E && !skip; E = E->next()) {
if (ClassDB::is_parent_class(type, E->get()))
skip = true;
}
if (skip)
continue;
if (search_box->get_text() == "") {
add_type(type, types, root, &to_select);
} else {
@ -706,4 +710,7 @@ CreateDialog::CreateDialog() {
help_bit = memnew(EditorHelpBit);
vbc->add_margin_child(TTR("Description:"), help_bit);
help_bit->connect("request_hide", this, "_closed");
type_blacklist.insert("PluginScript"); // PluginScript must be initialized before use, which is not possible here
type_blacklist.insert("ScriptCreateDialog"); // This is an exposed editor Node that doesn't have an Editor prefix.
}

View file

@ -58,6 +58,7 @@ class CreateDialog : public ConfirmationDialog {
String preferred_search_result_type;
EditorHelpBit *help_bit;
List<StringName> type_list;
Set<StringName> type_blacklist;
void _item_selected();

View file

@ -3075,6 +3075,7 @@ void EditorNode::register_editor_types() {
ClassDB::register_class<EditorInspectorPlugin>();
ClassDB::register_class<EditorProperty>();
ClassDB::register_class<AnimationTrackEditPlugin>();
ClassDB::register_class<ScriptCreateDialog>();
// FIXME: Is this stuff obsolete, or should it be ported to new APIs?
ClassDB::register_class<EditorScenePostImport>();
@ -4430,6 +4431,8 @@ void EditorNode::_bind_methods() {
ClassDB::bind_method("stop_child_process", &EditorNode::stop_child_process);
ClassDB::bind_method("get_script_create_dialog", &EditorNode::get_script_create_dialog);
ClassDB::bind_method("_sources_changed", &EditorNode::_sources_changed);
ClassDB::bind_method("_fs_changed", &EditorNode::_fs_changed);
ClassDB::bind_method("_dock_select_draw", &EditorNode::_dock_select_draw);

View file

@ -598,6 +598,7 @@ public:
EditorPluginList *get_editor_plugins_force_input_forwarding() { return editor_plugins_force_input_forwarding; }
EditorInspector *get_inspector() { return inspector_dock->get_inspector(); }
Container *get_inspector_dock_addon_area() { return inspector_dock->get_addon_area(); }
ScriptCreateDialog *get_script_create_dialog() { return scene_tree_dock->get_script_create_dialog(); }
ProjectSettingsEditor *get_project_settings() { return project_settings; }

View file

@ -717,6 +717,10 @@ EditorInterface *EditorPlugin::get_editor_interface() {
return EditorInterface::get_singleton();
}
ScriptCreateDialog *EditorPlugin::get_script_create_dialog() {
return EditorNode::get_singleton()->get_script_create_dialog();
}
void EditorPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_control_to_container", "container", "control"), &EditorPlugin::add_control_to_container);
@ -753,6 +757,7 @@ void EditorPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_force_draw_over_forwarding_enabled"), &EditorPlugin::set_force_draw_over_forwarding_enabled);
ClassDB::bind_method(D_METHOD("get_editor_interface"), &EditorPlugin::get_editor_interface);
ClassDB::bind_method(D_METHOD("get_script_create_dialog"), &EditorPlugin::get_script_create_dialog);
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_canvas_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
ClassDB::add_virtual_method(get_class_static(), MethodInfo("forward_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control")));

View file

@ -34,6 +34,7 @@
#include "editor/editor_inspector.h"
#include "editor/import/editor_import_plugin.h"
#include "editor/import/resource_importer_scene.h"
#include "editor/script_create_dialog.h"
#include "io/config_file.h"
#include "scene/gui/tool_button.h"
#include "scene/main/node.h"
@ -195,6 +196,7 @@ public:
virtual bool build(); // builds with external tools. Returns true if safe to continue running scene.
EditorInterface *get_editor_interface();
ScriptCreateDialog *get_script_create_dialog();
int update_overlays() const;

View file

@ -0,0 +1,10 @@
<svg width="17.067" height="17.067" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<g transform="translate(0 -1036.4)">
<path transform="translate(0 1036.4)" d="m6 1v1c-0.55228 0-1 0.44772-1 1v10h-1v-2h-2v2c2.826e-4 0.35698 0.19084 0.68674 0.5 0.86523 0.15194 0.088045 0.32439 0.13452 0.5 0.13477v1h6v-5l3-2v-3h3v-2c0-1.1046-0.89543-2-2-2z" fill="#a5efac"/>
<path transform="translate(0 1036.4)" d="m6 1c-1.1046 0-2 0.89543-2 2v7h-3v3c0 1.1046 0.89543 2 2 2s2-0.89543 2-2v-10c0-0.55228 0.44772-1 1-1s1 0.44772 1 1v3h5v-1h-4v-2c0-1.1046-0.89543-2-2-2zm-4 10h2v2c0 0.55228-0.44772 1-1 1s-1-0.44772-1-1z" fill="#87e29f"/>
<circle cx="3" cy="1048.4" r="0" fill="#e0e0e0"/>
<ellipse cx="12" cy="1048.4" rx=".5" ry="3" fill="#87e29f"/>
<ellipse transform="rotate(60)" cx="913.91" cy="513.79" rx=".5" ry="3" fill="#87e29f"/>
<ellipse transform="rotate(120)" cx="901.91" cy="-534.57" rx=".5" ry="3" fill="#87e29f"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 943 B

View file

@ -215,6 +215,9 @@ public:
void replace_node(Node *p_node, Node *p_by_node);
void open_script_dialog(Node *p_for_node);
ScriptCreateDialog *get_script_create_dialog() { return script_create_dialog; }
SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSelection *p_editor_selection, EditorData &p_editor_data);
};

View file

@ -582,6 +582,9 @@ void ScriptCreateDialog::_bind_methods() {
ClassDB::bind_method("_path_changed", &ScriptCreateDialog::_path_changed);
ClassDB::bind_method("_path_entered", &ScriptCreateDialog::_path_entered);
ClassDB::bind_method("_template_changed", &ScriptCreateDialog::_template_changed);
ClassDB::bind_method(D_METHOD("config", "inherits", "path"), &ScriptCreateDialog::config);
ADD_SIGNAL(MethodInfo("script_created", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script")));
}