Add class tree selection to script inheritance selection

This commit is contained in:
lupoDharkael 2019-02-18 16:45:26 +01:00
parent f5f2b5d4af
commit 76560c8afa
3 changed files with 39 additions and 0 deletions

View file

@ -2481,6 +2481,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel
add_child(rename_dialog);
script_create_dialog = memnew(ScriptCreateDialog);
script_create_dialog->set_inheritance_base_type("Node");
add_child(script_create_dialog);
script_create_dialog->connect("script_created", this, "_script_created");

View file

@ -34,6 +34,7 @@
#include "core/os/file_access.h"
#include "core/project_settings.h"
#include "core/script_language.h"
#include "editor/create_dialog.h"
#include "editor/editor_node.h"
#include "editor/editor_scale.h"
#include "editor_file_system.h"
@ -45,6 +46,7 @@ void ScriptCreateDialog::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
path_button->set_icon(get_icon("Folder", "EditorIcons"));
parent_browse_button->set_icon(get_icon("Folder", "EditorIcons"));
parent_search_button->set_icon(get_icon("ClassList", "EditorIcons"));
status_panel->add_style_override("panel", get_stylebox("bg", "Tree"));
} break;
}
@ -77,6 +79,11 @@ void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_
_path_changed(file_path->get_text());
}
void ScriptCreateDialog::set_inheritance_base_type(const String &p_base) {
base_type = p_base;
}
bool ScriptCreateDialog::_validate(const String &p_string) {
if (p_string.length() == 0)
@ -362,6 +369,17 @@ void ScriptCreateDialog::_file_selected(const String &p_file) {
}
}
void ScriptCreateDialog::_create() {
parent_name->set_text(select_class->get_selected_type());
}
void ScriptCreateDialog::_browse_class_in_tree() {
select_class->set_base_type(base_type);
select_class->popup_create(true);
}
void ScriptCreateDialog::_path_changed(const String &p_path) {
is_path_valid = false;
@ -595,6 +613,8 @@ 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("_create", &ScriptCreateDialog::_create);
ClassDB::bind_method("_browse_class_in_tree", &ScriptCreateDialog::_browse_class_in_tree);
ClassDB::bind_method(D_METHOD("config", "inherits", "path", "built_in_enabled"), &ScriptCreateDialog::config, DEFVAL(true));
@ -707,12 +727,18 @@ ScriptCreateDialog::ScriptCreateDialog() {
/* Inherits */
base_type = "Object";
hb = memnew(HBoxContainer);
hb->set_h_size_flags(SIZE_EXPAND_FILL);
parent_name = memnew(LineEdit);
parent_name->connect("text_changed", this, "_parent_name_changed");
parent_name->set_h_size_flags(SIZE_EXPAND_FILL);
hb->add_child(parent_name);
parent_search_button = memnew(Button);
parent_search_button->set_flat(true);
parent_search_button->connect("pressed", this, "_browse_class_in_tree");
hb->add_child(parent_search_button);
parent_browse_button = memnew(Button);
parent_browse_button->set_flat(true);
parent_browse_button->connect("pressed", this, "_browse_path", varray(true, false));
@ -777,6 +803,10 @@ ScriptCreateDialog::ScriptCreateDialog() {
/* Dialog Setup */
select_class = memnew(CreateDialog);
select_class->connect("create", this, "_create");
add_child(select_class);
file_browse = memnew(EditorFileDialog);
file_browse->connect("file_selected", this, "_file_selected");
file_browse->set_mode(EditorFileDialog::MODE_OPEN_FILE);

View file

@ -40,6 +40,8 @@
#include "scene/gui/option_button.h"
#include "scene/gui/panel_container.h"
class CreateDialog;
class ScriptCreateDialog : public ConfirmationDialog {
GDCLASS(ScriptCreateDialog, ConfirmationDialog);
@ -49,6 +51,7 @@ class ScriptCreateDialog : public ConfirmationDialog {
PanelContainer *status_panel;
LineEdit *parent_name;
Button *parent_browse_button;
Button *parent_search_button;
OptionButton *language_menu;
OptionButton *template_menu;
LineEdit *file_path;
@ -57,6 +60,7 @@ class ScriptCreateDialog : public ConfirmationDialog {
CheckButton *internal;
VBoxContainer *path_vb;
AcceptDialog *alert;
CreateDialog *select_class;
bool path_valid;
bool create_new;
bool is_browsing_parent;
@ -74,6 +78,7 @@ class ScriptCreateDialog : public ConfirmationDialog {
bool re_check_path;
String script_template;
Vector<String> template_list;
String base_type;
bool _can_be_built_in();
void _path_changed(const String &p_path = String());
@ -86,6 +91,8 @@ class ScriptCreateDialog : public ConfirmationDialog {
void _template_changed(int p_template = 0);
void _browse_path(bool browse_parent, bool p_save);
void _file_selected(const String &p_file);
void _create();
void _browse_class_in_tree();
virtual void ok_pressed();
void _create_new();
void _load_exist();
@ -99,6 +106,7 @@ protected:
public:
void config(const String &p_base_name, const String &p_base_path, bool p_built_in_enabled = true);
void set_inheritance_base_type(const String &p_base);
ScriptCreateDialog();
};