summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor/editor_autoload_settings.cpp110
-rw-r--r--editor/editor_autoload_settings.h2
-rw-r--r--editor/editor_node.h2
-rw-r--r--editor/editor_plugin.cpp11
-rw-r--r--editor/editor_plugin.h3
-rw-r--r--editor/project_settings_editor.h2
6 files changed, 91 insertions, 39 deletions
diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp
index 393c33c1b0..301ad2c56c 100644
--- a/editor/editor_autoload_settings.cpp
+++ b/editor/editor_autoload_settings.cpp
@@ -92,45 +92,7 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin
void EditorAutoloadSettings::_autoload_add() {
- String name = autoload_add_name->get_text();
-
- String error;
- if (!_autoload_name_is_valid(name, &error)) {
- EditorNode::get_singleton()->show_warning(error);
- return;
- }
-
- String path = autoload_add_path->get_line_edit()->get_text();
- if (!FileAccess::exists(path)) {
- EditorNode::get_singleton()->show_warning(TTR("Invalid Path.") + "\n" + TTR("File does not exist."));
- return;
- }
-
- if (!path.begins_with("res://")) {
- EditorNode::get_singleton()->show_warning(TTR("Invalid Path.") + "\n" + TTR("Not in resource path."));
- return;
- }
-
- name = "autoload/" + name;
-
- UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
-
- undo_redo->create_action(TTR("Add AutoLoad"));
- undo_redo->add_do_property(ProjectSettings::get_singleton(), name, "*" + path);
-
- if (ProjectSettings::get_singleton()->has_setting(name)) {
- undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, ProjectSettings::get_singleton()->get(name));
- } else {
- undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, Variant());
- }
-
- undo_redo->add_do_method(this, "update_autoload");
- undo_redo->add_undo_method(this, "update_autoload");
-
- undo_redo->add_do_method(this, "emit_signal", autoload_changed);
- undo_redo->add_undo_method(this, "emit_signal", autoload_changed);
-
- undo_redo->commit_action();
+ autoload_add(autoload_add_name->get_text(), autoload_add_path->get_line_edit()->get_text());
autoload_add_path->get_line_edit()->set_text("");
autoload_add_name->set_text("");
@@ -522,6 +484,74 @@ void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant &
undo_redo->commit_action();
}
+void EditorAutoloadSettings::autoload_add(const String &p_name, const String &p_path) {
+
+ String name = p_name;
+
+ String error;
+ if (!_autoload_name_is_valid(name, &error)) {
+ EditorNode::get_singleton()->show_warning(error);
+ return;
+ }
+
+ String path = p_path;
+ if (!FileAccess::exists(path)) {
+ EditorNode::get_singleton()->show_warning(TTR("Invalid Path.") + "\n" + TTR("File does not exist."));
+ return;
+ }
+
+ if (!path.begins_with("res://")) {
+ EditorNode::get_singleton()->show_warning(TTR("Invalid Path.") + "\n" + TTR("Not in resource path."));
+ return;
+ }
+
+ name = "autoload/" + name;
+
+ UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
+
+ undo_redo->create_action(TTR("Add AutoLoad"));
+ undo_redo->add_do_property(ProjectSettings::get_singleton(), name, "*" + path);
+
+ if (ProjectSettings::get_singleton()->has_setting(name)) {
+ undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, ProjectSettings::get_singleton()->get(name));
+ } else {
+ undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, Variant());
+ }
+
+ undo_redo->add_do_method(this, "update_autoload");
+ undo_redo->add_undo_method(this, "update_autoload");
+
+ undo_redo->add_do_method(this, "emit_signal", autoload_changed);
+ undo_redo->add_undo_method(this, "emit_signal", autoload_changed);
+
+ undo_redo->commit_action();
+}
+
+void EditorAutoloadSettings::autoload_remove(const String &p_name) {
+
+ String name = "autoload/" + p_name;
+
+ UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
+
+ int order = ProjectSettings::get_singleton()->get_order(name);
+
+ undo_redo->create_action(TTR("Remove Autoload"));
+
+ undo_redo->add_do_property(ProjectSettings::get_singleton(), name, Variant());
+
+ undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, ProjectSettings::get_singleton()->get(name));
+ undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_persisting", name, true);
+ undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", order);
+
+ undo_redo->add_do_method(this, "update_autoload");
+ undo_redo->add_undo_method(this, "update_autoload");
+
+ undo_redo->add_do_method(this, "emit_signal", autoload_changed);
+ undo_redo->add_undo_method(this, "emit_signal", autoload_changed);
+
+ undo_redo->commit_action();
+}
+
void EditorAutoloadSettings::_bind_methods() {
ClassDB::bind_method("_autoload_add", &EditorAutoloadSettings::_autoload_add);
@@ -535,6 +565,8 @@ void EditorAutoloadSettings::_bind_methods() {
ClassDB::bind_method("drop_data_fw", &EditorAutoloadSettings::drop_data_fw);
ClassDB::bind_method("update_autoload", &EditorAutoloadSettings::update_autoload);
+ ClassDB::bind_method("autoload_add", &EditorAutoloadSettings::autoload_add);
+ ClassDB::bind_method("autoload_remove", &EditorAutoloadSettings::autoload_remove);
ADD_SIGNAL(MethodInfo("autoload_changed"));
}
diff --git a/editor/editor_autoload_settings.h b/editor/editor_autoload_settings.h
index 39f902179c..b5c889fd06 100644
--- a/editor/editor_autoload_settings.h
+++ b/editor/editor_autoload_settings.h
@@ -84,6 +84,8 @@ protected:
public:
void update_autoload();
+ void autoload_add(const String &p_name, const String &p_path);
+ void autoload_remove(const String &p_name);
EditorAutoloadSettings();
};
diff --git a/editor/editor_node.h b/editor/editor_node.h
index 03102cdc81..403b09a919 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -653,6 +653,8 @@ public:
PropertyEditor *get_property_editor() { return property_editor; }
VBoxContainer *get_property_editor_vb() { return prop_editor_vb; }
+ ProjectSettingsEditor *get_project_settings() { return project_settings; }
+
static void add_editor_plugin(EditorPlugin *p_editor);
static void remove_editor_plugin(EditorPlugin *p_editor);
diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp
index 733680645f..31d0bfa8a9 100644
--- a/editor/editor_plugin.cpp
+++ b/editor/editor_plugin.cpp
@@ -301,6 +301,14 @@ void EditorPlugin::remove_custom_type(const String &p_type) {
EditorNode::get_editor_data().remove_custom_type(p_type);
}
+void EditorPlugin::add_autoload_singleton(const String &p_name, const String &p_path) {
+ EditorNode::get_singleton()->get_project_settings()->get_autoload_settings()->autoload_add(p_name, p_path);
+}
+
+void EditorPlugin::remove_autoload_singleton(const String &p_name) {
+ EditorNode::get_singleton()->get_project_settings()->get_autoload_settings()->autoload_remove(p_name);
+}
+
ToolButton *EditorPlugin::add_control_to_bottom_panel(Control *p_control, const String &p_title) {
return EditorNode::get_singleton()->add_bottom_panel_item(p_title, p_control);
@@ -705,6 +713,9 @@ void EditorPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_custom_type", "type", "base", "script", "icon"), &EditorPlugin::add_custom_type);
ClassDB::bind_method(D_METHOD("remove_custom_type", "type"), &EditorPlugin::remove_custom_type);
+ ClassDB::bind_method(D_METHOD("add_autoload_singleton", "name", "path"), &EditorPlugin::add_autoload_singleton);
+ ClassDB::bind_method(D_METHOD("remove_autoload_singleton", "name"), &EditorPlugin::remove_autoload_singleton);
+
ClassDB::bind_method(D_METHOD("update_overlays"), &EditorPlugin::update_overlays);
ClassDB::bind_method(D_METHOD("make_bottom_panel_item_visible", "item"), &EditorPlugin::make_bottom_panel_item_visible);
diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h
index e3e405479c..05cc6e07e3 100644
--- a/editor/editor_plugin.h
+++ b/editor/editor_plugin.h
@@ -212,6 +212,9 @@ public:
void add_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer);
void remove_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer);
+ void add_autoload_singleton(const String &p_name, const String &p_path);
+ void remove_autoload_singleton(const String &p_name);
+
EditorPlugin();
virtual ~EditorPlugin();
};
diff --git a/editor/project_settings_editor.h b/editor/project_settings_editor.h
index 452cf5b060..9364b0ff2c 100644
--- a/editor/project_settings_editor.h
+++ b/editor/project_settings_editor.h
@@ -176,6 +176,8 @@ public:
void popup_project_settings();
void set_plugins_page();
+ EditorAutoloadSettings *get_autoload_settings() { return autoload_settings; }
+
TabContainer *get_tabs();
void queue_save();