2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* code_editor.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2016-01-01 13:50:53 +00:00
|
|
|
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 01:10:30 +00: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 CODE_EDITOR_H
|
|
|
|
#define CODE_EDITOR_H
|
|
|
|
|
|
|
|
#include "tools/editor/editor_plugin.h"
|
|
|
|
#include "scene/gui/text_edit.h"
|
|
|
|
#include "scene/gui/dialogs.h"
|
|
|
|
#include "scene/main/timer.h"
|
2016-05-28 16:25:45 +00:00
|
|
|
#include "scene/gui/tool_button.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/gui/check_button.h"
|
2016-05-28 16:25:45 +00:00
|
|
|
#include "scene/gui/check_box.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/gui/line_edit.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GotoLineDialog : public ConfirmationDialog {
|
|
|
|
|
|
|
|
OBJ_TYPE(GotoLineDialog,ConfirmationDialog);
|
|
|
|
|
|
|
|
Label *line_label;
|
|
|
|
LineEdit *line;
|
|
|
|
|
|
|
|
TextEdit *text_editor;
|
|
|
|
|
|
|
|
virtual void ok_pressed();
|
|
|
|
public:
|
|
|
|
|
|
|
|
void popup_find_line(TextEdit *p_edit);
|
|
|
|
int get_line() const;
|
|
|
|
|
|
|
|
|
|
|
|
void set_text_editor(TextEdit *p_text_editor);
|
2016-03-08 23:00:52 +00:00
|
|
|
GotoLineDialog();
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2016-05-28 16:25:45 +00:00
|
|
|
class FindReplaceBar : public HBoxContainer {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-28 16:25:45 +00:00
|
|
|
OBJ_TYPE(FindReplaceBar,HBoxContainer);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-28 16:25:45 +00:00
|
|
|
LineEdit *search_text;
|
|
|
|
ToolButton *find_prev;
|
|
|
|
ToolButton *find_next;
|
|
|
|
CheckBox *case_sensitive;
|
|
|
|
CheckBox *whole_words;
|
|
|
|
Label *error_label;
|
|
|
|
TextureButton *hide_button;
|
|
|
|
|
|
|
|
LineEdit *replace_text;
|
|
|
|
ToolButton *replace;
|
|
|
|
ToolButton *replace_all;
|
|
|
|
CheckBox *selection_only;
|
|
|
|
|
|
|
|
VBoxContainer *text_vbc;
|
|
|
|
HBoxContainer *replace_hbc;
|
|
|
|
HBoxContainer *replace_options_hbc;
|
|
|
|
|
|
|
|
TextEdit *text_edit;
|
|
|
|
|
2016-05-30 16:15:41 +00:00
|
|
|
int result_line;
|
|
|
|
int result_col;
|
2016-05-28 16:25:45 +00:00
|
|
|
|
|
|
|
bool replace_all_mode;
|
2016-05-30 16:15:41 +00:00
|
|
|
bool preserve_cursor;
|
|
|
|
|
|
|
|
void _get_search_from(int& r_line, int& r_col);
|
2016-05-28 16:25:45 +00:00
|
|
|
|
|
|
|
void _show_search();
|
|
|
|
void _hide_bar();
|
2016-05-30 16:15:41 +00:00
|
|
|
|
|
|
|
void _editor_text_changed();
|
2016-05-28 16:25:45 +00:00
|
|
|
void _search_options_changed(bool p_pressed);
|
|
|
|
void _search_text_changed(const String& p_text);
|
|
|
|
void _search_text_entered(const String& p_text);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
void _unhandled_input(const InputEvent &p_event);
|
|
|
|
|
2016-05-30 16:15:41 +00:00
|
|
|
bool _search(uint32_t p_flags, int p_from_line, int p_from_col);
|
2016-05-28 16:25:45 +00:00
|
|
|
|
|
|
|
void _replace();
|
|
|
|
void _replace_all();
|
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
String get_search_text() const;
|
|
|
|
String get_replace_text() const;
|
|
|
|
|
|
|
|
bool is_case_sensitive() const;
|
|
|
|
bool is_whole_words() const;
|
|
|
|
bool is_selection_only() const;
|
|
|
|
void set_error(const String& p_label);
|
|
|
|
|
|
|
|
void set_text_edit(TextEdit *p_text_edit);
|
|
|
|
|
|
|
|
void popup_search();
|
|
|
|
void popup_replace();
|
|
|
|
|
2016-05-30 16:15:41 +00:00
|
|
|
bool search_current();
|
|
|
|
bool search_prev();
|
|
|
|
bool search_next();
|
2016-05-28 16:25:45 +00:00
|
|
|
|
|
|
|
FindReplaceBar();
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
class FindReplaceDialog : public ConfirmationDialog {
|
|
|
|
|
|
|
|
OBJ_TYPE(FindReplaceDialog,ConfirmationDialog);
|
|
|
|
|
|
|
|
LineEdit *search_text;
|
|
|
|
LineEdit *replace_text;
|
|
|
|
CheckButton *whole_words;
|
|
|
|
CheckButton *case_sensitive;
|
|
|
|
CheckButton *backwards;
|
|
|
|
CheckButton *prompt;
|
|
|
|
CheckButton *selection_only;
|
|
|
|
Button *skip;
|
|
|
|
Label *error_label;
|
|
|
|
MarginContainer *replace_mc;
|
|
|
|
Label *replace_label;
|
|
|
|
VBoxContainer *replace_vb;
|
|
|
|
|
|
|
|
void _search_text_entered(const String& p_text);
|
|
|
|
void _replace_text_entered(const String& p_text);
|
|
|
|
void _prompt_changed();
|
|
|
|
void _skip_pressed();
|
|
|
|
|
|
|
|
|
|
|
|
TextEdit *text_edit;
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void _search_callback();
|
|
|
|
void _replace_skip_callback();
|
|
|
|
|
|
|
|
bool _search();
|
|
|
|
void _replace();
|
|
|
|
|
|
|
|
virtual void ok_pressed();
|
|
|
|
static void _bind_methods();
|
|
|
|
public:
|
|
|
|
|
|
|
|
String get_search_text() const;
|
|
|
|
String get_replace_text() const;
|
|
|
|
bool is_whole_words() const;
|
|
|
|
bool is_case_sensitive() const;
|
|
|
|
bool is_backwards() const;
|
|
|
|
bool is_replace_mode() const;
|
|
|
|
bool is_replace_all_mode() const;
|
|
|
|
bool is_replace_selection_only() const;
|
|
|
|
void set_replace_selection_only(bool p_enable);
|
|
|
|
|
|
|
|
void set_error(const String& p_error);
|
|
|
|
|
|
|
|
void popup_search();
|
|
|
|
void popup_replace();
|
|
|
|
|
|
|
|
void set_text_edit(TextEdit *p_text_edit);
|
|
|
|
|
|
|
|
void search_next();
|
|
|
|
FindReplaceDialog();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-05-28 16:25:45 +00:00
|
|
|
class CodeTextEditor : public VBoxContainer {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-28 16:25:45 +00:00
|
|
|
OBJ_TYPE(CodeTextEditor,VBoxContainer);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
TextEdit *text_editor;
|
2016-05-28 16:25:45 +00:00
|
|
|
FindReplaceBar *find_replace_bar;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-07-24 15:11:32 +00:00
|
|
|
Label *line_nb;
|
|
|
|
Label *col_nb;
|
2014-02-10 01:10:30 +00:00
|
|
|
Label *info;
|
|
|
|
Timer *idle;
|
2014-05-04 03:22:49 +00:00
|
|
|
Timer *code_complete_timer;
|
2014-05-21 22:01:11 +00:00
|
|
|
bool enable_complete_timer;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-17 19:58:50 +00:00
|
|
|
Timer *font_resize_timer;
|
|
|
|
int font_resize_val;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Label *error;
|
|
|
|
|
2014-04-30 16:21:58 +00:00
|
|
|
void _on_settings_change();
|
2014-04-05 15:39:30 +00:00
|
|
|
|
2016-05-29 14:37:26 +00:00
|
|
|
void _update_font();
|
2014-12-17 01:31:57 +00:00
|
|
|
void _complete_request();
|
2016-06-17 19:58:50 +00:00
|
|
|
void _font_resize_timeout();
|
|
|
|
|
|
|
|
void _text_editor_input_event(const InputEvent& p_event);
|
2016-07-14 19:03:40 +00:00
|
|
|
void _zoom_in();
|
|
|
|
void _zoom_out();
|
|
|
|
void _reset_zoom();
|
2016-06-17 19:58:50 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
void set_error(const String& p_error);
|
|
|
|
|
|
|
|
virtual void _load_theme_settings() {}
|
|
|
|
virtual void _validate_script()=0;
|
2014-12-17 01:31:57 +00:00
|
|
|
virtual void _code_complete_script(const String& p_code, List<String>* r_options) {};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void _text_changed_idle_timeout();
|
2014-05-04 03:22:49 +00:00
|
|
|
void _code_complete_timer_timeout();
|
2014-02-10 01:10:30 +00:00
|
|
|
void _text_changed();
|
|
|
|
void _line_col_changed();
|
|
|
|
void _notification(int);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
TextEdit *get_text_edit() { return text_editor; }
|
2016-05-28 16:25:45 +00:00
|
|
|
FindReplaceBar *get_find_replace_bar() { return find_replace_bar; }
|
2014-02-10 01:10:30 +00:00
|
|
|
virtual void apply_code() {}
|
|
|
|
|
|
|
|
CodeTextEditor();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // CODE_EDITOR_H
|