initial commit, 4.5 stable
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
This commit is contained in:
6
editor/script/SCsub
Normal file
6
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")
|
90
editor/script/editor_script.cpp
Normal file
90
editor/script/editor_script.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
/**************************************************************************/
|
||||
/* 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 "editor/editor_interface.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_undo_redo_manager.h"
|
||||
#include "editor/scene/editor_scene_tabs.h"
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/resources/packed_scene.h"
|
||||
|
||||
void EditorScript::add_root_node(Node *p_node) {
|
||||
if (!EditorNode::get_singleton()) {
|
||||
EditorNode::add_io_error("EditorScript::add_root_node: " + TTR("Write your logic in the _run() method."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (EditorNode::get_singleton()->get_edited_scene()) {
|
||||
EditorNode::add_io_error("EditorScript::add_root_node: " + TTR("The current scene already has a root node."));
|
||||
return;
|
||||
}
|
||||
|
||||
const String &scene_path = p_node->get_scene_file_path();
|
||||
if (!scene_path.is_empty()) {
|
||||
Ref<PackedScene> scene = ResourceLoader::load(scene_path);
|
||||
if (scene.is_valid()) {
|
||||
memfree(scene->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE)); // Ensure node cache.
|
||||
|
||||
p_node->set_scene_inherited_state(scene->get_state());
|
||||
p_node->set_scene_file_path(String());
|
||||
}
|
||||
}
|
||||
|
||||
EditorNode::get_singleton()->set_edited_scene(p_node);
|
||||
EditorUndoRedoManager::get_singleton()->set_history_as_unsaved(EditorNode::get_editor_data().get_current_edited_scene_history_id());
|
||||
EditorSceneTabs::get_singleton()->update_scene_tabs();
|
||||
}
|
||||
|
||||
Node *EditorScript::get_scene() const {
|
||||
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 {
|
||||
return EditorInterface::get_singleton();
|
||||
}
|
||||
|
||||
void EditorScript::run() {
|
||||
GDVIRTUAL_CALL(_run);
|
||||
}
|
||||
|
||||
void EditorScript::_bind_methods() {
|
||||
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);
|
||||
|
||||
GDVIRTUAL_BIND(_run);
|
||||
}
|
54
editor/script/editor_script.h
Normal file
54
editor/script/editor_script.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/**************************************************************************/
|
||||
/* 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.inc"
|
||||
#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);
|
||||
Node *get_scene() const;
|
||||
EditorInterface *get_editor_interface() const;
|
||||
|
||||
virtual void run();
|
||||
};
|
64
editor/script/editor_script_plugin.cpp
Normal file
64
editor/script/editor_script_plugin.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/**************************************************************************/
|
||||
/* 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 "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_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), varray(command), nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
EditorScriptPlugin::EditorScriptPlugin() {
|
||||
EditorInterface::get_singleton()->get_command_palette()->connect("about_to_popup", callable_mp(this, &EditorScriptPlugin::command_palette_about_to_popup));
|
||||
}
|
48
editor/script/editor_script_plugin.h
Normal file
48
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"; }
|
||||
};
|
1202
editor/script/find_in_files.cpp
Normal file
1202
editor/script/find_in_files.cpp
Normal file
File diff suppressed because it is too large
Load Diff
235
editor/script/find_in_files.h
Normal file
235
editor/script/find_in_files.h
Normal file
@@ -0,0 +1,235 @@
|
||||
/**************************************************************************/
|
||||
/* 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 "scene/gui/dialogs.h"
|
||||
#include "scene/gui/margin_container.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 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);
|
||||
|
||||
void start_search();
|
||||
void stop_search();
|
||||
|
||||
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_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();
|
||||
|
||||
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 *_search_text_label = nullptr;
|
||||
Tree *_results_display = nullptr;
|
||||
Label *_status_label = nullptr;
|
||||
Button *_refresh_button = nullptr;
|
||||
Button *_cancel_button = nullptr;
|
||||
Button *_close_button = nullptr;
|
||||
ProgressBar *_progress_bar = nullptr;
|
||||
HashMap<String, TreeItem *> _file_items;
|
||||
HashMap<TreeItem *, Result> _result_items;
|
||||
bool _with_replace = false;
|
||||
|
||||
HBoxContainer *_replace_container = nullptr;
|
||||
LineEdit *_replace_line_edit = nullptr;
|
||||
Button *_replace_all_button = nullptr;
|
||||
};
|
1014
editor/script/script_create_dialog.cpp
Normal file
1014
editor/script/script_create_dialog.cpp
Normal file
File diff suppressed because it is too large
Load Diff
127
editor/script/script_create_dialog.h
Normal file
127
editor/script/script_create_dialog.h
Normal file
@@ -0,0 +1,127 @@
|
||||
/**************************************************************************/
|
||||
/* 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"
|
||||
#include "scene/gui/panel_container.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;
|
||||
VBoxContainer *path_vb = 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_class_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();
|
||||
};
|
4789
editor/script/script_editor_plugin.cpp
Normal file
4789
editor/script/script_editor_plugin.cpp
Normal file
File diff suppressed because it is too large
Load Diff
667
editor/script/script_editor_plugin.h
Normal file
667
editor/script/script_editor_plugin.h
Normal file
@@ -0,0 +1,667 @@
|
||||
/**************************************************************************/
|
||||
/* 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/object/script_language.h"
|
||||
#include "editor/plugins/editor_plugin.h"
|
||||
#include "scene/gui/dialogs.h"
|
||||
#include "scene/gui/panel_container.h"
|
||||
#include "scene/resources/syntax_highlighter.h"
|
||||
#include "scene/resources/text_file.h"
|
||||
|
||||
class CodeTextEditor;
|
||||
class EditorFileDialog;
|
||||
class EditorHelpSearch;
|
||||
class FindReplaceBar;
|
||||
class HSplitContainer;
|
||||
class ItemList;
|
||||
class MenuButton;
|
||||
class TabContainer;
|
||||
class TextureRect;
|
||||
class Tree;
|
||||
class VSplitContainer;
|
||||
class WindowWrapper;
|
||||
|
||||
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(); }
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ScriptEditorQuickOpen : public ConfirmationDialog {
|
||||
GDCLASS(ScriptEditorQuickOpen, ConfirmationDialog);
|
||||
|
||||
LineEdit *search_box = nullptr;
|
||||
Tree *search_options = nullptr;
|
||||
String function;
|
||||
|
||||
void _update_search();
|
||||
|
||||
void _sbox_input(const Ref<InputEvent> &p_event);
|
||||
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 EditorDebuggerNode;
|
||||
|
||||
class ScriptEditorBase : public VBoxContainer {
|
||||
GDCLASS(ScriptEditorBase, VBoxContainer);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
struct EditedFileData {
|
||||
String path;
|
||||
uint64_t last_modified_time = -1;
|
||||
} edited_file_data;
|
||||
|
||||
virtual void add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) = 0;
|
||||
virtual void set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) = 0;
|
||||
|
||||
virtual void apply_code() = 0;
|
||||
virtual Ref<Resource> get_edited_resource() const = 0;
|
||||
virtual Vector<String> get_functions() = 0;
|
||||
virtual void set_edited_resource(const Ref<Resource> &p_res) = 0;
|
||||
virtual void enable_editor(Control *p_shortcut_context = nullptr) = 0;
|
||||
virtual void reload_text() = 0;
|
||||
virtual String get_name() = 0;
|
||||
virtual Ref<Texture2D> get_theme_icon() = 0;
|
||||
virtual bool is_unsaved() = 0;
|
||||
virtual Variant get_edit_state() = 0;
|
||||
virtual void set_edit_state(const Variant &p_state) = 0;
|
||||
virtual Variant get_navigation_state() = 0;
|
||||
virtual void goto_line(int p_line, int p_column = 0) = 0;
|
||||
virtual void set_executing_line(int p_line) = 0;
|
||||
virtual void clear_executing_line() = 0;
|
||||
virtual void trim_trailing_whitespace() = 0;
|
||||
virtual void trim_final_newlines() = 0;
|
||||
virtual void insert_final_newline() = 0;
|
||||
virtual void convert_indent() = 0;
|
||||
virtual void ensure_focus() = 0;
|
||||
virtual void tag_saved_version() = 0;
|
||||
virtual void reload(bool p_soft) {}
|
||||
virtual PackedInt32Array get_breakpoints() = 0;
|
||||
virtual void set_breakpoint(int p_line, bool p_enabled) = 0;
|
||||
virtual void clear_breakpoints() = 0;
|
||||
virtual void add_callback(const String &p_function, const PackedStringArray &p_args) = 0;
|
||||
virtual void update_settings() = 0;
|
||||
virtual void set_debugger_active(bool p_active) = 0;
|
||||
virtual void update_toggle_files_button() {}
|
||||
|
||||
virtual bool show_members_overview() = 0;
|
||||
|
||||
virtual void set_tooltip_request_func(const Callable &p_toolip_callback) = 0;
|
||||
virtual Control *get_edit_menu() = 0;
|
||||
virtual void clear_edit_menu() = 0;
|
||||
virtual void set_find_replace_bar(FindReplaceBar *p_bar) = 0;
|
||||
|
||||
virtual Control *get_base_editor() const = 0;
|
||||
virtual CodeTextEditor *get_code_editor() const = 0;
|
||||
|
||||
virtual void validate() = 0;
|
||||
};
|
||||
|
||||
typedef ScriptEditorBase *(*CreateScriptEditorFunc)(const Ref<Resource> &p_resource);
|
||||
|
||||
class EditorScriptCodeCompletionCache;
|
||||
class FindInFilesDialog;
|
||||
class FindInFilesPanel;
|
||||
|
||||
class ScriptEditor : public PanelContainer {
|
||||
GDCLASS(ScriptEditor, PanelContainer);
|
||||
|
||||
enum MenuOptions {
|
||||
// File.
|
||||
FILE_MENU_NEW,
|
||||
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 *edit_menu = nullptr;
|
||||
MenuButton *script_search_menu = nullptr;
|
||||
MenuButton *debug_menu = nullptr;
|
||||
PopupMenu *context_menu = nullptr;
|
||||
Timer *autosave_timer = nullptr;
|
||||
uint64_t idle = 0;
|
||||
|
||||
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;
|
||||
Label *filename = 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;
|
||||
Button *scripts_visible = nullptr;
|
||||
FindReplaceBar *find_replace_bar = nullptr;
|
||||
|
||||
float zoom_factor = 1.0f;
|
||||
|
||||
TextureRect *script_icon = nullptr;
|
||||
Label *script_name_label = nullptr;
|
||||
|
||||
Button *script_back = nullptr;
|
||||
Button *script_forward = nullptr;
|
||||
|
||||
FindInFilesDialog *find_in_files_dialog = nullptr;
|
||||
FindInFilesPanel *find_in_files = nullptr;
|
||||
Button *find_in_files_button = nullptr;
|
||||
|
||||
WindowWrapper *window_wrapper = nullptr;
|
||||
|
||||
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;
|
||||
|
||||
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>());
|
||||
|
||||
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;
|
||||
bool reload_all_scripts = false;
|
||||
Vector<String> script_paths_to_reload;
|
||||
void _live_auto_reload_running_scripts();
|
||||
|
||||
void _update_selected_editor_menu();
|
||||
|
||||
void _editor_stop();
|
||||
|
||||
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 open_textfile_after_create = true;
|
||||
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 _set_execution(Ref<RefCounted> p_script, int p_line);
|
||||
void _clear_execution(Ref<RefCounted> p_script);
|
||||
String _get_debug_tooltip(const String &p_text, Node *p_se);
|
||||
void _breaked(bool p_breaked, bool p_can_debug);
|
||||
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 _editor_settings_changed();
|
||||
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 _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 _help_search(const String &p_text);
|
||||
|
||||
void _history_forward();
|
||||
void _history_back();
|
||||
|
||||
bool waiting_update_names;
|
||||
bool lock_history = false;
|
||||
|
||||
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 _on_find_in_files_close_button_clicked();
|
||||
|
||||
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);
|
||||
|
||||
static void _open_script_request(const String &p_path);
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
void trigger_live_script_reload_all();
|
||||
|
||||
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:
|
||||
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();
|
||||
};
|
3014
editor/script/script_text_editor.cpp
Normal file
3014
editor/script/script_text_editor.cpp
Normal file
File diff suppressed because it is too large
Load Diff
305
editor/script/script_text_editor.h
Normal file
305
editor/script/script_text_editor.h
Normal file
@@ -0,0 +1,305 @@
|
||||
/**************************************************************************/
|
||||
/* 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 "script_editor_plugin.h"
|
||||
|
||||
#include "editor/gui/code_editor.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 ScriptEditorBase {
|
||||
GDCLASS(ScriptTextEditor, ScriptEditorBase);
|
||||
|
||||
CodeTextEditor *code_editor = nullptr;
|
||||
RichTextLabel *warnings_panel = nullptr;
|
||||
RichTextLabel *errors_panel = nullptr;
|
||||
|
||||
Ref<Script> script;
|
||||
bool script_is_valid = false;
|
||||
bool editor_enabled = false;
|
||||
|
||||
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;
|
||||
|
||||
Vector<String> member_keywords;
|
||||
|
||||
HBoxContainer *edit_hb = nullptr;
|
||||
|
||||
MenuButton *edit_menu = nullptr;
|
||||
MenuButton *search_menu = nullptr;
|
||||
MenuButton *goto_menu = nullptr;
|
||||
PopupMenu *bookmarks_menu = nullptr;
|
||||
PopupMenu *breakpoints_menu = nullptr;
|
||||
PopupMenu *highlighter_menu = nullptr;
|
||||
PopupMenu *context_menu = nullptr;
|
||||
|
||||
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;
|
||||
|
||||
GotoLinePopup *goto_line_popup = nullptr;
|
||||
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 = 0;
|
||||
|
||||
PopupPanel *color_panel = nullptr;
|
||||
ColorPicker *color_picker = nullptr;
|
||||
Vector3i color_position;
|
||||
String color_args;
|
||||
|
||||
bool theme_loaded = false;
|
||||
|
||||
enum {
|
||||
EDIT_UNDO,
|
||||
EDIT_REDO,
|
||||
EDIT_CUT,
|
||||
EDIT_COPY,
|
||||
EDIT_PASTE,
|
||||
EDIT_SELECT_ALL,
|
||||
EDIT_COMPLETE,
|
||||
EDIT_AUTO_INDENT,
|
||||
EDIT_TRIM_TRAILING_WHITESAPCE,
|
||||
EDIT_TRIM_FINAL_NEWLINES,
|
||||
EDIT_CONVERT_INDENT_TO_SPACES,
|
||||
EDIT_CONVERT_INDENT_TO_TABS,
|
||||
EDIT_TOGGLE_COMMENT,
|
||||
EDIT_MOVE_LINE_UP,
|
||||
EDIT_MOVE_LINE_DOWN,
|
||||
EDIT_INDENT,
|
||||
EDIT_UNINDENT,
|
||||
EDIT_DELETE_LINE,
|
||||
EDIT_DUPLICATE_SELECTION,
|
||||
EDIT_DUPLICATE_LINES,
|
||||
EDIT_PICK_COLOR,
|
||||
EDIT_TO_UPPERCASE,
|
||||
EDIT_TO_LOWERCASE,
|
||||
EDIT_CAPITALIZE,
|
||||
EDIT_EVALUATE,
|
||||
EDIT_TOGGLE_WORD_WRAP,
|
||||
EDIT_TOGGLE_FOLD_LINE,
|
||||
EDIT_FOLD_ALL_LINES,
|
||||
EDIT_CREATE_CODE_REGION,
|
||||
EDIT_UNFOLD_ALL_LINES,
|
||||
SEARCH_FIND,
|
||||
SEARCH_FIND_NEXT,
|
||||
SEARCH_FIND_PREV,
|
||||
SEARCH_REPLACE,
|
||||
SEARCH_LOCATE_FUNCTION,
|
||||
SEARCH_GOTO_LINE,
|
||||
SEARCH_IN_FILES,
|
||||
REPLACE_IN_FILES,
|
||||
BOOKMARK_TOGGLE,
|
||||
BOOKMARK_GOTO_NEXT,
|
||||
BOOKMARK_GOTO_PREV,
|
||||
BOOKMARK_REMOVE_ALL,
|
||||
DEBUG_TOGGLE_BREAKPOINT,
|
||||
DEBUG_REMOVE_ALL_BREAKPOINTS,
|
||||
DEBUG_GOTO_NEXT_BREAKPOINT,
|
||||
DEBUG_GOTO_PREV_BREAKPOINT,
|
||||
HELP_CONTEXTUAL,
|
||||
LOOKUP_SYMBOL,
|
||||
EDIT_EMOJI_AND_SYMBOL,
|
||||
};
|
||||
|
||||
enum COLOR_MODE {
|
||||
MODE_RGB,
|
||||
MODE_STRING,
|
||||
MODE_HSV,
|
||||
MODE_OKHSL,
|
||||
MODE_RGB8,
|
||||
MODE_HEX,
|
||||
MODE_MAX
|
||||
};
|
||||
|
||||
void _enable_code_editor();
|
||||
|
||||
protected:
|
||||
void _update_breakpoint_list();
|
||||
void _breakpoint_item_pressed(int p_idx);
|
||||
void _breakpoint_toggled(int p_row);
|
||||
|
||||
void _on_caret_moved();
|
||||
|
||||
void _validate_script(); // No longer virtual.
|
||||
void _update_warnings();
|
||||
void _update_errors();
|
||||
void _update_bookmark_list();
|
||||
void _bookmark_item_pressed(int p_idx);
|
||||
|
||||
static void _code_complete_scripts(void *p_ud, const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_force);
|
||||
void _code_complete_script(const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_force);
|
||||
|
||||
void _load_theme_settings();
|
||||
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);
|
||||
void _warning_clicked(const Variant &p_line);
|
||||
|
||||
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);
|
||||
|
||||
HashMap<String, Ref<EditorSyntaxHighlighter>> highlighters;
|
||||
void _change_syntax_highlighter(int p_idx);
|
||||
|
||||
void _edit_option(int p_op);
|
||||
void _edit_option_toggle_inline_comment();
|
||||
void _make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, Vector2 p_pos);
|
||||
void _text_edit_gui_input(const Ref<InputEvent> &ev);
|
||||
void _color_changed(const Color &p_color);
|
||||
void _prepare_edit_menu();
|
||||
|
||||
void _goto_line(int p_line) { goto_line(p_line); }
|
||||
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);
|
||||
|
||||
void _convert_case(CodeTextEditor::CaseStyle p_case);
|
||||
|
||||
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);
|
||||
|
||||
String _get_absolute_path(const String &rel_path);
|
||||
|
||||
public:
|
||||
void _update_connected_methods();
|
||||
|
||||
virtual void add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override;
|
||||
virtual void set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override;
|
||||
void update_toggle_files_button() override;
|
||||
|
||||
virtual void apply_code() override;
|
||||
virtual Ref<Resource> get_edited_resource() const override;
|
||||
virtual void set_edited_resource(const Ref<Resource> &p_res) override;
|
||||
virtual void enable_editor(Control *p_shortcut_context = nullptr) override;
|
||||
virtual Vector<String> get_functions() override;
|
||||
virtual void reload_text() override;
|
||||
virtual String get_name() override;
|
||||
virtual Ref<Texture2D> get_theme_icon() override;
|
||||
virtual bool is_unsaved() override;
|
||||
virtual Variant get_edit_state() override;
|
||||
virtual void set_edit_state(const Variant &p_state) override;
|
||||
virtual Variant get_navigation_state() override;
|
||||
virtual void ensure_focus() override;
|
||||
virtual void trim_trailing_whitespace() override;
|
||||
virtual void trim_final_newlines() override;
|
||||
virtual void insert_final_newline() override;
|
||||
virtual void convert_indent() override;
|
||||
virtual void tag_saved_version() override;
|
||||
|
||||
virtual void goto_line(int p_line, int p_column = 0) override;
|
||||
void goto_line_selection(int p_line, int p_begin, int p_end);
|
||||
void goto_line_centered(int p_line, int p_column = 0);
|
||||
virtual void set_executing_line(int p_line) override;
|
||||
virtual void clear_executing_line() override;
|
||||
|
||||
virtual void reload(bool p_soft) 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) override;
|
||||
virtual void update_settings() override;
|
||||
|
||||
virtual bool show_members_overview() override;
|
||||
|
||||
virtual void set_tooltip_request_func(const Callable &p_toolip_callback) override;
|
||||
|
||||
virtual void set_debugger_active(bool p_active) override;
|
||||
|
||||
Control *get_edit_menu() override;
|
||||
virtual void clear_edit_menu() override;
|
||||
virtual void set_find_replace_bar(FindReplaceBar *p_bar) override;
|
||||
|
||||
static void register_editor();
|
||||
|
||||
virtual Control *get_base_editor() const override;
|
||||
virtual CodeTextEditor *get_code_editor() const override;
|
||||
|
||||
virtual void validate() override;
|
||||
|
||||
Variant get_previous_state();
|
||||
void store_previous_state();
|
||||
|
||||
ScriptTextEditor();
|
||||
~ScriptTextEditor();
|
||||
};
|
730
editor/script/text_editor.cpp
Normal file
730
editor/script/text_editor.cpp
Normal file
@@ -0,0 +1,730 @@
|
||||
/**************************************************************************/
|
||||
/* 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/editor_node.h"
|
||||
#include "editor/settings/editor_settings.h"
|
||||
#include "scene/gui/menu_button.h"
|
||||
#include "scene/gui/split_container.h"
|
||||
|
||||
void TextEditor::add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) {
|
||||
ERR_FAIL_COND(p_highlighter.is_null());
|
||||
|
||||
highlighters[p_highlighter->_get_name()] = p_highlighter;
|
||||
highlighter_menu->add_radio_check_item(p_highlighter->_get_name());
|
||||
}
|
||||
|
||||
void TextEditor::set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) {
|
||||
ERR_FAIL_COND(p_highlighter.is_null());
|
||||
|
||||
HashMap<String, Ref<EditorSyntaxHighlighter>>::Iterator el = highlighters.begin();
|
||||
while (el) {
|
||||
int highlighter_index = highlighter_menu->get_item_idx_from_text(el->key);
|
||||
highlighter_menu->set_item_checked(highlighter_index, el->value == p_highlighter);
|
||||
++el;
|
||||
}
|
||||
|
||||
CodeEdit *te = code_editor->get_text_editor();
|
||||
te->set_syntax_highlighter(p_highlighter);
|
||||
}
|
||||
|
||||
void TextEditor::_change_syntax_highlighter(int p_idx) {
|
||||
set_syntax_highlighter(highlighters[highlighter_menu->get_item_text(p_idx)]);
|
||||
}
|
||||
|
||||
void TextEditor::_load_theme_settings() {
|
||||
code_editor->get_text_editor()->get_syntax_highlighter()->update_cache();
|
||||
}
|
||||
|
||||
String TextEditor::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> TextEditor::get_theme_icon() {
|
||||
return EditorNode::get_singleton()->get_object_icon(edited_res.ptr(), "TextFile");
|
||||
}
|
||||
|
||||
Ref<Resource> TextEditor::get_edited_resource() const {
|
||||
return edited_res;
|
||||
}
|
||||
|
||||
void TextEditor::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;
|
||||
if (text_file.is_valid()) {
|
||||
code_editor->get_text_editor()->set_text(text_file->get_text());
|
||||
}
|
||||
|
||||
Ref<JSON> json_file = edited_res;
|
||||
if (json_file.is_valid()) {
|
||||
code_editor->get_text_editor()->set_text(json_file->get_parsed_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();
|
||||
}
|
||||
|
||||
void TextEditor::enable_editor(Control *p_shortcut_context) {
|
||||
if (editor_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
editor_enabled = true;
|
||||
|
||||
_load_theme_settings();
|
||||
|
||||
_validate_script();
|
||||
|
||||
if (p_shortcut_context) {
|
||||
for (int i = 0; i < edit_hb->get_child_count(); ++i) {
|
||||
Control *c = cast_to<Control>(edit_hb->get_child(i));
|
||||
if (c) {
|
||||
c->set_shortcut_context(p_shortcut_context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditor::add_callback(const String &p_function, const PackedStringArray &p_args) {
|
||||
}
|
||||
|
||||
void TextEditor::set_debugger_active(bool p_active) {
|
||||
}
|
||||
|
||||
Control *TextEditor::get_base_editor() const {
|
||||
return code_editor->get_text_editor();
|
||||
}
|
||||
|
||||
CodeTextEditor *TextEditor::get_code_editor() const {
|
||||
return code_editor;
|
||||
}
|
||||
|
||||
PackedInt32Array TextEditor::get_breakpoints() {
|
||||
return PackedInt32Array();
|
||||
}
|
||||
|
||||
void TextEditor::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());
|
||||
}
|
||||
|
||||
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();
|
||||
_validate_script();
|
||||
}
|
||||
|
||||
void TextEditor::_validate_script() {
|
||||
emit_signal(SNAME("name_changed"));
|
||||
emit_signal(SNAME("edited_script_changed"));
|
||||
|
||||
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::_update_bookmark_list() {
|
||||
bookmarks_menu->clear();
|
||||
|
||||
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);
|
||||
|
||||
PackedInt32Array bookmark_list = code_editor->get_text_editor()->get_bookmarked_lines();
|
||||
if (bookmark_list.is_empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bookmarks_menu->add_separator();
|
||||
|
||||
for (int i = 0; i < bookmark_list.size(); i++) {
|
||||
String line = code_editor->get_text_editor()->get_line(bookmark_list[i]).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_list[i] + 1) + " - \"" + line + "\"");
|
||||
bookmarks_menu->set_item_metadata(-1, bookmark_list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditor::_bookmark_item_pressed(int p_idx) {
|
||||
if (p_idx < 4) { // Any item before the separator.
|
||||
_edit_option(bookmarks_menu->get_item_id(p_idx));
|
||||
} else {
|
||||
code_editor->goto_line(bookmarks_menu->get_item_metadata(p_idx));
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
bool TextEditor::is_unsaved() {
|
||||
const bool unsaved =
|
||||
code_editor->get_text_editor()->get_version() != code_editor->get_text_editor()->get_saved_version() ||
|
||||
edited_res->get_path().is_empty(); // In memory.
|
||||
return unsaved;
|
||||
}
|
||||
|
||||
Variant TextEditor::get_edit_state() {
|
||||
return code_editor->get_edit_state();
|
||||
}
|
||||
|
||||
void TextEditor::set_edit_state(const Variant &p_state) {
|
||||
code_editor->set_edit_state(p_state);
|
||||
|
||||
Dictionary state = p_state;
|
||||
if (state.has("syntax_highlighter")) {
|
||||
int idx = highlighter_menu->get_item_idx_from_text(state["syntax_highlighter"]);
|
||||
if (idx >= 0) {
|
||||
_change_syntax_highlighter(idx);
|
||||
}
|
||||
}
|
||||
|
||||
ensure_focus();
|
||||
}
|
||||
|
||||
Variant TextEditor::get_navigation_state() {
|
||||
return code_editor->get_navigation_state();
|
||||
}
|
||||
|
||||
void TextEditor::trim_trailing_whitespace() {
|
||||
code_editor->trim_trailing_whitespace();
|
||||
}
|
||||
|
||||
void TextEditor::trim_final_newlines() {
|
||||
code_editor->trim_final_newlines();
|
||||
}
|
||||
|
||||
void TextEditor::insert_final_newline() {
|
||||
code_editor->insert_final_newline();
|
||||
}
|
||||
|
||||
void TextEditor::convert_indent() {
|
||||
code_editor->get_text_editor()->convert_indent();
|
||||
}
|
||||
|
||||
void TextEditor::tag_saved_version() {
|
||||
code_editor->get_text_editor()->tag_saved_version();
|
||||
edited_file_data.last_modified_time = FileAccess::get_modified_time(edited_file_data.path);
|
||||
}
|
||||
|
||||
void TextEditor::goto_line(int p_line, int p_column) {
|
||||
code_editor->goto_line(p_line, p_column);
|
||||
}
|
||||
|
||||
void TextEditor::goto_line_selection(int p_line, int p_begin, int p_end) {
|
||||
code_editor->goto_line_selection(p_line, p_begin, p_end);
|
||||
}
|
||||
|
||||
void TextEditor::set_executing_line(int p_line) {
|
||||
code_editor->set_executing_line(p_line);
|
||||
}
|
||||
|
||||
void TextEditor::clear_executing_line() {
|
||||
code_editor->clear_executing_line();
|
||||
}
|
||||
|
||||
void TextEditor::ensure_focus() {
|
||||
code_editor->get_text_editor()->grab_focus();
|
||||
}
|
||||
|
||||
Vector<String> TextEditor::get_functions() {
|
||||
return Vector<String>();
|
||||
}
|
||||
|
||||
bool TextEditor::show_members_overview() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextEditor::update_settings() {
|
||||
code_editor->update_editor_settings();
|
||||
}
|
||||
|
||||
void TextEditor::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));
|
||||
}
|
||||
|
||||
Control *TextEditor::get_edit_menu() {
|
||||
return edit_hb;
|
||||
}
|
||||
|
||||
void TextEditor::clear_edit_menu() {
|
||||
memdelete(edit_hb);
|
||||
}
|
||||
|
||||
void TextEditor::set_find_replace_bar(FindReplaceBar *p_bar) {
|
||||
code_editor->set_find_replace_bar(p_bar);
|
||||
}
|
||||
|
||||
void TextEditor::_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();
|
||||
} break;
|
||||
case EDIT_REDO: {
|
||||
tx->redo();
|
||||
callable_mp((Control *)tx, &Control::grab_focus).call_deferred();
|
||||
} break;
|
||||
case EDIT_CUT: {
|
||||
tx->cut();
|
||||
callable_mp((Control *)tx, &Control::grab_focus).call_deferred();
|
||||
} break;
|
||||
case EDIT_COPY: {
|
||||
tx->copy();
|
||||
callable_mp((Control *)tx, &Control::grab_focus).call_deferred();
|
||||
} break;
|
||||
case EDIT_PASTE: {
|
||||
tx->paste();
|
||||
callable_mp((Control *)tx, &Control::grab_focus).call_deferred();
|
||||
} break;
|
||||
case EDIT_SELECT_ALL: {
|
||||
tx->select_all();
|
||||
callable_mp((Control *)tx, &Control::grab_focus).call_deferred();
|
||||
} break;
|
||||
case EDIT_MOVE_LINE_UP: {
|
||||
code_editor->get_text_editor()->move_lines_up();
|
||||
} break;
|
||||
case EDIT_MOVE_LINE_DOWN: {
|
||||
code_editor->get_text_editor()->move_lines_down();
|
||||
} break;
|
||||
case EDIT_INDENT: {
|
||||
tx->indent_lines();
|
||||
} break;
|
||||
case EDIT_UNINDENT: {
|
||||
tx->unindent_lines();
|
||||
} break;
|
||||
case EDIT_DELETE_LINE: {
|
||||
code_editor->get_text_editor()->delete_lines();
|
||||
} break;
|
||||
case EDIT_DUPLICATE_SELECTION: {
|
||||
code_editor->get_text_editor()->duplicate_selection();
|
||||
} break;
|
||||
case EDIT_DUPLICATE_LINES: {
|
||||
code_editor->get_text_editor()->duplicate_lines();
|
||||
} 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;
|
||||
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 = code_editor->get_text_editor()->get_line_wrapping_mode();
|
||||
code_editor->get_text_editor()->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 = code_editor->get_text_editor()->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 = code_editor->get_text_editor()->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: {
|
||||
code_editor->get_text_editor()->show_emoji_and_symbol_picker();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditor::_convert_case(CodeTextEditor::CaseStyle p_case) {
|
||||
code_editor->convert_case(p_case);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void TextEditor::register_editor() {
|
||||
ScriptEditor::register_create_script_editor_function(create_editor);
|
||||
}
|
||||
|
||||
void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
|
||||
Ref<InputEventMouseButton> mb = 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"));
|
||||
bool can_fold = tx->can_fold_line(row);
|
||||
bool is_folded = tx->is_line_folded(row);
|
||||
|
||||
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()) {
|
||||
_make_context_menu(tx->has_selection(), can_fold, is_folded, get_local_mouse_position());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ref<InputEventKey> k = 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(0);
|
||||
tx->adjust_viewport_to_caret(0);
|
||||
_make_context_menu(tx->has_selection(0), tx->can_fold_line(line), tx->is_line_folded(line), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->get_caret_draw_pos(0)));
|
||||
context_menu->grab_focus();
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditor::_prepare_edit_menu() {
|
||||
const CodeEdit *tx = 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 TextEditor::_make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded, Vector2 p_position) {
|
||||
context_menu->clear();
|
||||
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_EMOJI_AND_SYMBOL_PICKER)) {
|
||||
context_menu->add_item(TTRC("Emoji & Symbols"), EDIT_EMOJI_AND_SYMBOL);
|
||||
context_menu->add_separator();
|
||||
}
|
||||
if (p_selection) {
|
||||
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_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("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_can_fold || p_is_folded) {
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
|
||||
}
|
||||
|
||||
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 TextEditor::update_toggle_files_button() {
|
||||
code_editor->update_toggle_files_button();
|
||||
}
|
||||
|
||||
TextEditor::TextEditor() {
|
||||
code_editor = memnew(CodeTextEditor);
|
||||
add_child(code_editor);
|
||||
code_editor->add_theme_constant_override("separation", 0);
|
||||
code_editor->connect("load_theme_settings", callable_mp(this, &TextEditor::_load_theme_settings));
|
||||
code_editor->connect("validate_script", callable_mp(this, &TextEditor::_validate_script));
|
||||
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->set_toggle_list_control(ScriptEditor::get_singleton()->get_left_list_split());
|
||||
|
||||
update_settings();
|
||||
|
||||
code_editor->get_text_editor()->set_context_menu_enabled(false);
|
||||
code_editor->get_text_editor()->connect(SceneStringName(gui_input), callable_mp(this, &TextEditor::_text_edit_gui_input));
|
||||
|
||||
context_menu = memnew(PopupMenu);
|
||||
add_child(context_menu);
|
||||
context_menu->connect(SceneStringName(id_pressed), callable_mp(this, &TextEditor::_edit_option));
|
||||
|
||||
edit_hb = memnew(HBoxContainer);
|
||||
|
||||
edit_menu = memnew(MenuButton);
|
||||
edit_menu->set_flat(false);
|
||||
edit_menu->set_theme_type_variation("FlatMenuButton");
|
||||
edit_menu->set_shortcut_context(this);
|
||||
edit_hb->add_child(edit_menu);
|
||||
edit_menu->set_text(TTRC("Edit"));
|
||||
edit_menu->set_switch_on_hover(true);
|
||||
edit_menu->connect("about_to_popup", callable_mp(this, &TextEditor::_prepare_edit_menu));
|
||||
edit_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &TextEditor::_edit_option));
|
||||
|
||||
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_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_up"), EDIT_MOVE_LINE_UP);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent"), EDIT_INDENT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unindent"), EDIT_UNINDENT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/delete_line"), EDIT_DELETE_LINE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_all_lines"), EDIT_FOLD_ALL_LINES);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_all_lines"), EDIT_UNFOLD_ALL_LINES);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
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_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->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_spaces"), EDIT_CONVERT_INDENT_TO_SPACES);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_tabs"), EDIT_CONVERT_INDENT_TO_TABS);
|
||||
|
||||
edit_menu->get_popup()->add_separator();
|
||||
PopupMenu *convert_case = memnew(PopupMenu);
|
||||
edit_menu->get_popup()->add_submenu_node_item(TTRC("Convert Case"), convert_case);
|
||||
convert_case->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_uppercase"), EDIT_TO_UPPERCASE);
|
||||
convert_case->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_lowercase"), EDIT_TO_LOWERCASE);
|
||||
convert_case->add_shortcut(ED_GET_SHORTCUT("script_text_editor/capitalize"), EDIT_CAPITALIZE);
|
||||
convert_case->connect(SceneStringName(id_pressed), callable_mp(this, &TextEditor::_edit_option));
|
||||
|
||||
highlighter_menu = memnew(PopupMenu);
|
||||
edit_menu->get_popup()->add_submenu_node_item(TTRC("Syntax Highlighter"), highlighter_menu);
|
||||
highlighter_menu->connect(SceneStringName(id_pressed), callable_mp(this, &TextEditor::_change_syntax_highlighter));
|
||||
|
||||
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);
|
||||
|
||||
search_menu = memnew(MenuButton);
|
||||
search_menu->set_flat(false);
|
||||
search_menu->set_theme_type_variation("FlatMenuButton");
|
||||
search_menu->set_shortcut_context(this);
|
||||
edit_hb->add_child(search_menu);
|
||||
search_menu->set_text(TTRC("Search"));
|
||||
search_menu->set_switch_on_hover(true);
|
||||
search_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &TextEditor::_edit_option));
|
||||
|
||||
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);
|
||||
|
||||
MenuButton *goto_menu = memnew(MenuButton);
|
||||
goto_menu->set_flat(false);
|
||||
goto_menu->set_theme_type_variation("FlatMenuButton");
|
||||
goto_menu->set_shortcut_context(this);
|
||||
edit_hb->add_child(goto_menu);
|
||||
goto_menu->set_text(TTRC("Go To"));
|
||||
goto_menu->set_switch_on_hover(true);
|
||||
goto_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &TextEditor::_edit_option));
|
||||
|
||||
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);
|
||||
_update_bookmark_list();
|
||||
bookmarks_menu->connect("about_to_popup", callable_mp(this, &TextEditor::_update_bookmark_list));
|
||||
bookmarks_menu->connect("index_pressed", callable_mp(this, &TextEditor::_bookmark_item_pressed));
|
||||
|
||||
goto_line_popup = memnew(GotoLinePopup);
|
||||
add_child(goto_line_popup);
|
||||
}
|
||||
|
||||
TextEditor::~TextEditor() {
|
||||
highlighters.clear();
|
||||
}
|
||||
|
||||
void TextEditor::validate() {
|
||||
code_editor->validate_script();
|
||||
}
|
162
editor/script/text_editor.h
Normal file
162
editor/script/text_editor.h
Normal file
@@ -0,0 +1,162 @@
|
||||
/**************************************************************************/
|
||||
/* 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_plugin.h"
|
||||
|
||||
#include "editor/gui/code_editor.h"
|
||||
|
||||
class TextEditor : public ScriptEditorBase {
|
||||
GDCLASS(TextEditor, ScriptEditorBase);
|
||||
|
||||
static ScriptEditorBase *create_editor(const Ref<Resource> &p_resource);
|
||||
|
||||
private:
|
||||
CodeTextEditor *code_editor = nullptr;
|
||||
|
||||
Ref<Resource> edited_res;
|
||||
bool editor_enabled = false;
|
||||
|
||||
HBoxContainer *edit_hb = nullptr;
|
||||
MenuButton *edit_menu = nullptr;
|
||||
PopupMenu *highlighter_menu = nullptr;
|
||||
MenuButton *search_menu = nullptr;
|
||||
PopupMenu *bookmarks_menu = nullptr;
|
||||
PopupMenu *context_menu = nullptr;
|
||||
|
||||
GotoLinePopup *goto_line_popup = nullptr;
|
||||
|
||||
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_WORD_WRAP,
|
||||
EDIT_TOGGLE_FOLD_LINE,
|
||||
EDIT_FOLD_ALL_LINES,
|
||||
EDIT_UNFOLD_ALL_LINES,
|
||||
SEARCH_FIND,
|
||||
SEARCH_FIND_NEXT,
|
||||
SEARCH_FIND_PREV,
|
||||
SEARCH_REPLACE,
|
||||
SEARCH_IN_FILES,
|
||||
REPLACE_IN_FILES,
|
||||
SEARCH_GOTO_LINE,
|
||||
BOOKMARK_TOGGLE,
|
||||
BOOKMARK_GOTO_NEXT,
|
||||
BOOKMARK_GOTO_PREV,
|
||||
BOOKMARK_REMOVE_ALL,
|
||||
EDIT_EMOJI_AND_SYMBOL,
|
||||
};
|
||||
|
||||
protected:
|
||||
void _edit_option(int p_op);
|
||||
void _make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded, Vector2 p_position);
|
||||
void _text_edit_gui_input(const Ref<InputEvent> &ev);
|
||||
void _prepare_edit_menu();
|
||||
|
||||
HashMap<String, Ref<EditorSyntaxHighlighter>> highlighters;
|
||||
void _change_syntax_highlighter(int p_idx);
|
||||
void _load_theme_settings();
|
||||
|
||||
void _convert_case(CodeTextEditor::CaseStyle p_case);
|
||||
|
||||
void _validate_script();
|
||||
|
||||
void _update_bookmark_list();
|
||||
void _bookmark_item_pressed(int p_idx);
|
||||
|
||||
public:
|
||||
virtual void add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override;
|
||||
virtual void set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override;
|
||||
|
||||
virtual String get_name() override;
|
||||
virtual Ref<Texture2D> get_theme_icon() override;
|
||||
virtual Ref<Resource> get_edited_resource() const override;
|
||||
virtual void set_edited_resource(const Ref<Resource> &p_res) override;
|
||||
virtual void enable_editor(Control *p_shortcut_context = nullptr) override;
|
||||
virtual void reload_text() override;
|
||||
virtual void apply_code() override;
|
||||
virtual bool is_unsaved() override;
|
||||
virtual Variant get_edit_state() override;
|
||||
virtual void set_edit_state(const Variant &p_state) override;
|
||||
virtual Variant get_navigation_state() override;
|
||||
virtual Vector<String> get_functions() override;
|
||||
virtual PackedInt32Array get_breakpoints() override;
|
||||
virtual void set_breakpoint(int p_line, bool p_enabled) override {}
|
||||
virtual void clear_breakpoints() override {}
|
||||
virtual void goto_line(int p_line, int p_column = 0) override;
|
||||
void goto_line_selection(int p_line, int p_begin, int p_end);
|
||||
virtual void set_executing_line(int p_line) override;
|
||||
virtual void clear_executing_line() override;
|
||||
virtual void trim_trailing_whitespace() override;
|
||||
virtual void trim_final_newlines() override;
|
||||
virtual void insert_final_newline() override;
|
||||
virtual void convert_indent() override;
|
||||
virtual void ensure_focus() override;
|
||||
virtual void tag_saved_version() override;
|
||||
virtual void update_settings() override;
|
||||
virtual bool show_members_overview() override;
|
||||
virtual void set_debugger_active(bool p_active) override;
|
||||
virtual void set_tooltip_request_func(const Callable &p_toolip_callback) override;
|
||||
virtual void add_callback(const String &p_function, const PackedStringArray &p_args) override;
|
||||
void update_toggle_files_button() override;
|
||||
|
||||
virtual Control *get_edit_menu() override;
|
||||
virtual void clear_edit_menu() override;
|
||||
virtual void set_find_replace_bar(FindReplaceBar *p_bar) override;
|
||||
|
||||
virtual void validate() override;
|
||||
|
||||
virtual Control *get_base_editor() const override;
|
||||
virtual CodeTextEditor *get_code_editor() const override;
|
||||
|
||||
static void register_editor();
|
||||
|
||||
TextEditor();
|
||||
~TextEditor();
|
||||
};
|
Reference in New Issue
Block a user