2018-05-28 17:52:28 +02:00
|
|
|
/**************************************************************************/
|
|
|
|
/* text_editor.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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_EDITOR_H
|
|
|
|
#define TEXT_EDITOR_H
|
|
|
|
|
|
|
|
#include "script_editor_plugin.h"
|
|
|
|
|
2022-11-19 12:45:49 +01:00
|
|
|
#include "editor/code_editor.h"
|
|
|
|
|
2018-05-28 17:52:28 +02:00
|
|
|
class TextEditor : public ScriptEditorBase {
|
2019-03-19 19:35:57 +01:00
|
|
|
GDCLASS(TextEditor, ScriptEditorBase);
|
2018-05-28 17:52:28 +02:00
|
|
|
|
2023-05-17 17:22:26 +02:00
|
|
|
static ScriptEditorBase *create_editor(const Ref<Resource> &p_resource);
|
|
|
|
|
2018-05-28 17:52:28 +02:00
|
|
|
private:
|
2019-11-20 10:09:59 +01:00
|
|
|
CodeTextEditor *code_editor = nullptr;
|
2018-05-28 17:52:28 +02:00
|
|
|
|
2023-01-28 15:05:23 +01:00
|
|
|
Ref<Resource> edited_res;
|
2019-11-20 10:09:59 +01:00
|
|
|
bool editor_enabled = false;
|
2018-05-28 17:52:28 +02:00
|
|
|
|
2019-11-20 10:09:59 +01:00
|
|
|
HBoxContainer *edit_hb = nullptr;
|
|
|
|
MenuButton *edit_menu = nullptr;
|
|
|
|
PopupMenu *highlighter_menu = nullptr;
|
|
|
|
MenuButton *search_menu = nullptr;
|
|
|
|
PopupMenu *bookmarks_menu = nullptr;
|
|
|
|
PopupMenu *context_menu = nullptr;
|
2018-05-28 17:52:28 +02:00
|
|
|
|
2019-11-20 10:09:59 +01:00
|
|
|
GotoLineDialog *goto_line_dialog = nullptr;
|
2018-05-28 17:52:28 +02:00
|
|
|
|
|
|
|
enum {
|
|
|
|
EDIT_UNDO,
|
|
|
|
EDIT_REDO,
|
|
|
|
EDIT_CUT,
|
|
|
|
EDIT_COPY,
|
|
|
|
EDIT_PASTE,
|
|
|
|
EDIT_SELECT_ALL,
|
|
|
|
EDIT_TRIM_TRAILING_WHITESAPCE,
|
2024-01-12 06:32:13 +01:00
|
|
|
EDIT_TRIM_FINAL_NEWLINES,
|
2018-05-28 17:52:28 +02:00
|
|
|
EDIT_CONVERT_INDENT_TO_SPACES,
|
|
|
|
EDIT_CONVERT_INDENT_TO_TABS,
|
|
|
|
EDIT_MOVE_LINE_UP,
|
|
|
|
EDIT_MOVE_LINE_DOWN,
|
2022-09-29 04:12:52 +02:00
|
|
|
EDIT_INDENT,
|
|
|
|
EDIT_UNINDENT,
|
2018-05-28 17:52:28 +02:00
|
|
|
EDIT_DELETE_LINE,
|
2021-06-29 12:09:07 +02:00
|
|
|
EDIT_DUPLICATE_SELECTION,
|
2022-09-28 17:09:45 +02:00
|
|
|
EDIT_DUPLICATE_LINES,
|
2018-05-28 17:52:28 +02:00
|
|
|
EDIT_TO_UPPERCASE,
|
|
|
|
EDIT_TO_LOWERCASE,
|
|
|
|
EDIT_CAPITALIZE,
|
2023-04-19 23:46:22 +02:00
|
|
|
EDIT_TOGGLE_WORD_WRAP,
|
2018-05-28 17:52:28 +02:00
|
|
|
EDIT_TOGGLE_FOLD_LINE,
|
|
|
|
EDIT_FOLD_ALL_LINES,
|
|
|
|
EDIT_UNFOLD_ALL_LINES,
|
|
|
|
SEARCH_FIND,
|
|
|
|
SEARCH_FIND_NEXT,
|
|
|
|
SEARCH_FIND_PREV,
|
|
|
|
SEARCH_REPLACE,
|
2019-08-09 23:55:01 +02:00
|
|
|
SEARCH_IN_FILES,
|
2020-02-09 10:10:58 +01:00
|
|
|
REPLACE_IN_FILES,
|
2018-05-28 17:52:28 +02:00
|
|
|
SEARCH_GOTO_LINE,
|
2019-04-20 01:51:25 +02:00
|
|
|
BOOKMARK_TOGGLE,
|
|
|
|
BOOKMARK_GOTO_NEXT,
|
|
|
|
BOOKMARK_GOTO_PREV,
|
|
|
|
BOOKMARK_REMOVE_ALL,
|
2018-05-28 17:52:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _edit_option(int p_op);
|
2019-06-22 20:22:52 +02:00
|
|
|
void _make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded, Vector2 p_position);
|
2018-05-28 17:52:28 +02:00
|
|
|
void _text_edit_gui_input(const Ref<InputEvent> &ev);
|
2021-08-17 05:41:46 +02:00
|
|
|
void _prepare_edit_menu();
|
2018-05-28 17:52:28 +02:00
|
|
|
|
2022-05-13 15:04:37 +02:00
|
|
|
HashMap<String, Ref<EditorSyntaxHighlighter>> highlighters;
|
2018-05-28 17:52:28 +02:00
|
|
|
void _change_syntax_highlighter(int p_idx);
|
|
|
|
void _load_theme_settings();
|
|
|
|
|
|
|
|
void _convert_case(CodeTextEditor::CaseStyle p_case);
|
|
|
|
|
|
|
|
void _validate_script();
|
|
|
|
|
2019-05-21 10:07:48 +02:00
|
|
|
void _update_bookmark_list();
|
|
|
|
void _bookmark_item_pressed(int p_idx);
|
|
|
|
|
2018-05-28 17:52:28 +02:00
|
|
|
public:
|
2020-05-03 18:08:15 +02:00
|
|
|
virtual void add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override;
|
|
|
|
virtual void set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override;
|
2018-05-28 17:52:28 +02:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual String get_name() override;
|
|
|
|
virtual Ref<Texture2D> get_theme_icon() override;
|
2022-05-03 01:43:50 +02:00
|
|
|
virtual Ref<Resource> get_edited_resource() const override;
|
|
|
|
virtual void set_edited_resource(const Ref<Resource> &p_res) override;
|
2022-10-23 10:45:44 +02:00
|
|
|
virtual void enable_editor(Control *p_shortcut_context = nullptr) override;
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual void reload_text() override;
|
|
|
|
virtual void apply_code() override;
|
|
|
|
virtual bool is_unsaved() override;
|
|
|
|
virtual Variant get_edit_state() override;
|
|
|
|
virtual void set_edit_state(const Variant &p_state) override;
|
2022-09-23 14:46:28 +02:00
|
|
|
virtual Variant get_navigation_state() override;
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual Vector<String> get_functions() override;
|
2022-08-05 03:41:48 +02:00
|
|
|
virtual PackedInt32Array get_breakpoints() override;
|
2021-07-20 13:24:56 +02:00
|
|
|
virtual void set_breakpoint(int p_line, bool p_enabled) override {}
|
|
|
|
virtual void clear_breakpoints() override {}
|
2024-07-06 01:27:19 +02:00
|
|
|
virtual void goto_line(int p_line, int p_column = 0) override;
|
2019-08-07 08:41:10 +02:00
|
|
|
void goto_line_selection(int p_line, int p_begin, int p_end);
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual void set_executing_line(int p_line) override;
|
|
|
|
virtual void clear_executing_line() override;
|
|
|
|
virtual void trim_trailing_whitespace() override;
|
2024-01-12 06:32:13 +01:00
|
|
|
virtual void trim_final_newlines() override;
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual void insert_final_newline() override;
|
2023-05-01 22:41:50 +02:00
|
|
|
virtual void convert_indent() override;
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual void ensure_focus() override;
|
|
|
|
virtual void tag_saved_version() override;
|
|
|
|
virtual void update_settings() override;
|
|
|
|
virtual bool show_members_overview() override;
|
|
|
|
virtual bool can_lose_focus_on_node_selection() override { return true; }
|
|
|
|
virtual void set_debugger_active(bool p_active) override;
|
2021-11-07 18:26:15 +01:00
|
|
|
virtual void set_tooltip_request_func(const Callable &p_toolip_callback) override;
|
2024-02-15 17:25:58 +01:00
|
|
|
virtual void add_callback(const String &p_function, const PackedStringArray &p_args) override;
|
2021-09-14 11:17:47 +02:00
|
|
|
void update_toggle_scripts_button() override;
|
2020-07-10 12:34:39 +02:00
|
|
|
|
|
|
|
virtual Control *get_edit_menu() override;
|
|
|
|
virtual void clear_edit_menu() override;
|
2021-06-03 01:05:41 +02:00
|
|
|
virtual void set_find_replace_bar(FindReplaceBar *p_bar) override;
|
2020-07-10 12:34:39 +02:00
|
|
|
|
|
|
|
virtual void validate() override;
|
2019-05-08 18:49:49 +02:00
|
|
|
|
2021-05-13 21:50:25 +02:00
|
|
|
virtual Control *get_base_editor() const override;
|
2024-02-18 03:16:58 +01:00
|
|
|
virtual CodeTextEditor *get_code_editor() const override;
|
2021-05-13 21:50:25 +02:00
|
|
|
|
2018-05-28 17:52:28 +02:00
|
|
|
static void register_editor();
|
|
|
|
|
|
|
|
TextEditor();
|
2019-07-25 18:30:48 +02:00
|
|
|
~TextEditor();
|
2018-05-28 17:52:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TEXT_EDITOR_H
|