summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp6
-rw-r--r--editor/plugins/script_editor_plugin.cpp121
-rw-r--r--editor/plugins/script_editor_plugin.h5
-rw-r--r--editor/plugins/script_text_editor.cpp26
4 files changed, 96 insertions, 62 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 7d6025cb03..90969752d3 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -4225,9 +4225,9 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
p = view_menu->get_popup();
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_grid", TTR("Show Grid"), KEY_G), SHOW_GRID);
- p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_helpers", TTR("Show helpers"), KEY_H), SHOW_HELPERS);
- p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_rulers", TTR("Show rulers"), KEY_R), SHOW_RULERS);
- p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_guides", TTR("Show guides"), KEY_Y), SHOW_GUIDES);
+ p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_helpers", TTR("Show Helpers"), KEY_H), SHOW_HELPERS);
+ p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_rulers", TTR("Show Rulers"), KEY_R), SHOW_RULERS);
+ p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_guides", TTR("Show Guides"), KEY_Y), SHOW_GUIDES);
p->add_separator();
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/center_selection", TTR("Center Selection"), KEY_F), VIEW_CENTER_TO_SELECTION);
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/frame_selection", TTR("Frame Selection"), KEY_MASK_SHIFT | KEY_F), VIEW_FRAME_TO_SELECTION);
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index d18422c0c0..5befbbae8d 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -429,36 +429,32 @@ void ScriptEditor::_add_recent_script(String p_path) {
return;
}
- // remove if already stored
- int already_recent = previous_scripts.find(p_path);
- if (already_recent >= 0) {
- previous_scripts.remove(already_recent);
+ Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scripts", Array());
+ if (rc.find(p_path) != -1) {
+ rc.erase(p_path);
+ }
+ rc.push_front(p_path);
+ if (rc.size() > 10) {
+ rc.resize(10);
}
- // add to list
- previous_scripts.insert(0, p_path);
-
+ EditorSettings::get_singleton()->set_project_metadata("recent_files", "scripts", rc);
_update_recent_scripts();
}
void ScriptEditor::_update_recent_scripts() {
- // make sure we don't exceed max size
- const int max_history = EDITOR_DEF("text_editor/files/maximum_recent_files", 20);
- if (previous_scripts.size() > max_history) {
- previous_scripts.resize(max_history);
- }
-
+ Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scripts", Array());
recent_scripts->clear();
recent_scripts->add_shortcut(ED_SHORTCUT("script_editor/open_recent", TTR("Open Recent"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_T));
recent_scripts->add_separator();
- const int max_shown = 8;
- for (int i = 0; i < previous_scripts.size() && i <= max_shown; i++) {
- String path = previous_scripts.get(i);
- // just show script name and last dir
- recent_scripts->add_item(path.get_slice("/", path.get_slice_count("/") - 2) + "/" + path.get_file());
+ String path;
+ for (int i = 0; i < rc.size(); i++) {
+
+ path = rc[i];
+ recent_scripts->add_item(path.replace("res://", ""));
}
recent_scripts->add_separator();
@@ -471,7 +467,7 @@ void ScriptEditor::_open_recent_script(int p_idx) {
// clear button
if (p_idx == recent_scripts->get_item_count() - 1) {
- previous_scripts.clear();
+ EditorSettings::get_singleton()->set_project_metadata("recent_files", "scripts", Array());
call_deferred("_update_recent_scripts");
return;
}
@@ -481,22 +477,34 @@ void ScriptEditor::_open_recent_script(int p_idx) {
p_idx -= 2;
}
- if (p_idx < previous_scripts.size() && p_idx >= 0) {
+ Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scripts", Array());
+ ERR_FAIL_INDEX(p_idx, rc.size());
- String path = previous_scripts.get(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);
- }
- // if it's a path then its most likely a delted file not help
- } else if (!path.is_resource_file()) {
- _help_class_open(path);
+ 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;
}
- previous_scripts.remove(p_idx);
- _update_recent_scripts();
+
+ // if it's a path then its most likely a deleted file not help
+ } else if (!path.is_resource_file()) {
+ _help_class_open(path);
+ return;
}
+
+ rc.remove(p_idx);
+ EditorSettings::get_singleton()->set_project_metadata("recent_files", "scripts", rc);
+ _update_recent_scripts();
+ _show_error_dialog(path);
+}
+
+void ScriptEditor::_show_error_dialog(String p_path) {
+
+ error_dialog->set_text(vformat(TTR("Can't open '%s'. The file could have been moved or deleted."), p_path));
+ error_dialog->popup_centered_minsize();
}
void ScriptEditor::_close_tab(int p_idx, bool p_save) {
@@ -508,14 +516,10 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save) {
Node *tselected = tab_container->get_child(selected);
ScriptEditorBase *current = Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected));
if (current) {
- _add_recent_script(current->get_edited_script()->get_path());
if (p_save) {
apply_scripts();
}
notify_script_close(current->get_edited_script());
- } else {
- EditorHelp *help = Object::cast_to<EditorHelp>(tab_container->get_child(selected));
- _add_recent_script(help->get_class());
}
// roll back to previous tab
@@ -1690,28 +1694,42 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
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"] = ProjectSettings::get_singleton()->get_resource_path();
- keys["file"] = ProjectSettings::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;
if (flags.size()) {
- int from = 0, to = 0;
+ String project_path = ProjectSettings::get_singleton()->get_resource_path();
+ String script_path = ProjectSettings::get_singleton()->globalize_path(p_script->get_path());
+
+ flags = flags.replacen("{line}", itos(p_line > 0 ? p_line : 0));
+ flags = flags.replacen("{col}", itos(p_col));
+ flags = flags.strip_edges().replace("\\\\", "\\");
+
+ int from = 0;
+ int num_chars = 0;
bool inside_quotes = false;
+
for (int i = 0; i < flags.size(); i++) {
+
if (flags[i] == '"' && (!i || flags[i - 1] != '\\')) {
+
+ if (!inside_quotes) {
+ from++;
+ }
inside_quotes = !inside_quotes;
+
} else if (flags[i] == '\0' || (!inside_quotes && flags[i] == ' ')) {
- args.push_back(flags.substr(from, to));
+
+ String arg = flags.substr(from, num_chars);
+
+ // do path replacement here, else there will be issues with spaces and quotes
+ arg = arg.replacen("{project}", project_path);
+ arg = arg.replacen("{file}", script_path);
+ args.push_back(arg);
+
from = i + 1;
- to = 0;
+ num_chars = 0;
} else {
- to++;
+ num_chars++;
}
}
}
@@ -1787,6 +1805,7 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
se->goto_line(p_line - 1);
notify_script_changed(p_script);
+ _add_recent_script(p_script->get_path());
return true;
}
@@ -2304,6 +2323,7 @@ void ScriptEditor::_help_class_open(const String &p_class) {
_go_to_tab(tab_container->get_tab_count() - 1);
eh->go_to_class(p_class, 0);
eh->connect("go_to_help", this, "_help_class_goto");
+ _add_recent_script(p_class);
_update_script_names();
_save_layout();
}
@@ -2332,6 +2352,7 @@ void ScriptEditor::_help_class_goto(const String &p_desc) {
_go_to_tab(tab_container->get_tab_count() - 1);
eh->go_to_help(p_desc);
eh->connect("go_to_help", this, "_help_class_goto");
+ _add_recent_script(eh->get_class());
_update_script_names();
_save_layout();
}
@@ -2738,6 +2759,10 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
add_child(file_dialog);
file_dialog->connect("file_selected", this, "_file_dialog_action");
+ error_dialog = memnew(AcceptDialog);
+ add_child(error_dialog);
+ error_dialog->get_ok()->set_text(TTR("I see.."));
+
debugger = memnew(ScriptEditorDebugger(editor));
debugger->connect("goto_script_line", this, "_goto_script_line");
debugger->connect("show_debugger", this, "_show_debugger");
diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h
index e60e4cf8c0..e98a4c97a6 100644
--- a/editor/plugins/script_editor_plugin.h
+++ b/editor/plugins/script_editor_plugin.h
@@ -198,6 +198,7 @@ class ScriptEditor : public PanelContainer {
VSplitContainer *list_split;
TabContainer *tab_container;
EditorFileDialog *file_dialog;
+ AcceptDialog *error_dialog;
ConfirmationDialog *erase_tab_confirm;
ScriptCreateDialog *script_create_dialog;
ScriptEditorDebugger *debugger;
@@ -227,8 +228,6 @@ class ScriptEditor : public PanelContainer {
Vector<ScriptHistory> history;
int history_pos;
- Vector<String> previous_scripts;
-
EditorHelpIndex *help_index;
void _tab_changed(int p_which);
@@ -250,6 +249,8 @@ class ScriptEditor : public PanelContainer {
void _update_recent_scripts();
void _open_recent_script(int p_idx);
+ void _show_error_dialog(String p_path);
+
void _close_tab(int p_idx, bool p_save = true);
void _close_current_tab();
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index a3728a1d46..87e92f0807 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -519,6 +519,7 @@ void ScriptTextEditor::tag_saved_version() {
void ScriptTextEditor::goto_line(int p_line, bool p_with_error) {
TextEdit *tx = code_editor->get_text_edit();
+ tx->deselect();
tx->unfold_line(p_line);
tx->call_deferred("cursor_set_line", p_line);
}
@@ -1283,12 +1284,9 @@ Variant ScriptTextEditor::get_drag_data_fw(const Point2 &p_point, Control *p_fro
bool ScriptTextEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
Dictionary d = p_data;
- if (d.has("type") &&
- (
-
- String(d["type"]) == "resource" ||
- String(d["type"]) == "files" ||
- String(d["type"]) == "nodes")) {
+ if (d.has("type") && (String(d["type"]) == "resource" ||
+ String(d["type"]) == "files" ||
+ String(d["type"]) == "nodes")) {
return true;
}
@@ -1329,6 +1327,10 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
Dictionary d = p_data;
+ TextEdit *te = code_editor->get_text_edit();
+ int row, col;
+ te->_get_mouse_pos(p_point, row, col);
+
if (d.has("type") && String(d["type"]) == "resource") {
Ref<Resource> res = d["resource"];
@@ -1341,7 +1343,9 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
return;
}
- code_editor->get_text_edit()->insert_text_at_cursor(res->get_path());
+ te->cursor_set_line(row);
+ te->cursor_set_column(col);
+ te->insert_text_at_cursor(res->get_path());
}
if (d.has("type") && String(d["type"]) == "files") {
@@ -1356,7 +1360,9 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
text_to_drop += "\"" + String(files[i]).c_escape() + "\"";
}
- code_editor->get_text_edit()->insert_text_at_cursor(text_to_drop);
+ te->cursor_set_line(row);
+ te->cursor_set_column(col);
+ te->insert_text_at_cursor(text_to_drop);
}
if (d.has("type") && String(d["type"]) == "nodes") {
@@ -1385,7 +1391,9 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
text_to_drop += "\"" + path.c_escape() + "\"";
}
- code_editor->get_text_edit()->insert_text_at_cursor(text_to_drop);
+ te->cursor_set_line(row);
+ te->cursor_set_column(col);
+ te->insert_text_at_cursor(text_to_drop);
}
}