summaryrefslogtreecommitdiff
path: root/editor/plugins/script_editor_plugin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins/script_editor_plugin.cpp')
-rw-r--r--editor/plugins/script_editor_plugin.cpp80
1 files changed, 35 insertions, 45 deletions
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index f70f0dc0aa..a3f2c2509f 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -1301,26 +1301,15 @@ void ScriptEditor::_menu_option(int p_option) {
break;
}
- if (script != nullptr) {
- Vector<DocData::ClassDoc> documentations = script->get_documentation();
- for (int j = 0; j < documentations.size(); j++) {
- const DocData::ClassDoc &doc = documentations.get(j);
- if (EditorHelp::get_doc_data()->has_doc(doc.name)) {
- EditorHelp::get_doc_data()->remove_doc(doc.name);
- }
- }
+ if (script.is_valid()) {
+ clear_docs_from_script(script);
}
EditorNode::get_singleton()->push_item(resource.ptr());
EditorNode::get_singleton()->save_resource_as(resource);
- if (script != nullptr) {
- Vector<DocData::ClassDoc> documentations = script->get_documentation();
- for (int j = 0; j < documentations.size(); j++) {
- const DocData::ClassDoc &doc = documentations.get(j);
- EditorHelp::get_doc_data()->add_doc(doc);
- update_doc(doc.name);
- }
+ if (script.is_valid()) {
+ update_docs_from_script(script);
}
} break;
@@ -2418,14 +2407,8 @@ void ScriptEditor::save_current_script() {
return;
}
- if (script != nullptr) {
- Vector<DocData::ClassDoc> documentations = script->get_documentation();
- for (int j = 0; j < documentations.size(); j++) {
- const DocData::ClassDoc &doc = documentations.get(j);
- if (EditorHelp::get_doc_data()->has_doc(doc.name)) {
- EditorHelp::get_doc_data()->remove_doc(doc.name);
- }
- }
+ if (script.is_valid()) {
+ clear_docs_from_script(script);
}
if (resource->is_built_in()) {
@@ -2440,13 +2423,8 @@ void ScriptEditor::save_current_script() {
EditorNode::get_singleton()->save_resource(resource);
}
- if (script != nullptr) {
- Vector<DocData::ClassDoc> documentations = script->get_documentation();
- for (int j = 0; j < documentations.size(); j++) {
- const DocData::ClassDoc &doc = documentations.get(j);
- EditorHelp::get_doc_data()->add_doc(doc);
- update_doc(doc.name);
- }
+ if (script.is_valid()) {
+ update_docs_from_script(script);
}
}
@@ -2491,25 +2469,14 @@ void ScriptEditor::save_all_scripts() {
continue;
}
- if (script != nullptr) {
- Vector<DocData::ClassDoc> documentations = script->get_documentation();
- for (int j = 0; j < documentations.size(); j++) {
- const DocData::ClassDoc &doc = documentations.get(j);
- if (EditorHelp::get_doc_data()->has_doc(doc.name)) {
- EditorHelp::get_doc_data()->remove_doc(doc.name);
- }
- }
+ if (script.is_valid()) {
+ clear_docs_from_script(script);
}
EditorNode::get_singleton()->save_resource(edited_res); //external script, save it
- if (script != nullptr) {
- Vector<DocData::ClassDoc> documentations = script->get_documentation();
- for (int j = 0; j < documentations.size(); j++) {
- const DocData::ClassDoc &doc = documentations.get(j);
- EditorHelp::get_doc_data()->add_doc(doc);
- update_doc(doc.name);
- }
+ if (script.is_valid()) {
+ update_docs_from_script(script);
}
} else {
// For built-in scripts, save their scenes instead.
@@ -3331,6 +3298,29 @@ void ScriptEditor::update_doc(const String &p_name) {
}
}
+void ScriptEditor::clear_docs_from_script(const Ref<Script> &p_script) {
+ ERR_FAIL_COND(p_script.is_null());
+
+ Vector<DocData::ClassDoc> documentations = p_script->get_documentation();
+ for (int j = 0; j < documentations.size(); j++) {
+ const DocData::ClassDoc &doc = documentations.get(j);
+ if (EditorHelp::get_doc_data()->has_doc(doc.name)) {
+ EditorHelp::get_doc_data()->remove_doc(doc.name);
+ }
+ }
+}
+
+void ScriptEditor::update_docs_from_script(const Ref<Script> &p_script) {
+ ERR_FAIL_COND(p_script.is_null());
+
+ Vector<DocData::ClassDoc> documentations = p_script->get_documentation();
+ for (int j = 0; j < documentations.size(); j++) {
+ const DocData::ClassDoc &doc = documentations.get(j);
+ EditorHelp::get_doc_data()->add_doc(doc);
+ update_doc(doc.name);
+ }
+}
+
void ScriptEditor::_update_selected_editor_menu() {
for (int i = 0; i < tab_container->get_tab_count(); i++) {
bool current = tab_container->get_current_tab() == i;