summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorPaulb23 <p_batty@hotmail.co.uk>2017-04-17 14:46:00 +0100
committerPaulb23 <p_batty@hotmail.co.uk>2017-04-18 12:30:52 +0100
commitc59bd79e02548533c61e1ce30e3009f7804658f7 (patch)
tree974620fdef210f70c93f23bba08fe4f3f8abeec3 /editor
parent84bca4e72f191450a794de795de7142da87495c6 (diff)
Convert indent on save
Diffstat (limited to 'editor')
-rw-r--r--editor/plugins/script_editor_plugin.cpp35
-rw-r--r--editor/plugins/script_editor_plugin.h4
2 files changed, 39 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);