summaryrefslogtreecommitdiff
path: root/editor/plugins/script_text_editor.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-04-26 08:11:41 +0200
committerGitHub <noreply@github.com>2017-04-26 08:11:41 +0200
commit95683f051ccdd073358abd9c95a3fb6d8a12ce6c (patch)
treecf12d7f1b8cfc3bf9aa988b9d2b48c742a2bfe33 /editor/plugins/script_text_editor.cpp
parent692b99fa0ce9d0017d7b1ba0c066ba3e2629bd1a (diff)
parent4b8152d5990e9bf52a0054cb7089cad17627f154 (diff)
Merge pull request #8519 from Paulb23/change_case_issue_8079
Ability to Convert Case, issue 8079
Diffstat (limited to 'editor/plugins/script_text_editor.cpp')
-rw-r--r--editor/plugins/script_text_editor.cpp65
1 files changed, 64 insertions, 1 deletions
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index e942d6cebd..84aa4739ea 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -240,6 +240,48 @@ Variant ScriptTextEditor::get_edit_state() {
return state;
}
+void ScriptTextEditor::_convert_case(CaseStyle p_case) {
+ TextEdit *te = code_editor->get_text_edit();
+ Ref<Script> scr = get_edited_script();
+ if (scr.is_null()) {
+ return;
+ }
+
+ if (te->is_selection_active()) {
+ te->begin_complex_operation();
+
+ int begin = te->get_selection_from_line();
+ int end = te->get_selection_to_line();
+ int begin_col = te->get_selection_from_column();
+ int end_col = te->get_selection_to_column();
+
+ for (int i = begin; i <= end; i++) {
+ String new_line = te->get_line(i);
+
+ switch (p_case) {
+ case UPPER: {
+ new_line = new_line.to_upper();
+ } break;
+ case LOWER: {
+ new_line = new_line.to_lower();
+ } break;
+ case CAPITALIZE: {
+ new_line = new_line.capitalize();
+ } break;
+ }
+
+ if (i == begin) {
+ new_line = te->get_line(i).left(begin_col) + new_line.right(begin_col);
+ }
+ if (i == end) {
+ new_line = new_line.left(end_col) + te->get_line(i).right(end_col);
+ }
+ te->set_line(i, new_line);
+ }
+ te->end_complex_operation();
+ }
+}
+
void ScriptTextEditor::trim_trailing_whitespace() {
TextEdit *tx = code_editor->get_text_edit();
@@ -919,7 +961,15 @@ void ScriptTextEditor::_edit_option(int p_op) {
case EDIT_PICK_COLOR: {
color_panel->popup();
} break;
-
+ case EDIT_TO_UPPERCASE: {
+ _convert_case(UPPER);
+ } break;
+ case EDIT_TO_LOWERCASE: {
+ _convert_case(LOWER);
+ } break;
+ case EDIT_CAPITALIZE: {
+ _convert_case(CAPITALIZE);
+ } break;
case SEARCH_FIND: {
code_editor->get_find_replace_bar()->popup_search();
@@ -1335,6 +1385,15 @@ ScriptTextEditor::ScriptTextEditor() {
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_breakpoints"), DEBUG_REMOVE_ALL_BREAKPOINTS);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_breakpoint"), DEBUG_GOTO_NEXT_BREAKPOINT);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_breakpoint"), DEBUG_GOTO_PREV_BREAKPOINT);
+ edit_menu->get_popup()->add_separator();
+ PopupMenu *convert_case = memnew(PopupMenu);
+ convert_case->set_name("convert_case");
+ edit_menu->get_popup()->add_child(convert_case);
+ edit_menu->get_popup()->add_submenu_item(TTR("Convert Case"), "convert_case");
+ convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/convert_to_uppercase", TTR("Uppercase")), EDIT_TO_UPPERCASE);
+ convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/convert_to_lowercase", TTR("Lowercase")), EDIT_TO_LOWERCASE);
+ convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/capitalize", TTR("Capitalize")), EDIT_CAPITALIZE);
+ convert_case->connect("id_pressed", this, "_edit_option");
search_menu = memnew(MenuButton);
edit_hb->add_child(search_menu);
@@ -1405,6 +1464,10 @@ void ScriptTextEditor::register_editor() {
ED_SHORTCUT("script_text_editor/goto_next_breakpoint", TTR("Goto Next Breakpoint"), KEY_MASK_CTRL | KEY_PERIOD);
ED_SHORTCUT("script_text_editor/goto_previous_breakpoint", TTR("Goto Previous Breakpoint"), KEY_MASK_CTRL | KEY_COMMA);
+ ED_SHORTCUT("script_text_editor/convert_to_uppercase", TTR("Convert To Uppercase"), KEY_MASK_SHIFT | KEY_F4);
+ ED_SHORTCUT("script_text_editor/convert_to_lowercase", TTR("Convert To Lowercase"), KEY_MASK_SHIFT | KEY_F3);
+ ED_SHORTCUT("script_text_editor/capitalize", TTR("Capitalize"), KEY_MASK_SHIFT | KEY_F2);
+
ED_SHORTCUT("script_text_editor/find", TTR("Find.."), KEY_MASK_CMD | KEY_F);
ED_SHORTCUT("script_text_editor/find_next", TTR("Find Next"), KEY_F3);
ED_SHORTCUT("script_text_editor/find_previous", TTR("Find Previous"), KEY_MASK_SHIFT | KEY_F3);