summaryrefslogtreecommitdiff
path: root/editor/editor_autoload_settings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_autoload_settings.cpp')
-rw-r--r--editor/editor_autoload_settings.cpp75
1 files changed, 49 insertions, 26 deletions
diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp
index a6a383ba58..6917b2b775 100644
--- a/editor/editor_autoload_settings.cpp
+++ b/editor/editor_autoload_settings.cpp
@@ -48,8 +48,6 @@ void EditorAutoloadSettings::_notification(int p_what) {
ResourceLoader::get_recognized_extensions_for_type("Script", &afn);
ResourceLoader::get_recognized_extensions_for_type("PackedScene", &afn);
- EditorFileDialog *file_dialog = autoload_add_path->get_file_dialog();
-
for (List<String>::Element *E = afn.front(); E; E = E->next()) {
file_dialog->add_filter("*." + E->get());
@@ -61,6 +59,9 @@ void EditorAutoloadSettings::_notification(int p_what) {
get_tree()->get_root()->call_deferred("add_child", info.node);
}
}
+ browse_button->set_icon(get_theme_icon("Folder", "EditorIcons"));
+ } else if (p_what == NOTIFICATION_THEME_CHANGED) {
+ browse_button->set_icon(get_theme_icon("Folder", "EditorIcons"));
}
}
@@ -116,8 +117,8 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin
void EditorAutoloadSettings::_autoload_add() {
- if (autoload_add(autoload_add_name->get_text(), autoload_add_path->get_line_edit()->get_text()))
- autoload_add_path->get_line_edit()->set_text("");
+ if (autoload_add(autoload_add_name->get_text(), autoload_add_path->get_text()))
+ autoload_add_path->set_text("");
autoload_add_name->set_text("");
add_autoload->set_disabled(true);
@@ -240,7 +241,7 @@ void EditorAutoloadSettings::_autoload_button_pressed(Object *p_item, int p_colu
case BUTTON_MOVE_UP:
case BUTTON_MOVE_DOWN: {
- TreeItem *swap = NULL;
+ TreeItem *swap = nullptr;
if (p_button == BUTTON_MOVE_UP) {
swap = ti->get_prev();
@@ -326,7 +327,7 @@ void EditorAutoloadSettings::_autoload_file_callback(const String &p_path) {
void EditorAutoloadSettings::_autoload_text_entered(const String p_name) {
- if (autoload_add_path->get_line_edit()->get_text() != "" && _autoload_name_is_valid(p_name, NULL)) {
+ if (autoload_add_path->get_text() != "" && _autoload_name_is_valid(p_name, nullptr)) {
_autoload_add();
}
}
@@ -334,19 +335,19 @@ void EditorAutoloadSettings::_autoload_text_entered(const String p_name) {
void EditorAutoloadSettings::_autoload_path_text_changed(const String p_path) {
add_autoload->set_disabled(
- p_path == "" || !_autoload_name_is_valid(autoload_add_name->get_text(), NULL));
+ p_path == "" || !_autoload_name_is_valid(autoload_add_name->get_text(), nullptr));
}
void EditorAutoloadSettings::_autoload_text_changed(const String p_name) {
add_autoload->set_disabled(
- autoload_add_path->get_line_edit()->get_text() == "" || !_autoload_name_is_valid(p_name, NULL));
+ autoload_add_path->get_text() == "" || !_autoload_name_is_valid(p_name, nullptr));
}
Node *EditorAutoloadSettings::_create_autoload(const String &p_path) {
RES res = ResourceLoader::load(p_path);
- ERR_FAIL_COND_V_MSG(res.is_null(), NULL, "Can't autoload: " + p_path + ".");
- Node *n = NULL;
+ ERR_FAIL_COND_V_MSG(res.is_null(), nullptr, "Can't autoload: " + p_path + ".");
+ Node *n = nullptr;
if (res->is_class("PackedScene")) {
Ref<PackedScene> ps = res;
n = ps->instance();
@@ -354,17 +355,17 @@ Node *EditorAutoloadSettings::_create_autoload(const String &p_path) {
Ref<Script> s = res;
StringName ibt = s->get_instance_base_type();
bool valid_type = ClassDB::is_parent_class(ibt, "Node");
- ERR_FAIL_COND_V_MSG(!valid_type, NULL, "Script does not inherit a Node: " + p_path + ".");
+ ERR_FAIL_COND_V_MSG(!valid_type, nullptr, "Script does not inherit a Node: " + p_path + ".");
Object *obj = ClassDB::instance(ibt);
- ERR_FAIL_COND_V_MSG(obj == NULL, NULL, "Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt) + ".");
+ ERR_FAIL_COND_V_MSG(obj == nullptr, nullptr, "Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt) + ".");
n = Object::cast_to<Node>(obj);
n->set_script(s);
}
- ERR_FAIL_COND_V_MSG(!n, NULL, "Path in autoload not a node or script: " + p_path + ".");
+ ERR_FAIL_COND_V_MSG(!n, nullptr, "Path in autoload not a node or script: " + p_path + ".");
return n;
}
@@ -429,7 +430,7 @@ void EditorAutoloadSettings::update_autoload() {
to_remove.erase(name);
need_to_add = false;
} else {
- info.node = NULL;
+ info.node = nullptr;
}
}
}
@@ -474,7 +475,7 @@ void EditorAutoloadSettings::update_autoload() {
if (info.node) {
info.node->queue_delete();
- info.node = NULL;
+ info.node = nullptr;
}
}
@@ -505,7 +506,7 @@ void EditorAutoloadSettings::update_autoload() {
if (!info->in_editor && !info->is_singleton) {
// No reason to keep this node
memdelete(info->node);
- info->node = NULL;
+ info->node = nullptr;
}
}
@@ -523,7 +524,7 @@ Variant EditorAutoloadSettings::get_drag_data_fw(const Point2 &p_point, Control
PackedStringArray autoloads;
- TreeItem *next = tree->get_next_selected(NULL);
+ TreeItem *next = tree->get_next_selected(nullptr);
while (next) {
autoloads.push_back(next->get_text(0));
@@ -604,7 +605,7 @@ void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant &
int order = ProjectSettings::get_singleton()->get_order("autoload/" + name);
AutoLoadInfo aux;
- List<AutoLoadInfo>::Element *E = NULL;
+ List<AutoLoadInfo>::Element *E = nullptr;
if (!move_to_back) {
aux.order = order;
@@ -805,9 +806,9 @@ EditorAutoloadSettings::EditorAutoloadSettings() {
}
}
- if (!info.is_singleton && !info.in_editor && info.node != NULL) {
+ if (!info.is_singleton && !info.in_editor && info.node != nullptr) {
memdelete(info.node);
- info.node = NULL;
+ info.node = nullptr;
}
}
@@ -823,13 +824,24 @@ EditorAutoloadSettings::EditorAutoloadSettings() {
l->set_text(TTR("Path:"));
hbc->add_child(l);
- autoload_add_path = memnew(EditorLineEditFileChooser);
- autoload_add_path->set_h_size_flags(SIZE_EXPAND_FILL);
- autoload_add_path->get_file_dialog()->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
- autoload_add_path->get_file_dialog()->connect("file_selected", callable_mp(this, &EditorAutoloadSettings::_autoload_file_callback));
- autoload_add_path->get_line_edit()->connect("text_changed", callable_mp(this, &EditorAutoloadSettings::_autoload_path_text_changed));
-
+ autoload_add_path = memnew(LineEdit);
hbc->add_child(autoload_add_path);
+ autoload_add_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ autoload_add_path->connect("text_changed", callable_mp(this, &EditorAutoloadSettings::_autoload_path_text_changed));
+
+ browse_button = memnew(Button);
+ hbc->add_child(browse_button);
+ browse_button->connect("pressed", callable_mp(this, &EditorAutoloadSettings::_browse_autoload_add_path));
+
+ file_dialog = memnew(EditorFileDialog);
+ hbc->add_child(file_dialog);
+ file_dialog->connect("file_selected", callable_mp(this, &EditorAutoloadSettings::_set_autoload_add_path));
+ file_dialog->connect("dir_selected", callable_mp(this, &EditorAutoloadSettings::_set_autoload_add_path));
+ file_dialog->connect("files_selected", callable_mp(this, &EditorAutoloadSettings::_set_autoload_add_path));
+
+ hbc->set_h_size_flags(SIZE_EXPAND_FILL);
+ file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
+ file_dialog->connect("file_selected", callable_mp(this, &EditorAutoloadSettings::_autoload_file_callback));
l = memnew(Label);
l->set_text(TTR("Node Name:"));
@@ -890,3 +902,14 @@ EditorAutoloadSettings::~EditorAutoloadSettings() {
}
}
}
+
+void EditorAutoloadSettings::_set_autoload_add_path(const String &p_text) {
+
+ autoload_add_path->set_text(p_text);
+ autoload_add_path->emit_signal("text_entered", p_text);
+}
+
+void EditorAutoloadSettings::_browse_autoload_add_path() {
+
+ file_dialog->popup_centered_ratio();
+} \ No newline at end of file