summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/connections_dialog.cpp2
-rw-r--r--editor/plugins/script_editor_plugin.cpp72
-rw-r--r--editor/plugins/script_editor_plugin.h7
-rw-r--r--editor/plugins/script_text_editor.cpp22
-rw-r--r--editor/plugins/script_text_editor.h1
5 files changed, 55 insertions, 49 deletions
diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp
index 9c6624d9e5..93c2b7493c 100644
--- a/editor/connections_dialog.cpp
+++ b/editor/connections_dialog.cpp
@@ -767,7 +767,7 @@ void ConnectionsDock::_something_activated() {
Ref<Script> script = c.target->get_script();
- if (script.is_valid() && ScriptEditor::get_singleton()->script_go_to_method(script, c.method)) {
+ if (script.is_valid() && ScriptEditor::get_singleton()->script_goto_method(script, c.method)) {
editor->call("_editor_select", EditorNode::EDITOR_SCRIPT);
}
}
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index 48a2897e7a..a99cd7a2d6 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -1406,10 +1406,10 @@ void ScriptEditor::_update_script_names() {
_update_script_colors();
}
-void ScriptEditor::edit(const Ref<Script> &p_script, bool p_grab_focus) {
+bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool p_grab_focus) {
if (p_script.is_null())
- return;
+ return false;
// refuse to open built-in if scene is not loaded
@@ -1417,22 +1417,46 @@ void ScriptEditor::edit(const Ref<Script> &p_script, bool p_grab_focus) {
bool open_dominant = EditorSettings::get_singleton()->get("text_editor/files/open_dominant_script_on_scene_change");
+ Error err = p_script->get_language()->open_in_external_editor(p_script, p_line >= 0 ? p_line : 0, p_col);
+ if (err == OK)
+ return false;
+ if (err != ERR_UNAVAILABLE)
+ WARN_PRINT("Couldn't open in custom external text editor");
+
if (p_script->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");
String flags = EditorSettings::get_singleton()->get("text_editor/external/exec_flags");
+
+ Dictionary keys;
+ keys["project"] = GlobalConfig::get_singleton()->get_resource_path();
+ keys["file"] = GlobalConfig::get_singleton()->globalize_path(p_script->get_path());
+ keys["line"] = p_line >= 0 ? p_line : 0;
+ keys["col"] = p_col;
+
+ flags = flags.format(keys).strip_edges().replace("\\\\", "\\");
+
List<String> args;
- flags = flags.strip_edges();
- if (flags != String()) {
- Vector<String> flagss = flags.split(" ", false);
- for (int i = 0; i < flagss.size(); i++)
- args.push_back(flagss[i]);
+
+ if (flags.size()) {
+ int from = 0, to = 0;
+ bool inside_quotes = false;
+ for (int i = 0; i < flags.size(); i++) {
+ if (flags[i] == '"' && (!i || flags[i - 1] != '\\')) {
+ inside_quotes = !inside_quotes;
+ } else if (flags[i] == '\0' || (!inside_quotes && flags[i] == ' ')) {
+ args.push_back(flags.substr(from, to));
+ from = i + 1;
+ to = 0;
+ } else {
+ to++;
+ }
+ }
}
- args.push_back(GlobalConfig::get_singleton()->globalize_path(p_script->get_path()));
Error err = OS::get_singleton()->execute(path, args, false);
if (err == OK)
- return;
+ return false;
WARN_PRINT("Couldn't open external text editor, using internal");
}
@@ -1451,8 +1475,11 @@ void ScriptEditor::edit(const Ref<Script> &p_script, bool p_grab_focus) {
}
if (is_visible_in_tree())
se->ensure_focus();
+
+ if (p_line >= 0)
+ se->goto_line(p_line - 1);
}
- return;
+ return true;
}
}
@@ -1465,7 +1492,7 @@ void ScriptEditor::edit(const Ref<Script> &p_script, bool p_grab_focus) {
if (se)
break;
}
- ERR_FAIL_COND(!se);
+ ERR_FAIL_COND_V(!se, false);
tab_container->add_child(se);
se->set_edited_script(p_script);
@@ -1492,6 +1519,11 @@ void ScriptEditor::edit(const Ref<Script> &p_script, bool p_grab_focus) {
_test_script_times_on_disk(p_script);
_update_modified_scripts_for_external_editor(p_script);
+
+ if (p_line >= 0)
+ se->goto_line(p_line - 1);
+
+ return true;
}
void ScriptEditor::save_all_scripts() {
@@ -1900,20 +1932,14 @@ void ScriptEditor::set_scene_root_script(Ref<Script> p_script) {
}
}
-bool ScriptEditor::script_go_to_method(Ref<Script> p_script, const String &p_method) {
+bool ScriptEditor::script_goto_method(Ref<Script> p_script, const String &p_method) {
- for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *current = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ int line = p_script->get_member_line(p_method);
- if (current && current->get_edited_script() == p_script) {
- if (current->goto_method(p_method)) {
- edit(p_script);
- return true;
- }
- break;
- }
- }
- return false;
+ if (line == -1)
+ return false;
+
+ return edit(p_script, line, 0);
}
void ScriptEditor::set_live_auto_reload_running_scripts(bool p_enabled) {
diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h
index fde3432b51..6a54609167 100644
--- a/editor/plugins/script_editor_plugin.h
+++ b/editor/plugins/script_editor_plugin.h
@@ -97,7 +97,6 @@ public:
virtual void tag_saved_version() = 0;
virtual void reload(bool p_soft) = 0;
virtual void get_breakpoints(List<int> *p_breakpoints) = 0;
- virtual bool goto_method(const String &p_method) = 0;
virtual void add_callback(const String &p_function, PoolStringArray p_args) = 0;
virtual void update_settings() = 0;
virtual void set_debugger_active(bool p_active) = 0;
@@ -316,7 +315,9 @@ public:
void apply_scripts() const;
void ensure_select_current();
- void edit(const Ref<Script> &p_script, bool p_grab_focus = true);
+
+ _FORCE_INLINE_ bool edit(const Ref<Script> &p_script, bool p_grab_focus = true) { return edit(p_script, -1, 0, p_grab_focus); }
+ bool edit(const Ref<Script> &p_script, int p_line, int p_col, bool p_grab_focus = true);
Dictionary get_state() const;
void set_state(const Dictionary &p_state);
@@ -333,7 +334,7 @@ public:
void set_scene_root_script(Ref<Script> p_script);
- bool script_go_to_method(Ref<Script> p_script, const String &p_method);
+ bool script_goto_method(Ref<Script> p_script, const String &p_method);
virtual void edited_scene_changed();
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 0eb53d1a66..052c19f34e 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -69,26 +69,6 @@ Ref<Script> ScriptTextEditor::get_edited_script() const {
return script;
}
-bool ScriptTextEditor::goto_method(const String &p_method) {
-
- Vector<String> functions = get_functions();
-
- String method_search = p_method + ":";
-
- for (int i = 0; i < functions.size(); i++) {
- String function = functions[i];
-
- if (function.begins_with(method_search)) {
-
- int line = function.get_slice(":", 1).to_int();
- goto_line(line - 1);
- return true;
- }
- }
-
- return false;
-}
-
void ScriptTextEditor::_load_theme_settings() {
TextEdit *text_edit = code_editor->get_text_edit();
@@ -386,7 +366,7 @@ void ScriptTextEditor::tag_saved_version() {
}
void ScriptTextEditor::goto_line(int p_line, bool p_with_error) {
- code_editor->get_text_edit()->cursor_set_line(p_line);
+ code_editor->get_text_edit()->call_deferred("cursor_set_line", p_line);
}
void ScriptTextEditor::ensure_focus() {
diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h
index 01f58c6fdc..8e089e1ebf 100644
--- a/editor/plugins/script_text_editor.h
+++ b/editor/plugins/script_text_editor.h
@@ -138,7 +138,6 @@ public:
virtual void add_callback(const String &p_function, PoolStringArray p_args);
virtual void update_settings();
- virtual bool goto_method(const String &p_method);
virtual void set_tooltip_request_func(String p_method, Object *p_obj);