diff options
author | Paulb23 <p_batty@hotmail.co.uk> | 2017-04-17 14:46:00 +0100 |
---|---|---|
committer | Paulb23 <p_batty@hotmail.co.uk> | 2017-04-18 12:30:52 +0100 |
commit | c59bd79e02548533c61e1ce30e3009f7804658f7 (patch) | |
tree | 974620fdef210f70c93f23bba08fe4f3f8abeec3 | |
parent | 84bca4e72f191450a794de795de7142da87495c6 (diff) |
Convert indent on save
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 35 | ||||
-rw-r--r-- | editor/plugins/script_editor_plugin.h | 4 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.cpp | 6 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.h | 2 |
4 files changed, 47 insertions, 0 deletions
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index bc6f2134a2..2695d9d882 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -530,6 +530,15 @@ void ScriptEditor::_resave_scripts(const String &p_str) { if (trim_trailing_whitespace_on_save) { se->trim_trailing_whitespace(); } + + if (convert_indent_on_save) { + if (use_space_indentation) { + se->convert_indent_to_spaces(); + } else { + se->convert_indent_to_tabs(); + } + } + editor->save_resource(script); se->tag_saved_version(); } @@ -795,12 +804,28 @@ void ScriptEditor::_menu_option(int p_option) { if (trim_trailing_whitespace_on_save) current->trim_trailing_whitespace(); + + if (convert_indent_on_save) { + if (use_space_indentation) { + current->convert_indent_to_spaces(); + } else { + current->convert_indent_to_tabs(); + } + } editor->save_resource(current->get_edited_script()); } break; case FILE_SAVE_AS: { current->trim_trailing_whitespace(); + + if (convert_indent_on_save) { + if (use_space_indentation) { + current->convert_indent_to_spaces(); + } else { + current->convert_indent_to_tabs(); + } + } editor->push_item(current->get_edited_script()->cast_to<Object>()); editor->save_resource_as(current->get_edited_script()); @@ -1483,6 +1508,14 @@ void ScriptEditor::save_all_scripts() { se->trim_trailing_whitespace(); } + if (convert_indent_on_save) { + if (use_space_indentation) { + se->convert_indent_to_spaces(); + } else { + se->convert_indent_to_tabs(); + } + } + Ref<Script> script = se->get_edited_script(); if (script.is_valid()) se->apply_code(); @@ -2163,6 +2196,8 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { edit_pass = 0; trim_trailing_whitespace_on_save = false; + convert_indent_on_save = false; + use_space_indentation = false; ScriptServer::edit_request_func = _open_script_request; } diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 51d9bd3fc8..fde3432b51 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -91,6 +91,8 @@ public: virtual void set_edit_state(const Variant &p_state) = 0; virtual void goto_line(int p_line, bool p_with_error = false) = 0; virtual void trim_trailing_whitespace() = 0; + virtual void convert_indent_to_spaces() = 0; + virtual void convert_indent_to_tabs() = 0; virtual void ensure_focus() = 0; virtual void tag_saved_version() = 0; virtual void reload(bool p_soft) = 0; @@ -252,6 +254,8 @@ class ScriptEditor : public VBoxContainer { void _res_saved_callback(const Ref<Resource> &p_res); bool trim_trailing_whitespace_on_save; + bool use_space_indentation; + bool convert_indent_on_save; void _trim_trailing_whitespace(TextEdit *tx); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 7247636920..30178c32ff 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -2163,6 +2163,12 @@ void VisualScriptEditor::goto_line(int p_line, bool p_with_error) { void VisualScriptEditor::trim_trailing_whitespace() { } +void VisualScriptEditor::convert_indent_to_spaces() { +} + +void VisualScriptEditor::convert_indent_to_tabs() { +} + void VisualScriptEditor::ensure_focus() { graph->grab_focus(); diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index 7322da5cfb..0b23fa92f4 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -240,6 +240,8 @@ public: virtual void set_edit_state(const Variant &p_state); virtual void goto_line(int p_line, bool p_with_error = false); virtual void trim_trailing_whitespace(); + virtual void convert_indent_to_spaces(); + virtual void convert_indent_to_tabs(); virtual void ensure_focus(); virtual void tag_saved_version(); virtual void reload(bool p_soft); |