You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-13 13:31:48 +00:00
Expose Syntax highlighter for editor plugins
This commit is contained in:
@@ -63,6 +63,8 @@ void ScriptEditorBase::_bind_methods() {
|
||||
// TODO: This signal is no use for VisualScript.
|
||||
ADD_SIGNAL(MethodInfo("search_in_files_requested", PropertyInfo(Variant::STRING, "text")));
|
||||
ADD_SIGNAL(MethodInfo("replace_in_files_requested", PropertyInfo(Variant::STRING, "text")));
|
||||
|
||||
BIND_VMETHOD(MethodInfo("add_syntax_highlighter", PropertyInfo(Variant::OBJECT, "highlighter")));
|
||||
}
|
||||
|
||||
static bool _is_built_in_script(Script *p_script) {
|
||||
@@ -2019,8 +2021,11 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
|
||||
|
||||
if (p_resource->get_class_name() != StringName("VisualScript")) {
|
||||
bool highlighter_set = false;
|
||||
for (int i = 0; i < syntax_highlighters_func_count; i++) {
|
||||
SyntaxHighlighter *highlighter = syntax_highlighters_funcs[i]();
|
||||
for (int i = 0; i < syntax_highlighters.size(); i++) {
|
||||
Ref<SyntaxHighlighter> highlighter = syntax_highlighters[i]->_create();
|
||||
if (highlighter.is_null()) {
|
||||
continue;
|
||||
}
|
||||
se->add_syntax_highlighter(highlighter);
|
||||
|
||||
if (script != nullptr && !highlighter_set) {
|
||||
@@ -2768,6 +2773,18 @@ Vector<Ref<Script>> ScriptEditor::get_open_scripts() const {
|
||||
return out_scripts;
|
||||
}
|
||||
|
||||
Array ScriptEditor::_get_open_script_editors() const {
|
||||
Array script_editors;
|
||||
for (int i = 0; i < tab_container->get_child_count(); i++) {
|
||||
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
|
||||
if (!se) {
|
||||
continue;
|
||||
}
|
||||
script_editors.push_back(se);
|
||||
}
|
||||
return script_editors;
|
||||
}
|
||||
|
||||
void ScriptEditor::set_scene_root_script(Ref<Script> p_script) {
|
||||
bool open_dominant = EditorSettings::get_singleton()->get("text_editor/files/open_dominant_script_on_scene_change");
|
||||
|
||||
@@ -2813,12 +2830,14 @@ void ScriptEditor::_open_script_request(const String &p_path) {
|
||||
}
|
||||
}
|
||||
|
||||
int ScriptEditor::syntax_highlighters_func_count = 0;
|
||||
CreateSyntaxHighlighterFunc ScriptEditor::syntax_highlighters_funcs[ScriptEditor::SYNTAX_HIGHLIGHTER_FUNC_MAX];
|
||||
void ScriptEditor::register_syntax_highlighter(const Ref<SyntaxHighlighter> &p_syntax_highlighter) {
|
||||
if (syntax_highlighters.find(p_syntax_highlighter) == -1) {
|
||||
syntax_highlighters.push_back(p_syntax_highlighter);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEditor::register_create_syntax_highlighter_function(CreateSyntaxHighlighterFunc p_func) {
|
||||
ERR_FAIL_COND(syntax_highlighters_func_count == SYNTAX_HIGHLIGHTER_FUNC_MAX);
|
||||
syntax_highlighters_funcs[syntax_highlighters_func_count++] = p_func;
|
||||
void ScriptEditor::unregister_syntax_highlighter(const Ref<SyntaxHighlighter> &p_syntax_highlighter) {
|
||||
syntax_highlighters.erase(p_syntax_highlighter);
|
||||
}
|
||||
|
||||
int ScriptEditor::script_editor_func_count = 0;
|
||||
@@ -2927,6 +2946,12 @@ void ScriptEditor::_bind_methods() {
|
||||
ClassDB::bind_method("_update_members_overview", &ScriptEditor::_update_members_overview);
|
||||
ClassDB::bind_method("_update_recent_scripts", &ScriptEditor::_update_recent_scripts);
|
||||
|
||||
ClassDB::bind_method("get_current_editor", &ScriptEditor::_get_current_editor);
|
||||
ClassDB::bind_method("get_open_script_editors", &ScriptEditor::_get_open_script_editors);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("register_syntax_highlighter", "syntax_highlighter"), &ScriptEditor::register_syntax_highlighter);
|
||||
ClassDB::bind_method(D_METHOD("unregister_syntax_highlighter", "syntax_highlighter"), &ScriptEditor::unregister_syntax_highlighter);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_drag_data_fw", "point", "from"), &ScriptEditor::get_drag_data_fw);
|
||||
ClassDB::bind_method(D_METHOD("can_drop_data_fw", "point", "data", "from"), &ScriptEditor::can_drop_data_fw);
|
||||
ClassDB::bind_method(D_METHOD("drop_data_fw", "point", "data", "from"), &ScriptEditor::drop_data_fw);
|
||||
|
||||
@@ -236,14 +236,12 @@ class ScriptEditor : public PanelContainer {
|
||||
|
||||
enum {
|
||||
SCRIPT_EDITOR_FUNC_MAX = 32,
|
||||
SYNTAX_HIGHLIGHTER_FUNC_MAX = 32
|
||||
};
|
||||
|
||||
static int script_editor_func_count;
|
||||
static CreateScriptEditorFunc script_editor_funcs[SCRIPT_EDITOR_FUNC_MAX];
|
||||
|
||||
static int syntax_highlighters_func_count;
|
||||
static CreateSyntaxHighlighterFunc syntax_highlighters_funcs[SYNTAX_HIGHLIGHTER_FUNC_MAX];
|
||||
Vector<Ref<SyntaxHighlighter> > syntax_highlighters;
|
||||
|
||||
struct ScriptHistory {
|
||||
Control *control;
|
||||
@@ -322,6 +320,7 @@ class ScriptEditor : public PanelContainer {
|
||||
void _script_created(Ref<Script> p_script);
|
||||
|
||||
ScriptEditorBase *_get_current_editor() const;
|
||||
Array _get_open_script_editors() const;
|
||||
|
||||
void _save_layout();
|
||||
void _editor_settings_changed();
|
||||
@@ -441,7 +440,9 @@ public:
|
||||
|
||||
void set_live_auto_reload_running_scripts(bool p_enabled);
|
||||
|
||||
static void register_create_syntax_highlighter_function(CreateSyntaxHighlighterFunc p_func);
|
||||
void register_syntax_highlighter(const Ref<SyntaxHighlighter> &p_syntax_highlighter);
|
||||
void unregister_syntax_highlighter(const Ref<SyntaxHighlighter> &p_syntax_highlighter);
|
||||
|
||||
static void register_create_script_editor_function(CreateScriptEditorFunc p_func);
|
||||
|
||||
ScriptEditor(EditorNode *p_editor);
|
||||
|
||||
@@ -1410,6 +1410,8 @@ void ScriptTextEditor::_bind_methods() {
|
||||
ClassDB::bind_method("get_drag_data_fw", &ScriptTextEditor::get_drag_data_fw);
|
||||
ClassDB::bind_method("can_drop_data_fw", &ScriptTextEditor::can_drop_data_fw);
|
||||
ClassDB::bind_method("drop_data_fw", &ScriptTextEditor::drop_data_fw);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_syntax_highlighter", "highlighter"), &ScriptTextEditor::add_syntax_highlighter);
|
||||
}
|
||||
|
||||
Control *ScriptTextEditor::get_edit_menu() {
|
||||
|
||||
@@ -471,6 +471,7 @@ void TextEditor::_convert_case(CodeTextEditor::CaseStyle p_case) {
|
||||
}
|
||||
|
||||
void TextEditor::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("add_syntax_highlighter", "highlighter"), &TextEditor::add_syntax_highlighter);
|
||||
}
|
||||
|
||||
static ScriptEditorBase *create_editor(const RES &p_resource) {
|
||||
|
||||
Reference in New Issue
Block a user