2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* text_edit.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2016-01-01 14:50:53 +01:00
|
|
|
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#ifndef TEXT_EDIT_H
|
|
|
|
#define TEXT_EDIT_H
|
|
|
|
|
|
|
|
#include "scene/gui/control.h"
|
|
|
|
#include "scene/gui/scroll_bar.h"
|
|
|
|
#include "scene/main/timer.h"
|
|
|
|
|
|
|
|
|
|
|
|
class TextEdit : public Control {
|
|
|
|
|
|
|
|
OBJ_TYPE( TextEdit, Control );
|
|
|
|
|
|
|
|
struct Cursor {
|
|
|
|
int last_fit_x;
|
|
|
|
int line,column; ///< cursor
|
|
|
|
int x_ofs,line_ofs;
|
|
|
|
} cursor;
|
|
|
|
|
|
|
|
struct Selection {
|
|
|
|
|
|
|
|
enum Mode {
|
|
|
|
|
|
|
|
MODE_NONE,
|
|
|
|
MODE_SHIFT,
|
|
|
|
MODE_POINTER
|
|
|
|
};
|
|
|
|
|
|
|
|
Mode selecting_mode;
|
|
|
|
int selecting_line,selecting_column;
|
2015-08-13 00:34:07 +02:00
|
|
|
bool selecting_text;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
bool active;
|
|
|
|
|
|
|
|
int from_line,from_column;
|
|
|
|
int to_line,to_column;
|
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
bool shiftclick_left;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} selection;
|
|
|
|
|
|
|
|
struct Cache {
|
|
|
|
|
|
|
|
Ref<Texture> tab_icon;
|
|
|
|
Ref<StyleBox> style_normal;
|
|
|
|
Ref<StyleBox> style_focus;
|
|
|
|
Ref<Font> font;
|
|
|
|
Color font_color;
|
|
|
|
Color font_selected_color;
|
|
|
|
Color keyword_color;
|
|
|
|
Color selection_color;
|
|
|
|
Color mark_color;
|
|
|
|
Color breakpoint_color;
|
|
|
|
Color current_line_color;
|
2014-12-17 05:53:34 +01:00
|
|
|
Color brace_mismatch_color;
|
2016-03-16 22:20:42 +01:00
|
|
|
Color word_highlighted_color;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
int row_height;
|
|
|
|
int line_spacing;
|
|
|
|
int line_number_w;
|
|
|
|
Size2 size;
|
|
|
|
} cache;
|
|
|
|
|
|
|
|
struct ColorRegion {
|
|
|
|
|
|
|
|
Color color;
|
|
|
|
String begin_key;
|
|
|
|
String end_key;
|
|
|
|
bool line_only;
|
|
|
|
bool eq;
|
|
|
|
ColorRegion(const String& p_begin_key="",const String& p_end_key="",const Color &p_color=Color(),bool p_line_only=false) { begin_key=p_begin_key; end_key=p_end_key; color=p_color; line_only=p_line_only || p_end_key==""; eq=begin_key==end_key; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class Text {
|
|
|
|
public:
|
|
|
|
struct ColorRegionInfo {
|
|
|
|
|
|
|
|
int region;
|
|
|
|
bool end;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Line {
|
|
|
|
int width_cache : 24;
|
|
|
|
bool marked : 1;
|
|
|
|
bool breakpoint : 1;
|
|
|
|
Map<int,ColorRegionInfo> region_info;
|
|
|
|
String data;
|
|
|
|
};
|
|
|
|
private:
|
|
|
|
const Vector<ColorRegion> *color_regions;
|
|
|
|
mutable Vector<Line> text;
|
|
|
|
Ref<Font> font;
|
|
|
|
int tab_size;
|
|
|
|
|
|
|
|
void _update_line_cache(int p_line) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
void set_tab_size(int p_tab_size);
|
|
|
|
void set_font(const Ref<Font>& p_font);
|
|
|
|
void set_color_regions(const Vector<ColorRegion>*p_regions) { color_regions=p_regions; }
|
|
|
|
int get_line_width(int p_line) const;
|
2016-03-09 00:00:52 +01:00
|
|
|
int get_max_width() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
const Map<int,ColorRegionInfo>& get_color_region_info(int p_line);
|
|
|
|
void set(int p_line,const String& p_string);
|
|
|
|
void set_marked(int p_line,bool p_marked) { text[p_line].marked=p_marked; }
|
|
|
|
bool is_marked(int p_line) const { return text[p_line].marked; }
|
|
|
|
void set_breakpoint(int p_line,bool p_breakpoint) { text[p_line].breakpoint=p_breakpoint; }
|
|
|
|
bool is_breakpoint(int p_line) const { return text[p_line].breakpoint; }
|
|
|
|
void insert(int p_at,const String& p_text);
|
|
|
|
void remove(int p_at);
|
|
|
|
int size() const { return text.size(); }
|
|
|
|
void clear();
|
|
|
|
void clear_caches();
|
2014-11-12 15:39:21 +01:00
|
|
|
_FORCE_INLINE_ const String& operator[](int p_line) const { return text[p_line].data; }
|
2014-02-10 02:10:30 +01:00
|
|
|
Text() { tab_size=4; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TextOperation {
|
|
|
|
|
|
|
|
enum Type {
|
|
|
|
TYPE_NONE,
|
|
|
|
TYPE_INSERT,
|
|
|
|
TYPE_REMOVE
|
|
|
|
};
|
|
|
|
|
|
|
|
Type type;
|
|
|
|
int from_line,from_column;
|
|
|
|
int to_line, to_column;
|
|
|
|
String text;
|
2016-03-13 21:08:12 +01:00
|
|
|
uint32_t prev_version;
|
2014-02-10 02:10:30 +01:00
|
|
|
uint32_t version;
|
|
|
|
bool chain_forward;
|
|
|
|
bool chain_backward;
|
|
|
|
};
|
|
|
|
|
|
|
|
TextOperation current_op;
|
|
|
|
|
|
|
|
List<TextOperation> undo_stack;
|
2014-08-02 03:10:38 +02:00
|
|
|
List<TextOperation>::Element *undo_stack_pos;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void _clear_redo();
|
|
|
|
void _do_text_op(const TextOperation& p_op, bool p_reverse);
|
|
|
|
|
|
|
|
|
|
|
|
//syntax coloring
|
|
|
|
Color symbol_color;
|
|
|
|
HashMap<String,Color> keywords;
|
|
|
|
Color custom_bg_color;
|
|
|
|
|
|
|
|
Vector<ColorRegion> color_regions;
|
|
|
|
|
|
|
|
Set<String> completion_prefixes;
|
|
|
|
bool completion_enabled;
|
|
|
|
Vector<String> completion_strings;
|
|
|
|
Vector<String> completion_options;
|
|
|
|
bool completion_active;
|
|
|
|
String completion_current;
|
|
|
|
String completion_base;
|
|
|
|
int completion_index;
|
|
|
|
Rect2i completion_rect;
|
|
|
|
int completion_line_ofs;
|
2014-12-17 02:31:57 +01:00
|
|
|
String completion_hint;
|
|
|
|
int completion_hint_offset;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
bool setting_text;
|
|
|
|
|
|
|
|
// data
|
|
|
|
Text text;
|
|
|
|
|
|
|
|
uint32_t version;
|
|
|
|
uint32_t saved_version;
|
|
|
|
|
|
|
|
int max_chars;
|
|
|
|
bool readonly;
|
|
|
|
bool syntax_coloring;
|
|
|
|
int tab_size;
|
|
|
|
|
|
|
|
bool setting_row;
|
|
|
|
bool wrap;
|
|
|
|
bool draw_tabs;
|
|
|
|
bool cursor_changed_dirty;
|
|
|
|
bool text_changed_dirty;
|
|
|
|
bool undo_enabled;
|
|
|
|
bool line_numbers;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-16 22:20:42 +01:00
|
|
|
bool highlight_all_occurrences;
|
2016-03-07 03:32:51 +01:00
|
|
|
bool scroll_past_end_of_file_enabled;
|
2014-04-30 18:21:58 +02:00
|
|
|
bool auto_brace_completion_enabled;
|
2014-12-17 05:53:34 +01:00
|
|
|
bool brace_matching_enabled;
|
2015-11-29 17:02:35 +01:00
|
|
|
bool auto_indent;
|
2014-08-02 03:10:38 +02:00
|
|
|
bool cut_copy_line;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
uint64_t last_dblclk;
|
|
|
|
|
|
|
|
Timer *idle_detect;
|
2015-12-09 19:56:41 +01:00
|
|
|
Timer *click_select_held;
|
2014-02-10 02:10:30 +01:00
|
|
|
HScrollBar *h_scroll;
|
|
|
|
VScrollBar *v_scroll;
|
|
|
|
bool updating_scrolls;
|
|
|
|
|
|
|
|
|
|
|
|
Object *tooltip_obj;
|
|
|
|
StringName tooltip_func;
|
|
|
|
Variant tooltip_ud;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-04-26 14:42:19 +02:00
|
|
|
bool next_operation_is_complex;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-03-04 11:05:42 +01:00
|
|
|
bool callhint_below;
|
|
|
|
Vector2 callhint_offset;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
int get_visible_rows() const;
|
|
|
|
|
|
|
|
int get_char_count();
|
|
|
|
|
|
|
|
int get_char_pos_for(int p_px,String p_pos) const;
|
|
|
|
int get_column_x_offset(int p_column,String p_pos);
|
|
|
|
|
|
|
|
void adjust_viewport_to_cursor();
|
|
|
|
void _scroll_moved(double);
|
|
|
|
void _update_scrollbars();
|
2015-12-09 19:56:41 +01:00
|
|
|
void _click_selection_held();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void _pre_shift_selection();
|
|
|
|
void _post_shift_selection();
|
|
|
|
|
|
|
|
// void mouse_motion(const Point& p_pos, const Point& p_rel, int p_button_mask);
|
|
|
|
Size2 get_minimum_size();
|
|
|
|
|
|
|
|
int get_row_height() const;
|
|
|
|
|
|
|
|
void _update_caches();
|
|
|
|
void _cursor_changed_emit();
|
|
|
|
void _text_changed_emit();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-04-26 14:42:19 +02:00
|
|
|
void _begin_compex_operation();
|
|
|
|
void _end_compex_operation();
|
2014-02-10 02:10:30 +01:00
|
|
|
void _push_current_op();
|
|
|
|
|
|
|
|
/* super internal api, undo/redo builds on it */
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void _base_insert_text(int p_line, int p_column,const String& p_text,int &r_end_line,int &r_end_column);
|
|
|
|
String _base_get_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column) const;
|
|
|
|
void _base_remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column);
|
|
|
|
|
2016-03-16 22:20:42 +01:00
|
|
|
int _get_column_pos_of_word(const String &p_key, const String &p_search, int p_from_column);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
DVector<int> _search_bind(const String &p_key,uint32_t p_search_flags, int p_from_line,int p_from_column) const;
|
|
|
|
|
|
|
|
void _clear();
|
|
|
|
void _cancel_completion();
|
2014-12-17 02:31:57 +01:00
|
|
|
void _cancel_code_hint();
|
2014-02-10 02:10:30 +01:00
|
|
|
void _confirm_completion();
|
|
|
|
void _update_completion_candidates();
|
|
|
|
|
2015-11-07 13:39:03 +01:00
|
|
|
void _get_mouse_pos(const Point2i& p_mouse, int &r_row, int &r_col) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual String get_tooltip(const Point2& p_pos) const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void _insert_text(int p_line, int p_column,const String& p_text,int *r_end_line=NULL,int *r_end_char=NULL);
|
|
|
|
void _remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column);
|
|
|
|
void _insert_text_at_cursor(const String& p_text);
|
|
|
|
void _input_event(const InputEvent& p_input);
|
|
|
|
void _notification(int p_what);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-04-27 12:34:37 +02:00
|
|
|
void _consume_pair_symbol(CharType ch);
|
|
|
|
void _consume_backspace_for_pair_symbol(int prev_line, int prev_column);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum SearchFlags {
|
|
|
|
|
|
|
|
SEARCH_MATCH_CASE=1,
|
|
|
|
SEARCH_WHOLE_WORDS=2,
|
|
|
|
SEARCH_BACKWARDS=4
|
|
|
|
};
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-04-17 13:30:40 +02:00
|
|
|
virtual CursorShape get_cursor_shape(const Point2& p_pos=Point2i()) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
//void delete_char();
|
|
|
|
//void delete_line();
|
|
|
|
|
|
|
|
void set_text(String p_text);
|
|
|
|
void insert_text_at_cursor(const String& p_text);
|
2014-11-12 15:39:21 +01:00
|
|
|
void insert_at(const String& p_text, int at);
|
2014-02-10 02:10:30 +01:00
|
|
|
int get_line_count() const;
|
|
|
|
void set_line_as_marked(int p_line,bool p_marked);
|
|
|
|
void set_line_as_breakpoint(int p_line,bool p_breakpoint);
|
|
|
|
bool is_line_set_as_breakpoint(int p_line) const;
|
|
|
|
void get_breakpoints(List<int> *p_breakpoints) const;
|
|
|
|
String get_text();
|
|
|
|
String get_line(int line) const;
|
2014-11-12 15:39:21 +01:00
|
|
|
void set_line(int line, String new_text);
|
2014-02-10 02:10:30 +01:00
|
|
|
void backspace_at_cursor();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-07 03:32:51 +01:00
|
|
|
inline void set_scroll_pass_end_of_file(bool p_enabled) {
|
|
|
|
scroll_past_end_of_file_enabled = p_enabled;
|
|
|
|
update();
|
|
|
|
}
|
2014-04-30 18:21:58 +02:00
|
|
|
inline void set_auto_brace_completion(bool p_enabled) {
|
|
|
|
auto_brace_completion_enabled = p_enabled;
|
|
|
|
}
|
2014-12-17 05:53:34 +01:00
|
|
|
inline void set_brace_matching(bool p_enabled) {
|
|
|
|
brace_matching_enabled=p_enabled;
|
|
|
|
update();
|
|
|
|
}
|
2016-03-04 11:05:42 +01:00
|
|
|
inline void set_callhint_settings(bool below, Vector2 offset) {
|
|
|
|
callhint_below = below;
|
|
|
|
callhint_offset = offset;
|
|
|
|
}
|
2015-11-29 17:02:35 +01:00
|
|
|
void set_auto_indent(bool p_auto_indent);
|
2014-12-17 05:53:34 +01:00
|
|
|
|
2015-08-13 00:34:07 +02:00
|
|
|
void cursor_set_column(int p_col, bool p_adjust_viewport=true);
|
|
|
|
void cursor_set_line(int p_row, bool p_adjust_viewport=true);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
int cursor_get_column() const;
|
|
|
|
int cursor_get_line() const;
|
|
|
|
|
|
|
|
void set_readonly(bool p_readonly);
|
|
|
|
|
|
|
|
void set_max_chars(int p_max_chars);
|
|
|
|
void set_wrap(bool p_wrap);
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
void set_syntax_coloring(bool p_enabled);
|
|
|
|
bool is_syntax_coloring_enabled() const;
|
|
|
|
|
|
|
|
void cut();
|
|
|
|
void copy();
|
|
|
|
void paste();
|
|
|
|
void select_all();
|
|
|
|
void select(int p_from_line,int p_from_column,int p_to_line,int p_to_column);
|
|
|
|
void deselect();
|
|
|
|
|
2016-03-16 22:20:42 +01:00
|
|
|
void set_highlight_all_occurrences(const bool p_enabled);
|
2014-02-10 02:10:30 +01:00
|
|
|
bool is_selection_active() const;
|
|
|
|
int get_selection_from_line() const;
|
2014-08-02 03:10:38 +02:00
|
|
|
int get_selection_from_column() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
int get_selection_to_line() const;
|
|
|
|
int get_selection_to_column() const;
|
|
|
|
String get_selection_text() const;
|
|
|
|
|
2014-05-06 11:36:39 +02:00
|
|
|
String get_word_under_cursor() const;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
bool search(const String &p_key,uint32_t p_search_flags, int p_from_line, int p_from_column,int &r_line,int &r_column) const;
|
|
|
|
|
|
|
|
void undo();
|
|
|
|
void redo();
|
2014-12-17 02:31:57 +01:00
|
|
|
void clear_undo_history();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-03-11 19:10:01 +01:00
|
|
|
void set_tab_size(const int p_size);
|
2014-02-10 02:10:30 +01:00
|
|
|
void set_draw_tabs(bool p_draw);
|
|
|
|
bool is_drawing_tabs() const;
|
|
|
|
|
|
|
|
void add_keyword_color(const String& p_keyword,const Color& p_color);
|
|
|
|
void add_color_region(const String& p_begin_key=String(),const String& p_end_key=String(),const Color &p_color=Color(),bool p_line_only=false);
|
|
|
|
void set_symbol_color(const Color& p_color);
|
|
|
|
void set_custom_bg_color(const Color& p_color);
|
|
|
|
void clear_colors();
|
|
|
|
|
|
|
|
int get_v_scroll() const;
|
|
|
|
void set_v_scroll(int p_scroll);
|
|
|
|
|
|
|
|
int get_h_scroll() const;
|
|
|
|
void set_h_scroll(int p_scroll);
|
|
|
|
|
|
|
|
uint32_t get_version() const;
|
|
|
|
uint32_t get_saved_version() const;
|
|
|
|
void tag_saved_version();
|
|
|
|
|
|
|
|
void set_show_line_numbers(bool p_show);
|
|
|
|
|
|
|
|
void set_tooltip_request_func(Object *p_obj, const StringName& p_function, const Variant& p_udata);
|
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
void set_completion(bool p_enabled,const Vector<String>& p_prefixes);
|
2014-02-10 02:10:30 +01:00
|
|
|
void code_complete(const Vector<String> &p_strings);
|
2014-12-17 02:31:57 +01:00
|
|
|
void set_code_hint(const String& p_hint);
|
2014-02-10 02:10:30 +01:00
|
|
|
void query_code_comple();
|
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
String get_text_for_completion();
|
|
|
|
|
2015-10-17 15:29:54 +02:00
|
|
|
virtual bool is_text_field() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
TextEdit();
|
|
|
|
~TextEdit();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // TEXT_EDIT_H
|