|
@@ -31,7 +31,6 @@
|
|
|
#include "script_editor_plugin.h"
|
|
|
|
|
|
#include "core/io/resource_loader.h"
|
|
|
-#include "core/io/resource_saver.h"
|
|
|
#include "core/os/file_access.h"
|
|
|
#include "core/os/input.h"
|
|
|
#include "core/os/keyboard.h"
|
|
@@ -283,7 +282,6 @@ void ScriptEditor::_breaked(bool p_breaked, bool p_can_debug) {
|
|
|
|
|
|
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
|
|
|
if (!se) {
|
|
|
-
|
|
|
continue;
|
|
|
}
|
|
|
|
|
@@ -402,7 +400,10 @@ void ScriptEditor::_go_to_tab(int p_idx) {
|
|
|
if (is_visible_in_tree())
|
|
|
Object::cast_to<ScriptEditorBase>(c)->ensure_focus();
|
|
|
|
|
|
- notify_script_changed(Object::cast_to<ScriptEditorBase>(c)->get_edited_script());
|
|
|
+ Ref<Script> script = Object::cast_to<ScriptEditorBase>(c)->get_edited_resource();
|
|
|
+ if (script != NULL) {
|
|
|
+ notify_script_changed(script);
|
|
|
+ }
|
|
|
}
|
|
|
if (Object::cast_to<EditorHelp>(c)) {
|
|
|
|
|
@@ -482,12 +483,23 @@ void ScriptEditor::_open_recent_script(int p_idx) {
|
|
|
String path = rc[p_idx];
|
|
|
// if its not on disk its a help file or deleted
|
|
|
if (FileAccess::exists(path)) {
|
|
|
- Ref<Script> script = ResourceLoader::load(path);
|
|
|
- if (script.is_valid()) {
|
|
|
- edit(script, true);
|
|
|
- return;
|
|
|
+ List<String> extensions;
|
|
|
+ ResourceLoader::get_recognized_extensions_for_type("Script", &extensions);
|
|
|
+
|
|
|
+ if (extensions.find(path.get_extension())) {
|
|
|
+ Ref<Script> script = ResourceLoader::load(path);
|
|
|
+ if (script.is_valid()) {
|
|
|
+ edit(script, true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ Error err;
|
|
|
+ Ref<TextFile> text_file = _load_text_file(path, &err);
|
|
|
+ if (text_file.is_valid()) {
|
|
|
+ edit(text_file, true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
// if it's a path then its most likely a deleted file not help
|
|
|
} else if (!path.is_resource_file()) {
|
|
|
_help_class_open(path);
|
|
@@ -513,12 +525,17 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) {
|
|
|
return;
|
|
|
|
|
|
Node *tselected = tab_container->get_child(selected);
|
|
|
+
|
|
|
ScriptEditorBase *current = Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected));
|
|
|
if (current) {
|
|
|
if (p_save) {
|
|
|
apply_scripts();
|
|
|
}
|
|
|
- notify_script_close(current->get_edited_script());
|
|
|
+
|
|
|
+ Ref<Script> script = current->get_edited_resource();
|
|
|
+ if (script != NULL) {
|
|
|
+ notify_script_close(script);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// roll back to previous tab
|
|
@@ -589,7 +606,7 @@ void ScriptEditor::_close_docs_tab() {
|
|
|
|
|
|
void ScriptEditor::_copy_script_path() {
|
|
|
ScriptEditorBase *se = _get_current_editor();
|
|
|
- Ref<Script> script = se->get_edited_script();
|
|
|
+ RES script = se->get_edited_resource();
|
|
|
OS::get_singleton()->set_clipboard(script->get_path());
|
|
|
}
|
|
|
|
|
@@ -655,7 +672,7 @@ void ScriptEditor::_resave_scripts(const String &p_str) {
|
|
|
if (!se)
|
|
|
continue;
|
|
|
|
|
|
- Ref<Script> script = se->get_edited_script();
|
|
|
+ RES script = se->get_edited_resource();
|
|
|
|
|
|
if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1)
|
|
|
continue; //internal script, who cares
|
|
@@ -672,7 +689,14 @@ void ScriptEditor::_resave_scripts(const String &p_str) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- editor->save_resource(script);
|
|
|
+ Ref<TextFile> text_file = script;
|
|
|
+ if (text_file != NULL) {
|
|
|
+ se->apply_code();
|
|
|
+ _save_text_file(text_file, text_file->get_path());
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ editor->save_resource(script);
|
|
|
+ }
|
|
|
se->tag_saved_version();
|
|
|
}
|
|
|
|
|
@@ -689,25 +713,37 @@ void ScriptEditor::_reload_scripts() {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- Ref<Script> script = se->get_edited_script();
|
|
|
+ RES edited_res = se->get_edited_resource();
|
|
|
|
|
|
- if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) {
|
|
|
+ if (edited_res->get_path() == "" || edited_res->get_path().find("local://") != -1 || edited_res->get_path().find("::") != -1) {
|
|
|
|
|
|
continue; //internal script, who cares
|
|
|
}
|
|
|
|
|
|
- uint64_t last_date = script->get_last_modified_time();
|
|
|
- uint64_t date = FileAccess::get_modified_time(script->get_path());
|
|
|
+ uint64_t last_date = edited_res->get_last_modified_time();
|
|
|
+ uint64_t date = FileAccess::get_modified_time(edited_res->get_path());
|
|
|
|
|
|
if (last_date == date) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), true);
|
|
|
- ERR_CONTINUE(!rel_script.is_valid());
|
|
|
- script->set_source_code(rel_script->get_source_code());
|
|
|
- script->set_last_modified_time(rel_script->get_last_modified_time());
|
|
|
- script->reload();
|
|
|
+ Ref<Script> script = edited_res;
|
|
|
+ if (script != NULL) {
|
|
|
+ Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), true);
|
|
|
+ ERR_CONTINUE(!rel_script.is_valid());
|
|
|
+ script->set_source_code(rel_script->get_source_code());
|
|
|
+ script->set_last_modified_time(rel_script->get_last_modified_time());
|
|
|
+ script->reload();
|
|
|
+ }
|
|
|
+
|
|
|
+ Ref<TextFile> text_file = edited_res;
|
|
|
+ if (text_file != NULL) {
|
|
|
+ Error err;
|
|
|
+ Ref<TextFile> rel_text_file = _load_text_file(text_file->get_path(), &err);
|
|
|
+ ERR_CONTINUE(!rel_text_file.is_valid());
|
|
|
+ text_file->set_text(rel_text_file->get_text());
|
|
|
+ text_file->set_last_modified_time(rel_text_file->get_last_modified_time());
|
|
|
+ }
|
|
|
se->reload_text();
|
|
|
}
|
|
|
|
|
@@ -725,7 +761,7 @@ void ScriptEditor::_res_saved_callback(const Ref<Resource> &p_res) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- Ref<Script> script = se->get_edited_script();
|
|
|
+ RES script = se->get_edited_resource();
|
|
|
|
|
|
if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) {
|
|
|
continue; //internal script, who cares
|
|
@@ -750,7 +786,7 @@ void ScriptEditor::_live_auto_reload_running_scripts() {
|
|
|
debugger->reload_scripts();
|
|
|
}
|
|
|
|
|
|
-bool ScriptEditor::_test_script_times_on_disk(Ref<Script> p_for_script) {
|
|
|
+bool ScriptEditor::_test_script_times_on_disk(RES p_for_script) {
|
|
|
|
|
|
disk_changed_list->clear();
|
|
|
TreeItem *r = disk_changed_list->create_item();
|
|
@@ -765,21 +801,20 @@ bool ScriptEditor::_test_script_times_on_disk(Ref<Script> p_for_script) {
|
|
|
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
|
|
|
if (se) {
|
|
|
|
|
|
- Ref<Script> script = se->get_edited_script();
|
|
|
-
|
|
|
- if (p_for_script.is_valid() && p_for_script != script)
|
|
|
+ RES edited_res = se->get_edited_resource();
|
|
|
+ if (edited_res.is_valid() && p_for_script != edited_res)
|
|
|
continue;
|
|
|
|
|
|
- if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1)
|
|
|
+ if (edited_res->get_path() == "" || edited_res->get_path().find("local://") != -1 || edited_res->get_path().find("::") != -1)
|
|
|
continue; //internal script, who cares
|
|
|
|
|
|
- uint64_t last_date = script->get_last_modified_time();
|
|
|
- uint64_t date = FileAccess::get_modified_time(script->get_path());
|
|
|
+ uint64_t last_date = edited_res->get_last_modified_time();
|
|
|
+ uint64_t date = FileAccess::get_modified_time(edited_res->get_path());
|
|
|
|
|
|
if (last_date != date) {
|
|
|
|
|
|
TreeItem *ti = disk_changed_list->create_item(r);
|
|
|
- ti->set_text(0, script->get_path().get_file());
|
|
|
+ ti->set_text(0, edited_res->get_path().get_file());
|
|
|
|
|
|
if (!use_autoreload || se->is_unsaved()) {
|
|
|
need_ask = true;
|
|
@@ -804,6 +839,49 @@ bool ScriptEditor::_test_script_times_on_disk(Ref<Script> p_for_script) {
|
|
|
void ScriptEditor::_file_dialog_action(String p_file) {
|
|
|
|
|
|
switch (file_dialog_option) {
|
|
|
+ case FILE_OPEN: {
|
|
|
+
|
|
|
+ List<String> extensions;
|
|
|
+ ResourceLoader::get_recognized_extensions_for_type("Script", &extensions);
|
|
|
+ if (extensions.find(p_file.get_extension())) {
|
|
|
+ Ref<Script> scr = ResourceLoader::load(p_file);
|
|
|
+ if (!scr.is_valid()) {
|
|
|
+ editor->show_warning(TTR("Error could not load file."), TTR("Error!"));
|
|
|
+ file_dialog_option = -1;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ edit(scr);
|
|
|
+ file_dialog_option = -1;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Error error;
|
|
|
+ Ref<TextFile> text_file = _load_text_file(p_file, &error);
|
|
|
+ if (error != OK) {
|
|
|
+ editor->show_warning(TTR("Error could not load file."), TTR("Error!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (text_file.is_valid()) {
|
|
|
+ edit(text_file);
|
|
|
+ file_dialog_option = -1;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ case FILE_SAVE_AS: {
|
|
|
+ ScriptEditorBase *current = _get_current_editor();
|
|
|
+
|
|
|
+ String path = ProjectSettings::get_singleton()->localize_path(p_file);
|
|
|
+ Error err = _save_text_file(current->get_edited_resource(), path);
|
|
|
+
|
|
|
+ if (err != OK) {
|
|
|
+ editor->show_accept(TTR("Error saving file!"), TTR("OK"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ ((Resource *)current->get_edited_resource().ptr())->set_path(path);
|
|
|
+ _update_script_names();
|
|
|
+ } break;
|
|
|
case THEME_SAVE_AS: {
|
|
|
if (!EditorSettings::get_singleton()->save_text_editor_theme_as(p_file)) {
|
|
|
editor->show_warning(TTR("Error while saving theme"), TTR("Error saving"));
|
|
@@ -823,7 +901,8 @@ Ref<Script> ScriptEditor::_get_current_script() {
|
|
|
ScriptEditorBase *current = _get_current_editor();
|
|
|
|
|
|
if (current) {
|
|
|
- return current->get_edited_script();
|
|
|
+ Ref<Script> script = current->get_edited_resource();
|
|
|
+ return script != NULL ? script : NULL;
|
|
|
} else {
|
|
|
return NULL;
|
|
|
}
|
|
@@ -848,8 +927,19 @@ void ScriptEditor::_menu_option(int p_option) {
|
|
|
script_create_dialog->popup_centered(Size2(300, 300) * EDSCALE);
|
|
|
} break;
|
|
|
case FILE_OPEN: {
|
|
|
+ file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE);
|
|
|
+ file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
|
|
|
+ file_dialog_option = FILE_OPEN;
|
|
|
|
|
|
- editor->open_resource("Script");
|
|
|
+ List<String> extensions;
|
|
|
+ ResourceLoader::get_recognized_extensions_for_type("Script", &extensions);
|
|
|
+ file_dialog->clear_filters();
|
|
|
+ for (int i = 0; i < extensions.size(); i++) {
|
|
|
+ file_dialog->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
|
|
|
+ }
|
|
|
+
|
|
|
+ file_dialog->popup_centered_ratio();
|
|
|
+ file_dialog->set_title(TTR("Open File"));
|
|
|
return;
|
|
|
} break;
|
|
|
case FILE_SAVE_ALL: {
|
|
@@ -929,7 +1019,14 @@ void ScriptEditor::_menu_option(int p_option) {
|
|
|
current->convert_indent_to_tabs();
|
|
|
}
|
|
|
}
|
|
|
- editor->save_resource(current->get_edited_script());
|
|
|
+
|
|
|
+ Ref<TextFile> text_file = current->get_edited_resource();
|
|
|
+ if (text_file != NULL) {
|
|
|
+ current->apply_code();
|
|
|
+ _save_text_file(text_file, text_file->get_path());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ editor->save_resource(current->get_edited_resource());
|
|
|
|
|
|
} break;
|
|
|
case FILE_SAVE_AS: {
|
|
@@ -943,8 +1040,25 @@ void ScriptEditor::_menu_option(int p_option) {
|
|
|
current->convert_indent_to_tabs();
|
|
|
}
|
|
|
}
|
|
|
- editor->push_item(Object::cast_to<Object>(current->get_edited_script().ptr()));
|
|
|
- editor->save_resource_as(current->get_edited_script());
|
|
|
+
|
|
|
+ Ref<TextFile> text_file = current->get_edited_resource();
|
|
|
+ if (text_file != NULL) {
|
|
|
+ file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
|
|
|
+ file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
|
|
|
+ file_dialog_option = FILE_SAVE_AS;
|
|
|
+
|
|
|
+ List<String> extensions;
|
|
|
+ ResourceLoader::get_recognized_extensions_for_type("Script", &extensions);
|
|
|
+ file_dialog->clear_filters();
|
|
|
+ file_dialog->set_current_dir(text_file->get_path().get_base_dir());
|
|
|
+ file_dialog->set_current_file(text_file->get_path().get_file());
|
|
|
+ file_dialog->popup_centered_ratio();
|
|
|
+ file_dialog->set_title(TTR("Save File As..."));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ editor->push_item(Object::cast_to<Object>(current->get_edited_resource().ptr()));
|
|
|
+ editor->save_resource_as(current->get_edited_resource());
|
|
|
|
|
|
} break;
|
|
|
|
|
@@ -956,8 +1070,8 @@ void ScriptEditor::_menu_option(int p_option) {
|
|
|
} break;
|
|
|
case FILE_RUN: {
|
|
|
|
|
|
- Ref<Script> scr = current->get_edited_script();
|
|
|
- if (scr.is_null()) {
|
|
|
+ Ref<Script> scr = current->get_edited_resource();
|
|
|
+ if (scr == NULL || scr.is_null()) {
|
|
|
EditorNode::get_singleton()->show_warning("Can't obtain the script for running");
|
|
|
break;
|
|
|
}
|
|
@@ -1000,8 +1114,7 @@ void ScriptEditor::_menu_option(int p_option) {
|
|
|
_copy_script_path();
|
|
|
} break;
|
|
|
case SHOW_IN_FILE_SYSTEM: {
|
|
|
- ScriptEditorBase *se = _get_current_editor();
|
|
|
- Ref<Script> script = se->get_edited_script();
|
|
|
+ RES script = current->get_edited_resource();
|
|
|
FileSystemDock *file_system_dock = EditorNode::get_singleton()->get_filesystem_dock();
|
|
|
file_system_dock->navigate_to_path(script->get_path());
|
|
|
// Ensure that the FileSystem dock is visible.
|
|
@@ -1259,8 +1372,8 @@ void ScriptEditor::close_builtin_scripts_from_scene(const String &p_scene) {
|
|
|
|
|
|
if (se) {
|
|
|
|
|
|
- Ref<Script> script = se->get_edited_script();
|
|
|
- if (!script.is_valid())
|
|
|
+ Ref<Script> script = se->get_edited_resource();
|
|
|
+ if (script == NULL || !script.is_valid())
|
|
|
continue;
|
|
|
|
|
|
if (script->get_path().find("::") != -1 && script->get_path().begins_with(p_scene)) { //is an internal script and belongs to scene being closed
|
|
@@ -1307,9 +1420,13 @@ void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) {
|
|
|
if (!se)
|
|
|
continue;
|
|
|
|
|
|
+ Ref<Script> script = se->get_edited_resource();
|
|
|
+ if (script == NULL) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
List<int> bpoints;
|
|
|
se->get_breakpoints(&bpoints);
|
|
|
- Ref<Script> script = se->get_edited_script();
|
|
|
String base = script->get_path();
|
|
|
ERR_CONTINUE(base.begins_with("local://") || base == "");
|
|
|
|
|
@@ -1452,7 +1569,7 @@ void ScriptEditor::_update_members_overview() {
|
|
|
members_overview->set_item_metadata(i, functions[i].get_slice(":", 1).to_int() - 1);
|
|
|
}
|
|
|
|
|
|
- String path = se->get_edited_script()->get_path();
|
|
|
+ String path = se->get_edited_resource()->get_path();
|
|
|
bool built_in = !path.is_resource_file();
|
|
|
String name = built_in ? path.get_file() : se->get_name();
|
|
|
filename->set_text(name);
|
|
@@ -1570,7 +1687,7 @@ void ScriptEditor::_update_script_names() {
|
|
|
if (se) {
|
|
|
|
|
|
Ref<Texture> icon = se->get_icon();
|
|
|
- String path = se->get_edited_script()->get_path();
|
|
|
+ String path = se->get_edited_resource()->get_path();
|
|
|
bool built_in = !path.is_resource_file();
|
|
|
String name = built_in ? path.get_file() : se->get_name();
|
|
|
|
|
@@ -1579,7 +1696,7 @@ void ScriptEditor::_update_script_names() {
|
|
|
sd.name = name;
|
|
|
sd.tooltip = path;
|
|
|
sd.index = i;
|
|
|
- sd.used = used.has(se->get_edited_script());
|
|
|
+ sd.used = used.has(se->get_edited_resource());
|
|
|
sd.category = 0;
|
|
|
sd.ref = se;
|
|
|
|
|
@@ -1681,11 +1798,65 @@ void ScriptEditor::_update_script_names() {
|
|
|
_update_script_colors();
|
|
|
}
|
|
|
|
|
|
-bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool p_grab_focus) {
|
|
|
+Ref<TextFile> ScriptEditor::_load_text_file(const String &p_path, Error *r_error) {
|
|
|
+ if (r_error) {
|
|
|
+ *r_error = ERR_FILE_CANT_OPEN;
|
|
|
+ }
|
|
|
+
|
|
|
+ String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
|
|
|
+ String path = ResourceLoader::path_remap(local_path);
|
|
|
+
|
|
|
+ TextFile *text_file = memnew(TextFile);
|
|
|
+ Ref<TextFile> text_res(text_file);
|
|
|
+ Error err = text_file->load_text(path);
|
|
|
+
|
|
|
+ if (err != OK) {
|
|
|
+ ERR_FAIL_COND_V(err != OK, RES());
|
|
|
+ }
|
|
|
+
|
|
|
+ text_file->set_file_path(local_path);
|
|
|
+ text_file->set_path(local_path, true);
|
|
|
+
|
|
|
+ if (r_error) {
|
|
|
+ *r_error = OK;
|
|
|
+ }
|
|
|
+
|
|
|
+ return text_res;
|
|
|
+}
|
|
|
+
|
|
|
+Error ScriptEditor::_save_text_file(Ref<TextFile> p_text_file, const String &p_path) {
|
|
|
+ Ref<TextFile> sqscr = p_text_file;
|
|
|
+ ERR_FAIL_COND_V(sqscr.is_null(), ERR_INVALID_PARAMETER);
|
|
|
+
|
|
|
+ String source = sqscr->get_text();
|
|
|
+
|
|
|
+ Error err;
|
|
|
+ FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
|
|
|
+
|
|
|
+ if (err) {
|
|
|
+
|
|
|
+ ERR_FAIL_COND_V(err, err);
|
|
|
+ }
|
|
|
+
|
|
|
+ file->store_string(source);
|
|
|
+ if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) {
|
|
|
+ memdelete(file);
|
|
|
+ return ERR_CANT_CREATE;
|
|
|
+ }
|
|
|
+ file->close();
|
|
|
+ memdelete(file);
|
|
|
+
|
|
|
+ _res_saved_callback(sqscr);
|
|
|
+ return OK;
|
|
|
+}
|
|
|
+
|
|
|
+bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_grab_focus) {
|
|
|
|
|
|
- if (p_script.is_null())
|
|
|
+ if (p_resource.is_null())
|
|
|
return false;
|
|
|
|
|
|
+ Ref<Script> script = p_resource;
|
|
|
+
|
|
|
// refuse to open built-in if scene is not loaded
|
|
|
|
|
|
// see if already has it
|
|
@@ -1694,17 +1865,17 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
|
|
|
|
|
|
const bool should_open = open_dominant || !EditorNode::get_singleton()->is_changing_scene();
|
|
|
|
|
|
- if (p_script->get_language()->overrides_external_editor()) {
|
|
|
+ if (script != NULL && script->get_language()->overrides_external_editor()) {
|
|
|
if (should_open) {
|
|
|
- Error err = p_script->get_language()->open_in_external_editor(p_script, p_line >= 0 ? p_line : 0, p_col);
|
|
|
+ Error err = script->get_language()->open_in_external_editor(script, p_line >= 0 ? p_line : 0, p_col);
|
|
|
if (err != OK)
|
|
|
ERR_PRINT("Couldn't open script in the overridden external text editor");
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if ((debugger->get_dump_stack_script() != p_script || debugger->get_debug_with_external_editor()) &&
|
|
|
- p_script->get_path().is_resource_file() &&
|
|
|
+ if ((debugger->get_dump_stack_script() != p_resource || debugger->get_debug_with_external_editor()) &&
|
|
|
+ p_resource->get_path().is_resource_file() &&
|
|
|
bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor"))) {
|
|
|
|
|
|
String path = EditorSettings::get_singleton()->get("text_editor/external/exec_path");
|
|
@@ -1714,7 +1885,7 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
|
|
|
|
|
|
if (flags.size()) {
|
|
|
String project_path = ProjectSettings::get_singleton()->get_resource_path();
|
|
|
- String script_path = ProjectSettings::get_singleton()->globalize_path(p_script->get_path());
|
|
|
+ String script_path = ProjectSettings::get_singleton()->globalize_path(p_resource->get_path());
|
|
|
|
|
|
flags = flags.replacen("{line}", itos(p_line > 0 ? p_line : 0));
|
|
|
flags = flags.replacen("{col}", itos(p_col));
|
|
@@ -1762,7 +1933,7 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
|
|
|
if (!se)
|
|
|
continue;
|
|
|
|
|
|
- if (se->get_edited_script() == p_script) {
|
|
|
+ if (se->get_edited_resource() == p_resource) {
|
|
|
|
|
|
if (should_open) {
|
|
|
if (tab_container->get_current_tab() != i) {
|
|
@@ -1784,7 +1955,7 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
|
|
|
ScriptEditorBase *se;
|
|
|
|
|
|
for (int i = script_editor_func_count - 1; i >= 0; i--) {
|
|
|
- se = script_editor_funcs[i](p_script);
|
|
|
+ se = script_editor_funcs[i](p_resource);
|
|
|
if (se)
|
|
|
break;
|
|
|
}
|
|
@@ -1795,9 +1966,9 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
|
|
|
SyntaxHighlighter *highlighter = syntax_highlighters_funcs[i]();
|
|
|
se->add_syntax_highlighter(highlighter);
|
|
|
|
|
|
- if (!highlighter_set) {
|
|
|
+ if (script != NULL && !highlighter_set) {
|
|
|
List<String> languages = highlighter->get_supported_languages();
|
|
|
- if (languages.find(p_script->get_language()->get_name())) {
|
|
|
+ if (languages.find(script->get_language()->get_name())) {
|
|
|
se->set_syntax_highlighter(highlighter);
|
|
|
highlighter_set = true;
|
|
|
}
|
|
@@ -1805,7 +1976,7 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
|
|
|
}
|
|
|
|
|
|
tab_container->add_child(se);
|
|
|
- se->set_edited_script(p_script);
|
|
|
+ se->set_edited_resource(p_resource);
|
|
|
se->set_tooltip_request_func("_get_debug_tooltip", this);
|
|
|
if (se->get_edit_menu()) {
|
|
|
se->get_edit_menu()->hide();
|
|
@@ -1829,14 +2000,14 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
|
|
|
|
|
|
//test for modification, maybe the script was not edited but was loaded
|
|
|
|
|
|
- _test_script_times_on_disk(p_script);
|
|
|
- _update_modified_scripts_for_external_editor(p_script);
|
|
|
+ _test_script_times_on_disk(p_resource);
|
|
|
+ _update_modified_scripts_for_external_editor(p_resource);
|
|
|
|
|
|
if (p_line >= 0)
|
|
|
se->goto_line(p_line - 1);
|
|
|
|
|
|
- notify_script_changed(p_script);
|
|
|
- _add_recent_script(p_script->get_path());
|
|
|
+ notify_script_changed(p_resource);
|
|
|
+ _add_recent_script(p_resource->get_path());
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -1863,12 +2034,19 @@ void ScriptEditor::save_all_scripts() {
|
|
|
if (!se->is_unsaved())
|
|
|
continue;
|
|
|
|
|
|
- Ref<Script> script = se->get_edited_script();
|
|
|
- if (script.is_valid())
|
|
|
+ RES edited_res = se->get_edited_resource();
|
|
|
+ if (edited_res.is_valid()) {
|
|
|
se->apply_code();
|
|
|
+ }
|
|
|
|
|
|
- if (script->get_path() != "" && script->get_path().find("local://") == -1 && script->get_path().find("::") == -1)
|
|
|
- editor->save_resource(script); //external script, save it
|
|
|
+ if (edited_res->get_path() != "" && edited_res->get_path().find("local://") == -1 && edited_res->get_path().find("::") == -1) {
|
|
|
+ Ref<TextFile> text_file = edited_res;
|
|
|
+ if (text_file != NULL) {
|
|
|
+ _save_text_file(text_file, text_file->get_path());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ editor->save_resource(edited_res); //external script, save it
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
_update_script_names();
|
|
@@ -1938,7 +2116,7 @@ void ScriptEditor::_add_callback(Object *p_obj, const String &p_function, const
|
|
|
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
|
|
|
if (!se)
|
|
|
continue;
|
|
|
- if (se->get_edited_script() != script)
|
|
|
+ if (se->get_edited_resource() != script)
|
|
|
continue;
|
|
|
|
|
|
se->add_callback(p_function, p_args);
|
|
@@ -2228,9 +2406,12 @@ void ScriptEditor::_make_script_list_context_menu() {
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_other_tabs"), CLOSE_OTHER_TABS);
|
|
|
context_menu->add_separator();
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/copy_path"), FILE_COPY_PATH);
|
|
|
- context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/reload_script_soft"), FILE_TOOL_RELOAD_SOFT);
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/show_in_file_system"), SHOW_IN_FILE_SYSTEM);
|
|
|
- Ref<Script> scr = se->get_edited_script();
|
|
|
+ }
|
|
|
+
|
|
|
+ Ref<Script> scr = se->get_edited_resource();
|
|
|
+ if (scr != NULL) {
|
|
|
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/reload_script_soft"), FILE_TOOL_RELOAD_SOFT);
|
|
|
if (!scr.is_null() && scr->is_tool()) {
|
|
|
context_menu->add_separator();
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/run_file"), FILE_RUN);
|
|
@@ -2239,8 +2420,6 @@ void ScriptEditor::_make_script_list_context_menu() {
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_file"), FILE_CLOSE);
|
|
|
}
|
|
|
|
|
|
- EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(selected));
|
|
|
-
|
|
|
context_menu->add_separator();
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/window_move_up"), WINDOW_MOVE_UP);
|
|
|
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/window_move_down"), WINDOW_MOVE_DOWN);
|
|
@@ -2268,14 +2447,28 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) {
|
|
|
|
|
|
restoring_layout = true;
|
|
|
|
|
|
+ List<String> extensions;
|
|
|
+ ResourceLoader::get_recognized_extensions_for_type("Script", &extensions);
|
|
|
+
|
|
|
for (int i = 0; i < scripts.size(); i++) {
|
|
|
|
|
|
String path = scripts[i];
|
|
|
if (!FileAccess::exists(path))
|
|
|
continue;
|
|
|
- Ref<Script> scr = ResourceLoader::load(path);
|
|
|
- if (scr.is_valid()) {
|
|
|
- edit(scr);
|
|
|
+
|
|
|
+ if (extensions.find(path.get_extension())) {
|
|
|
+ Ref<Script> scr = ResourceLoader::load(path);
|
|
|
+ if (scr.is_valid()) {
|
|
|
+ edit(scr);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Error error;
|
|
|
+ Ref<TextFile> text_file = _load_text_file(path, &error);
|
|
|
+ if (error == OK && text_file.is_valid()) {
|
|
|
+ edit(text_file);
|
|
|
+ continue;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -2311,7 +2504,7 @@ void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) {
|
|
|
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
|
|
|
if (se) {
|
|
|
|
|
|
- String path = se->get_edited_script()->get_path();
|
|
|
+ String path = se->get_edited_resource()->get_path();
|
|
|
if (!path.is_resource_file())
|
|
|
continue;
|
|
|
|
|
@@ -2436,7 +2629,10 @@ void ScriptEditor::_update_history_pos(int p_new_pos) {
|
|
|
Object::cast_to<ScriptEditorBase>(n)->set_edit_state(history[history_pos].state);
|
|
|
Object::cast_to<ScriptEditorBase>(n)->ensure_focus();
|
|
|
|
|
|
- notify_script_changed(Object::cast_to<ScriptEditorBase>(n)->get_edited_script());
|
|
|
+ Ref<Script> script = Object::cast_to<ScriptEditorBase>(n)->get_edited_resource();
|
|
|
+ if (script != NULL) {
|
|
|
+ notify_script_changed(script);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (Object::cast_to<EditorHelp>(n)) {
|
|
@@ -2473,7 +2669,11 @@ Vector<Ref<Script> > ScriptEditor::get_open_scripts() const {
|
|
|
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
|
|
|
if (!se)
|
|
|
continue;
|
|
|
- out_scripts.push_back(se->get_edited_script());
|
|
|
+
|
|
|
+ Ref<Script> script = se->get_edited_resource();
|
|
|
+ if (script != NULL) {
|
|
|
+ out_scripts.push_back(script);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return out_scripts;
|
|
@@ -2519,6 +2719,14 @@ void ScriptEditor::_open_script_request(const String &p_path) {
|
|
|
Ref<Script> script = ResourceLoader::load(p_path);
|
|
|
if (script.is_valid()) {
|
|
|
script_editor->edit(script, false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Error err;
|
|
|
+ Ref<TextFile> text_file = script_editor->_load_text_file(p_path, &err);
|
|
|
+ if (text_file.is_valid()) {
|
|
|
+ script_editor->edit(text_file, false);
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -2552,7 +2760,7 @@ void ScriptEditor::_on_find_in_files_requested(String text) {
|
|
|
|
|
|
void ScriptEditor::_on_find_in_files_result_selected(String fpath, int line_number, int begin, int end) {
|
|
|
|
|
|
- Ref<Resource> res = ResourceLoader::load(fpath);
|
|
|
+ RES res = ResourceLoader::load(fpath);
|
|
|
edit(res);
|
|
|
|
|
|
ScriptEditorBase *seb = _get_current_editor();
|
|
@@ -2968,14 +3176,21 @@ ScriptEditor::~ScriptEditor() {
|
|
|
|
|
|
void ScriptEditorPlugin::edit(Object *p_object) {
|
|
|
|
|
|
- if (!Object::cast_to<Script>(p_object))
|
|
|
- return;
|
|
|
+ if (Object::cast_to<Script>(p_object)) {
|
|
|
+ script_editor->edit(Object::cast_to<Script>(p_object));
|
|
|
+ }
|
|
|
|
|
|
- script_editor->edit(Object::cast_to<Script>(p_object));
|
|
|
+ if (Object::cast_to<TextFile>(p_object)) {
|
|
|
+ script_editor->edit(Object::cast_to<TextFile>(p_object));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
bool ScriptEditorPlugin::handles(Object *p_object) const {
|
|
|
|
|
|
+ if (Object::cast_to<TextFile>(p_object)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
if (Object::cast_to<Script>(p_object)) {
|
|
|
|
|
|
bool valid = _can_open_in_editor(Object::cast_to<Script>(p_object));
|