Skip to content

Commit 45fabe8

Browse files
committed
Implement EditorExtensionSourceCodePlugin
This plugin can provide source-code editing capabilities for GDExtension classes, such as: - Providing the path to source code files so they can be opened by the editor. - Opening source code files in external editors. - Creating class source code files. - Providing templates to use when creating source code files. - Editing class source code files to add callback methods when connecting signals to a non-existent method.
1 parent 06827c9 commit 45fabe8

24 files changed

+2379
-9
lines changed

core/object/object.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,22 @@ class Object {
874874

875875
StringName get_class_name_for_extension(const GDExtension *p_library) const;
876876

877+
#ifdef TOOLS_ENABLED
878+
const StringName get_extension_class_name() const {
879+
if (_extension != nullptr) {
880+
return _extension->class_name;
881+
}
882+
return StringName();
883+
}
884+
885+
const GDExtension *get_extension_library() const {
886+
if (_extension != nullptr) {
887+
return _extension->library;
888+
}
889+
return nullptr;
890+
}
891+
#endif
892+
877893
/* IAPI */
878894

879895
void set(const StringName &p_name, const Variant &p_value, bool *r_valid = nullptr);

doc/classes/EditorExtensionSourceCodePlugin.xml

Lines changed: 274 additions & 0 deletions
Large diffs are not rendered by default.

doc/classes/EditorPlugin.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,13 @@
487487
See [method add_inspector_plugin] for an example of how to register a plugin.
488488
</description>
489489
</method>
490+
<method name="add_extension_source_code_plugin">
491+
<return type="void" />
492+
<param index="0" name="plugin" type="EditorExtensionSourceCodePlugin" />
493+
<description>
494+
Registers a new [EditorExtensionSourceCodePlugin]. Source code plugins are used to provide source code editing capabilities to GDExtension classes.
495+
</description>
496+
</method>
490497
<method name="add_import_plugin">
491498
<return type="void" />
492499
<param index="0" name="importer" type="EditorImportPlugin" />
@@ -705,6 +712,13 @@
705712
Removes an export plugin registered by [method add_export_plugin].
706713
</description>
707714
</method>
715+
<method name="remove_extension_source_code_plugin">
716+
<return type="void" />
717+
<param index="0" name="plugin" type="EditorExtensionSourceCodePlugin" />
718+
<description>
719+
Removes a source code plugin registered by [method add_extension_source_code_plugin].
720+
</description>
721+
</method>
708722
<method name="remove_import_plugin">
709723
<return type="void" />
710724
<param index="0" name="importer" type="EditorImportPlugin" />

doc/classes/ValidationContext.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<class name="ValidationContext" inherits="Object" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3+
<brief_description>
4+
</brief_description>
5+
<description>
6+
</description>
7+
<tutorials>
8+
</tutorials>
9+
<methods>
10+
<method name="add_validation">
11+
<return type="void" />
12+
<param index="0" name="severity" type="int" enum="ValidationContext.ValidationSeverity" />
13+
<param index="1" name="message" type="String" />
14+
<description>
15+
Report a validation issue with the given [param message] at the specified [param severity] level. If any of the messages are reported at the error level, the validation context will be marked as invalid.
16+
</description>
17+
</method>
18+
</methods>
19+
<constants>
20+
<constant name="VALIDATION_SEVERITY_INFO" value="0" enum="ValidationSeverity">
21+
The message contains informational content that needs to be displayed to the user but does not indicate a problem.
22+
</constant>
23+
<constant name="VALIDATION_SEVERITY_WARNING" value="1" enum="ValidationSeverity">
24+
The message contains a warning about a potential issue that should be looked at, but is not necessarily an error.
25+
</constant>
26+
<constant name="VALIDATION_SEVERITY_ERROR" value="2" enum="ValidationSeverity">
27+
The message indicates an error that needs to be addressed.
28+
</constant>
29+
</constants>
30+
</class>

editor/SCsub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ if env.editor_build:
8080
SConscript("debugger/SCsub")
8181
SConscript("doc/SCsub")
8282
SConscript("docks/SCsub")
83+
SConscript("extension/SCsub")
8384
SConscript("export/SCsub")
8485
SConscript("file_system/SCsub")
8586
SConscript("gui/SCsub")

editor/docks/filesystem_dock.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "editor/editor_node.h"
4444
#include "editor/editor_string_names.h"
4545
#include "editor/editor_undo_redo_manager.h"
46+
#include "editor/extension/extension_source_code_manager.h"
4647
#include "editor/gui/create_dialog.h"
4748
#include "editor/gui/directory_create_dialog.h"
4849
#include "editor/gui/editor_dir_dialog.h"
@@ -2572,6 +2573,15 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
25722573
make_script_dialog->popup_centered();
25732574
} break;
25742575

