diff options
Diffstat (limited to 'scene/gui/text_edit.cpp')
-rw-r--r-- | scene/gui/text_edit.cpp | 202 |
1 files changed, 107 insertions, 95 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index cbc0c283de..f1b061c506 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -32,7 +32,7 @@ #include "os/input.h" #include "os/os.h" -#include "globals.h" +#include "global_config.h" #include "message_queue.h" #include "scene/main/viewport.h" @@ -247,7 +247,7 @@ void TextEdit::Text::clear_caches() { void TextEdit::Text::clear() { - text.clear();; + text.clear(); insert(0,""); } @@ -482,14 +482,6 @@ void TextEdit::_notification(int p_what) { Color color = cache.font_color; int in_region=-1; - if (line_length_guideline) { - int x=xmargin_beg+cache.font->get_char_size('0').width*line_length_guideline_col-cursor.x_ofs; - if (x>xmargin_beg && x<xmargin_end) { - Color guideline_color(color.r,color.g,color.b,color.a*0.25f); - VisualServer::get_singleton()->canvas_item_add_line(ci,Point2(x,0),Point2(x,cache.size.height),guideline_color); - } - } - if (syntax_coloring) { if (cache.background_color.a>0.01) { @@ -1080,6 +1072,14 @@ void TextEdit::_notification(int p_what) { } } + if (line_length_guideline) { + int x=xmargin_beg+cache.font->get_char_size('0').width*line_length_guideline_col-cursor.x_ofs; + if (x>xmargin_beg && x<xmargin_end) { + VisualServer::get_singleton()->canvas_item_add_line(ci,Point2(x,0),Point2(x,cache.size.height),cache.line_length_guideline_color); + } + } + + bool completion_below = false; if (completion_active) { // code completion box @@ -2431,6 +2431,8 @@ void TextEdit::_gui_input(const InputEvent& p_gui_input) { if (k.mod.shift) _post_shift_selection(); + else if(k.mod.command || k.mod.control) + deselect(); } break; #else @@ -2440,25 +2442,30 @@ void TextEdit::_gui_input(const InputEvent& p_gui_input) { if (k.mod.shift) _pre_shift_selection(); - // compute whitespace symbols seq length - int current_line_whitespace_len = 0; - while(current_line_whitespace_len < text[cursor.line].length()) { - CharType c = text[cursor.line][current_line_whitespace_len]; - if(c != '\t' && c != ' ') - break; - current_line_whitespace_len++; - } - - if(cursor_get_column() == current_line_whitespace_len) + if (k.mod.command) { + cursor_set_line(0); cursor_set_column(0); - else - cursor_set_column(current_line_whitespace_len); + } + else { + // compute whitespace symbols seq length + int current_line_whitespace_len = 0; + while( current_line_whitespace_len < text[cursor.line].length() ) { + CharType c = text[cursor.line][current_line_whitespace_len]; + if( c != '\t' && c != ' ' ) + break; + current_line_whitespace_len++; + } - if (k.mod.command) - cursor_set_line(0); + if( cursor_get_column() == current_line_whitespace_len ) + cursor_set_column(0); + else + cursor_set_column(current_line_whitespace_len); + } if (k.mod.shift) _post_shift_selection(); + else if(k.mod.command || k.mod.control) + deselect(); _cancel_completion(); completion_hint=""; @@ -2481,6 +2488,8 @@ void TextEdit::_gui_input(const InputEvent& p_gui_input) { if (k.mod.shift) _post_shift_selection(); + else if(k.mod.command || k.mod.control) + deselect(); } break; #else @@ -2495,6 +2504,8 @@ void TextEdit::_gui_input(const InputEvent& p_gui_input) { if (k.mod.shift) _post_shift_selection(); + else if(k.mod.command || k.mod.control) + deselect(); _cancel_completion(); completion_hint=""; @@ -3036,7 +3047,7 @@ void TextEdit::adjust_viewport_to_cursor() { cursor.line_ofs=cursor.line; int visible_width=cache.size.width-cache.style_normal->get_minimum_size().width-cache.line_number_w-cache.breakpoint_gutter_width; - if (v_scroll->is_visible()) + if (v_scroll->is_visible_in_tree()) visible_width-=v_scroll->get_combined_minimum_size().width; visible_width-=20; // give it a little more space @@ -3044,7 +3055,7 @@ void TextEdit::adjust_viewport_to_cursor() { //printf("rowofs %i, visrows %i, cursor.line %i\n",cursor.line_ofs,get_visible_rows(),cursor.line); int visible_rows = get_visible_rows(); - if (h_scroll->is_visible()) + if (h_scroll->is_visible_in_tree()) visible_rows-=((h_scroll->get_combined_minimum_size().height-1)/get_row_height()); if (cursor.line>=(cursor.line_ofs+visible_rows)) @@ -3078,12 +3089,12 @@ void TextEdit::center_viewport_to_cursor() { cursor.line_ofs=cursor.line; int visible_width=cache.size.width-cache.style_normal->get_minimum_size().width-cache.line_number_w-cache.breakpoint_gutter_width; - if (v_scroll->is_visible()) + if (v_scroll->is_visible_in_tree()) visible_width-=v_scroll->get_combined_minimum_size().width; visible_width-=20; // give it a little more space int visible_rows = get_visible_rows(); - if (h_scroll->is_visible()) + if (h_scroll->is_visible_in_tree()) visible_rows-=((h_scroll->get_combined_minimum_size().height-1)/get_row_height()); int max_ofs = text.size()-(scroll_past_end_of_file_enabled?1:visible_rows); @@ -3205,9 +3216,9 @@ void TextEdit::_scroll_moved(double p_to_val) { if (updating_scrolls) return; - if (h_scroll->is_visible()) + if (h_scroll->is_visible_in_tree()) cursor.x_ofs=h_scroll->get_value(); - if (v_scroll->is_visible()) + if (v_scroll->is_visible_in_tree()) cursor.line_ofs=v_scroll->get_value(); update(); } @@ -3458,7 +3469,7 @@ void TextEdit::_reset_caret_blink_timer() { void TextEdit::_toggle_draw_caret() { draw_caret = !draw_caret; - if (is_visible() && has_focus() && window_has_focus) { + if (is_visible_in_tree() && has_focus() && window_has_focus) { update(); } } @@ -3484,6 +3495,7 @@ void TextEdit::_update_caches() { cache.selection_color=get_color("selection_color"); cache.mark_color=get_color("mark_color"); cache.current_line_color=get_color("current_line_color"); + cache.line_length_guideline_color=get_color("line_length_guideline_color"); cache.breakpoint_color=get_color("breakpoint_color"); cache.brace_mismatch_color=get_color("brace_mismatch_color"); cache.word_highlighted_color=get_color("word_highlighted_color"); @@ -4255,7 +4267,7 @@ void TextEdit::_update_completion_candidates() { //no completion here //print_line("cancel!"); cancel=true; - } if (inquote && first_quote!=-1) { + } else if (inquote && first_quote!=-1) { s=l.substr(first_quote,cofs-first_quote); //print_line("s: 1"+s); @@ -4357,7 +4369,7 @@ void TextEdit::_update_completion_candidates() { if (completion_options.size()==1) { //one option to complete, just complete it automagically _confirm_completion(); - // insert_text_at_cursor(completion_options[0].substr(s.length(),completion_options[0].length()-s.length())); + //insert_text_at_cursor(completion_options[0].substr(s.length(),completion_options[0].length()-s.length())); _cancel_completion(); return; @@ -4608,90 +4620,90 @@ PopupMenu *TextEdit::get_menu() const { void TextEdit::_bind_methods() { - ClassDB::bind_method(_MD("_gui_input"),&TextEdit::_gui_input); - ClassDB::bind_method(_MD("_scroll_moved"),&TextEdit::_scroll_moved); - ClassDB::bind_method(_MD("_cursor_changed_emit"),&TextEdit::_cursor_changed_emit); - ClassDB::bind_method(_MD("_text_changed_emit"),&TextEdit::_text_changed_emit); - ClassDB::bind_method(_MD("_push_current_op"),&TextEdit::_push_current_op); - ClassDB::bind_method(_MD("_click_selection_held"),&TextEdit::_click_selection_held); - ClassDB::bind_method(_MD("_toggle_draw_caret"),&TextEdit::_toggle_draw_caret); + ClassDB::bind_method(D_METHOD("_gui_input"),&TextEdit::_gui_input); + ClassDB::bind_method(D_METHOD("_scroll_moved"),&TextEdit::_scroll_moved); + ClassDB::bind_method(D_METHOD("_cursor_changed_emit"),&TextEdit::_cursor_changed_emit); + ClassDB::bind_method(D_METHOD("_text_changed_emit"),&TextEdit::_text_changed_emit); + ClassDB::bind_method(D_METHOD("_push_current_op"),&TextEdit::_push_current_op); + ClassDB::bind_method(D_METHOD("_click_selection_held"),&TextEdit::_click_selection_held); + ClassDB::bind_method(D_METHOD("_toggle_draw_caret"),&TextEdit::_toggle_draw_caret); BIND_CONSTANT( SEARCH_MATCH_CASE ); BIND_CONSTANT( SEARCH_WHOLE_WORDS ); BIND_CONSTANT( SEARCH_BACKWARDS ); /* - ClassDB::bind_method(_MD("delete_char"),&TextEdit::delete_char); - ClassDB::bind_method(_MD("delete_line"),&TextEdit::delete_line); + ClassDB::bind_method(D_METHOD("delete_char"),&TextEdit::delete_char); + ClassDB::bind_method(D_METHOD("delete_line"),&TextEdit::delete_line); */ - ClassDB::bind_method(_MD("set_text","text"),&TextEdit::set_text); - ClassDB::bind_method(_MD("insert_text_at_cursor","text"),&TextEdit::insert_text_at_cursor); + ClassDB::bind_method(D_METHOD("set_text","text"),&TextEdit::set_text); + ClassDB::bind_method(D_METHOD("insert_text_at_cursor","text"),&TextEdit::insert_text_at_cursor); - ClassDB::bind_method(_MD("get_line_count"),&TextEdit::get_line_count); - ClassDB::bind_method(_MD("get_text"),&TextEdit::get_text); - ClassDB::bind_method(_MD("get_line","line"),&TextEdit::get_line); + ClassDB::bind_method(D_METHOD("get_line_count"),&TextEdit::get_line_count); + ClassDB::bind_method(D_METHOD("get_text"),&TextEdit::get_text); + ClassDB::bind_method(D_METHOD("get_line","line"),&TextEdit::get_line); - ClassDB::bind_method(_MD("cursor_set_column","column","adjust_viewport"),&TextEdit::cursor_set_column,DEFVAL(false)); - ClassDB::bind_method(_MD("cursor_set_line","line","adjust_viewport"),&TextEdit::cursor_set_line,DEFVAL(false)); + ClassDB::bind_method(D_METHOD("cursor_set_column","column","adjust_viewport"),&TextEdit::cursor_set_column,DEFVAL(false)); + ClassDB::bind_method(D_METHOD("cursor_set_line","line","adjust_viewport"),&TextEdit::cursor_set_line,DEFVAL(false)); - ClassDB::bind_method(_MD("cursor_get_column"),&TextEdit::cursor_get_column); - ClassDB::bind_method(_MD("cursor_get_line"),&TextEdit::cursor_get_line); - ClassDB::bind_method(_MD("cursor_set_blink_enabled", "enable"),&TextEdit::cursor_set_blink_enabled); - ClassDB::bind_method(_MD("cursor_get_blink_enabled"),&TextEdit::cursor_get_blink_enabled); - ClassDB::bind_method(_MD("cursor_set_blink_speed", "blink_speed"),&TextEdit::cursor_set_blink_speed); - ClassDB::bind_method(_MD("cursor_get_blink_speed"),&TextEdit::cursor_get_blink_speed); - ClassDB::bind_method(_MD("cursor_set_block_mode", "enable"), &TextEdit::cursor_set_block_mode); - ClassDB::bind_method(_MD("cursor_is_block_mode"), &TextEdit::cursor_is_block_mode); + ClassDB::bind_method(D_METHOD("cursor_get_column"),&TextEdit::cursor_get_column); + ClassDB::bind_method(D_METHOD("cursor_get_line"),&TextEdit::cursor_get_line); + ClassDB::bind_method(D_METHOD("cursor_set_blink_enabled", "enable"),&TextEdit::cursor_set_blink_enabled); + ClassDB::bind_method(D_METHOD("cursor_get_blink_enabled"),&TextEdit::cursor_get_blink_enabled); + ClassDB::bind_method(D_METHOD("cursor_set_blink_speed", "blink_speed"),&TextEdit::cursor_set_blink_speed); + ClassDB::bind_method(D_METHOD("cursor_get_blink_speed"),&TextEdit::cursor_get_blink_speed); + ClassDB::bind_method(D_METHOD("cursor_set_block_mode", "enable"), &TextEdit::cursor_set_block_mode); + ClassDB::bind_method(D_METHOD("cursor_is_block_mode"), &TextEdit::cursor_is_block_mode); - ClassDB::bind_method(_MD("set_readonly","enable"),&TextEdit::set_readonly); - ClassDB::bind_method(_MD("set_wrap","enable"),&TextEdit::set_wrap); - ClassDB::bind_method(_MD("set_max_chars","amount"),&TextEdit::set_max_chars); + ClassDB::bind_method(D_METHOD("set_readonly","enable"),&TextEdit::set_readonly); + ClassDB::bind_method(D_METHOD("set_wrap","enable"),&TextEdit::set_wrap); + ClassDB::bind_method(D_METHOD("set_max_chars","amount"),&TextEdit::set_max_chars); - ClassDB::bind_method(_MD("cut"),&TextEdit::cut); - ClassDB::bind_method(_MD("copy"),&TextEdit::copy); - ClassDB::bind_method(_MD("paste"),&TextEdit::paste); - ClassDB::bind_method(_MD("select_all"),&TextEdit::select_all); - ClassDB::bind_method(_MD("select","from_line","from_column","to_line","to_column"),&TextEdit::select); + ClassDB::bind_method(D_METHOD("cut"),&TextEdit::cut); + ClassDB::bind_method(D_METHOD("copy"),&TextEdit::copy); + ClassDB::bind_method(D_METHOD("paste"),&TextEdit::paste); + ClassDB::bind_method(D_METHOD("select_all"),&TextEdit::select_all); + ClassDB::bind_method(D_METHOD("select","from_line","from_column","to_line","to_column"),&TextEdit::select); - ClassDB::bind_method(_MD("is_selection_active"),&TextEdit::is_selection_active); - ClassDB::bind_method(_MD("get_selection_from_line"),&TextEdit::get_selection_from_line); - ClassDB::bind_method(_MD("get_selection_from_column"),&TextEdit::get_selection_from_column); - ClassDB::bind_method(_MD("get_selection_to_line"),&TextEdit::get_selection_to_line); - ClassDB::bind_method(_MD("get_selection_to_column"),&TextEdit::get_selection_to_column); - ClassDB::bind_method(_MD("get_selection_text"),&TextEdit::get_selection_text); - ClassDB::bind_method(_MD("get_word_under_cursor"),&TextEdit::get_word_under_cursor); - ClassDB::bind_method(_MD("search","flags","from_line","from_column","to_line","to_column"),&TextEdit::_search_bind); + ClassDB::bind_method(D_METHOD("is_selection_active"),&TextEdit::is_selection_active); + ClassDB::bind_method(D_METHOD("get_selection_from_line"),&TextEdit::get_selection_from_line); + ClassDB::bind_method(D_METHOD("get_selection_from_column"),&TextEdit::get_selection_from_column); + ClassDB::bind_method(D_METHOD("get_selection_to_line"),&TextEdit::get_selection_to_line); + ClassDB::bind_method(D_METHOD("get_selection_to_column"),&TextEdit::get_selection_to_column); + ClassDB::bind_method(D_METHOD("get_selection_text"),&TextEdit::get_selection_text); + ClassDB::bind_method(D_METHOD("get_word_under_cursor"),&TextEdit::get_word_under_cursor); + ClassDB::bind_method(D_METHOD("search","flags","from_line","from_column","to_line","to_column"),&TextEdit::_search_bind); - ClassDB::bind_method(_MD("undo"),&TextEdit::undo); - ClassDB::bind_method(_MD("redo"),&TextEdit::redo); - ClassDB::bind_method(_MD("clear_undo_history"),&TextEdit::clear_undo_history); + ClassDB::bind_method(D_METHOD("undo"),&TextEdit::undo); + ClassDB::bind_method(D_METHOD("redo"),&TextEdit::redo); + ClassDB::bind_method(D_METHOD("clear_undo_history"),&TextEdit::clear_undo_history); - ClassDB::bind_method(_MD("set_show_line_numbers", "enable"), &TextEdit::set_show_line_numbers); - ClassDB::bind_method(_MD("is_show_line_numbers_enabled"), &TextEdit::is_show_line_numbers_enabled); + ClassDB::bind_method(D_METHOD("set_show_line_numbers", "enable"), &TextEdit::set_show_line_numbers); + ClassDB::bind_method(D_METHOD("is_show_line_numbers_enabled"), &TextEdit::is_show_line_numbers_enabled); - ClassDB::bind_method(_MD("set_highlight_all_occurrences", "enable"), &TextEdit::set_highlight_all_occurrences); - ClassDB::bind_method(_MD("is_highlight_all_occurrences_enabled"), &TextEdit::is_highlight_all_occurrences_enabled); + ClassDB::bind_method(D_METHOD("set_highlight_all_occurrences", "enable"), &TextEdit::set_highlight_all_occurrences); + ClassDB::bind_method(D_METHOD("is_highlight_all_occurrences_enabled"), &TextEdit::is_highlight_all_occurrences_enabled); - ClassDB::bind_method(_MD("set_syntax_coloring","enable"),&TextEdit::set_syntax_coloring); - ClassDB::bind_method(_MD("is_syntax_coloring_enabled"),&TextEdit::is_syntax_coloring_enabled); + ClassDB::bind_method(D_METHOD("set_syntax_coloring","enable"),&TextEdit::set_syntax_coloring); + ClassDB::bind_method(D_METHOD("is_syntax_coloring_enabled"),&TextEdit::is_syntax_coloring_enabled); - ClassDB::bind_method(_MD("add_keyword_color","keyword","color"),&TextEdit::add_keyword_color); - ClassDB::bind_method(_MD("add_color_region","begin_key","end_key","color","line_only"),&TextEdit::add_color_region,DEFVAL(false)); - ClassDB::bind_method(_MD("clear_colors"),&TextEdit::clear_colors); - ClassDB::bind_method(_MD("menu_option"),&TextEdit::menu_option); - ClassDB::bind_method(_MD("get_menu:PopupMenu"),&TextEdit::get_menu); + ClassDB::bind_method(D_METHOD("add_keyword_color","keyword","color"),&TextEdit::add_keyword_color); + ClassDB::bind_method(D_METHOD("add_color_region","begin_key","end_key","color","line_only"),&TextEdit::add_color_region,DEFVAL(false)); + ClassDB::bind_method(D_METHOD("clear_colors"),&TextEdit::clear_colors); + ClassDB::bind_method(D_METHOD("menu_option"),&TextEdit::menu_option); + ClassDB::bind_method(D_METHOD("get_menu:PopupMenu"),&TextEdit::get_menu); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "syntax_highlighting"), _SCS("set_syntax_coloring"), _SCS("is_syntax_coloring_enabled")); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_line_numbers"), _SCS("set_show_line_numbers"), _SCS("is_show_line_numbers_enabled")); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "highlight_all_occurrences"), _SCS("set_highlight_all_occurrences"), _SCS("is_highlight_all_occurrences_enabled")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "syntax_highlighting"), "set_syntax_coloring", "is_syntax_coloring_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_line_numbers"), "set_show_line_numbers", "is_show_line_numbers_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "highlight_all_occurrences"), "set_highlight_all_occurrences", "is_highlight_all_occurrences_enabled"); ADD_GROUP("Caret","caret_"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_block_mode"), _SCS("cursor_set_block_mode"), _SCS("cursor_is_block_mode")); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), _SCS("cursor_set_blink_enabled"), _SCS("cursor_get_blink_enabled")); - ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "caret_blink_speed",PROPERTY_HINT_RANGE,"0.1,10,0.1"), _SCS("cursor_set_blink_speed"),_SCS("cursor_get_blink_speed") ); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_block_mode"), "cursor_set_block_mode", "cursor_is_block_mode"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), "cursor_set_blink_enabled", "cursor_get_blink_enabled"); + ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "caret_blink_speed",PROPERTY_HINT_RANGE,"0.1,10,0.1"), "cursor_set_blink_speed","cursor_get_blink_speed") ; ADD_SIGNAL(MethodInfo("cursor_changed")); ADD_SIGNAL(MethodInfo("text_changed")); @@ -4732,8 +4744,8 @@ TextEdit::TextEdit() { tab_size=4; text.set_tab_size(tab_size); text.clear(); - // text.insert(1,"Mongolia.."); - // text.insert(2,"PAIS GENEROSO!!"); + //text.insert(1,"Mongolia.."); + //text.insert(2,"PAIS GENEROSO!!"); text.set_color_regions(&color_regions); h_scroll = memnew( HScrollBar ); |