diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-04-21 13:01:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-21 13:01:43 +0200 |
commit | 71bbe6eb01d1664340ea624aca36aa47c693981d (patch) | |
tree | 7fab2ac8f65a8d3190d4255d1ba22cbb52a8697f | |
parent | 7879968136828a6b98daab9ee4e8897eb8c26048 (diff) | |
parent | 6ea253aa776e03dc7174b289c6747cd8d0410245 (diff) |
Merge pull request #27979 from Paulb23/remember_script_state
Restore script editor state between sessions
-rw-r--r-- | editor/code_editor.cpp | 42 | ||||
-rw-r--r-- | editor/editor_node.cpp | 1 | ||||
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 31 | ||||
-rw-r--r-- | editor/plugins/script_text_editor.cpp | 10 | ||||
-rw-r--r-- | editor/plugins/text_editor.cpp | 10 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 11 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 1 |
7 files changed, 93 insertions, 13 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 134384c167..ec159ab173 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -1180,17 +1180,57 @@ Variant CodeTextEditor::get_edit_state() { Dictionary state; state["scroll_position"] = text_editor->get_v_scroll(); + state["h_scroll_position"] = text_editor->get_h_scroll(); state["column"] = text_editor->cursor_get_column(); state["row"] = text_editor->cursor_get_line(); + state["selection"] = get_text_edit()->is_selection_active(); + if (get_text_edit()->is_selection_active()) { + state["selection_from_line"] = text_editor->get_selection_from_line(); + state["selection_from_column"] = text_editor->get_selection_from_column(); + state["selection_to_line"] = text_editor->get_selection_to_line(); + state["selection_to_column"] = text_editor->get_selection_to_column(); + } + + state["folded_lines"] = text_editor->get_folded_lines(); + state["breakpoints"] = text_editor->get_breakpoints_array(); + + state["syntax_highlighter"] = TTR("Standard"); + SyntaxHighlighter *syntax_highlighter = text_editor->_get_syntax_highlighting(); + if (syntax_highlighter) { + state["syntax_highlighter"] = syntax_highlighter->get_name(); + } + return state; } void CodeTextEditor::set_edit_state(const Variant &p_state) { Dictionary state = p_state; - text_editor->cursor_set_column(state["column"]); + + /* update the row first as it sets the column to 0 */ text_editor->cursor_set_line(state["row"]); + text_editor->cursor_set_column(state["column"]); text_editor->set_v_scroll(state["scroll_position"]); + text_editor->set_h_scroll(state["h_scroll_position"]); + + if (state.has("selection")) { + text_editor->select(state["selection_from_line"], state["selection_from_column"], state["selection_to_line"], state["selection_to_column"]); + } + + if (state.has("folded_lines")) { + Vector<int> folded_lines = state["folded_lines"]; + for (int i = 0; i < folded_lines.size(); i++) { + text_editor->fold_line(folded_lines[i]); + } + } + + if (state.has("breakpoints")) { + Array breakpoints = state["breakpoints"]; + for (int i = 0; i < breakpoints.size(); i++) { + text_editor->set_line_as_breakpoint(breakpoints[i], true); + } + } + text_editor->grab_focus(); } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index b729de2e2f..09e582bbe7 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -2523,6 +2523,7 @@ int EditorNode::_next_unsaved_scene(bool p_valid_filename, int p_start) { void EditorNode::_exit_editor() { exiting = true; resource_preview->stop(); //stop early to avoid crashes + _save_docks(); get_tree()->quit(); } diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index d7d4cec07d..8fdeb1cd39 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -2482,22 +2482,33 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) { for (int i = 0; i < scripts.size(); i++) { String path = scripts[i]; + + Dictionary script_info = scripts[i]; + if (!script_info.empty()) { + path = script_info["path"]; + } + if (!FileAccess::exists(path)) continue; if (extensions.find(path.get_extension())) { Ref<Script> scr = ResourceLoader::load(path); - if (scr.is_valid()) { - edit(scr); + if (!scr.is_valid()) { continue; } + edit(scr); + } else { + Error error; + Ref<TextFile> text_file = _load_text_file(path, &error); + if (error != OK || !text_file.is_valid()) { + continue; + } + edit(text_file); } - Error error; - Ref<TextFile> text_file = _load_text_file(path, &error); - if (error == OK && text_file.is_valid()) { - edit(text_file); - continue; + if (!script_info.empty()) { + ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); + se->set_edit_state(script_info["state"]); } } @@ -2537,7 +2548,11 @@ void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) { if (!path.is_resource_file()) continue; - scripts.push_back(path); + Dictionary script_info; + script_info["path"] = path; + script_info["state"] = se->get_edit_state(); + + scripts.push_back(script_info); } EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(i)); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index c586985957..4e5034b6b7 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -320,7 +320,6 @@ void ScriptTextEditor::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: _load_theme_settings(); - _change_syntax_highlighter(EditorSettings::get_singleton()->get_project_metadata("script_text_editor", "syntax_highlighter", 0)); break; } } @@ -365,6 +364,14 @@ Variant ScriptTextEditor::get_edit_state() { void ScriptTextEditor::set_edit_state(const Variant &p_state) { code_editor->set_edit_state(p_state); + + Dictionary state = p_state; + if (state.has("syntax_highlighter")) { + int idx = highlighter_menu->get_item_idx_from_text(state["syntax_highlighter"]); + if (idx >= 0) { + _change_syntax_highlighter(idx); + } + } } void ScriptTextEditor::_convert_case(CodeTextEditor::CaseStyle p_case) { @@ -1026,7 +1033,6 @@ void ScriptTextEditor::_change_syntax_highlighter(int p_idx) { } // highlighter_menu->set_item_checked(p_idx, true); set_syntax_highlighter(highlighters[highlighter_menu->get_item_text(p_idx)]); - EditorSettings::get_singleton()->set_project_metadata("script_text_editor", "syntax_highlighter", p_idx); } void ScriptTextEditor::_bind_methods() { diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index fe32c97a64..2886b3dc51 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -66,7 +66,6 @@ void TextEditor::_change_syntax_highlighter(int p_idx) { el = el->next(); } set_syntax_highlighter(highlighters[highlighter_menu->get_item_text(p_idx)]); - EditorSettings::get_singleton()->set_project_metadata("text_editor", "syntax_highlighter", p_idx); } void TextEditor::_load_theme_settings() { @@ -234,6 +233,14 @@ Variant TextEditor::get_edit_state() { void TextEditor::set_edit_state(const Variant &p_state) { code_editor->set_edit_state(p_state); + + Dictionary state = p_state; + if (state.has("syntax_highlighter")) { + int idx = highlighter_menu->get_item_idx_from_text(state["syntax_highlighter"]); + if (idx >= 0) { + _change_syntax_highlighter(idx); + } + } } void TextEditor::trim_trailing_whitespace() { @@ -299,7 +306,6 @@ void TextEditor::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: _load_theme_settings(); - _change_syntax_highlighter(EditorSettings::get_singleton()->get_project_metadata("text_editor", "syntax_highlighter", 0)); break; } } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 39a0b0aaf2..d06f066295 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -5189,6 +5189,17 @@ bool TextEdit::is_folded(int p_line) const { return false; } +Vector<int> TextEdit::get_folded_lines() const { + Vector<int> folded_lines; + + for (int i = 0; i < text.size(); i++) { + if (is_folded(i)) { + folded_lines.push_back(i); + } + } + return folded_lines; +} + void TextEdit::fold_line(int p_line) { ERR_FAIL_INDEX(p_line, text.size()); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 96b409c6d4..503bead785 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -490,6 +490,7 @@ public: bool can_fold(int p_line) const; bool is_folded(int p_line) const; + Vector<int> get_folded_lines() const; void fold_line(int p_line); void unfold_line(int p_line); void toggle_fold_line(int p_line); |