godot/editor/code_editor.h

241 lines
6.9 KiB
C++
Raw Normal View History

2014-02-10 01:10:30 +00:00
/*************************************************************************/
/* code_editor.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
2014-02-10 01:10:30 +00:00
/*************************************************************************/
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
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. */
/*************************************************************************/
2014-02-10 01:10:30 +00:00
#ifndef CODE_EDITOR_H
#define CODE_EDITOR_H
#include "editor/editor_plugin.h"
#include "scene/gui/check_box.h"
#include "scene/gui/check_button.h"
#include "scene/gui/dialogs.h"
2014-02-10 01:10:30 +00:00
#include "scene/gui/line_edit.h"
#include "scene/gui/text_edit.h"
#include "scene/gui/tool_button.h"
#include "scene/main/timer.h"
2014-02-10 01:10:30 +00:00
class GotoLineDialog : public ConfirmationDialog {
GDCLASS(GotoLineDialog, ConfirmationDialog);
2014-02-10 01:10:30 +00:00
Label *line_label;
LineEdit *line;
TextEdit *text_editor;
virtual void ok_pressed();
public:
2014-02-10 01:10:30 +00:00
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
};
class FindReplaceBar : public HBoxContainer {
2014-02-10 01:10:30 +00:00
GDCLASS(FindReplaceBar, HBoxContainer);
2014-02-10 01:10:30 +00:00
LineEdit *search_text;
ToolButton *find_prev;
ToolButton *find_next;
CheckBox *case_sensitive;
CheckBox *whole_words;
TextureButton *hide_button;
LineEdit *replace_text;
Button *replace;
Button *replace_all;
CheckBox *selection_only;
VBoxContainer *vbc_lineedit;
HBoxContainer *hbc_button_replace;
HBoxContainer *hbc_option_replace;
TextEdit *text_edit;
int result_line;
int result_col;
bool replace_all_mode;
bool preserve_cursor;
void _get_search_from(int &r_line, int &r_col);
void _show_search();
void _hide_bar();
void _editor_text_changed();
void _search_options_changed(bool p_pressed);
void _search_text_changed(const String &p_text);
void _search_text_entered(const String &p_text);
void _replace_text_entered(const String &p_text);
void _update_size();
protected:
void _notification(int p_what);
void _unhandled_input(const Ref<InputEvent> &p_event);
bool _search(uint32_t p_flags, int p_from_line, int p_from_col);
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();
bool search_current();
bool search_prev();
bool search_next();
FindReplaceBar();
};
2014-02-10 01:10:30 +00:00
typedef void (*CodeTextEditorCodeCompleteFunc)(void *p_ud, const String &p_code, List<String> *r_options, bool &r_forced);
class CodeTextEditor : public VBoxContainer {
2014-02-10 01:10:30 +00:00
GDCLASS(CodeTextEditor, VBoxContainer);
2014-02-10 01:10:30 +00:00
TextEdit *text_editor;
FindReplaceBar *find_replace_bar;
HBoxContainer *status_bar;
ToolButton *warning_button;
Label *warning_count_label;
2014-02-10 01:10:30 +00:00
Label *line_and_col_txt;
2014-02-10 01:10:30 +00:00
Label *info;
Timer *idle;
Timer *code_complete_timer;
2014-02-10 01:10:30 +00:00
Timer *font_resize_timer;
int font_resize_val;
2017-11-01 20:49:39 +00:00
real_t font_size;
Label *error;
int error_line;
int error_column;
2014-02-10 01:10:30 +00:00
2014-04-30 16:21:58 +00:00
void _on_settings_change();
void _update_font();
void _complete_request();
void _font_resize_timeout();
2017-11-01 20:49:39 +00:00
bool _add_font_size(int p_delta);
void _text_editor_gui_input(const Ref<InputEvent> &p_event);
2016-07-14 19:03:40 +00:00
void _zoom_in();
void _zoom_out();
2017-11-01 20:49:39 +00:00
void _zoom_changed();
2016-07-14 19:03:40 +00:00
void _reset_zoom();
CodeTextEditorCodeCompleteFunc code_complete_func;
void *code_complete_ud;
void _warning_label_gui_input(const Ref<InputEvent> &p_event);
void _warning_button_pressed();
void _set_show_warnings_panel(bool p_show);
void _error_pressed(const Ref<InputEvent> &p_event);
2014-02-10 01:10:30 +00:00
protected:
virtual void _load_theme_settings() {}
virtual void _validate_script() {}
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();
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();
bool is_warnings_panel_opened;
2014-02-10 01:10:30 +00:00
public:
void trim_trailing_whitespace();
void convert_indent_to_spaces();
void convert_indent_to_tabs();
enum CaseStyle {
UPPER,
LOWER,
CAPITALIZE,
};
void convert_case(CaseStyle p_case);
void move_lines_up();
void move_lines_down();
void delete_lines();
void clone_lines_down();
/// Toggle inline comment on currently selected lines, or on current line if nothing is selected,
/// by adding or removing comment delimiter
void toggle_inline_comment(const String &delimiter);
void goto_line(int p_line);
void goto_line_selection(int p_line, int p_begin, int p_end);
Variant get_edit_state();
void set_edit_state(const Variant &p_state);
void set_warning_nb(int p_warning_nb);
2016-10-10 08:38:12 +00:00
void update_editor_settings();
void set_error(const String &p_error);
void set_error_pos(int p_line, int p_column);
void update_line_and_column() { _line_col_changed(); }
2014-02-10 01:10:30 +00:00
TextEdit *get_text_edit() { return text_editor; }
FindReplaceBar *get_find_replace_bar() { return find_replace_bar; }
2014-02-10 01:10:30 +00:00
virtual void apply_code() {}
void goto_error();
2014-02-10 01:10:30 +00:00
void set_code_complete_func(CodeTextEditorCodeCompleteFunc p_code_complete_func, void *p_ud);
2014-02-10 01:10:30 +00:00
CodeTextEditor();
};
#endif // CODE_EDITOR_H