Merge commit '921d0574a0' as 'engine'
This commit is contained in:
commit
add768b79b
14224 changed files with 7489260 additions and 0 deletions
6
engine/editor/script/SCsub
Normal file
6
engine/editor/script/SCsub
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
from misc.utility.scons_hints import *
|
||||
|
||||
Import("env")
|
||||
|
||||
env.add_source_files(env.editor_sources, "*.cpp")
|
||||
74
engine/editor/script/editor_script.cpp
Normal file
74
engine/editor/script/editor_script.cpp
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/**************************************************************************/
|
||||
/* editor_script.cpp */
|
||||
/**************************************************************************/
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "editor_script.h"
|
||||
|
||||
#include "core/object/class_db.h"
|
||||
#include "editor/editor_interface.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "scene/main/node.h"
|
||||
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
void EditorScript::add_root_node(Node *p_node) {
|
||||
WARN_DEPRECATED_MSG("EditorScript::add_root_node is deprecated. Use EditorInterface::add_root_node instead.");
|
||||
EditorInterface::get_singleton()->add_root_node(p_node);
|
||||
}
|
||||
|
||||
Node *EditorScript::get_scene() const {
|
||||
WARN_DEPRECATED_MSG("EditorScript::get_scene is deprecated. Use EditorInterface::get_edited_scene_root instead.");
|
||||
if (!EditorNode::get_singleton()) {
|
||||
EditorNode::add_io_error("EditorScript::get_scene: " + TTR("Write your logic in the _run() method."));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return EditorNode::get_singleton()->get_edited_scene();
|
||||
}
|
||||
|
||||
EditorInterface *EditorScript::get_editor_interface() const {
|
||||
WARN_DEPRECATED_MSG("EditorInterface is a global singleton and can be accessed directly by its name.");
|
||||
return EditorInterface::get_singleton();
|
||||
}
|
||||
#endif // DISABLE_DEPRECATED
|
||||
|
||||
void EditorScript::run() {
|
||||
GDVIRTUAL_CALL(_run);
|
||||
}
|
||||
|
||||
void EditorScript::_bind_methods() {
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
ClassDB::bind_method(D_METHOD("add_root_node", "node"), &EditorScript::add_root_node);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_scene"), &EditorScript::get_scene);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_editor_interface"), &EditorScript::get_editor_interface);
|
||||
#endif // DISABLE_DEPRECATED
|
||||
|
||||
GDVIRTUAL_BIND(_run);
|
||||
}
|
||||
56
engine/editor/script/editor_script.h
Normal file
56
engine/editor/script/editor_script.h
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/**************************************************************************/
|
||||
/* editor_script.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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/object/gdvirtual.gen.h"
|
||||
#include "core/object/ref_counted.h"
|
||||
|
||||
class EditorInterface;
|
||||
class EditorNode;
|
||||
class Node;
|
||||
|
||||
class EditorScript : public RefCounted {
|
||||
GDCLASS(EditorScript, RefCounted);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
GDVIRTUAL0_REQUIRED(_run)
|
||||
|
||||
public:
|
||||
void add_root_node(Node *p_node);
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
Node *get_scene() const;
|
||||
#endif // DISABLE_DEPRECATED
|
||||
EditorInterface *get_editor_interface() const;
|
||||
|
||||
virtual void run();
|
||||
};
|
||||
66
engine/editor/script/editor_script_plugin.cpp
Normal file
66
engine/editor/script/editor_script_plugin.cpp
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/**************************************************************************/
|
||||
/* editor_script_plugin.cpp */
|
||||
/**************************************************************************/
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "editor_script_plugin.h"
|
||||
|
||||
#include "core/io/resource_loader.h"
|
||||
#include "core/object/callable_mp.h"
|
||||
#include "editor/editor_interface.h"
|
||||
#include "editor/script/editor_script.h"
|
||||
#include "editor/settings/editor_command_palette.h"
|
||||
|
||||
Ref<EditorScript> create_instance(const StringName &p_name) {
|
||||
Ref<EditorScript> es;
|
||||
es.instantiate();
|
||||
Ref<Script> scr = ResourceLoader::load(ScriptServer::get_global_class_path(p_name), "Script", ResourceFormatLoader::CACHE_MODE_REUSE);
|
||||
if (scr.is_valid()) {
|
||||
es->set_script(scr);
|
||||
}
|
||||
return es;
|
||||
}
|
||||
|
||||
void EditorScriptPlugin::run_command(const StringName &p_name) {
|
||||
create_instance(p_name)->run();
|
||||
}
|
||||
|
||||
void EditorScriptPlugin::command_palette_about_to_popup() {
|
||||
for (const StringName &command : commands) {
|
||||
EditorInterface::get_singleton()->get_command_palette()->remove_command("editor_scripts/" + command);
|
||||
}
|
||||
commands.clear();
|
||||
ScriptServer::get_indirect_inheriters_list(SNAME("EditorScript"), &commands);
|
||||
for (const StringName &command : commands) {
|
||||
EditorInterface::get_singleton()->get_command_palette()->add_command(String(command).capitalize(), "editor_scripts/" + command, callable_mp(this, &EditorScriptPlugin::run_command).bind(command));
|
||||
}
|
||||
}
|
||||
|
||||
EditorScriptPlugin::EditorScriptPlugin() {
|
||||
EditorInterface::get_singleton()->get_command_palette()->connect("about_to_popup", callable_mp(this, &EditorScriptPlugin::command_palette_about_to_popup));
|
||||
}
|
||||
48
engine/editor/script/editor_script_plugin.h
Normal file
48
engine/editor/script/editor_script_plugin.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/**************************************************************************/
|
||||
/* editor_script_plugin.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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "editor/plugins/editor_plugin.h"
|
||||
|
||||
class EditorScriptPlugin : public EditorPlugin {
|
||||
GDCLASS(EditorScriptPlugin, EditorPlugin);
|
||||
|
||||
private:
|
||||
List<StringName> commands;
|
||||
|
||||
void run_command(const StringName &p_name);
|
||||
void command_palette_about_to_popup();
|
||||
|
||||
public:
|
||||
EditorScriptPlugin();
|
||||
|
||||
virtual String get_plugin_name() const override { return "EditorScript"; }
|
||||
};
|
||||
1535
engine/editor/script/find_in_files.cpp
Normal file
1535
engine/editor/script/find_in_files.cpp
Normal file
File diff suppressed because it is too large
Load diff
299
engine/editor/script/find_in_files.h
Normal file
299
engine/editor/script/find_in_files.h
Normal file
|
|
@ -0,0 +1,299 @@
|
|||
/**************************************************************************/
|
||||
/* find_in_files.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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/templates/hash_map.h"
|
||||
#include "editor/docks/editor_dock.h"
|
||||
#include "scene/gui/dialogs.h"
|
||||
|
||||
// Performs the actual search
|
||||
class FindInFiles : public Node {
|
||||
GDCLASS(FindInFiles, Node);
|
||||
|
||||
public:
|
||||
static const char *SIGNAL_RESULT_FOUND;
|
||||
static const char *SIGNAL_FINISHED;
|
||||
|
||||
void set_search_text(const String &p_pattern);
|
||||
void set_whole_words(bool p_whole_word);
|
||||
void set_match_case(bool p_match_case);
|
||||
void set_folder(const String &folder);
|
||||
void set_filter(const HashSet<String> &exts);
|
||||
void set_includes(const HashSet<String> &p_include_wildcards);
|
||||
void set_excludes(const HashSet<String> &p_exclude_wildcards);
|
||||
|
||||
String get_search_text() const { return _pattern; }
|
||||
|
||||
bool is_whole_words() const { return _whole_words; }
|
||||
bool is_match_case() const { return _match_case; }
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
bool is_searching() const { return _searching; }
|
||||
float get_progress() const;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
void _process();
|
||||
void _iterate();
|
||||
void _scan_dir(const String &path, PackedStringArray &out_folders, PackedStringArray &out_files_to_scan);
|
||||
void _scan_file(const String &fpath);
|
||||
|
||||
bool _is_file_matched(const HashSet<String> &p_wildcards, const String &p_file_path, bool p_case_sensitive) const;
|
||||
|
||||
// Config
|
||||
String _pattern;
|
||||
HashSet<String> _extension_filter;
|
||||
HashSet<String> _include_wildcards;
|
||||
HashSet<String> _exclude_wildcards;
|
||||
String _root_dir;
|
||||
bool _whole_words = true;
|
||||
bool _match_case = true;
|
||||
|
||||
// State
|
||||
bool _searching = false;
|
||||
String _current_dir;
|
||||
Vector<PackedStringArray> _folders_stack;
|
||||
Vector<String> _files_to_scan;
|
||||
int _initial_files_count = 0;
|
||||
};
|
||||
|
||||
class LineEdit;
|
||||
class CheckBox;
|
||||
class FileDialog;
|
||||
class HBoxContainer;
|
||||
|
||||
// Prompts search parameters
|
||||
class FindInFilesDialog : public AcceptDialog {
|
||||
GDCLASS(FindInFilesDialog, AcceptDialog);
|
||||
|
||||
public:
|
||||
enum FindInFilesMode {
|
||||
SEARCH_MODE,
|
||||
REPLACE_MODE
|
||||
};
|
||||
|
||||
static const char *SIGNAL_FIND_REQUESTED;
|
||||
static const char *SIGNAL_REPLACE_REQUESTED;
|
||||
|
||||
FindInFilesDialog();
|
||||
|
||||
void set_search_text(const String &text);
|
||||
void set_replace_text(const String &text);
|
||||
|
||||
void set_find_in_files_mode(FindInFilesMode p_mode);
|
||||
|
||||
String get_search_text() const;
|
||||
String get_replace_text() const;
|
||||
bool is_match_case() const;
|
||||
bool is_whole_words() const;
|
||||
String get_folder() const;
|
||||
HashSet<String> get_filter() const;
|
||||
HashSet<String> get_includes() const;
|
||||
HashSet<String> get_excludes() const;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
void _visibility_changed();
|
||||
void custom_action(const String &p_action) override;
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
void _on_folder_button_pressed();
|
||||
void _on_folder_selected(String path);
|
||||
void _on_search_text_modified(const String &text);
|
||||
void _on_search_text_submitted(const String &text);
|
||||
void _on_replace_text_submitted(const String &text);
|
||||
|
||||
String validate_filter_wildcard(const String &p_expression) const;
|
||||
|
||||
FindInFilesMode _mode;
|
||||
LineEdit *_search_text_line_edit = nullptr;
|
||||
|
||||
Label *_replace_label = nullptr;
|
||||
LineEdit *_replace_text_line_edit = nullptr;
|
||||
|
||||
LineEdit *_folder_line_edit = nullptr;
|
||||
CheckBox *_match_case_checkbox = nullptr;
|
||||
CheckBox *_whole_words_checkbox = nullptr;
|
||||
Button *_find_button = nullptr;
|
||||
Button *_replace_button = nullptr;
|
||||
FileDialog *_folder_dialog = nullptr;
|
||||
HBoxContainer *_filters_container = nullptr;
|
||||
LineEdit *_includes_line_edit = nullptr;
|
||||
LineEdit *_excludes_line_edit = nullptr;
|
||||
|
||||
HashMap<String, bool> _filters_preferences;
|
||||
};
|
||||
|
||||
class Button;
|
||||
class CheckButton;
|
||||
class Tree;
|
||||
class TreeItem;
|
||||
class ProgressBar;
|
||||
|
||||
// Display search results
|
||||
class FindInFilesPanel : public MarginContainer {
|
||||
GDCLASS(FindInFilesPanel, MarginContainer);
|
||||
|
||||
public:
|
||||
static const char *SIGNAL_RESULT_SELECTED;
|
||||
static const char *SIGNAL_FILES_MODIFIED;
|
||||
static const char *SIGNAL_CLOSE_BUTTON_CLICKED;
|
||||
|
||||
FindInFilesPanel();
|
||||
|
||||
FindInFiles *get_finder() const { return _finder; }
|
||||
|
||||
void set_with_replace(bool with_replace);
|
||||
void set_replace_text(const String &text);
|
||||
bool is_keep_results() const;
|
||||
void set_search_labels_visibility(bool p_visible);
|
||||
|
||||
void start_search();
|
||||
void stop_search();
|
||||
|
||||
void update_layout(EditorDock::DockLayout p_layout);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
void _notification(int p_what);
|
||||
|
||||
private:
|
||||
void _on_button_clicked(TreeItem *p_item, int p_column, int p_id, int p_mouse_button_index);
|
||||
void _on_result_found(const String &fpath, int line_number, int begin, int end, String text);
|
||||
void _on_theme_changed();
|
||||
void _on_finished();
|
||||
void _on_refresh_button_clicked();
|
||||
void _on_cancel_button_clicked();
|
||||
void _on_close_button_clicked();
|
||||
void _on_result_selected();
|
||||
void _on_item_edited();
|
||||
void _on_replace_text_changed(const String &text);
|
||||
void _on_replace_all_clicked();
|
||||
|
||||
enum {
|
||||
FIND_BUTTON_REPLACE,
|
||||
FIND_BUTTON_REMOVE,
|
||||
};
|
||||
|
||||
struct Result {
|
||||
int line_number = 0;
|
||||
int begin = 0;
|
||||
int end = 0;
|
||||
int begin_trimmed = 0;
|
||||
};
|
||||
|
||||
void apply_replaces_in_file(const String &fpath, const Vector<Result> &locations, const String &new_text);
|
||||
void update_replace_buttons();
|
||||
void update_matches_text();
|
||||
String get_replace_text();
|
||||
|
||||
void draw_result_text(Object *item_obj, Rect2 rect);
|
||||
|
||||
void clear();
|
||||
|
||||
FindInFiles *_finder = nullptr;
|
||||
Label *_find_label = nullptr;
|
||||
Label *_search_text_label = nullptr;
|
||||
Tree *_results_display = nullptr;
|
||||
Label *_status_label = nullptr;
|
||||
CheckButton *_keep_results_button = nullptr;
|
||||
Button *_refresh_button = nullptr;
|
||||
Button *_cancel_button = nullptr;
|
||||
Button *_close_button = nullptr;
|
||||
ProgressBar *_progress_bar = nullptr;
|
||||
HashMap<String, TreeItem *> _file_items;
|
||||
HashMap<TreeItem *, int> _file_items_results_count;
|
||||
HashMap<TreeItem *, Result> _result_items;
|
||||
bool _with_replace = false;
|
||||
|
||||
HBoxContainer *_replace_container = nullptr;
|
||||
LineEdit *_replace_line_edit = nullptr;
|
||||
Button *_replace_all_button = nullptr;
|
||||
|
||||
bool _floating = false;
|
||||
MarginContainer *_results_mc = nullptr;
|
||||
};
|
||||
|
||||
class PopupMenu;
|
||||
class TabContainer;
|
||||
|
||||
// Contains several FindInFilesPanels. A FindInFilesPanel contains the results of a
|
||||
// `Find in Files` search or a `Replace in Files` search, while a
|
||||
// FindInFilesContainer can contain several FindInFilesPanels so that multiple search
|
||||
// results can remain at the same time.
|
||||
class FindInFilesContainer : public EditorDock {
|
||||
GDCLASS(FindInFilesContainer, EditorDock);
|
||||
|
||||
enum {
|
||||
PANEL_CLOSE,
|
||||
PANEL_CLOSE_OTHERS,
|
||||
PANEL_CLOSE_RIGHT,
|
||||
PANEL_CLOSE_ALL,
|
||||
};
|
||||
|
||||
void _on_theme_changed();
|
||||
void _on_tab_close_pressed(int p_tab);
|
||||
void _update_bar_visibility();
|
||||
void _bar_menu_option(int p_option);
|
||||
void _bar_input(const Ref<InputEvent> &p_input);
|
||||
void _on_dock_closed();
|
||||
|
||||
TabContainer *_tabs = nullptr;
|
||||
bool _update_bar = true;
|
||||
PopupMenu *_tabs_context_menu = nullptr;
|
||||
|
||||
FindInFilesPanel *_create_new_panel();
|
||||
FindInFilesPanel *_get_current_panel();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
void _notification(int p_what);
|
||||
|
||||
void _on_find_in_files_result_selected(const String &p_fpath, int p_line_number, int p_begin, int p_end);
|
||||
void _on_find_in_files_modified_files(const PackedStringArray &p_paths);
|
||||
void _on_find_in_files_close_button_clicked(FindInFilesPanel *p_panel);
|
||||
|
||||
virtual void update_layout(EditorDock::DockLayout p_layout) override;
|
||||
|
||||
public:
|
||||
FindInFilesContainer();
|
||||
|
||||
FindInFilesPanel *get_panel_for_results(const String &p_label);
|
||||
};
|
||||
1034
engine/editor/script/script_create_dialog.cpp
Normal file
1034
engine/editor/script/script_create_dialog.cpp
Normal file
File diff suppressed because it is too large
Load diff
124
engine/editor/script/script_create_dialog.h
Normal file
124
engine/editor/script/script_create_dialog.h
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
/**************************************************************************/
|
||||
/* script_create_dialog.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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/object/script_language.h"
|
||||
#include "scene/gui/check_box.h"
|
||||
#include "scene/gui/dialogs.h"
|
||||
#include "scene/gui/option_button.h"
|
||||
|
||||
class CreateDialog;
|
||||
class EditorFileDialog;
|
||||
class EditorValidationPanel;
|
||||
class LineEdit;
|
||||
|
||||
class ScriptCreateDialog : public ConfirmationDialog {
|
||||
GDCLASS(ScriptCreateDialog, ConfirmationDialog);
|
||||
|
||||
enum {
|
||||
MSG_ID_SCRIPT,
|
||||
MSG_ID_PATH,
|
||||
MSG_ID_BUILT_IN,
|
||||
MSG_ID_TEMPLATE,
|
||||
};
|
||||
|
||||
EditorValidationPanel *validation_panel = nullptr;
|
||||
LineEdit *parent_name = nullptr;
|
||||
Button *parent_browse_button = nullptr;
|
||||
Button *parent_search_button = nullptr;
|
||||
OptionButton *language_menu = nullptr;
|
||||
OptionButton *template_menu = nullptr;
|
||||
LineEdit *file_path = nullptr;
|
||||
LineEdit *built_in_name = nullptr;
|
||||
Button *path_button = nullptr;
|
||||
EditorFileDialog *file_browse = nullptr;
|
||||
CheckBox *built_in = nullptr;
|
||||
CheckBox *use_templates = nullptr;
|
||||
AcceptDialog *alert = nullptr;
|
||||
CreateDialog *select_class = nullptr;
|
||||
|
||||
bool is_browsing_parent = false;
|
||||
String path_error;
|
||||
String template_inactive_message;
|
||||
bool is_new_script_created = true;
|
||||
bool is_path_valid = false;
|
||||
bool supports_built_in = false;
|
||||
bool can_inherit_from_file = false;
|
||||
bool is_parent_name_valid = false;
|
||||
bool is_built_in = false;
|
||||
bool is_using_templates = true;
|
||||
bool built_in_enabled = true;
|
||||
bool load_enabled = true;
|
||||
int default_language;
|
||||
bool re_check_path = false;
|
||||
|
||||
Control *path_controls[2];
|
||||
Control *name_controls[2];
|
||||
|
||||
Vector<ScriptLanguage::ScriptTemplate> template_list;
|
||||
ScriptLanguage *language = nullptr;
|
||||
|
||||
String base_type;
|
||||
|
||||
void _path_hbox_sorted();
|
||||
bool _can_be_built_in();
|
||||
void _path_changed(const String &p_path = String());
|
||||
void _language_changed(int l = 0);
|
||||
void _built_in_pressed();
|
||||
void _use_template_pressed();
|
||||
bool _validate_parent(const String &p_string);
|
||||
String _validate_path(const String &p_path, bool p_file_must_exist, bool *r_path_valid = nullptr);
|
||||
void _parent_name_changed(const String &p_parent);
|
||||
void _template_changed(int p_template = 0);
|
||||
void _browse_path(bool browse_parent, bool p_save);
|
||||
void _file_selected(const String &p_file);
|
||||
void _create();
|
||||
void _browse_class_in_tree();
|
||||
virtual void ok_pressed() override;
|
||||
void _create_new();
|
||||
void _load_exist();
|
||||
void _update_template_menu();
|
||||
void _update_dialog();
|
||||
ScriptLanguage::ScriptTemplate _get_current_template() const;
|
||||
Vector<ScriptLanguage::ScriptTemplate> _get_user_templates(const ScriptLanguage *p_language, const StringName &p_object, const String &p_dir, const ScriptLanguage::TemplateLocation &p_origin) const;
|
||||
ScriptLanguage::ScriptTemplate _parse_template(const ScriptLanguage *p_language, const String &p_path, const String &p_filename, const ScriptLanguage::TemplateLocation &p_origin, const String &p_inherits) const;
|
||||
String _get_script_origin_label(const ScriptLanguage::TemplateLocation &p_origin) const;
|
||||
String _adjust_file_path(const String &p_base_path) const;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void config(const String &p_base_name, const String &p_base_path, bool p_built_in_enabled = true, bool p_load_enabled = true);
|
||||
void set_inheritance_base_type(const String &p_base);
|
||||
ScriptCreateDialog();
|
||||
};
|
||||
713
engine/editor/script/script_editor_base.cpp
Normal file
713
engine/editor/script/script_editor_base.cpp
Normal file
|
|
@ -0,0 +1,713 @@
|
|||
/**************************************************************************/
|
||||
/* script_editor_base.cpp */
|
||||
/**************************************************************************/
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "script_editor_base.h"
|
||||
|
||||
#include "core/io/json.h"
|
||||
#include "core/object/callable_mp.h"
|
||||
#include "core/object/class_db.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/script/script_editor_plugin.h"
|
||||
#include "editor/script/syntax_highlighters.h"
|
||||
#include "editor/settings/editor_settings.h"
|
||||
#include "scene/gui/menu_button.h"
|
||||
#include "scene/gui/rich_text_label.h"
|
||||
#include "scene/gui/split_container.h"
|
||||
#include "servers/display/display_server.h"
|
||||
|
||||
void ScriptEditorBase::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("name_changed"));
|
||||
|
||||
// First use in TextEditorBase.
|
||||
ADD_SIGNAL(MethodInfo("edited_script_changed"));
|
||||
ADD_SIGNAL(MethodInfo("search_in_files_requested", PropertyInfo(Variant::STRING, "text")));
|
||||
ClassDB::bind_method(D_METHOD("add_syntax_highlighter", "highlighter"), &ScriptEditorBase::add_syntax_highlighter);
|
||||
ClassDB::bind_method(D_METHOD("get_base_editor"), &ScriptEditorBase::get_base_editor);
|
||||
|
||||
// First use in ScriptTextEditor.
|
||||
ADD_SIGNAL(MethodInfo("request_save_history"));
|
||||
ADD_SIGNAL(MethodInfo("request_help", PropertyInfo(Variant::STRING, "topic")));
|
||||
ADD_SIGNAL(MethodInfo("request_open_script_at_line", PropertyInfo(Variant::OBJECT, "script"), PropertyInfo(Variant::INT, "line")));
|
||||
ADD_SIGNAL(MethodInfo("go_to_help", PropertyInfo(Variant::STRING, "what")));
|
||||
ADD_SIGNAL(MethodInfo("request_save_previous_state", PropertyInfo(Variant::DICTIONARY, "state")));
|
||||
ADD_SIGNAL(MethodInfo("replace_in_files_requested", PropertyInfo(Variant::STRING, "text")));
|
||||
ADD_SIGNAL(MethodInfo("go_to_method", PropertyInfo(Variant::OBJECT, "script"), PropertyInfo(Variant::STRING, "method")));
|
||||
}
|
||||
|
||||
String ScriptEditorBase::get_name() {
|
||||
String name;
|
||||
|
||||
name = edited_res->get_path().get_file();
|
||||
if (name.is_empty()) {
|
||||
// This appears for newly created built-in text_files before saving the scene.
|
||||
name = TTR("[unsaved]");
|
||||
} else if (edited_res->is_built_in()) {
|
||||
const String &text_file_name = edited_res->get_name();
|
||||
if (!text_file_name.is_empty()) {
|
||||
// If the built-in text_file has a custom resource name defined,
|
||||
// display the built-in text_file name as follows: `ResourceName (scene_file.tscn)`
|
||||
name = vformat("%s (%s)", text_file_name, name.get_slice("::", 0));
|
||||
}
|
||||
}
|
||||
|
||||
if (is_unsaved()) {
|
||||
name += "(*)";
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
Ref<Texture2D> ScriptEditorBase::get_theme_icon() {
|
||||
return EditorNode::get_singleton()->get_object_icon(edited_res.ptr());
|
||||
}
|
||||
|
||||
void ScriptEditorBase::tag_saved_version() {
|
||||
edited_file_data.last_modified_time = FileAccess::get_modified_time(edited_file_data.path);
|
||||
}
|
||||
|
||||
//// TextEditorBase
|
||||
|
||||
TextEditorBase *TextEditorBase::EditMenus::_get_active_editor() {
|
||||
return Object::cast_to<TextEditorBase>(ScriptEditor::get_singleton()->get_current_editor());
|
||||
}
|
||||
|
||||
void TextEditorBase::EditMenus::_edit_option(int p_op) {
|
||||
TextEditorBase *script_text_editor = _get_active_editor();
|
||||
ERR_FAIL_NULL(script_text_editor);
|
||||
script_text_editor->_edit_option(p_op);
|
||||
}
|
||||
|
||||
void TextEditorBase::EditMenus::_prepare_edit_menu() {
|
||||
TextEditorBase *script_text_editor = _get_active_editor();
|
||||
ERR_FAIL_NULL(script_text_editor);
|
||||
const CodeEdit *tx = script_text_editor->code_editor->get_text_editor();
|
||||
PopupMenu *popup = edit_menu->get_popup();
|
||||
popup->set_item_disabled(popup->get_item_index(EDIT_UNDO), !tx->has_undo());
|
||||
popup->set_item_disabled(popup->get_item_index(EDIT_REDO), !tx->has_redo());
|
||||
}
|
||||
|
||||
void TextEditorBase::EditMenus::_update_highlighter_menu() {
|
||||
TextEditorBase *script_text_editor = _get_active_editor();
|
||||
ERR_FAIL_NULL(script_text_editor);
|
||||
|
||||
Ref<EditorSyntaxHighlighter> current_highlighter = script_text_editor->get_code_editor()->get_text_editor()->get_syntax_highlighter();
|
||||
highlighter_menu->clear();
|
||||
for (const Ref<EditorSyntaxHighlighter> &highlighter : script_text_editor->highlighters) {
|
||||
highlighter_menu->add_radio_check_item(highlighter->_get_name());
|
||||
highlighter_menu->set_item_checked(-1, highlighter == current_highlighter);
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditorBase::EditMenus::_change_syntax_highlighter(int p_idx) {
|
||||
TextEditorBase *script_text_editor = _get_active_editor();
|
||||
ERR_FAIL_NULL(script_text_editor);
|
||||
ERR_FAIL_INDEX(p_idx, (int)script_text_editor->highlighters.size());
|
||||
script_text_editor->set_syntax_highlighter(script_text_editor->highlighters[p_idx]);
|
||||
}
|
||||
|
||||
void TextEditorBase::EditMenus::_update_bookmark_list() {
|
||||
bookmarks_menu->clear();
|
||||
bookmarks_menu->reset_size();
|
||||
|
||||
bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);
|
||||
bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL);
|
||||
bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT);
|
||||
bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV);
|
||||
|
||||
TextEditorBase *script_text_editor = _get_active_editor();
|
||||
if (script_text_editor == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
PackedInt32Array bookmark_list = script_text_editor->code_editor->get_text_editor()->get_bookmarked_lines();
|
||||
if (bookmark_list.is_empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bookmarks_menu->add_separator();
|
||||
|
||||
for (int32_t bookmark : bookmark_list) {
|
||||
// Strip edges to remove spaces or tabs.
|
||||
// Also replace any tabs by spaces, since we can't print tabs in the menu.
|
||||
String line = script_text_editor->code_editor->get_text_editor()->get_line(bookmark).replace("\t", " ").strip_edges();
|
||||
|
||||
// Limit the size of the line if too big.
|
||||
if (line.length() > 50) {
|
||||
line = line.substr(0, 50);
|
||||
}
|
||||
|
||||
bookmarks_menu->add_item(String::num_int64(bookmark + 1) + " - `" + line + "`");
|
||||
bookmarks_menu->set_item_metadata(-1, bookmark);
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditorBase::EditMenus::_bookmark_item_pressed(int p_idx) {
|
||||
TextEditorBase *script_text_editor = _get_active_editor();
|
||||
ERR_FAIL_NULL(script_text_editor);
|
||||
if (p_idx < 4) { // Any item before the separator.
|
||||
script_text_editor->_edit_option(bookmarks_menu->get_item_id(p_idx));
|
||||
} else {
|
||||
script_text_editor->code_editor->goto_line_centered(bookmarks_menu->get_item_metadata(p_idx));
|
||||
}
|
||||
}
|
||||
|
||||
TextEditorBase::EditMenus::EditMenus() {
|
||||
edit_menu = memnew(MenuButton);
|
||||
edit_menu->set_flat(false);
|
||||
edit_menu->set_theme_type_variation("FlatMenuButton");
|
||||
edit_menu->set_text(TTRC("Edit"));
|
||||
edit_menu->set_switch_on_hover(true);
|
||||
|
||||
add_child(edit_menu);
|
||||
edit_menu->connect("about_to_popup", callable_mp(this, &EditMenus::_prepare_edit_menu));
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_text_select_all"), EDIT_SELECT_ALL);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/duplicate_selection"), EDIT_DUPLICATE_SELECTION);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/duplicate_lines"), EDIT_DUPLICATE_LINES);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_word_wrap"), EDIT_TOGGLE_WORD_WRAP);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
{
|
||||
edit_menu_line = memnew(PopupMenu);
|
||||
edit_menu_line->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_up"), EDIT_MOVE_LINE_UP);
|
||||
edit_menu_line->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN);
|
||||
edit_menu_line->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent"), EDIT_INDENT);
|
||||
edit_menu_line->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unindent"), EDIT_UNINDENT);
|
||||
edit_menu_line->add_shortcut(ED_GET_SHORTCUT("script_text_editor/delete_line"), EDIT_DELETE_LINE);
|
||||
edit_menu_line->add_shortcut(ED_GET_SHORTCUT("script_text_editor/join_lines"), EDIT_JOIN_LINES);
|
||||
edit_menu_line->connect(SceneStringName(id_pressed), callable_mp(this, &EditMenus::_edit_option));
|
||||
edit_menu->get_popup()->add_submenu_node_item(TTRC("Line"), edit_menu_line);
|
||||
}
|
||||
{
|
||||
edit_menu_fold = memnew(PopupMenu);
|
||||
edit_menu_fold->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
|
||||
edit_menu_fold->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_all_lines"), EDIT_FOLD_ALL_LINES);
|
||||
edit_menu_fold->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_all_lines"), EDIT_UNFOLD_ALL_LINES);
|
||||
edit_menu_fold->connect(SceneStringName(id_pressed), callable_mp(this, &EditMenus::_edit_option));
|
||||
edit_menu->get_popup()->add_submenu_node_item(TTRC("Folding"), edit_menu_fold);
|
||||
}
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/trim_trailing_whitespace"), EDIT_TRIM_TRAILING_WHITESAPCE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/trim_final_newlines"), EDIT_TRIM_FINAL_NEWLINES);
|
||||
{
|
||||
edit_menu_convert_indent = memnew(PopupMenu);
|
||||
edit_menu_convert_indent->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_spaces"), EDIT_CONVERT_INDENT_TO_SPACES);
|
||||
edit_menu_convert_indent->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_tabs"), EDIT_CONVERT_INDENT_TO_TABS);
|
||||
edit_menu_convert_indent->connect(SceneStringName(id_pressed), callable_mp(this, &EditMenus::_edit_option));
|
||||
edit_menu->get_popup()->add_submenu_node_item(TTRC("Indentation"), edit_menu_convert_indent);
|
||||
}
|
||||
edit_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &EditMenus::_edit_option));
|
||||
edit_menu->get_popup()->add_separator();
|
||||
{
|
||||
edit_menu_convert = memnew(PopupMenu);
|
||||
edit_menu_convert->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_uppercase"), EDIT_TO_UPPERCASE);
|
||||
edit_menu_convert->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_lowercase"), EDIT_TO_LOWERCASE);
|
||||
edit_menu_convert->add_shortcut(ED_GET_SHORTCUT("script_text_editor/capitalize"), EDIT_CAPITALIZE);
|
||||
edit_menu_convert->connect(SceneStringName(id_pressed), callable_mp(this, &EditMenus::_edit_option));
|
||||
edit_menu->get_popup()->add_submenu_node_item(TTRC("Convert Case"), edit_menu_convert);
|
||||
}
|
||||
highlighter_menu = memnew(PopupMenu);
|
||||
edit_menu->get_popup()->add_submenu_node_item(TTRC("Syntax Highlighter"), highlighter_menu);
|
||||
|
||||
highlighter_menu->connect("about_to_popup", callable_mp(this, &EditMenus::_update_highlighter_menu));
|
||||
highlighter_menu->connect(SceneStringName(id_pressed), callable_mp(this, &EditMenus::_change_syntax_highlighter));
|
||||
|
||||
search_menu = memnew(MenuButton);
|
||||
search_menu->set_flat(false);
|
||||
search_menu->set_theme_type_variation("FlatMenuButton");
|
||||
search_menu->set_text(TTRC("Search"));
|
||||
search_menu->set_switch_on_hover(true);
|
||||
|
||||
add_child(search_menu);
|
||||
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find"), SEARCH_FIND);
|
||||
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_next"), SEARCH_FIND_NEXT);
|
||||
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_previous"), SEARCH_FIND_PREV);
|
||||
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE);
|
||||
search_menu->get_popup()->add_separator();
|
||||
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("editor/find_in_files"), SEARCH_IN_FILES);
|
||||
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace_in_files"), REPLACE_IN_FILES);
|
||||
search_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &EditMenus::_edit_option));
|
||||
|
||||
goto_menu = memnew(MenuButton);
|
||||
goto_menu->set_flat(false);
|
||||
goto_menu->set_theme_type_variation("FlatMenuButton");
|
||||
goto_menu->set_text(TTRC("Go To"));
|
||||
goto_menu->set_switch_on_hover(true);
|
||||
add_child(goto_menu);
|
||||
goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE);
|
||||
goto_menu->get_popup()->add_separator();
|
||||
|
||||
bookmarks_menu = memnew(PopupMenu);
|
||||
goto_menu->get_popup()->add_submenu_node_item(TTRC("Bookmarks"), bookmarks_menu);
|
||||
bookmarks_menu->connect("about_to_popup", callable_mp(this, &EditMenus::_update_bookmark_list));
|
||||
bookmarks_menu->connect("index_pressed", callable_mp(this, &EditMenus::_bookmark_item_pressed));
|
||||
|
||||
goto_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &EditMenus::_edit_option));
|
||||
|
||||
// Update immediately for shortcuts.
|
||||
_update_bookmark_list();
|
||||
}
|
||||
|
||||
void TextEditorBase::_make_context_menu(bool p_selection, bool p_foldable, const Vector2 &p_position, bool p_show) {
|
||||
context_menu->clear();
|
||||
if (DisplayServer::get_singleton()->has_feature(DisplayServerEnums::FEATURE_EMOJI_AND_SYMBOL_PICKER)) {
|
||||
context_menu->add_item(TTRC("Emoji & Symbols"), EDIT_EMOJI_AND_SYMBOL);
|
||||
context_menu->add_separator();
|
||||
}
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO);
|
||||
context_menu->add_separator();
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE);
|
||||
context_menu->add_separator();
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_text_select_all"), EDIT_SELECT_ALL);
|
||||
context_menu->add_separator();
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent"), EDIT_INDENT);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unindent"), EDIT_UNINDENT);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);
|
||||
|
||||
if (p_selection) {
|
||||
context_menu->add_separator();
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_uppercase"), EDIT_TO_UPPERCASE);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_lowercase"), EDIT_TO_LOWERCASE);
|
||||
}
|
||||
|
||||
if (p_foldable) {
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
|
||||
}
|
||||
|
||||
if (p_show) {
|
||||
_show_context_menu(p_position);
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditorBase::_show_context_menu(const Vector2 &p_position) {
|
||||
const CodeEdit *tx = code_editor->get_text_editor();
|
||||
context_menu->set_item_disabled(context_menu->get_item_index(EDIT_UNDO), !tx->has_undo());
|
||||
context_menu->set_item_disabled(context_menu->get_item_index(EDIT_REDO), !tx->has_redo());
|
||||
|
||||
context_menu->set_position(get_screen_position() + p_position);
|
||||
context_menu->reset_size();
|
||||
context_menu->popup();
|
||||
}
|
||||
|
||||
void TextEditorBase::_text_edit_gui_input(const Ref<InputEvent> &p_ev) {
|
||||
Ref<InputEventMouseButton> mb = p_ev;
|
||||
|
||||
if (mb.is_valid()) {
|
||||
if (mb->get_button_index() == MouseButton::RIGHT) {
|
||||
CodeEdit *tx = code_editor->get_text_editor();
|
||||
|
||||
tx->apply_ime();
|
||||
|
||||
Point2i pos = tx->get_line_column_at_pos(mb->get_global_position() - tx->get_global_position());
|
||||
int row = pos.y;
|
||||
int col = pos.x;
|
||||
|
||||
tx->set_move_caret_on_right_click_enabled(EDITOR_GET("text_editor/behavior/navigation/move_caret_on_right_click"));
|
||||
|
||||
if (tx->is_move_caret_on_right_click_enabled()) {
|
||||
tx->remove_secondary_carets();
|
||||
if (tx->has_selection()) {
|
||||
int from_line = tx->get_selection_from_line();
|
||||
int to_line = tx->get_selection_to_line();
|
||||
int from_column = tx->get_selection_from_column();
|
||||
int to_column = tx->get_selection_to_column();
|
||||
|
||||
if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) {
|
||||
// Right click is outside the selected text.
|
||||
tx->deselect();
|
||||
}
|
||||
}
|
||||
if (!tx->has_selection()) {
|
||||
tx->set_caret_line(row, true, false, -1);
|
||||
tx->set_caret_column(col);
|
||||
}
|
||||
}
|
||||
|
||||
if (!mb->is_pressed()) {
|
||||
bool can_fold = tx->can_fold_line(row);
|
||||
bool is_folded = tx->is_line_folded(row);
|
||||
_make_context_menu(tx->has_selection(), can_fold || is_folded, get_local_mouse_position());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ref<InputEventKey> k = p_ev;
|
||||
if (k.is_valid() && k->is_pressed() && k->is_action("ui_menu", true)) {
|
||||
CodeEdit *tx = code_editor->get_text_editor();
|
||||
int line = tx->get_caret_line();
|
||||
tx->adjust_viewport_to_caret();
|
||||
bool can_fold = tx->can_fold_line(line);
|
||||
bool is_folded = tx->is_line_folded(line);
|
||||
_make_context_menu(tx->has_selection(0), can_fold || is_folded, (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->get_caret_draw_pos(0)));
|
||||
context_menu->grab_focus();
|
||||
}
|
||||
}
|
||||
|
||||
bool TextEditorBase::_edit_option(int p_op) {
|
||||
CodeEdit *tx = code_editor->get_text_editor();
|
||||
tx->apply_ime();
|
||||
|
||||
switch (p_op) {
|
||||
case EDIT_UNDO: {
|
||||
tx->undo();
|
||||
callable_mp((Control *)tx, &Control::grab_focus).call_deferred(false);
|
||||
} break;
|
||||
case EDIT_REDO: {
|
||||
tx->redo();
|
||||
callable_mp((Control *)tx, &Control::grab_focus).call_deferred(false);
|
||||
} break;
|
||||
case EDIT_CUT: {
|
||||
tx->cut();
|
||||
callable_mp((Control *)tx, &Control::grab_focus).call_deferred(false);
|
||||
} break;
|
||||
case EDIT_COPY: {
|
||||
tx->copy();
|
||||
callable_mp((Control *)tx, &Control::grab_focus).call_deferred(false);
|
||||
} break;
|
||||
case EDIT_PASTE: {
|
||||
tx->paste();
|
||||
callable_mp((Control *)tx, &Control::grab_focus).call_deferred(false);
|
||||
} break;
|
||||
case EDIT_SELECT_ALL: {
|
||||
tx->select_all();
|
||||
callable_mp((Control *)tx, &Control::grab_focus).call_deferred(false);
|
||||
} break;
|
||||
case EDIT_MOVE_LINE_UP: {
|
||||
tx->move_lines_up();
|
||||
} break;
|
||||
case EDIT_MOVE_LINE_DOWN: {
|
||||
tx->move_lines_down();
|
||||
} break;
|
||||
case EDIT_INDENT: {
|
||||
tx->indent_lines();
|
||||
} break;
|
||||
case EDIT_UNINDENT: {
|
||||
tx->unindent_lines();
|
||||
} break;
|
||||
case EDIT_DELETE_LINE: {
|
||||
tx->delete_lines();
|
||||
} break;
|
||||
case EDIT_JOIN_LINES: {
|
||||
tx->join_lines();
|
||||
} break;
|
||||
case EDIT_DUPLICATE_SELECTION: {
|
||||
tx->duplicate_selection();
|
||||
} break;
|
||||
case EDIT_DUPLICATE_LINES: {
|
||||
tx->duplicate_lines();
|
||||
} break;
|
||||
case EDIT_TRIM_TRAILING_WHITESAPCE: {
|
||||
trim_trailing_whitespace();
|
||||
} break;
|
||||
case EDIT_TRIM_FINAL_NEWLINES: {
|
||||
trim_final_newlines();
|
||||
} break;
|
||||
case EDIT_CONVERT_INDENT_TO_SPACES: {
|
||||
code_editor->set_indent_using_spaces(true);
|
||||
convert_indent();
|
||||
} break;
|
||||
case EDIT_CONVERT_INDENT_TO_TABS: {
|
||||
code_editor->set_indent_using_spaces(false);
|
||||
convert_indent();
|
||||
} break;
|
||||
case EDIT_TO_UPPERCASE: {
|
||||
_convert_case(CodeTextEditor::UPPER);
|
||||
} break;
|
||||
case EDIT_TO_LOWERCASE: {
|
||||
_convert_case(CodeTextEditor::LOWER);
|
||||
} break;
|
||||
case EDIT_CAPITALIZE: {
|
||||
_convert_case(CodeTextEditor::CAPITALIZE);
|
||||
} break;
|
||||
case EDIT_TOGGLE_WORD_WRAP: {
|
||||
TextEdit::LineWrappingMode wrap = tx->get_line_wrapping_mode();
|
||||
tx->set_line_wrapping_mode(wrap == TextEdit::LINE_WRAPPING_BOUNDARY ? TextEdit::LINE_WRAPPING_NONE : TextEdit::LINE_WRAPPING_BOUNDARY);
|
||||
} break;
|
||||
case SEARCH_FIND: {
|
||||
code_editor->get_find_replace_bar()->popup_search();
|
||||
} break;
|
||||
case SEARCH_FIND_NEXT: {
|
||||
code_editor->get_find_replace_bar()->search_next();
|
||||
} break;
|
||||
case SEARCH_FIND_PREV: {
|
||||
code_editor->get_find_replace_bar()->search_prev();
|
||||
} break;
|
||||
case SEARCH_REPLACE: {
|
||||
code_editor->get_find_replace_bar()->popup_replace();
|
||||
} break;
|
||||
case SEARCH_IN_FILES: {
|
||||
String selected_text = tx->get_selected_text();
|
||||
|
||||
// Yep, because it doesn't make sense to instance this dialog for every single script open...
|
||||
// So this will be delegated to the ScriptEditor.
|
||||
emit_signal(SNAME("search_in_files_requested"), selected_text);
|
||||
} break;
|
||||
case REPLACE_IN_FILES: {
|
||||
String selected_text = tx->get_selected_text();
|
||||
emit_signal(SNAME("replace_in_files_requested"), selected_text);
|
||||
} break;
|
||||
case SEARCH_GOTO_LINE: {
|
||||
goto_line_popup->popup_find_line(code_editor);
|
||||
} break;
|
||||
case BOOKMARK_TOGGLE: {
|
||||
code_editor->toggle_bookmark();
|
||||
} break;
|
||||
case BOOKMARK_GOTO_NEXT: {
|
||||
code_editor->goto_next_bookmark();
|
||||
} break;
|
||||
case BOOKMARK_GOTO_PREV: {
|
||||
code_editor->goto_prev_bookmark();
|
||||
} break;
|
||||
case BOOKMARK_REMOVE_ALL: {
|
||||
code_editor->remove_all_bookmarks();
|
||||
} break;
|
||||
case EDIT_EMOJI_AND_SYMBOL: {
|
||||
tx->show_emoji_and_symbol_picker();
|
||||
} break;
|
||||
case EDIT_TOGGLE_FOLD_LINE: {
|
||||
tx->toggle_foldable_lines_at_carets();
|
||||
} break;
|
||||
case EDIT_FOLD_ALL_LINES: {
|
||||
tx->fold_all_lines();
|
||||
} break;
|
||||
case EDIT_UNFOLD_ALL_LINES: {
|
||||
tx->unfold_all_lines();
|
||||
} break;
|
||||
default: {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextEditorBase::_load_theme_settings() {
|
||||
code_editor->get_text_editor()->get_syntax_highlighter()->update_cache();
|
||||
}
|
||||
|
||||
void TextEditorBase::_validate_script() {
|
||||
emit_signal(SNAME("name_changed"));
|
||||
emit_signal(SNAME("edited_script_changed"));
|
||||
}
|
||||
|
||||
void TextEditorBase::add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) {
|
||||
ERR_FAIL_COND(p_highlighter.is_null());
|
||||
|
||||
highlighters.push_back(p_highlighter);
|
||||
}
|
||||
|
||||
void TextEditorBase::set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) {
|
||||
ERR_FAIL_COND(p_highlighter.is_null());
|
||||
|
||||
CodeEdit *te = code_editor->get_text_editor();
|
||||
p_highlighter->_set_edited_resource(edited_res);
|
||||
te->set_syntax_highlighter(p_highlighter);
|
||||
}
|
||||
|
||||
void TextEditorBase::set_edited_resource(const Ref<Resource> &p_res) {
|
||||
ERR_FAIL_COND(edited_res.is_valid());
|
||||
ERR_FAIL_COND(p_res.is_null());
|
||||
|
||||
edited_res = p_res;
|
||||
|
||||
Ref<TextFile> text_file = edited_res;
|
||||
String text;
|
||||
if (text_file.is_valid()) {
|
||||
text = text_file->get_text();
|
||||
}
|
||||
|
||||
Ref<JSON> json_file = edited_res;
|
||||
if (json_file.is_valid()) {
|
||||
text = json_file->get_parsed_text();
|
||||
}
|
||||
|
||||
code_editor->get_text_editor()->set_text(text);
|
||||
code_editor->get_text_editor()->clear_undo_history();
|
||||
code_editor->get_text_editor()->tag_saved_version();
|
||||
|
||||
emit_signal(SNAME("name_changed"));
|
||||
code_editor->update_line_and_column();
|
||||
}
|
||||
|
||||
bool TextEditorBase::is_unsaved() {
|
||||
return code_editor->get_text_editor()->get_version() != code_editor->get_text_editor()->get_saved_version() || edited_res->get_path().is_empty(); // In memory.
|
||||
}
|
||||
|
||||
void TextEditorBase::tag_saved_version() {
|
||||
code_editor->get_text_editor()->tag_saved_version();
|
||||
ScriptEditorBase::tag_saved_version();
|
||||
}
|
||||
|
||||
void TextEditorBase::reload_text() {
|
||||
ERR_FAIL_COND(edited_res.is_null());
|
||||
|
||||
CodeEdit *te = code_editor->get_text_editor();
|
||||
int column = te->get_caret_column();
|
||||
int row = te->get_caret_line();
|
||||
int h = te->get_h_scroll();
|
||||
int v = te->get_v_scroll();
|
||||
|
||||
Ref<TextFile> text_file = edited_res;
|
||||
if (text_file.is_valid()) {
|
||||
te->set_text(text_file->get_text());
|
||||
}
|
||||
|
||||
Ref<JSON> json_file = edited_res;
|
||||
if (json_file.is_valid()) {
|
||||
te->set_text(json_file->get_parsed_text());
|
||||
}
|
||||
|
||||
Ref<Script> script = edited_res;
|
||||
if (script.is_valid()) {
|
||||
te->set_text(script->get_source_code());
|
||||
}
|
||||
|
||||
te->set_caret_line(row);
|
||||
te->set_caret_column(column);
|
||||
te->set_h_scroll(h);
|
||||
te->set_v_scroll(v);
|
||||
|
||||
te->tag_saved_version();
|
||||
|
||||
code_editor->update_line_and_column();
|
||||
if (editor_enabled) {
|
||||
_validate_script();
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditorBase::enable_editor() {
|
||||
if (editor_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
editor_enabled = true;
|
||||
|
||||
_load_theme_settings();
|
||||
|
||||
_validate_script();
|
||||
}
|
||||
|
||||
void TextEditorBase::set_tooltip_request_func(const Callable &p_toolip_callback) {
|
||||
Variant args[1] = { this };
|
||||
const Variant *argp[] = { &args[0] };
|
||||
code_editor->get_text_editor()->set_tooltip_request_func(p_toolip_callback.bindp(argp, 1));
|
||||
}
|
||||
|
||||
void TextEditorBase::set_edit_state(const Variant &p_state) {
|
||||
code_editor->set_edit_state(p_state);
|
||||
|
||||
Dictionary state = p_state;
|
||||
if (state.has("syntax_highlighter")) {
|
||||
for (const Ref<EditorSyntaxHighlighter> &highlighter : highlighters) {
|
||||
if (highlighter->_get_name() == String(state["syntax_highlighter"])) {
|
||||
set_syntax_highlighter(highlighter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ensure_focus();
|
||||
}
|
||||
|
||||
TextEditorBase::TextEditorBase() {
|
||||
code_editor = memnew(CodeTextEditor);
|
||||
code_editor->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
|
||||
code_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
code_editor->show_toggle_files_button();
|
||||
code_editor->get_text_editor()->set_context_menu_enabled(false);
|
||||
code_editor->get_text_editor()->connect(SceneStringName(gui_input), callable_mp(this, &TextEditorBase::_text_edit_gui_input));
|
||||
code_editor->connect("validate_script", callable_mp(this, &TextEditorBase::_validate_script));
|
||||
code_editor->connect("load_theme_settings", callable_mp(this, &TextEditorBase::_load_theme_settings));
|
||||
code_editor->connect("show_goto_popup", callable_mp(this, &TextEditorBase::_edit_option).bind(SEARCH_GOTO_LINE));
|
||||
|
||||
context_menu = memnew(PopupMenu);
|
||||
context_menu->connect(SceneStringName(id_pressed), callable_mp(this, &TextEditorBase::_edit_option));
|
||||
add_child(context_menu);
|
||||
|
||||
goto_line_popup = memnew(GotoLinePopup);
|
||||
add_child(goto_line_popup);
|
||||
|
||||
Ref<EditorPlainTextSyntaxHighlighter> plain_highlighter;
|
||||
plain_highlighter.instantiate();
|
||||
add_syntax_highlighter(plain_highlighter);
|
||||
|
||||
Ref<EditorStandardSyntaxHighlighter> highlighter;
|
||||
highlighter.instantiate();
|
||||
add_syntax_highlighter(highlighter);
|
||||
set_syntax_highlighter(plain_highlighter);
|
||||
|
||||
update_settings();
|
||||
}
|
||||
|
||||
TextEditorBase::~TextEditorBase() {
|
||||
highlighters.clear();
|
||||
}
|
||||
|
||||
//// CodeEditorBase
|
||||
|
||||
bool CodeEditorBase::_warning_clicked(const Variant &p_line) {
|
||||
if (p_line.get_type() == Variant::INT) {
|
||||
goto_line_centered(p_line.operator int64_t());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CodeEditorBase::EditMenusCEB::EditMenusCEB() {
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_text_completion_query"), EDIT_COMPLETE);
|
||||
_popup_move_item(EDIT_TRIM_TRAILING_WHITESAPCE, edit_menu->get_popup(), false);
|
||||
edit_menu_line->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
|
||||
}
|
||||
|
||||
CodeEditorBase::CodeEditorBase() {
|
||||
warnings_panel = memnew(RichTextLabel);
|
||||
warnings_panel->set_custom_minimum_size(Size2(0, 100 * EDSCALE));
|
||||
warnings_panel->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
warnings_panel->set_meta_underline(true);
|
||||
warnings_panel->set_selection_enabled(true);
|
||||
warnings_panel->set_context_menu_enabled(true);
|
||||
warnings_panel->set_focus_mode(FOCUS_CLICK);
|
||||
warnings_panel->hide();
|
||||
warnings_panel->connect("meta_clicked", callable_mp(this, &CodeEditorBase::_warning_clicked));
|
||||
|
||||
editor_box = memnew(VSplitContainer);
|
||||
add_child(editor_box);
|
||||
editor_box->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
|
||||
editor_box->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
editor_box->add_child(code_editor);
|
||||
editor_box->add_child(warnings_panel);
|
||||
}
|
||||
269
engine/editor/script/script_editor_base.h
Normal file
269
engine/editor/script/script_editor_base.h
Normal file
|
|
@ -0,0 +1,269 @@
|
|||
/**************************************************************************/
|
||||
/* script_editor_base.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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "editor/gui/code_editor.h"
|
||||
#include "scene/gui/box_container.h"
|
||||
|
||||
class EditorSyntaxHighlighter;
|
||||
class MenuButton;
|
||||
class VSplitContainer;
|
||||
|
||||
class ScriptEditorBase : public VBoxContainer {
|
||||
GDCLASS(ScriptEditorBase, VBoxContainer);
|
||||
|
||||
protected:
|
||||
Ref<Resource> edited_res;
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
struct EditedFileData {
|
||||
String path;
|
||||
uint64_t last_modified_time = -1;
|
||||
} edited_file_data;
|
||||
|
||||
virtual String get_name();
|
||||
virtual Ref<Texture2D> get_theme_icon();
|
||||
|
||||
virtual void set_toggle_list_control(Control *p_toggle_list_control) = 0;
|
||||
virtual void update_toggle_files_button() = 0;
|
||||
|
||||
virtual bool show_members_overview() { return false; }
|
||||
|
||||
virtual void set_edited_resource(const Ref<Resource> &p_res) = 0;
|
||||
virtual Ref<Resource> get_edited_resource() const { return edited_res; }
|
||||
|
||||
virtual void apply_code() = 0;
|
||||
virtual void validate_script() = 0;
|
||||
virtual bool is_unsaved() = 0;
|
||||
virtual void tag_saved_version();
|
||||
|
||||
virtual void add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) {}
|
||||
virtual Control *get_base_editor() const { return nullptr; }
|
||||
};
|
||||
|
||||
typedef ScriptEditorBase *(*CreateScriptEditorFunc)(const Ref<Resource> &p_resource);
|
||||
|
||||
class TextEditorBase : public ScriptEditorBase {
|
||||
GDCLASS(TextEditorBase, ScriptEditorBase);
|
||||
|
||||
void _post_init();
|
||||
|
||||
protected:
|
||||
enum {
|
||||
EDIT_UNDO,
|
||||
EDIT_REDO,
|
||||
EDIT_CUT,
|
||||
EDIT_COPY,
|
||||
EDIT_PASTE,
|
||||
EDIT_SELECT_ALL,
|
||||
EDIT_TRIM_TRAILING_WHITESAPCE,
|
||||
EDIT_TRIM_FINAL_NEWLINES,
|
||||
EDIT_CONVERT_INDENT_TO_SPACES,
|
||||
EDIT_CONVERT_INDENT_TO_TABS,
|
||||
EDIT_MOVE_LINE_UP,
|
||||
EDIT_MOVE_LINE_DOWN,
|
||||
EDIT_INDENT,
|
||||
EDIT_UNINDENT,
|
||||
EDIT_DELETE_LINE,
|
||||
EDIT_DUPLICATE_SELECTION,
|
||||
EDIT_DUPLICATE_LINES,
|
||||
EDIT_TO_UPPERCASE,
|
||||
EDIT_TO_LOWERCASE,
|
||||
EDIT_CAPITALIZE,
|
||||
EDIT_TOGGLE_FOLD_LINE,
|
||||
EDIT_FOLD_ALL_LINES,
|
||||
EDIT_TOGGLE_WORD_WRAP,
|
||||
EDIT_UNFOLD_ALL_LINES,
|
||||
EDIT_EMOJI_AND_SYMBOL,
|
||||
|
||||
SEARCH_FIND,
|
||||
SEARCH_FIND_NEXT,
|
||||
SEARCH_FIND_PREV,
|
||||
SEARCH_REPLACE,
|
||||
SEARCH_IN_FILES,
|
||||
SEARCH_GOTO_LINE,
|
||||
|
||||
REPLACE_IN_FILES,
|
||||
|
||||
BOOKMARK_TOGGLE,
|
||||
BOOKMARK_GOTO_NEXT,
|
||||
BOOKMARK_GOTO_PREV,
|
||||
BOOKMARK_REMOVE_ALL,
|
||||
|
||||
EDIT_JOIN_LINES,
|
||||
|
||||
BASE_ENUM_COUNT,
|
||||
};
|
||||
|
||||
class EditMenus : public HBoxContainer {
|
||||
GDCLASS(EditMenus, HBoxContainer);
|
||||
|
||||
protected:
|
||||
MenuButton *edit_menu = nullptr;
|
||||
MenuButton *search_menu = nullptr;
|
||||
MenuButton *goto_menu = nullptr;
|
||||
PopupMenu *bookmarks_menu = nullptr;
|
||||
PopupMenu *highlighter_menu = nullptr;
|
||||
|
||||
PopupMenu *edit_menu_line = nullptr;
|
||||
PopupMenu *edit_menu_fold = nullptr;
|
||||
PopupMenu *edit_menu_convert_indent = nullptr;
|
||||
PopupMenu *edit_menu_convert = nullptr;
|
||||
|
||||
TextEditorBase *_get_active_editor();
|
||||
void _edit_option(int p_op);
|
||||
void _prepare_edit_menu();
|
||||
void _update_highlighter_menu();
|
||||
void _change_syntax_highlighter(int p_idx);
|
||||
void _update_bookmark_list();
|
||||
void _bookmark_item_pressed(int p_idx);
|
||||
|
||||
public:
|
||||
EditMenus();
|
||||
};
|
||||
|
||||
static void _popup_move_item(int p_target_id, PopupMenu *r_popup, bool p_move_after = true, int p_idx = -1) {
|
||||
int target_idx = r_popup->get_item_index(p_target_id) + p_move_after;
|
||||
if (target_idx >= 0 && target_idx < r_popup->get_item_count()) {
|
||||
r_popup->set_item_index(p_idx, target_idx);
|
||||
}
|
||||
}
|
||||
|
||||
static inline EditMenus *edit_menus = nullptr;
|
||||
|
||||
bool editor_enabled = false;
|
||||
CodeTextEditor *code_editor = nullptr;
|
||||
|
||||
GotoLinePopup *goto_line_popup = nullptr;
|
||||
|
||||
LocalVector<Ref<EditorSyntaxHighlighter>> highlighters;
|
||||
|
||||
PopupMenu *context_menu = nullptr;
|
||||
MenuButton *search_menu = nullptr;
|
||||
|
||||
void _make_context_menu(bool p_selection, bool p_foldable, const Vector2 &p_position = Vector2(0, 0), bool p_show = true);
|
||||
void _show_context_menu(const Vector2 &p_position);
|
||||
|
||||
virtual void _text_edit_gui_input(const Ref<InputEvent> &p_ev);
|
||||
virtual bool _edit_option(int p_op);
|
||||
|
||||
virtual void _load_theme_settings();
|
||||
virtual void _validate_script();
|
||||
|
||||
void _convert_case(CodeTextEditor::CaseStyle p_case) { code_editor->convert_case(p_case); }
|
||||
|
||||
public:
|
||||
virtual void add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override;
|
||||
virtual void set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter);
|
||||
|
||||
virtual void set_edited_resource(const Ref<Resource> &p_res) override;
|
||||
|
||||
virtual bool is_unsaved() override;
|
||||
virtual void tag_saved_version() override;
|
||||
|
||||
virtual void reload_text();
|
||||
virtual void enable_editor();
|
||||
|
||||
virtual Control *get_edit_menu() = 0;
|
||||
|
||||
virtual Control *get_base_editor() const override { return code_editor->get_text_editor(); }
|
||||
virtual CodeTextEditor *get_code_editor() const { return code_editor; }
|
||||
|
||||
virtual void set_tooltip_request_func(const Callable &p_toolip_callback);
|
||||
|
||||
virtual void ensure_focus() { code_editor->get_text_editor()->grab_focus(); }
|
||||
virtual void convert_indent() { code_editor->get_text_editor()->convert_indent(); }
|
||||
|
||||
virtual void trim_trailing_whitespace() { code_editor->trim_trailing_whitespace(); }
|
||||
virtual void trim_final_newlines() { code_editor->trim_final_newlines(); }
|
||||
virtual void insert_final_newline() { code_editor->insert_final_newline(); }
|
||||
|
||||
virtual void goto_line(int p_line, int p_column = 0) { code_editor->goto_line(p_line, p_column); }
|
||||
virtual void goto_line_selection(int p_line, int p_begin, int p_end) { code_editor->goto_line_selection(p_line, p_begin, p_end); }
|
||||
virtual void goto_line_centered(int p_line, int p_column = 0) { code_editor->goto_line_centered(p_line, p_column); }
|
||||
virtual void set_executing_line(int p_line) { code_editor->set_executing_line(p_line); }
|
||||
virtual void clear_executing_line() { code_editor->clear_executing_line(); }
|
||||
|
||||
virtual Variant get_edit_state() { return code_editor->get_edit_state(); }
|
||||
virtual void set_edit_state(const Variant &p_state);
|
||||
virtual Variant get_navigation_state() { return code_editor->get_navigation_state(); }
|
||||
|
||||
virtual void update_settings() { code_editor->update_editor_settings(); }
|
||||
virtual void set_find_replace_bar(FindReplaceBar *p_bar) { code_editor->set_find_replace_bar(p_bar); }
|
||||
|
||||
virtual void validate_script() override { code_editor->validate_script(); }
|
||||
|
||||
virtual void set_toggle_list_control(Control *p_toggle_list_control) override {
|
||||
code_editor->set_toggle_list_control(p_toggle_list_control);
|
||||
}
|
||||
virtual void update_toggle_files_button() override { code_editor->update_toggle_files_button(); }
|
||||
|
||||
TextEditorBase();
|
||||
~TextEditorBase();
|
||||
};
|
||||
|
||||
class CodeEditorBase : public TextEditorBase {
|
||||
GDCLASS(CodeEditorBase, TextEditorBase);
|
||||
|
||||
protected:
|
||||
enum {
|
||||
EDIT_COMPLETE = BASE_ENUM_COUNT,
|
||||
EDIT_TOGGLE_COMMENT,
|
||||
|
||||
CODE_ENUM_COUNT,
|
||||
};
|
||||
|
||||
class EditMenusCEB : public EditMenus {
|
||||
GDCLASS(EditMenusCEB, EditMenus);
|
||||
|
||||
public:
|
||||
EditMenusCEB();
|
||||
};
|
||||
|
||||
VSplitContainer *editor_box = nullptr;
|
||||
RichTextLabel *warnings_panel = nullptr;
|
||||
|
||||
virtual void _code_complete_script(const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_force) = 0;
|
||||
virtual bool _warning_clicked(const Variant &p_line);
|
||||
|
||||
public:
|
||||
virtual bool show_members_overview() override { return true; }
|
||||
|
||||
virtual Vector<String> get_functions() { return Vector<String>(); }
|
||||
|
||||
virtual PackedInt32Array get_breakpoints() { return PackedInt32Array(); }
|
||||
virtual void set_breakpoint(int p_line, bool p_enabled) {}
|
||||
virtual void clear_breakpoints() {}
|
||||
|
||||
CodeEditorBase();
|
||||
};
|
||||
4460
engine/editor/script/script_editor_plugin.cpp
Normal file
4460
engine/editor/script/script_editor_plugin.cpp
Normal file
File diff suppressed because it is too large
Load diff
507
engine/editor/script/script_editor_plugin.h
Normal file
507
engine/editor/script/script_editor_plugin.h
Normal file
|
|
@ -0,0 +1,507 @@
|
|||
/**************************************************************************/
|
||||
/* script_editor_plugin.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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/error/error_list.h"
|
||||
#include "core/object/script_language.h"
|
||||
#include "editor/plugins/editor_plugin.h"
|
||||
#include "editor/script/script_editor_base.h"
|
||||
#include "scene/gui/dialogs.h"
|
||||
#include "scene/gui/panel_container.h"
|
||||
#include "scene/resources/text_file.h"
|
||||
|
||||
class CodeTextEditor;
|
||||
class EditorFileDialog;
|
||||
class EditorHelpSearch;
|
||||
class FilterLineEdit;
|
||||
class FindReplaceBar;
|
||||
class HSplitContainer;
|
||||
class ItemList;
|
||||
class MenuButton;
|
||||
class TabContainer;
|
||||
class TextureRect;
|
||||
class Tree;
|
||||
class VSplitContainer;
|
||||
class WindowWrapper;
|
||||
class EditorSyntaxHighlighter;
|
||||
class ScriptEditorBase;
|
||||
|
||||
class ScriptEditorQuickOpen : public ConfirmationDialog {
|
||||
GDCLASS(ScriptEditorQuickOpen, ConfirmationDialog);
|
||||
|
||||
FilterLineEdit *search_box = nullptr;
|
||||
Tree *search_options = nullptr;
|
||||
String function;
|
||||
|
||||
void _update_search();
|
||||
|
||||
Vector<String> functions;
|
||||
|
||||
void _confirmed();
|
||||
void _text_changed(const String &p_newtext);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void popup_dialog(const Vector<String> &p_functions, bool p_dontclear = false);
|
||||
ScriptEditorQuickOpen();
|
||||
};
|
||||
|
||||
class EditorScriptCodeCompletionCache;
|
||||
class FindInFilesContainer;
|
||||
class FindInFilesDialog;
|
||||
|
||||
class ScriptEditor : public PanelContainer {
|
||||
GDCLASS(ScriptEditor, PanelContainer);
|
||||
|
||||
enum MenuOptions {
|
||||
// File.
|
||||
FILE_MENU_NEW_SCRIPT,
|
||||
FILE_MENU_NEW_TEXTFILE,
|
||||
FILE_MENU_OPEN,
|
||||
FILE_MENU_REOPEN_CLOSED,
|
||||
FILE_MENU_OPEN_RECENT,
|
||||
|
||||
FILE_MENU_SAVE,
|
||||
FILE_MENU_SAVE_AS,
|
||||
FILE_MENU_SAVE_ALL,
|
||||
|
||||
FILE_MENU_SOFT_RELOAD_TOOL,
|
||||
FILE_MENU_COPY_PATH,
|
||||
FILE_MENU_COPY_UID,
|
||||
FILE_MENU_SHOW_IN_FILE_SYSTEM,
|
||||
|
||||
FILE_MENU_HISTORY_PREV,
|
||||
FILE_MENU_HISTORY_NEXT,
|
||||
|
||||
FILE_MENU_THEME_SUBMENU,
|
||||
|
||||
FILE_MENU_CLOSE,
|
||||
FILE_MENU_CLOSE_ALL,
|
||||
FILE_MENU_CLOSE_OTHER_TABS,
|
||||
FILE_MENU_CLOSE_TABS_BELOW,
|
||||
FILE_MENU_CLOSE_DOCS,
|
||||
|
||||
FILE_MENU_RUN,
|
||||
|
||||
FILE_MENU_TOGGLE_FILES_PANEL,
|
||||
|
||||
FILE_MENU_MOVE_UP,
|
||||
FILE_MENU_MOVE_DOWN,
|
||||
FILE_MENU_SORT,
|
||||
|
||||
// Search.
|
||||
HELP_SEARCH_FIND,
|
||||
HELP_SEARCH_FIND_NEXT,
|
||||
HELP_SEARCH_FIND_PREVIOUS,
|
||||
|
||||
SEARCH_IN_FILES,
|
||||
REPLACE_IN_FILES,
|
||||
|
||||
SEARCH_HELP,
|
||||
SEARCH_WEBSITE,
|
||||
|
||||
// Theme.
|
||||
THEME_IMPORT,
|
||||
THEME_RELOAD,
|
||||
THEME_SAVE_AS,
|
||||
};
|
||||
|
||||
enum ScriptSortBy {
|
||||
SORT_BY_NAME,
|
||||
SORT_BY_PATH,
|
||||
SORT_BY_NONE,
|
||||
};
|
||||
|
||||
enum ScriptListName {
|
||||
DISPLAY_NAME,
|
||||
DISPLAY_DIR_AND_NAME,
|
||||
DISPLAY_FULL_PATH,
|
||||
};
|
||||
|
||||
HBoxContainer *menu_hb = nullptr;
|
||||
MenuButton *file_menu = nullptr;
|
||||
MenuButton *script_search_menu = nullptr;
|
||||
MenuButton *debug_menu = nullptr;
|
||||
PopupMenu *context_menu = nullptr;
|
||||
Timer *autosave_timer = nullptr;
|
||||
LocalVector<Control *> editor_menus;
|
||||
|
||||
PopupMenu *recent_scripts = nullptr;
|
||||
PopupMenu *theme_submenu = nullptr;
|
||||
|
||||
Button *help_search = nullptr;
|
||||
Button *site_search = nullptr;
|
||||
Button *make_floating = nullptr;
|
||||
bool is_floating = false;
|
||||
EditorHelpSearch *help_search_dialog = nullptr;
|
||||
|
||||
ItemList *script_list = nullptr;
|
||||
HSplitContainer *script_split = nullptr;
|
||||
ItemList *members_overview = nullptr;
|
||||
LineEdit *filter_scripts = nullptr;
|
||||
LineEdit *filter_methods = nullptr;
|
||||
VBoxContainer *scripts_vbox = nullptr;
|
||||
VBoxContainer *overview_vbox = nullptr;
|
||||
HBoxContainer *buttons_hbox = nullptr;
|
||||
Button *members_overview_alphabeta_sort_button = nullptr;
|
||||
bool members_overview_enabled;
|
||||
ItemList *help_overview = nullptr;
|
||||
bool help_overview_enabled;
|
||||
VSplitContainer *list_split = nullptr;
|
||||
TabContainer *tab_container = nullptr;
|
||||
EditorFileDialog *file_dialog = nullptr;
|
||||
AcceptDialog *error_dialog = nullptr;
|
||||
ConfirmationDialog *erase_tab_confirm = nullptr;
|
||||
ScriptCreateDialog *script_create_dialog = nullptr;
|
||||
FindReplaceBar *find_replace_bar = nullptr;
|
||||
|
||||
float zoom_factor = 1.0f;
|
||||
|
||||
HBoxContainer *script_name_button_hbox = nullptr;
|
||||
Control *script_name_button_left_spacer = nullptr;
|
||||
Control *script_name_button_right_spacer = nullptr;
|
||||
Button *script_name_button = nullptr;
|
||||
int script_name_width = 0;
|
||||
|
||||
Button *script_back = nullptr;
|
||||
Button *script_forward = nullptr;
|
||||
|
||||
FindInFilesDialog *find_in_files_dialog = nullptr;
|
||||
FindInFilesContainer *find_in_files = nullptr;
|
||||
|
||||
WindowWrapper *window_wrapper = nullptr;
|
||||
|
||||
#ifdef ANDROID_ENABLED
|
||||
Control *virtual_keyboard_spacer = nullptr;
|
||||
int last_kb_height = -1;
|
||||
#endif
|
||||
|
||||
enum {
|
||||
SCRIPT_EDITOR_FUNC_MAX = 32,
|
||||
};
|
||||
|
||||
static int script_editor_func_count;
|
||||
static CreateScriptEditorFunc script_editor_funcs[SCRIPT_EDITOR_FUNC_MAX];
|
||||
|
||||
Vector<Ref<EditorSyntaxHighlighter>> syntax_highlighters;
|
||||
|
||||
struct ScriptHistory {
|
||||
Control *control = nullptr;
|
||||
Variant state;
|
||||
};
|
||||
|
||||
Vector<ScriptHistory> history;
|
||||
int history_pos;
|
||||
|
||||
List<String> previous_scripts;
|
||||
List<int> script_close_queue;
|
||||
|
||||
List<String> _get_recognized_extensions();
|
||||
|
||||
void _tab_changed(int p_which);
|
||||
void _menu_option(int p_option);
|
||||
void _theme_option(int p_option);
|
||||
void _show_save_theme_as_dialog();
|
||||
bool _has_docs_tab() const;
|
||||
bool _has_script_tab() const;
|
||||
void _prepare_file_menu();
|
||||
void _file_menu_closed();
|
||||
|
||||
Tree *disk_changed_list = nullptr;
|
||||
ConfirmationDialog *disk_changed = nullptr;
|
||||
|
||||
bool restoring_layout;
|
||||
|
||||
void _resave_scripts(const String &p_str);
|
||||
|
||||
bool _test_script_times_on_disk(Ref<Resource> p_for_script = Ref<Resource>());
|
||||
bool _script_exists(const String &p_path) const;
|
||||
|
||||
void _add_recent_script(const String &p_path);
|
||||
void _update_recent_scripts();
|
||||
void _open_recent_script(int p_idx);
|
||||
|
||||
void _show_error_dialog(const String &p_path);
|
||||
|
||||
void _close_tab(int p_idx, bool p_save = true, bool p_history_back = true);
|
||||
void _update_find_replace_bar();
|
||||
|
||||
void _close_current_tab(bool p_save = true, bool p_history_back = true);
|
||||
void _close_discard_current_tab(const String &p_str);
|
||||
void _close_docs_tab();
|
||||
void _close_other_tabs();
|
||||
void _close_tabs_below();
|
||||
void _close_all_tabs();
|
||||
void _queue_close_tabs();
|
||||
|
||||
void _copy_script_path();
|
||||
void _copy_script_uid();
|
||||
|
||||
void _ask_close_current_unsaved_tab(ScriptEditorBase *current);
|
||||
|
||||
bool grab_focus_block;
|
||||
|
||||
bool pending_auto_reload;
|
||||
bool auto_reload_running_scripts;
|
||||
Vector<String> script_paths_to_reload;
|
||||
void _live_auto_reload_running_scripts();
|
||||
|
||||
void _update_selected_editor_menu();
|
||||
|
||||
int edit_pass;
|
||||
|
||||
void _add_callback(Object *p_obj, const String &p_function, const PackedStringArray &p_args);
|
||||
void _res_saved_callback(const Ref<Resource> &p_res);
|
||||
void _scene_saved_callback(const String &p_path);
|
||||
void _mark_built_in_scripts_as_saved(const String &p_parent_path);
|
||||
|
||||
bool trim_trailing_whitespace_on_save;
|
||||
bool trim_final_newlines_on_save;
|
||||
bool convert_indent_on_save;
|
||||
bool external_editor_active;
|
||||
|
||||
void _goto_script_line2(int p_line);
|
||||
void _goto_script_line(Ref<RefCounted> p_script, int p_line);
|
||||
void _change_execution(Ref<RefCounted> p_script, int p_line = -1, bool p_set = false);
|
||||
void _set_execution(Ref<RefCounted> p_script, int p_line) { _change_execution(p_script, p_line, true); }
|
||||
void _clear_execution(Ref<RefCounted> p_script) { _change_execution(p_script); }
|
||||
String _get_debug_tooltip(const String &p_text, Node *p_se);
|
||||
void _script_created(Ref<Script> p_script);
|
||||
void _set_breakpoint(Ref<RefCounted> p_script, int p_line, bool p_enabled);
|
||||
void _clear_breakpoints();
|
||||
Array _get_cached_breakpoints_for_script(const String &p_path) const;
|
||||
|
||||
ScriptEditorBase *_get_current_editor() const;
|
||||
TypedArray<ScriptEditorBase> _get_open_script_editors() const;
|
||||
|
||||
Ref<ConfigFile> script_editor_cache;
|
||||
void _save_editor_state(ScriptEditorBase *p_editor);
|
||||
void _save_layout();
|
||||
void _apply_editor_settings();
|
||||
void _filesystem_changed();
|
||||
void _files_moved(const String &p_old_file, const String &p_new_file);
|
||||
void _file_removed(const String &p_file);
|
||||
void _autosave_scripts();
|
||||
void _update_autosave_timer();
|
||||
void _reload_scripts(bool p_refresh_only = false);
|
||||
void _auto_format_text(ScriptEditorBase *p_seb);
|
||||
|
||||
void _update_members_overview_visibility();
|
||||
void _update_members_overview();
|
||||
void _toggle_members_overview_alpha_sort(bool p_alphabetic_sort);
|
||||
void _filter_scripts_text_changed(const String &p_newtext);
|
||||
void _filter_methods_text_changed(const String &p_newtext);
|
||||
void _update_script_names();
|
||||
bool _sort_list_on_update;
|
||||
|
||||
void _members_overview_selected(int p_idx);
|
||||
void _script_selected(int p_idx);
|
||||
|
||||
void _update_help_overview_visibility();
|
||||
void _update_help_overview();
|
||||
void _help_overview_selected(int p_idx);
|
||||
|
||||
void _update_online_doc();
|
||||
|
||||
void _find_scripts(Node *p_base, Node *p_current, HashSet<Ref<Script>> &used);
|
||||
|
||||
void _tree_changed();
|
||||
|
||||
void _split_dragged(float);
|
||||
|
||||
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
|
||||
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
|
||||
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
|
||||
|
||||
virtual void input(const Ref<InputEvent> &p_event) override;
|
||||
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
|
||||
|
||||
void _script_list_clicked(int p_item, Vector2 p_local_mouse_pos, MouseButton p_mouse_button_index);
|
||||
void _make_script_list_context_menu();
|
||||
|
||||
void _calculate_script_name_button_size();
|
||||
void _calculate_script_name_button_ratio();
|
||||
|
||||
void _help_search(const String &p_text);
|
||||
|
||||
void _history_forward();
|
||||
void _history_back();
|
||||
|
||||
bool waiting_update_names;
|
||||
bool lock_history = false;
|
||||
void _unlock_history();
|
||||
|
||||
void _help_class_open(const String &p_class);
|
||||
void _help_class_goto(const String &p_desc);
|
||||
bool _help_tab_goto(const String &p_name, const String &p_desc);
|
||||
void _update_history_arrows();
|
||||
void _save_history();
|
||||
void _save_previous_state(Dictionary p_state);
|
||||
void _go_to_tab(int p_idx);
|
||||
void _update_history_pos(int p_new_pos);
|
||||
void _update_script_colors();
|
||||
void _update_modified_scripts_for_external_editor(Ref<Script> p_for_script = Ref<Script>());
|
||||
|
||||
void _script_changed();
|
||||
int file_dialog_option;
|
||||
void _file_dialog_action(const String &p_file);
|
||||
|
||||
Ref<Script> _get_current_script();
|
||||
TypedArray<Script> _get_open_scripts() const;
|
||||
|
||||
HashSet<String> textfile_extensions;
|
||||
Ref<TextFile> _load_text_file(const String &p_path, Error *r_error) const;
|
||||
Error _save_text_file(Ref<TextFile> p_text_file, const String &p_path);
|
||||
|
||||
void _on_replace_in_files_requested(const String &text);
|
||||
void _on_find_in_files_result_selected(const String &fpath, int line_number, int begin, int end);
|
||||
void _start_find_in_files(bool with_replace);
|
||||
void _on_find_in_files_modified_files(const PackedStringArray &paths);
|
||||
|
||||
void _set_script_zoom_factor(float p_zoom_factor);
|
||||
void _update_code_editor_zoom_factor(CodeTextEditor *p_code_text_editor);
|
||||
|
||||
void _window_changed(bool p_visible);
|
||||
|
||||
void _close_builtin_scripts_from_scene(const String &p_scene);
|
||||
|
||||
static ScriptEditor *script_editor;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
static ScriptEditor *get_singleton() { return script_editor; }
|
||||
|
||||
bool toggle_files_panel();
|
||||
bool is_files_panel_toggled();
|
||||
void apply_scripts() const;
|
||||
void reload_scripts(bool p_refresh_only = false);
|
||||
void open_find_in_files_dialog(const String &text);
|
||||
void open_script_create_dialog(const String &p_base_name, const String &p_base_path);
|
||||
void open_text_file_create_dialog(const String &p_base_path, const String &p_base_name = "");
|
||||
Ref<Resource> open_file(const String &p_file);
|
||||
Error close_file(const String &p_file);
|
||||
|
||||
void ensure_select_current();
|
||||
|
||||
bool is_editor_floating();
|
||||
|
||||
_FORCE_INLINE_ bool edit(const Ref<Resource> &p_resource, bool p_grab_focus = true) { return edit(p_resource, -1, 0, p_grab_focus); }
|
||||
bool edit(const Ref<Resource> &p_resource, int p_line, int p_col, bool p_grab_focus = true);
|
||||
|
||||
Vector<String> _get_breakpoints();
|
||||
void get_breakpoints(List<String> *p_breakpoints);
|
||||
|
||||
void reload_open_files();
|
||||
PackedStringArray get_unsaved_files() const;
|
||||
PackedStringArray get_unsaved_scripts() const;
|
||||
void save_current_script();
|
||||
void save_all_scripts();
|
||||
void update_script_times();
|
||||
|
||||
void set_window_layout(Ref<ConfigFile> p_layout);
|
||||
void get_window_layout(Ref<ConfigFile> p_layout);
|
||||
|
||||
void set_scene_root_script(Ref<Script> p_script);
|
||||
Vector<Ref<Script>> get_open_scripts() const;
|
||||
|
||||
ScriptEditorBase *get_current_editor() const { return _get_current_editor(); }
|
||||
|
||||
bool script_goto_method(Ref<Script> p_script, const String &p_method);
|
||||
|
||||
virtual void edited_scene_changed();
|
||||
|
||||
void notify_script_close(const Ref<Script> &p_script);
|
||||
void notify_script_changed(const Ref<Script> &p_script);
|
||||
|
||||
void goto_help(const String &p_desc) { _help_class_goto(p_desc); }
|
||||
void update_doc(const String &p_name);
|
||||
void clear_docs_from_script(const Ref<Script> &p_script);
|
||||
void update_docs_from_script(const Ref<Script> &p_script);
|
||||
|
||||
void trigger_live_script_reload(const String &p_script_path);
|
||||
|
||||
VSplitContainer *get_left_list_split() { return list_split; }
|
||||
|
||||
void set_live_auto_reload_running_scripts(bool p_enabled);
|
||||
|
||||
void register_syntax_highlighter(const Ref<EditorSyntaxHighlighter> &p_syntax_highlighter);
|
||||
void unregister_syntax_highlighter(const Ref<EditorSyntaxHighlighter> &p_syntax_highlighter);
|
||||
|
||||
static void register_create_script_editor_function(CreateScriptEditorFunc p_func);
|
||||
|
||||
ScriptEditor(WindowWrapper *p_wrapper);
|
||||
};
|
||||
|
||||
class ScriptEditorPlugin : public EditorPlugin {
|
||||
GDCLASS(ScriptEditorPlugin, EditorPlugin);
|
||||
|
||||
ScriptEditor *script_editor = nullptr;
|
||||
WindowWrapper *window_wrapper = nullptr;
|
||||
|
||||
String last_editor;
|
||||
|
||||
void _focus_another_editor();
|
||||
|
||||
void _save_last_editor(const String &p_editor);
|
||||
void _window_visibility_changed(bool p_visible);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
static bool open_in_external_editor(const String &p_path, int p_line, int p_col, bool p_ignore_project = false);
|
||||
|
||||
virtual String get_plugin_name() const override { return TTRC("Script"); }
|
||||
bool has_main_screen() const override { return true; }
|
||||
virtual void edit(Object *p_object) override;
|
||||
virtual bool handles(Object *p_object) const override;
|
||||
virtual void make_visible(bool p_visible) override;
|
||||
virtual void selected_notify() override;
|
||||
|
||||
virtual String get_unsaved_status(const String &p_for_scene) const override;
|
||||
virtual void save_external_data() override;
|
||||
virtual void apply_changes() override;
|
||||
|
||||
virtual void set_window_layout(Ref<ConfigFile> p_layout) override;
|
||||
virtual void get_window_layout(Ref<ConfigFile> p_layout) override;
|
||||
|
||||
virtual void get_breakpoints(List<String> *p_breakpoints) override;
|
||||
|
||||
virtual void edited_scene_changed() override;
|
||||
|
||||
ScriptEditorPlugin();
|
||||
};
|
||||
2794
engine/editor/script/script_text_editor.cpp
Normal file
2794
engine/editor/script/script_text_editor.cpp
Normal file
File diff suppressed because it is too large
Load diff
245
engine/editor/script/script_text_editor.h
Normal file
245
engine/editor/script/script_text_editor.h
Normal file
|
|
@ -0,0 +1,245 @@
|
|||
/**************************************************************************/
|
||||
/* script_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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "editor/gui/code_editor.h"
|
||||
#include "editor/script/script_editor_base.h"
|
||||
#include "editor/script/script_editor_plugin.h"
|
||||
#include "scene/gui/color_picker.h"
|
||||
#include "scene/gui/dialogs.h"
|
||||
#include "scene/gui/option_button.h"
|
||||
#include "scene/gui/tree.h"
|
||||
|
||||
class RichTextLabel;
|
||||
|
||||
class ConnectionInfoDialog : public AcceptDialog {
|
||||
GDCLASS(ConnectionInfoDialog, AcceptDialog);
|
||||
|
||||
Label *method = nullptr;
|
||||
Tree *tree = nullptr;
|
||||
|
||||
virtual void ok_pressed() override;
|
||||
|
||||
public:
|
||||
void popup_connections(const String &p_method, const Vector<Node *> &p_nodes);
|
||||
|
||||
ConnectionInfoDialog();
|
||||
};
|
||||
|
||||
class ScriptTextEditor : public CodeEditorBase {
|
||||
GDCLASS(ScriptTextEditor, CodeEditorBase);
|
||||
|
||||
Variant pending_state;
|
||||
bool script_is_valid = false;
|
||||
|
||||
RichTextLabel *errors_panel = nullptr;
|
||||
Label *drag_info_label = nullptr;
|
||||
|
||||
Vector<String> functions;
|
||||
List<ScriptLanguage::Warning> warnings;
|
||||
List<ScriptLanguage::ScriptError> errors;
|
||||
HashMap<String, List<ScriptLanguage::ScriptError>> depended_errors;
|
||||
HashSet<int> safe_lines;
|
||||
|
||||
List<Connection> missing_connections;
|
||||
|
||||
int inline_color_line = -1;
|
||||
int inline_color_start = -1;
|
||||
int inline_color_end = -1;
|
||||
PopupPanel *inline_color_popup = nullptr;
|
||||
ColorPicker *inline_color_picker = nullptr;
|
||||
OptionButton *inline_color_options = nullptr;
|
||||
Ref<Texture2D> color_alpha_texture;
|
||||
|
||||
ScriptEditorQuickOpen *quick_open = nullptr;
|
||||
ConnectionInfoDialog *connection_info_dialog = nullptr;
|
||||
|
||||
int connection_gutter = -1;
|
||||
void _gutter_clicked(int p_line, int p_gutter);
|
||||
void _update_gutter_indexes();
|
||||
|
||||
int line_number_gutter = -1;
|
||||
Color default_line_number_color = Color(1, 1, 1);
|
||||
Color safe_line_number_color = Color(1, 1, 1);
|
||||
|
||||
Color marked_line_color = Color(1, 1, 1);
|
||||
Color warning_line_color = Color(1, 1, 1);
|
||||
Color folded_code_region_color = Color(1, 1, 1);
|
||||
int previous_line = -1; // Previous caret line number when user continuously operates in this editor. Affects history state. Reset to -1 on editor switch.
|
||||
|
||||
PopupPanel *color_panel = nullptr;
|
||||
ColorPicker *color_picker = nullptr;
|
||||
Vector3i color_position;
|
||||
String color_args;
|
||||
|
||||
bool theme_loaded = false;
|
||||
|
||||
enum {
|
||||
EDIT_AUTO_INDENT = CODE_ENUM_COUNT,
|
||||
EDIT_PICK_COLOR,
|
||||
EDIT_EVALUATE,
|
||||
EDIT_CREATE_CODE_REGION,
|
||||
|
||||
SEARCH_LOCATE_FUNCTION,
|
||||
|
||||
DEBUG_TOGGLE_BREAKPOINT,
|
||||
DEBUG_REMOVE_ALL_BREAKPOINTS,
|
||||
DEBUG_GOTO_NEXT_BREAKPOINT,
|
||||
DEBUG_GOTO_PREV_BREAKPOINT,
|
||||
|
||||
SHOW_TOOLTIP_AT_CARET,
|
||||
HELP_CONTEXTUAL,
|
||||
LOOKUP_SYMBOL,
|
||||
};
|
||||
|
||||
enum COLOR_MODE {
|
||||
MODE_RGB,
|
||||
MODE_STRING,
|
||||
MODE_HSV,
|
||||
MODE_OKHSL,
|
||||
MODE_RGB8,
|
||||
MODE_HEX,
|
||||
MODE_MAX
|
||||
};
|
||||
|
||||
class EditMenusSTE : public EditMenusCEB {
|
||||
GDCLASS(EditMenusSTE, EditMenusCEB);
|
||||
PopupMenu *breakpoints_menu = nullptr;
|
||||
|
||||
void _update_breakpoint_list();
|
||||
void _breakpoint_item_pressed(int p_idx);
|
||||
|
||||
public:
|
||||
EditMenusSTE();
|
||||
};
|
||||
|
||||
void _enable_code_editor();
|
||||
|
||||
struct DraggedExport {
|
||||
ObjectID obj_id;
|
||||
String variable_name;
|
||||
Variant value;
|
||||
String class_name;
|
||||
};
|
||||
|
||||
LocalVector<DraggedExport> pending_dragged_exports;
|
||||
Vector<ObjectID> _get_objects_for_export_assignment() const;
|
||||
String _get_dropped_resource_as_exported_member(const Ref<Resource> &p_resource, const Vector<ObjectID> &p_script_instance_obj_ids);
|
||||
void _assign_dragged_export_variables();
|
||||
|
||||
static ScriptEditorBase *create_editor(const Ref<Resource> &p_resource);
|
||||
|
||||
protected:
|
||||
void _breakpoint_toggled(int p_row);
|
||||
|
||||
void _on_caret_moved();
|
||||
|
||||
void _update_warnings();
|
||||
void _update_errors();
|
||||
|
||||
static void _code_complete_scripts(void *p_ud, const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_force);
|
||||
virtual void _code_complete_script(const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_force) override;
|
||||
|
||||
void _set_theme_for_script();
|
||||
void _show_errors_panel(bool p_show);
|
||||
void _show_warnings_panel(bool p_show);
|
||||
void _error_clicked(const Variant &p_line);
|
||||
virtual bool _warning_clicked(const Variant &p_line) override;
|
||||
void _on_mouse_exited();
|
||||
|
||||
bool _is_valid_color_info(const Dictionary &p_info);
|
||||
Array _inline_object_parse(const String &p_text);
|
||||
void _inline_object_draw(const Dictionary &p_info, const Rect2 &p_rect);
|
||||
void _inline_object_handle_click(const Dictionary &p_info, const Rect2 &p_rect);
|
||||
String _picker_color_stringify(const Color &p_color, COLOR_MODE p_mode);
|
||||
void _picker_color_changed(const Color &p_color);
|
||||
void _update_color_constructor_options();
|
||||
void _update_background_color();
|
||||
void _update_color_text();
|
||||
|
||||
void _notification(int p_what);
|
||||
|
||||
void _edit_option_toggle_inline_comment();
|
||||
void _color_changed(const Color &p_color);
|
||||
|
||||
void _lookup_symbol(const String &p_symbol, int p_row, int p_column);
|
||||
void _validate_symbol(const String &p_symbol);
|
||||
|
||||
void _show_symbol_tooltip(const String &p_symbol, int p_row, int p_column, bool p_shortcut = false);
|
||||
|
||||
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
|
||||
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
|
||||
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
|
||||
|
||||
void _set_drop_info_text(const Dictionary &p_info) const;
|
||||
|
||||
String _get_absolute_path(const String &rel_path);
|
||||
|
||||
void _goto_line(int p_line) { goto_line(p_line); }
|
||||
|
||||
void _make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, const Vector2 &p_pos);
|
||||
|
||||
virtual void _text_edit_gui_input(const Ref<InputEvent> &p_ev) override;
|
||||
virtual bool _edit_option(int p_op) override;
|
||||
|
||||
virtual void _load_theme_settings() override;
|
||||
virtual void _validate_script() override;
|
||||
|
||||
public:
|
||||
void _update_connected_methods();
|
||||
|
||||
virtual void apply_code() override;
|
||||
virtual void set_edited_resource(const Ref<Resource> &p_res) override;
|
||||
virtual void enable_editor() override;
|
||||
virtual Vector<String> get_functions() override;
|
||||
|
||||
virtual Control *get_edit_menu() override;
|
||||
|
||||
virtual Ref<Texture2D> get_theme_icon() override;
|
||||
|
||||
virtual Variant get_edit_state() override;
|
||||
virtual void set_edit_state(const Variant &p_state) override;
|
||||
|
||||
virtual PackedInt32Array get_breakpoints() override;
|
||||
virtual void set_breakpoint(int p_line, bool p_enabled) override;
|
||||
virtual void clear_breakpoints() override;
|
||||
|
||||
virtual void add_callback(const String &p_function, const PackedStringArray &p_args);
|
||||
virtual void update_settings() override;
|
||||
|
||||
static void register_editor();
|
||||
|
||||
Variant get_previous_state();
|
||||
void store_previous_state();
|
||||
|
||||
ScriptTextEditor();
|
||||
~ScriptTextEditor();
|
||||
};
|
||||
308
engine/editor/script/syntax_highlighters.cpp
Normal file
308
engine/editor/script/syntax_highlighters.cpp
Normal file
|
|
@ -0,0 +1,308 @@
|
|||
/**************************************************************************/
|
||||
/* syntax_highlighters.cpp */
|
||||
/**************************************************************************/
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "syntax_highlighters.h"
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/object/class_db.h"
|
||||
#include "core/object/script_language.h"
|
||||
#include "editor/settings/editor_settings.h"
|
||||
|
||||
String EditorSyntaxHighlighter::_get_name() const {
|
||||
String ret = "Unnamed";
|
||||
GDVIRTUAL_CALL(_get_name, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
PackedStringArray EditorSyntaxHighlighter::_get_supported_languages() const {
|
||||
PackedStringArray ret;
|
||||
GDVIRTUAL_CALL(_get_supported_languages, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Ref<EditorSyntaxHighlighter> EditorSyntaxHighlighter::_create() const {
|
||||
Ref<EditorSyntaxHighlighter> syntax_highlighter;
|
||||
if (GDVIRTUAL_IS_OVERRIDDEN(_create)) {
|
||||
GDVIRTUAL_CALL(_create, syntax_highlighter);
|
||||
} else {
|
||||
syntax_highlighter.instantiate();
|
||||
if (get_script_instance()) {
|
||||
syntax_highlighter->set_script(get_script_instance()->get_script());
|
||||
}
|
||||
}
|
||||
return syntax_highlighter;
|
||||
}
|
||||
|
||||
void EditorSyntaxHighlighter::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("_get_edited_resource"), &EditorSyntaxHighlighter::_get_edited_resource);
|
||||
|
||||
GDVIRTUAL_BIND(_get_name)
|
||||
GDVIRTUAL_BIND(_get_supported_languages)
|
||||
GDVIRTUAL_BIND(_create)
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
void EditorStandardSyntaxHighlighter::_update_cache() {
|
||||
highlighter->set_text_edit(text_edit);
|
||||
highlighter->clear_keyword_colors();
|
||||
highlighter->clear_member_keyword_colors();
|
||||
highlighter->clear_color_regions();
|
||||
|
||||
highlighter->set_symbol_color(EDITOR_GET("text_editor/theme/highlighting/symbol_color"));
|
||||
highlighter->set_function_color(EDITOR_GET("text_editor/theme/highlighting/function_color"));
|
||||
highlighter->set_number_color(EDITOR_GET("text_editor/theme/highlighting/number_color"));
|
||||
highlighter->set_member_variable_color(EDITOR_GET("text_editor/theme/highlighting/member_variable_color"));
|
||||
|
||||
/* Engine types. */
|
||||
const Color type_color = EDITOR_GET("text_editor/theme/highlighting/engine_type_color");
|
||||
LocalVector<StringName> types;
|
||||
ClassDB::get_class_list(types);
|
||||
for (const StringName &type : types) {
|
||||
highlighter->add_keyword_color(type, type_color);
|
||||
}
|
||||
|
||||
/* User types. */
|
||||
const Color usertype_color = EDITOR_GET("text_editor/theme/highlighting/user_type_color");
|
||||
LocalVector<StringName> global_classes;
|
||||
ScriptServer::get_global_class_list(global_classes);
|
||||
for (const StringName &class_name : global_classes) {
|
||||
highlighter->add_keyword_color(class_name, usertype_color);
|
||||
}
|
||||
|
||||
/* Autoloads. */
|
||||
HashMap<StringName, ProjectSettings::AutoloadInfo> autoloads(ProjectSettings::get_singleton()->get_autoload_list());
|
||||
for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : autoloads) {
|
||||
const ProjectSettings::AutoloadInfo &info = E.value;
|
||||
if (info.is_singleton) {
|
||||
highlighter->add_keyword_color(info.name, usertype_color);
|
||||
}
|
||||
}
|
||||
|
||||
const ScriptLanguage *scr_lang = script_language;
|
||||
StringName instance_base;
|
||||
|
||||
if (scr_lang == nullptr) {
|
||||
const Ref<Script> scr = _get_edited_resource();
|
||||
if (scr.is_valid()) {
|
||||
scr_lang = scr->get_language();
|
||||
instance_base = scr->get_instance_base_type();
|
||||
}
|
||||
}
|
||||
|
||||
if (scr_lang != nullptr) {
|
||||
/* Core types. */
|
||||
const Color basetype_color = EDITOR_GET("text_editor/theme/highlighting/base_type_color");
|
||||
List<String> core_types;
|
||||
scr_lang->get_core_type_words(&core_types);
|
||||
for (const String &E : core_types) {
|
||||
highlighter->add_keyword_color(E, basetype_color);
|
||||
}
|
||||
|
||||
/* Reserved words. */
|
||||
const Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color");
|
||||
const Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color");
|
||||
for (const String &keyword : scr_lang->get_reserved_words()) {
|
||||
if (scr_lang->is_control_flow_keyword(keyword)) {
|
||||
highlighter->add_keyword_color(keyword, control_flow_keyword_color);
|
||||
} else {
|
||||
highlighter->add_keyword_color(keyword, keyword_color);
|
||||
}
|
||||
}
|
||||
|
||||
/* Member types. */
|
||||
const Color member_variable_color = EDITOR_GET("text_editor/theme/highlighting/member_variable_color");
|
||||
if (instance_base != StringName()) {
|
||||
List<PropertyInfo> plist;
|
||||
ClassDB::get_property_list(instance_base, &plist);
|
||||
for (const PropertyInfo &E : plist) {
|
||||
String prop_name = E.name;
|
||||
if (E.usage & PROPERTY_USAGE_CATEGORY || E.usage & PROPERTY_USAGE_GROUP || E.usage & PROPERTY_USAGE_SUBGROUP) {
|
||||
continue;
|
||||
}
|
||||
if (prop_name.contains_char('/')) {
|
||||
continue;
|
||||
}
|
||||
highlighter->add_member_keyword_color(prop_name, member_variable_color);
|
||||
}
|
||||
|
||||
List<String> clist;
|
||||
ClassDB::get_integer_constant_list(instance_base, &clist);
|
||||
for (const String &E : clist) {
|
||||
highlighter->add_member_keyword_color(E, member_variable_color);
|
||||
}
|
||||
}
|
||||
|
||||
/* Comments */
|
||||
const Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color");
|
||||
for (const String &comment : scr_lang->get_comment_delimiters()) {
|
||||
String beg = comment.get_slicec(' ', 0);
|
||||
String end = comment.get_slice_count(" ") > 1 ? comment.get_slicec(' ', 1) : String();
|
||||
highlighter->add_color_region(beg, end, comment_color, end.is_empty());
|
||||
}
|
||||
|
||||
/* Doc comments */
|
||||
const Color doc_comment_color = EDITOR_GET("text_editor/theme/highlighting/doc_comment_color");
|
||||
for (const String &doc_comment : scr_lang->get_doc_comment_delimiters()) {
|
||||
String beg = doc_comment.get_slicec(' ', 0);
|
||||
String end = doc_comment.get_slice_count(" ") > 1 ? doc_comment.get_slicec(' ', 1) : String();
|
||||
highlighter->add_color_region(beg, end, doc_comment_color, end.is_empty());
|
||||
}
|
||||
|
||||
/* Strings */
|
||||
const Color string_color = EDITOR_GET("text_editor/theme/highlighting/string_color");
|
||||
for (const String &string : scr_lang->get_string_delimiters()) {
|
||||
String beg = string.get_slicec(' ', 0);
|
||||
String end = string.get_slice_count(" ") > 1 ? string.get_slicec(' ', 1) : String();
|
||||
highlighter->add_color_region(beg, end, string_color, end.is_empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ref<EditorSyntaxHighlighter> EditorStandardSyntaxHighlighter::_create() const {
|
||||
Ref<EditorStandardSyntaxHighlighter> syntax_highlighter;
|
||||
syntax_highlighter.instantiate();
|
||||
return syntax_highlighter;
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
Ref<EditorSyntaxHighlighter> EditorPlainTextSyntaxHighlighter::_create() const {
|
||||
Ref<EditorPlainTextSyntaxHighlighter> syntax_highlighter;
|
||||
syntax_highlighter.instantiate();
|
||||
return syntax_highlighter;
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
void EditorJSONSyntaxHighlighter::_update_cache() {
|
||||
highlighter->set_text_edit(text_edit);
|
||||
highlighter->clear_keyword_colors();
|
||||
highlighter->clear_member_keyword_colors();
|
||||
highlighter->clear_color_regions();
|
||||
|
||||
highlighter->set_symbol_color(EDITOR_GET("text_editor/theme/highlighting/symbol_color"));
|
||||
highlighter->set_number_color(EDITOR_GET("text_editor/theme/highlighting/number_color"));
|
||||
|
||||
const Color string_color = EDITOR_GET("text_editor/theme/highlighting/string_color");
|
||||
highlighter->add_color_region("\"", "\"", string_color);
|
||||
}
|
||||
|
||||
Ref<EditorSyntaxHighlighter> EditorJSONSyntaxHighlighter::_create() const {
|
||||
Ref<EditorJSONSyntaxHighlighter> syntax_highlighter;
|
||||
syntax_highlighter.instantiate();
|
||||
return syntax_highlighter;
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
void EditorMarkdownSyntaxHighlighter::_update_cache() {
|
||||
highlighter->set_text_edit(text_edit);
|
||||
highlighter->clear_keyword_colors();
|
||||
highlighter->clear_member_keyword_colors();
|
||||
highlighter->clear_color_regions();
|
||||
|
||||
// Disable automatic symbolic highlights, as these don't make sense for prose.
|
||||
highlighter->set_symbol_color(EDITOR_GET("text_editor/theme/highlighting/text_color"));
|
||||
highlighter->set_number_color(EDITOR_GET("text_editor/theme/highlighting/text_color"));
|
||||
highlighter->set_member_variable_color(EDITOR_GET("text_editor/theme/highlighting/text_color"));
|
||||
highlighter->set_function_color(EDITOR_GET("text_editor/theme/highlighting/text_color"));
|
||||
|
||||
// Headings (any level).
|
||||
const Color function_color = EDITOR_GET("text_editor/theme/highlighting/function_color");
|
||||
highlighter->add_color_region("#", "", function_color);
|
||||
|
||||
// Bold.
|
||||
highlighter->add_color_region("**", "**", function_color);
|
||||
// `__bold__` syntax is not supported as color regions must begin with a symbol,
|
||||
// not a character that is valid in an identifier.
|
||||
|
||||
// Code (both inline code and triple-backticks code blocks).
|
||||
const Color code_color = EDITOR_GET("text_editor/theme/highlighting/engine_type_color");
|
||||
highlighter->add_color_region("`", "`", code_color);
|
||||
|
||||
// Link (both references and inline links with URLs). The URL is not highlighted.
|
||||
const Color link_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color");
|
||||
highlighter->add_color_region("[", "]", link_color);
|
||||
|
||||
// Quote.
|
||||
const Color quote_color = EDITOR_GET("text_editor/theme/highlighting/string_color");
|
||||
highlighter->add_color_region(">", "", quote_color, true);
|
||||
|
||||
// HTML comment, which is also supported in Markdown.
|
||||
const Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color");
|
||||
highlighter->add_color_region("<!--", "-->", comment_color);
|
||||
}
|
||||
|
||||
Ref<EditorSyntaxHighlighter> EditorMarkdownSyntaxHighlighter::_create() const {
|
||||
Ref<EditorMarkdownSyntaxHighlighter> syntax_highlighter;
|
||||
syntax_highlighter.instantiate();
|
||||
return syntax_highlighter;
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
void EditorConfigFileSyntaxHighlighter::_update_cache() {
|
||||
highlighter->set_text_edit(text_edit);
|
||||
highlighter->clear_keyword_colors();
|
||||
highlighter->clear_member_keyword_colors();
|
||||
highlighter->clear_color_regions();
|
||||
|
||||
highlighter->set_symbol_color(EDITOR_GET("text_editor/theme/highlighting/symbol_color"));
|
||||
highlighter->set_number_color(EDITOR_GET("text_editor/theme/highlighting/number_color"));
|
||||
// Assume that all function-style syntax is for types such as `Vector2()` and `PackedStringArray()`.
|
||||
highlighter->set_function_color(EDITOR_GET("text_editor/theme/highlighting/base_type_color"));
|
||||
|
||||
// Disable member variable highlighting as it's not relevant for ConfigFile.
|
||||
highlighter->set_member_variable_color(EDITOR_GET("text_editor/theme/highlighting/text_color"));
|
||||
|
||||
const Color string_color = EDITOR_GET("text_editor/theme/highlighting/string_color");
|
||||
highlighter->add_color_region("\"", "\"", string_color);
|
||||
|
||||
// FIXME: Sections in ConfigFile must be at the beginning of a line. Otherwise, it can be an array within a line.
|
||||
const Color function_color = EDITOR_GET("text_editor/theme/highlighting/function_color");
|
||||
highlighter->add_color_region("[", "]", function_color);
|
||||
|
||||
const Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color");
|
||||
highlighter->add_keyword_color("true", keyword_color);
|
||||
highlighter->add_keyword_color("false", keyword_color);
|
||||
highlighter->add_keyword_color("null", keyword_color);
|
||||
highlighter->add_keyword_color("ExtResource", keyword_color);
|
||||
highlighter->add_keyword_color("SubResource", keyword_color);
|
||||
|
||||
const Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color");
|
||||
highlighter->add_color_region(";", "", comment_color);
|
||||
}
|
||||
|
||||
Ref<EditorSyntaxHighlighter> EditorConfigFileSyntaxHighlighter::_create() const {
|
||||
Ref<EditorConfigFileSyntaxHighlighter> syntax_highlighter;
|
||||
syntax_highlighter.instantiate();
|
||||
return syntax_highlighter;
|
||||
}
|
||||
143
engine/editor/script/syntax_highlighters.h
Normal file
143
engine/editor/script/syntax_highlighters.h
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
/**************************************************************************/
|
||||
/* syntax_highlighters.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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "scene/resources/syntax_highlighter.h"
|
||||
|
||||
class EditorSyntaxHighlighter : public SyntaxHighlighter {
|
||||
GDCLASS(EditorSyntaxHighlighter, SyntaxHighlighter)
|
||||
|
||||
private:
|
||||
Ref<RefCounted> edited_resource;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
GDVIRTUAL0RC(String, _get_name)
|
||||
GDVIRTUAL0RC(PackedStringArray, _get_supported_languages)
|
||||
GDVIRTUAL0RC(Ref<EditorSyntaxHighlighter>, _create)
|
||||
|
||||
public:
|
||||
virtual String _get_name() const;
|
||||
virtual PackedStringArray _get_supported_languages() const;
|
||||
|
||||
void _set_edited_resource(const Ref<Resource> &p_res) { edited_resource = p_res; }
|
||||
Ref<RefCounted> _get_edited_resource() { return edited_resource; }
|
||||
|
||||
virtual Ref<EditorSyntaxHighlighter> _create() const;
|
||||
};
|
||||
|
||||
class EditorStandardSyntaxHighlighter : public EditorSyntaxHighlighter {
|
||||
GDCLASS(EditorStandardSyntaxHighlighter, EditorSyntaxHighlighter)
|
||||
|
||||
private:
|
||||
Ref<CodeHighlighter> highlighter;
|
||||
ScriptLanguage *script_language = nullptr; // See GH-89610.
|
||||
|
||||
public:
|
||||
virtual void _update_cache() override;
|
||||
virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override { return highlighter->get_line_syntax_highlighting(p_line); }
|
||||
|
||||
virtual String _get_name() const override { return TTR("Standard"); }
|
||||
|
||||
virtual Ref<EditorSyntaxHighlighter> _create() const override;
|
||||
|
||||
void _set_script_language(ScriptLanguage *p_script_language) { script_language = p_script_language; }
|
||||
|
||||
EditorStandardSyntaxHighlighter() { highlighter.instantiate(); }
|
||||
};
|
||||
|
||||
class EditorPlainTextSyntaxHighlighter : public EditorSyntaxHighlighter {
|
||||
GDCLASS(EditorPlainTextSyntaxHighlighter, EditorSyntaxHighlighter)
|
||||
|
||||
public:
|
||||
virtual String _get_name() const override { return TTR("Plain Text"); }
|
||||
|
||||
virtual Ref<EditorSyntaxHighlighter> _create() const override;
|
||||
};
|
||||
|
||||
class EditorJSONSyntaxHighlighter : public EditorSyntaxHighlighter {
|
||||
GDCLASS(EditorJSONSyntaxHighlighter, EditorSyntaxHighlighter)
|
||||
|
||||
private:
|
||||
Ref<CodeHighlighter> highlighter;
|
||||
|
||||
public:
|
||||
virtual void _update_cache() override;
|
||||
virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override { return highlighter->get_line_syntax_highlighting(p_line); }
|
||||
|
||||
virtual PackedStringArray _get_supported_languages() const override { return PackedStringArray{ "json" }; }
|
||||
virtual String _get_name() const override { return TTR("JSON"); }
|
||||
|
||||
virtual Ref<EditorSyntaxHighlighter> _create() const override;
|
||||
|
||||
EditorJSONSyntaxHighlighter() { highlighter.instantiate(); }
|
||||
};
|
||||
|
||||
class EditorMarkdownSyntaxHighlighter : public EditorSyntaxHighlighter {
|
||||
GDCLASS(EditorMarkdownSyntaxHighlighter, EditorSyntaxHighlighter)
|
||||
|
||||
private:
|
||||
Ref<CodeHighlighter> highlighter;
|
||||
|
||||
public:
|
||||
virtual void _update_cache() override;
|
||||
virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override { return highlighter->get_line_syntax_highlighting(p_line); }
|
||||
|
||||
virtual PackedStringArray _get_supported_languages() const override { return PackedStringArray{ "md", "markdown" }; }
|
||||
virtual String _get_name() const override { return TTR("Markdown"); }
|
||||
|
||||
virtual Ref<EditorSyntaxHighlighter> _create() const override;
|
||||
|
||||
EditorMarkdownSyntaxHighlighter() { highlighter.instantiate(); }
|
||||
};
|
||||
|
||||
class EditorConfigFileSyntaxHighlighter : public EditorSyntaxHighlighter {
|
||||
GDCLASS(EditorConfigFileSyntaxHighlighter, EditorSyntaxHighlighter)
|
||||
|
||||
private:
|
||||
Ref<CodeHighlighter> highlighter;
|
||||
|
||||
public:
|
||||
virtual void _update_cache() override;
|
||||
virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override { return highlighter->get_line_syntax_highlighting(p_line); }
|
||||
|
||||
// While not explicitly designed for those formats, this highlighter happens
|
||||
// to handle TSCN, TRES, `project.godot` well. We can expose it in case the
|
||||
// user opens one of these using the script editor (which can be done using
|
||||
// the All Files filter).
|
||||
virtual PackedStringArray _get_supported_languages() const override { return PackedStringArray{ "ini", "cfg", "tscn", "tres", "godot" }; }
|
||||
virtual String _get_name() const override { return TTR("ConfigFile"); }
|
||||
|
||||
virtual Ref<EditorSyntaxHighlighter> _create() const override;
|
||||
|
||||
EditorConfigFileSyntaxHighlighter() { highlighter.instantiate(); }
|
||||
};
|
||||
88
engine/editor/script/text_editor.cpp
Normal file
88
engine/editor/script/text_editor.cpp
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/**************************************************************************/
|
||||
/* text_editor.cpp */
|
||||
/**************************************************************************/
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "text_editor.h"
|
||||
|
||||
#include "core/io/json.h"
|
||||
#include "editor/script/script_editor_plugin.h"
|
||||
#include "editor/settings/editor_settings.h"
|
||||
|
||||
void TextEditor::_validate_script() {
|
||||
TextEditorBase::_validate_script();
|
||||
|
||||
Ref<JSON> json_file = edited_res;
|
||||
if (json_file.is_valid()) {
|
||||
CodeEdit *te = code_editor->get_text_editor();
|
||||
|
||||
te->set_line_background_color(code_editor->get_error_pos().x, Color(0, 0, 0, 0));
|
||||
code_editor->set_error("");
|
||||
|
||||
if (json_file->parse(te->get_text(), true) != OK) {
|
||||
code_editor->set_error(json_file->get_error_message().replace("[", "[lb]"));
|
||||
code_editor->set_error_pos(json_file->get_error_line(), 0);
|
||||
te->set_line_background_color(code_editor->get_error_pos().x, EDITOR_GET("text_editor/theme/highlighting/mark_color"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditor::apply_code() {
|
||||
Ref<TextFile> text_file = edited_res;
|
||||
if (text_file.is_valid()) {
|
||||
text_file->set_text(code_editor->get_text_editor()->get_text());
|
||||
}
|
||||
|
||||
Ref<JSON> json_file = edited_res;
|
||||
if (json_file.is_valid()) {
|
||||
json_file->parse(code_editor->get_text_editor()->get_text(), true);
|
||||
}
|
||||
code_editor->get_text_editor()->get_syntax_highlighter()->update_cache();
|
||||
}
|
||||
|
||||
ScriptEditorBase *TextEditor::create_editor(const Ref<Resource> &p_resource) {
|
||||
if (Object::cast_to<TextFile>(*p_resource) || Object::cast_to<JSON>(*p_resource)) {
|
||||
return memnew(TextEditor);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Control *TextEditor::get_edit_menu() {
|
||||
if (!edit_menus) {
|
||||
edit_menus = memnew(EditMenus);
|
||||
}
|
||||
return edit_menus;
|
||||
}
|
||||
|
||||
void TextEditor::register_editor() {
|
||||
ScriptEditor::register_create_script_editor_function(create_editor);
|
||||
}
|
||||
|
||||
TextEditor::TextEditor() {
|
||||
add_child(code_editor);
|
||||
}
|
||||
53
engine/editor/script/text_editor.h
Normal file
53
engine/editor/script/text_editor.h
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/**************************************************************************/
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "editor/script/script_editor_base.h"
|
||||
|
||||
class TextEditor : public TextEditorBase {
|
||||
GDCLASS(TextEditor, TextEditorBase);
|
||||
|
||||
static ScriptEditorBase *create_editor(const Ref<Resource> &p_resource);
|
||||
|
||||
static inline EditMenus *edit_menus = nullptr;
|
||||
|
||||
protected:
|
||||
virtual void _validate_script() override;
|
||||
|
||||
public:
|
||||
virtual void apply_code() override;
|
||||
|
||||
virtual Control *get_edit_menu() override;
|
||||
|
||||
static void register_editor();
|
||||
|
||||
TextEditor();
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue