Browse Source

Convert indent on save

Paulb23 8 years ago
parent
commit
c59bd79e02

+ 35 - 0
editor/plugins/script_editor_plugin.cpp

@@ -530,6 +530,15 @@ void ScriptEditor::_resave_scripts(const String &p_str) {
 		if (trim_trailing_whitespace_on_save) {
 		if (trim_trailing_whitespace_on_save) {
 			se->trim_trailing_whitespace();
 			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);
 		editor->save_resource(script);
 		se->tag_saved_version();
 		se->tag_saved_version();
 	}
 	}
@@ -795,12 +804,28 @@ void ScriptEditor::_menu_option(int p_option) {
 
 
 				if (trim_trailing_whitespace_on_save)
 				if (trim_trailing_whitespace_on_save)
 					current->trim_trailing_whitespace();
 					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());
 				editor->save_resource(current->get_edited_script());
 
 
 			} break;
 			} break;
 			case FILE_SAVE_AS: {
 			case FILE_SAVE_AS: {
 
 
 				current->trim_trailing_whitespace();
 				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->push_item(current->get_edited_script()->cast_to<Object>());
 				editor->save_resource_as(current->get_edited_script());
 				editor->save_resource_as(current->get_edited_script());
 
 
@@ -1483,6 +1508,14 @@ void ScriptEditor::save_all_scripts() {
 			se->trim_trailing_whitespace();
 			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();
 		Ref<Script> script = se->get_edited_script();
 		if (script.is_valid())
 		if (script.is_valid())
 			se->apply_code();
 			se->apply_code();
@@ -2163,6 +2196,8 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
 
 
 	edit_pass = 0;
 	edit_pass = 0;
 	trim_trailing_whitespace_on_save = false;
 	trim_trailing_whitespace_on_save = false;
+	convert_indent_on_save = false;
+	use_space_indentation = false;
 
 
 	ScriptServer::edit_request_func = _open_script_request;
 	ScriptServer::edit_request_func = _open_script_request;
 }
 }

+ 4 - 0
editor/plugins/script_editor_plugin.h

@@ -91,6 +91,8 @@ public:
 	virtual void set_edit_state(const Variant &p_state) = 0;
 	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 goto_line(int p_line, bool p_with_error = false) = 0;
 	virtual void trim_trailing_whitespace() = 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 ensure_focus() = 0;
 	virtual void tag_saved_version() = 0;
 	virtual void tag_saved_version() = 0;
 	virtual void reload(bool p_soft) = 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);
 	void _res_saved_callback(const Ref<Resource> &p_res);
 
 
 	bool trim_trailing_whitespace_on_save;
 	bool trim_trailing_whitespace_on_save;
+	bool use_space_indentation;
+	bool convert_indent_on_save;
 
 
 	void _trim_trailing_whitespace(TextEdit *tx);
 	void _trim_trailing_whitespace(TextEdit *tx);
 
 

+ 6 - 0
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::trim_trailing_whitespace() {
 }
 }
 
 
+void VisualScriptEditor::convert_indent_to_spaces() {
+}
+
+void VisualScriptEditor::convert_indent_to_tabs() {
+}
+
 void VisualScriptEditor::ensure_focus() {
 void VisualScriptEditor::ensure_focus() {
 
 
 	graph->grab_focus();
 	graph->grab_focus();

+ 2 - 0
modules/visual_script/visual_script_editor.h

@@ -240,6 +240,8 @@ public:
 	virtual void set_edit_state(const Variant &p_state);
 	virtual void set_edit_state(const Variant &p_state);
 	virtual void goto_line(int p_line, bool p_with_error = false);
 	virtual void goto_line(int p_line, bool p_with_error = false);
 	virtual void trim_trailing_whitespace();
 	virtual void trim_trailing_whitespace();
+	virtual void convert_indent_to_spaces();
+	virtual void convert_indent_to_tabs();
 	virtual void ensure_focus();
 	virtual void ensure_focus();
 	virtual void tag_saved_version();
 	virtual void tag_saved_version();
 	virtual void reload(bool p_soft);
 	virtual void reload(bool p_soft);