Path: blob/master/editor/script/script_text_editor.h
20854 views
/**************************************************************************/1/* script_text_editor.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "editor/script/script_editor_base.h"33#include "script_editor_plugin.h"3435#include "editor/gui/code_editor.h"36#include "scene/gui/color_picker.h"37#include "scene/gui/dialogs.h"38#include "scene/gui/option_button.h"39#include "scene/gui/tree.h"4041class RichTextLabel;4243class ConnectionInfoDialog : public AcceptDialog {44GDCLASS(ConnectionInfoDialog, AcceptDialog);4546Label *method = nullptr;47Tree *tree = nullptr;4849virtual void ok_pressed() override;5051public:52void popup_connections(const String &p_method, const Vector<Node *> &p_nodes);5354ConnectionInfoDialog();55};5657class ScriptTextEditor : public CodeEditorBase {58GDCLASS(ScriptTextEditor, CodeEditorBase);5960Variant pending_state;61bool script_is_valid = false;6263RichTextLabel *errors_panel = nullptr;6465Vector<String> functions;66List<ScriptLanguage::Warning> warnings;67List<ScriptLanguage::ScriptError> errors;68HashMap<String, List<ScriptLanguage::ScriptError>> depended_errors;69HashSet<int> safe_lines;7071List<Connection> missing_connections;7273int inline_color_line = -1;74int inline_color_start = -1;75int inline_color_end = -1;76PopupPanel *inline_color_popup = nullptr;77ColorPicker *inline_color_picker = nullptr;78OptionButton *inline_color_options = nullptr;79Ref<Texture2D> color_alpha_texture;8081ScriptEditorQuickOpen *quick_open = nullptr;82ConnectionInfoDialog *connection_info_dialog = nullptr;8384int connection_gutter = -1;85void _gutter_clicked(int p_line, int p_gutter);86void _update_gutter_indexes();8788int line_number_gutter = -1;89Color default_line_number_color = Color(1, 1, 1);90Color safe_line_number_color = Color(1, 1, 1);9192Color marked_line_color = Color(1, 1, 1);93Color warning_line_color = Color(1, 1, 1);94Color folded_code_region_color = Color(1, 1, 1);95int previous_line = 0;9697PopupPanel *color_panel = nullptr;98ColorPicker *color_picker = nullptr;99Vector3i color_position;100String color_args;101102bool theme_loaded = false;103104enum {105EDIT_AUTO_INDENT = CODE_ENUM_COUNT,106EDIT_PICK_COLOR,107EDIT_EVALUATE,108EDIT_CREATE_CODE_REGION,109110SEARCH_LOCATE_FUNCTION,111112DEBUG_TOGGLE_BREAKPOINT,113DEBUG_REMOVE_ALL_BREAKPOINTS,114DEBUG_GOTO_NEXT_BREAKPOINT,115DEBUG_GOTO_PREV_BREAKPOINT,116117HELP_CONTEXTUAL,118LOOKUP_SYMBOL,119};120121enum COLOR_MODE {122MODE_RGB,123MODE_STRING,124MODE_HSV,125MODE_OKHSL,126MODE_RGB8,127MODE_HEX,128MODE_MAX129};130131class EditMenusSTE : public EditMenusCEB {132GDCLASS(EditMenusSTE, EditMenusCEB);133PopupMenu *breakpoints_menu = nullptr;134135void _update_breakpoint_list();136void _breakpoint_item_pressed(int p_idx);137138public:139EditMenusSTE();140};141142void _enable_code_editor();143144struct DraggedExport {145ObjectID obj_id;146String variable_name;147Variant value;148String class_name;149};150151LocalVector<DraggedExport> pending_dragged_exports;152Vector<ObjectID> _get_objects_for_export_assignment() const;153String _get_dropped_resource_as_exported_member(const Ref<Resource> &p_resource, const Vector<ObjectID> &p_script_instance_obj_ids);154void _assign_dragged_export_variables();155156static ScriptEditorBase *create_editor(const Ref<Resource> &p_resource);157158protected:159void _breakpoint_toggled(int p_row);160161void _on_caret_moved();162163void _update_warnings();164void _update_errors();165166static void _code_complete_scripts(void *p_ud, const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_force);167virtual void _code_complete_script(const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_force) override;168169void _set_theme_for_script();170void _show_errors_panel(bool p_show);171void _show_warnings_panel(bool p_show);172void _error_clicked(const Variant &p_line);173virtual bool _warning_clicked(const Variant &p_line) override;174175bool _is_valid_color_info(const Dictionary &p_info);176Array _inline_object_parse(const String &p_text);177void _inline_object_draw(const Dictionary &p_info, const Rect2 &p_rect);178void _inline_object_handle_click(const Dictionary &p_info, const Rect2 &p_rect);179String _picker_color_stringify(const Color &p_color, COLOR_MODE p_mode);180void _picker_color_changed(const Color &p_color);181void _update_color_constructor_options();182void _update_background_color();183void _update_color_text();184185void _notification(int p_what);186187void _edit_option_toggle_inline_comment();188void _color_changed(const Color &p_color);189190void _lookup_symbol(const String &p_symbol, int p_row, int p_column);191void _validate_symbol(const String &p_symbol);192193void _show_symbol_tooltip(const String &p_symbol, int p_row, int p_column);194195Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);196bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;197void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);198199String _get_absolute_path(const String &rel_path);200201void _goto_line(int p_line) { goto_line(p_line); }202203void _make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, const Vector2 &p_pos);204205virtual void _text_edit_gui_input(const Ref<InputEvent> &p_ev) override;206virtual bool _edit_option(int p_op) override;207208virtual void _load_theme_settings() override;209virtual void _validate_script() override;210211public:212void _update_connected_methods();213214virtual void apply_code() override;215virtual void set_edited_resource(const Ref<Resource> &p_res) override;216virtual void enable_editor() override;217virtual Vector<String> get_functions() override;218219virtual Control *get_edit_menu() override;220221virtual Ref<Texture2D> get_theme_icon() override;222223virtual Variant get_edit_state() override;224virtual void set_edit_state(const Variant &p_state) override;225226virtual PackedInt32Array get_breakpoints() override;227virtual void set_breakpoint(int p_line, bool p_enabled) override;228virtual void clear_breakpoints() override;229230virtual void add_callback(const String &p_function, const PackedStringArray &p_args);231virtual void update_settings() override;232233static void register_editor();234235Variant get_previous_state();236void store_previous_state();237238ScriptTextEditor();239~ScriptTextEditor();240};241242243