2576+
case FILE_MENU_NEW_EXTENSION_CLASS: {
2577+
String fpath = current_path;
2578+
if (!fpath.ends_with("/")) {
2579+
fpath = fpath.get_base_dir();
2580+
}
2581+
make_extension_class_dialog->config("Node", fpath);
2582+
make_extension_class_dialog->popup_centered();
2583+
} break;
2584+
25752585
case FILE_MENU_COPY_PATH: {
25762586
if (!p_selected.is_empty()) {
25772587
const String &fpath = p_selected[0];
@@ -3336,6 +3346,12 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, const Vect
33363346
new_menu->add_icon_item(get_editor_theme_icon(SNAME("Folder")), TTRC("Folder..."), FILE_MENU_NEW_FOLDER);
33373347
new_menu->add_icon_item(get_editor_theme_icon(SNAME("PackedScene")), TTRC("Scene..."), FILE_MENU_NEW_SCENE);
33383348
new_menu->add_icon_item(get_editor_theme_icon(SNAME("Script")), TTRC("Script..."), FILE_MENU_NEW_SCRIPT);
3349+
new_menu->add_icon_item(get_editor_theme_icon(SNAME("ExtensionClass")), TTRC("Extension class..."), FILE_MENU_NEW_EXTENSION_CLASS);
3350+
if (!ExtensionSourceCodeManager::get_singleton()->has_plugins_that_can_create_class_source()) {
3351+
int item_idx = new_menu->get_item_count() - 1;
3352+
new_menu->set_item_disabled(item_idx, true);
3353+
new_menu->set_item_tooltip(item_idx, "No extension source code plugins available.");
3354+
}
33393355
new_menu->add_icon_item(get_editor_theme_icon(SNAME("Object")), TTRC("Resource..."), FILE_MENU_NEW_RESOURCE);
33403356
new_menu->add_icon_item(get_editor_theme_icon(SNAME("TextFile")), TTRC("TextFile..."), FILE_MENU_NEW_TEXTFILE);
33413357

@@ -3560,6 +3576,12 @@ void FileSystemDock::_tree_empty_click(const Vector2 &p_pos, MouseButton p_butto
35603576
tree_popup->add_icon_item(get_editor_theme_icon(SNAME("Folder")), TTRC("New Folder..."), FILE_MENU_NEW_FOLDER);
35613577
tree_popup->add_icon_item(get_editor_theme_icon(SNAME("PackedScene")), TTRC("New Scene..."), FILE_MENU_NEW_SCENE);
35623578
tree_popup->add_icon_item(get_editor_theme_icon(SNAME("Script")), TTRC("New Script..."), FILE_MENU_NEW_SCRIPT);
3579+
tree_popup->add_icon_item(get_editor_theme_icon(SNAME("ExtensionClass")), TTRC("Extension class..."), FILE_MENU_NEW_EXTENSION_CLASS);
3580+
if (!ExtensionSourceCodeManager::get_singleton()->has_plugins_that_can_create_class_source()) {
3581+
int item_idx = tree_popup->get_item_count() - 1;
3582+
tree_popup->set_item_disabled(item_idx, true);
3583+
tree_popup->set_item_tooltip(item_idx, "No extension source code plugins available.");
3584+
}
35633585
tree_popup->add_icon_item(get_editor_theme_icon(SNAME("Object")), TTRC("New Resource..."), FILE_MENU_NEW_RESOURCE);
35643586
tree_popup->add_icon_item(get_editor_theme_icon(SNAME("TextFile")), TTRC("New TextFile..."), FILE_MENU_NEW_TEXTFILE);
35653587
// To keep consistency with options added to "Create New..." menu (for plugin which has slot as CONTEXT_SLOT_FILESYSTEM_CREATE).
@@ -3637,6 +3659,12 @@ void FileSystemDock::_file_list_empty_clicked(const Vector2 &p_pos, MouseButton
36373659
file_list_popup->add_icon_item(get_editor_theme_icon(SNAME("Folder")), TTRC("New Folder..."), FILE_MENU_NEW_FOLDER);
36383660
file_list_popup->add_icon_item(get_editor_theme_icon(SNAME("PackedScene")), TTRC("New Scene..."), FILE_MENU_NEW_SCENE);
36393661
file_list_popup->add_icon_item(get_editor_theme_icon(SNAME("Script")), TTRC("New Script..."), FILE_MENU_NEW_SCRIPT);
3662+
file_list_popup->add_icon_item(get_editor_theme_icon(SNAME("ExtensionClass")), TTRC("Extension class..."), FILE_MENU_NEW_EXTENSION_CLASS);
3663+
if (!ExtensionSourceCodeManager::get_singleton()->has_plugins_that_can_create_class_source()) {
3664+
int item_idx = file_list_popup->get_item_count() - 1;
3665+
file_list_popup->set_item_disabled(item_idx, true);
3666+
file_list_popup->set_item_tooltip(item_idx, "No extension source code plugins available.");
3667+
}
36403668
file_list_popup->add_icon_item(get_editor_theme_icon(SNAME("Object")), TTRC("New Resource..."), FILE_MENU_NEW_RESOURCE);
36413669
file_list_popup->add_icon_item(get_editor_theme_icon(SNAME("TextFile")), TTRC("New TextFile..."), FILE_MENU_NEW_TEXTFILE);
36423670
// To keep consistency with options added to "Create New..." menu (for plugin which has slot as CONTEXT_SLOT_FILESYSTEM_CREATE).
@@ -4371,6 +4399,10 @@ FileSystemDock::FileSystemDock() {
43714399
make_script_dialog->set_title(TTRC("Create Script"));
43724400
add_child(make_script_dialog);
43734401

4402+
make_extension_class_dialog = memnew(ExtensionClassCreateDialog);
4403+
make_extension_class_dialog->set_title(TTRC("Create Extension Class"));
4404+
add_child(make_extension_class_dialog);
4405+
43744406
make_shader_dialog = memnew(ShaderCreateDialog);
43754407
add_child(make_shader_dialog);
43764408

editor/docks/filesystem_dock.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#pragma once
3232

3333
#include "editor/docks/editor_dock.h"
34+
#include "editor/extension/extension_class_create_dialog.h"
3435
#include "editor/file_system/dependency_editor.h"
3536
#include "editor/file_system/editor_file_system.h"
3637
#include "editor/file_system/file_info.h"
@@ -131,6 +132,7 @@ class FileSystemDock : public EditorDock {
131132
FILE_MENU_NEW_TEXTFILE,
132133
FILE_MENU_NEW_FOLDER,
133134
FILE_MENU_NEW_SCRIPT,
135+
FILE_MENU_NEW_EXTENSION_CLASS,
134136
FILE_MENU_NEW_SCENE,
135137
FILE_MENU_RUN_SCRIPT,
136138
FILE_MENU_MAX,
@@ -202,6 +204,7 @@ class FileSystemDock : public EditorDock {
202204

203205
SceneCreateDialog *make_scene_dialog = nullptr;
204206
ScriptCreateDialog *make_script_dialog = nullptr;
207+
ExtensionClassCreateDialog *make_extension_class_dialog = nullptr;
205208
ShaderCreateDialog *make_shader_dialog = nullptr;
206209
CreateDialog *new_resource_dialog = nullptr;
207210

editor/editor_node.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
#include "editor/export/project_zip_packer.h"
101101
#include "editor/export/register_exporters.h"
102102
#include "editor/export/shader_baker_export_plugin.h"
103+
#include "editor/extension/extension_source_code_manager.h"
103104
#include "editor/file_system/dependency_editor.h"
104105
#include "editor/file_system/editor_paths.h"
105106
#include "editor/gui/editor_about.h"
@@ -7842,6 +7843,8 @@ EditorNode::EditorNode() {
78427843

78437844
EditorContextMenuPluginManager::create();
78447845

7846+
ExtensionSourceCodeManager::create();
7847+
78457848
// Used for previews.
78467849
FileDialog::set_get_icon_callback(callable_mp_static(_file_dialog_get_icon));
78477850
FileDialog::set_get_thumbnail_callback(callable_mp_static(_file_dialog_get_thumbnail));
@@ -8916,6 +8919,7 @@ EditorNode::~EditorNode() {
89168919
EditorTranslationParser::get_singleton()->clean_parsers();
89178920
ResourceImporterScene::clean_up_importer_plugins();
89188921
EditorContextMenuPluginManager::cleanup();
8922+
ExtensionSourceCodeManager::cleanup();
89198923

89208924
remove_print_handler(&print_handler);
89218925
EditorHelp::cleanup_doc();

editor/extension/SCsub

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env python
2+
from misc.utility.scons_hints import *
3+
4+
Import("env")
5+
6+
env.add_source_files(env.editor_sources, "*.cpp")

0 commit comments

Comments
 (0)