Skip to content

Commit

Permalink
GH-655 Use EditorInterface::get_singleton where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Aug 15, 2024
1 parent 313bdd5 commit 0333834
Show file tree
Hide file tree
Showing 21 changed files with 56 additions and 77 deletions.
6 changes: 2 additions & 4 deletions src/common/file_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@
//
#include "common/file_utils.h"

#include "editor/plugins/orchestrator_editor_plugin.h"

#include <godot_cpp/classes/editor_interface.hpp>
#include <godot_cpp/classes/editor_paths.hpp>

namespace FileUtils
{
Ref<FileAccess> open_project_settings_file(const String& p_file_name, FileAccess::ModeFlags p_flags)
{
const EditorPaths* ep = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_paths();
const EditorPaths* ep = EditorInterface::get_singleton()->get_editor_paths();
return FileAccess::open(ep->get_project_settings_dir().path_join(p_file_name), p_flags);
}

void for_each_line(const Ref<FileAccess>& p_file, std::function<void(const String&)> p_callback)
void for_each_line(const Ref<FileAccess>& p_file, const std::function<void(const String&)>& p_callback)
{
if (p_file.is_valid() && p_file->is_open())
{
Expand Down
2 changes: 1 addition & 1 deletion src/common/file_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace FileUtils
/// For the specified file, reads each line and calls the specified callback function with the line.
/// @param p_file the file to read
/// @param p_callback the callback function to call for each line
void for_each_line(const Ref<FileAccess>& p_file, std::function<void(const String&)> p_callback);
void for_each_line(const Ref<FileAccess>& p_file, const std::function<void(const String&)>& p_callback);
}

#endif // ORCHESTRATOR_FILE_UTILS_H
17 changes: 8 additions & 9 deletions src/common/scene_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
//
#include "scene_utils.h"

#include "editor/plugins/orchestrator_editor_plugin.h"
#include "script/script_server.h"

#include <godot_cpp/classes/editor_interface.hpp>
Expand All @@ -36,7 +35,7 @@ namespace SceneUtils
{
ERR_FAIL_COND_V_MSG(p_class_name.is_empty(), nullptr, "Class name cannot be empty.");

VBoxContainer* vbox = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_main_screen();
VBoxContainer* vbox = EditorInterface::get_singleton()->get_editor_main_screen();
if (vbox->has_theme_icon(p_class_name, "EditorIcons"))
return vbox->get_theme_icon(p_class_name, "EditorIcons");

Expand Down Expand Up @@ -66,13 +65,13 @@ namespace SceneUtils

bool has_editor_icon(const String& p_icon_name)
{
VBoxContainer* vbox = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_main_screen();
VBoxContainer* vbox = EditorInterface::get_singleton()->get_editor_main_screen();
return vbox->has_theme_icon(p_icon_name);
}

Color get_editor_color(const String& p_color_name, const String& p_category)
{
VBoxContainer* vbox = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_main_screen();
VBoxContainer* vbox = EditorInterface::get_singleton()->get_editor_main_screen();
return vbox->get_theme_color(p_color_name, p_category);
}

Expand All @@ -83,31 +82,31 @@ namespace SceneUtils

Ref<Texture2D> get_editor_icon(const String& p_icon_name)
{
VBoxContainer* vbox = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_main_screen();
VBoxContainer* vbox = EditorInterface::get_singleton()->get_editor_main_screen();
return vbox->get_theme_icon(p_icon_name, "EditorIcons");
}

Ref<StyleBox> get_editor_style(const String& p_style_name)
{
VBoxContainer* vbox = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_main_screen();
VBoxContainer* vbox = EditorInterface::get_singleton()->get_editor_main_screen();
return vbox->get_theme_stylebox(p_style_name, "EditorStyles");
}

Ref<Font> get_editor_font(const String& p_font_name)
{
VBoxContainer* vbox = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_main_screen();
VBoxContainer* vbox = EditorInterface::get_singleton()->get_editor_main_screen();
return vbox->get_theme_font(p_font_name, "EditorFonts");
}

int get_editor_font_size(const String& p_font_name)
{
VBoxContainer* vbox = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_main_screen();
VBoxContainer* vbox = EditorInterface::get_singleton()->get_editor_main_screen();
return vbox->get_theme_font_size(p_font_name, "EditorFonts");
}

Ref<StyleBox> get_editor_stylebox(const String& p_stylebox_name, const String& p_class_name)
{
VBoxContainer* vbox = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_main_screen();
VBoxContainer* vbox = EditorInterface::get_singleton()->get_editor_main_screen();
return vbox->get_theme_stylebox(p_stylebox_name, p_class_name);
}

Expand Down
3 changes: 1 addition & 2 deletions src/editor/about_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <godot_cpp/classes/os.hpp>
#include <godot_cpp/classes/scroll_container.hpp>
#include <godot_cpp/classes/style_box_empty.hpp>
#include <godot_cpp/classes/style_box_flat.hpp>
#include <godot_cpp/classes/tab_container.hpp>
#include <godot_cpp/classes/texture_rect.hpp>
#include <godot_cpp/classes/theme.hpp>
Expand Down Expand Up @@ -259,7 +258,7 @@ void OrchestratorAboutDialog::_on_theme_changed()
}
}

Ref<Theme> theme = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_theme();
Ref<Theme> theme = EditorInterface::get_singleton()->get_editor_theme();
if (theme.is_valid())
{
Ref<StyleBox> sb = theme->get_stylebox("panel", "EditorAbout");
Expand Down
6 changes: 3 additions & 3 deletions src/editor/component_panels/component_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
#include "common/callable_lambda.h"
#include "common/name_utils.h"
#include "common/scene_utils.h"
#include "editor/plugins/orchestrator_editor_plugin.h"

#include <godot_cpp/classes/accept_dialog.hpp>
#include <godot_cpp/classes/button.hpp>
#include <godot_cpp/classes/confirmation_dialog.hpp>
#include <godot_cpp/classes/editor_interface.hpp>
#include <godot_cpp/classes/h_box_container.hpp>
#include <godot_cpp/classes/input_event_mouse_button.hpp>
#include <godot_cpp/classes/label.hpp>
Expand Down Expand Up @@ -112,7 +112,7 @@ void OrchestratorScriptComponentPanel::_remove_confirmed()
{
if (_tree->get_selected())
{
OrchestratorPlugin::get_singleton()->get_editor_interface()->inspect_object(nullptr);
EditorInterface::get_singleton()->inspect_object(nullptr);
_handle_remove(_tree->get_selected());

update();
Expand Down Expand Up @@ -234,7 +234,7 @@ void OrchestratorScriptComponentPanel::_update_theme()
if (!_theme_changing)
return;

Ref<Theme> theme = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_theme();
Ref<Theme> theme = EditorInterface::get_singleton()->get_editor_theme();
if (theme.is_valid() && _panel)
{
Ref<StyleBoxFlat> sb = theme->get_stylebox("panel", "ItemList")->duplicate();
Expand Down
4 changes: 2 additions & 2 deletions src/editor/component_panels/functions_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
#include "common/dictionary_utils.h"
#include "common/scene_utils.h"
#include "common/settings.h"
#include "editor/plugins/orchestrator_editor_plugin.h"
#include "editor/script_connections.h"
#include "script/script.h"

#include <godot_cpp/classes/button.hpp>
#include <godot_cpp/classes/editor_interface.hpp>
#include <godot_cpp/classes/h_box_container.hpp>
#include <godot_cpp/classes/popup_menu.hpp>
#include <godot_cpp/classes/tree.hpp>
Expand Down Expand Up @@ -147,7 +147,7 @@ void OrchestratorScriptFunctionsComponentPanel::_handle_item_selected()
{
const Ref<OScriptNode> node = function->get_owning_node();
if (node.is_valid())
OrchestratorPlugin::get_singleton()->get_editor_interface()->edit_resource(node);
EditorInterface::get_singleton()->edit_resource(node);
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/editor/component_panels/signals_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

#include "common/dictionary_utils.h"
#include "common/scene_utils.h"
#include "common/settings.h"
#include "editor/plugins/orchestrator_editor_plugin.h"

#include <godot_cpp/classes/editor_interface.hpp>
#include <godot_cpp/classes/popup_menu.hpp>
#include <godot_cpp/classes/tree.hpp>

Expand Down Expand Up @@ -73,13 +72,13 @@ void OrchestratorScriptSignalsComponentPanel::_handle_item_selected()
TreeItem* item = _tree->get_selected();

Ref<OScriptSignal> signal = _orchestration->get_custom_signal(_get_tree_item_name(item));
OrchestratorPlugin::get_singleton()->get_editor_interface()->edit_resource(signal);
EditorInterface::get_singleton()->edit_resource(signal);
}

void OrchestratorScriptSignalsComponentPanel::_handle_item_activated(TreeItem* p_item)
{
Ref<OScriptSignal> signal = _orchestration->get_custom_signal(_get_tree_item_name(p_item));
OrchestratorPlugin::get_singleton()->get_editor_interface()->edit_resource(signal);
EditorInterface::get_singleton()->edit_resource(signal);
}

bool OrchestratorScriptSignalsComponentPanel::_handle_item_renamed(const String& p_old_name, const String& p_new_name)
Expand Down
5 changes: 3 additions & 2 deletions src/editor/component_panels/variables_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "editor/plugins/inspector_plugins.h"
#include "editor/plugins/orchestrator_editor_plugin.h"

#include <godot_cpp/classes/editor_interface.hpp>
#include <godot_cpp/classes/popup_menu.hpp>
#include <godot_cpp/classes/tree.hpp>

Expand Down Expand Up @@ -145,13 +146,13 @@ void OrchestratorScriptVariablesComponentPanel::_handle_item_selected()
TreeItem* item = _tree->get_selected();

Ref<OScriptVariable> variable = _orchestration->get_variable(_get_tree_item_name(item));
OrchestratorPlugin::get_singleton()->get_editor_interface()->edit_resource(variable);
EditorInterface::get_singleton()->edit_resource(variable);
}

void OrchestratorScriptVariablesComponentPanel::_handle_item_activated(TreeItem* p_item)
{
Ref<OScriptVariable> variable = _orchestration->get_variable(_get_tree_item_name(p_item));
OrchestratorPlugin::get_singleton()->get_editor_interface()->edit_resource(variable);
EditorInterface::get_singleton()->edit_resource(variable);
}

bool OrchestratorScriptVariablesComponentPanel::_handle_item_renamed(const String& p_old_name, const String& p_new_name)
Expand Down
6 changes: 3 additions & 3 deletions src/editor/editor_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
//
#include "editor/editor_cache.h"
#include "plugins/orchestrator_editor_debugger_plugin.h"
#include "plugins/orchestrator_editor_plugin.h"

#include <godot_cpp/classes/editor_interface.hpp>
#include <godot_cpp/classes/editor_paths.hpp>

#if GODOT_VERSION >= 0x040300
Expand All @@ -29,7 +29,7 @@ PackedInt64Array OrchestratorEditorCache::_get_breakpoints_for_path(const String

Error OrchestratorEditorCache::load()
{
const EditorInterface* ei = OrchestratorPlugin::get_singleton()->get_editor_interface();
const EditorInterface* ei = EditorInterface::get_singleton();

_cache = Ref<ConfigFile>(memnew(ConfigFile));

Expand Down Expand Up @@ -65,7 +65,7 @@ Error OrchestratorEditorCache::save()
{
if (_cache.is_valid())
{
const EditorInterface* ei = OrchestratorPlugin::get_singleton()->get_editor_interface();
const EditorInterface* ei = EditorInterface::get_singleton();
return _cache->save(ei->get_editor_paths()->get_project_settings_dir().path_join(CACHE_FILE));
}

Expand Down
8 changes: 4 additions & 4 deletions src/editor/editor_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void OrchestratorEditorPanel::_update_scene_tab_signals(bool p_connect)

void OrchestratorEditorPanel::_update_file_system_dock_signals(bool p_connect)
{
FileSystemDock* file_system_dock = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_file_system_dock();
FileSystemDock* file_system_dock = EditorInterface::get_singleton()->get_file_system_dock();
if (!file_system_dock)
return;

Expand Down Expand Up @@ -405,7 +405,7 @@ bool OrchestratorEditorPanel::_has_open_files() const

void OrchestratorEditorPanel::_show_editor_viewport(const String& p_file_name)
{
OrchestratorPlugin::get_singleton()->get_editor_interface()->inspect_object(nullptr);
EditorInterface::get_singleton()->inspect_object(nullptr);

_files_context.show(p_file_name);

Expand Down Expand Up @@ -567,7 +567,7 @@ void OrchestratorEditorPanel::_show_create_new_script_dialog()
_script_create_dialog->set_title("Create Orchestration");
_script_create_dialog->config(inherits, "new_script.os", false, false);

Ref<EditorSettings> editor_settings = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_settings();
Ref<EditorSettings> editor_settings = EditorInterface::get_singleton()->get_editor_settings();
editor_settings->set_project_metadata("script_setup", "last_selected_language", language_name);

_script_create_dialog->popup_centered();
Expand Down Expand Up @@ -821,7 +821,7 @@ void OrchestratorEditorPanel::_navigate_to_file_in_filesystem()

const String file_name = _files_context.get_selected_file_name();
if (!file_name.is_empty())
OrchestratorPlugin::get_singleton()->get_editor_interface()->get_file_system_dock()->navigate_to_path(file_name);
EditorInterface::get_singleton()->get_file_system_dock()->navigate_to_path(file_name);
}

void OrchestratorEditorPanel::edit_resource(const Ref<Resource>& p_resource)
Expand Down
2 changes: 1 addition & 1 deletion src/editor/editor_viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ OrchestratorGraphEdit* OrchestratorEditorViewport::_get_or_create_tab(const Stri
if (!script_graph.is_valid())
return nullptr;

OrchestratorGraphEdit* graph = memnew(OrchestratorGraphEdit(OrchestratorPlugin::get_singleton(), script_graph));
OrchestratorGraphEdit* graph = memnew(OrchestratorGraphEdit(script_graph));
_tabs->add_child(graph);

const String tab_icon = graph->is_function() ? "MemberMethod" : "ClassList";
Expand Down
5 changes: 2 additions & 3 deletions src/editor/file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//
#include "editor/file_dialog.h"

#include "plugins/orchestrator_editor_plugin.h"
#include <godot_cpp/classes/editor_interface.hpp>
#include <godot_cpp/classes/line_edit.hpp>

void OrchestratorFileDialog::_focus_file_text()
Expand All @@ -37,8 +37,7 @@ void OrchestratorFileDialog::_focus_file_text()

void OrchestratorFileDialog::popup_file_dialog()
{
const float EDSCALE = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_scale();
popup_centered_clamped(Size2(1050, 700) * EDSCALE, 0.8);
popup_centered_clamped(Size2(1050, 700) * EditorInterface::get_singleton()->get_editor_scale(), 0.8);
_focus_file_text();
}

Expand Down
19 changes: 9 additions & 10 deletions src/editor/graph/graph_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "editor/graph/graph_node_pin.h"
#include "editor/graph/graph_node_spawner.h"
#include "editor/graph/nodes/graph_node_comment.h"
#include "editor/plugins/orchestrator_editor_plugin.h"
#include "nodes/graph_node_factory.h"
#include "script/language.h"
#include "script/nodes/script_nodes.h"
Expand All @@ -40,6 +39,7 @@
#include <godot_cpp/classes/confirmation_dialog.hpp>
#include <godot_cpp/classes/display_server.hpp>
#include <godot_cpp/classes/editor_inspector.hpp>
#include <godot_cpp/classes/editor_interface.hpp>
#include <godot_cpp/classes/geometry2d.hpp>
#include <godot_cpp/classes/input.hpp>
#include <godot_cpp/classes/input_event_action.hpp>
Expand Down Expand Up @@ -99,7 +99,7 @@ EPinDirection OrchestratorGraphEdit::DragContext::get_direction() const
return output_port ? PD_Output : PD_Input;
}

OrchestratorGraphEdit::OrchestratorGraphEdit(OrchestratorPlugin* p_plugin, const Ref<OScriptGraph>& p_graph)
OrchestratorGraphEdit::OrchestratorGraphEdit(const Ref<OScriptGraph>& p_graph)
{
internal::gdextension_interface_get_godot_version(&_version);
_is_43p = _version.major == 4 && _version.minor >= 3;
Expand All @@ -109,7 +109,6 @@ OrchestratorGraphEdit::OrchestratorGraphEdit(OrchestratorPlugin* p_plugin, const
set_show_arrange_button(OrchestratorSettings::get_singleton()->get_setting("ui/graph/show_arrange_button", false));
set_right_disconnects(true);

_plugin = p_plugin;
_script_graph = p_graph;

_cache_connection_knots();
Expand Down Expand Up @@ -357,10 +356,10 @@ void OrchestratorGraphEdit::set_spawn_position_center_view()
void OrchestratorGraphEdit::goto_class_help(const String& p_class_name)
{
#if GODOT_VERSION >= 0x040300
_plugin->get_editor_interface()->get_script_editor()->goto_help(p_class_name);
EditorInterface::get_singleton()->get_script_editor()->goto_help(p_class_name);
#else
_plugin->get_editor_interface()->set_main_screen_editor("Script");
_plugin->get_editor_interface()->get_script_editor()->call("_help_class_open", p_class_name);
EditorInterface::get_singleton()->set_main_screen_editor("Script");
EditorInterface::get_singleton()->get_script_editor()->call("_help_class_open", p_class_name);
#endif
}

Expand Down Expand Up @@ -1638,12 +1637,12 @@ void OrchestratorGraphEdit::_on_node_selected(Node* p_node)
// object to resolve whether the object has any property default values so
// it can properly revert values accordingly with the rollback button.
//
_plugin->get_editor_interface()->edit_resource(node->get_inspect_object());
EditorInterface::get_singleton()->edit_resource(node->get_inspect_object());
}

void OrchestratorGraphEdit::_on_node_deselected(Node* p_node)
{
_plugin->get_editor_interface()->inspect_object(nullptr);
EditorInterface::get_singleton()->inspect_object(nullptr);

OrchestratorSettings* os = OrchestratorSettings::get_singleton();
if (os->get_setting("ui/nodes/highlight_selected_connections", false))
Expand Down Expand Up @@ -1878,9 +1877,9 @@ void OrchestratorGraphEdit::_on_project_settings_changed()

void OrchestratorGraphEdit::_on_inspect_script()
{
_plugin->get_editor_interface()->inspect_object(get_orchestration()->get_self().ptr());
EditorInterface::get_singleton()->inspect_object(get_orchestration()->get_self().ptr());

EditorInspector* inspector = _plugin->get_editor_interface()->get_inspector();
EditorInspector* inspector = EditorInterface::get_singleton()->get_inspector();

TypedArray<Node> fields = inspector->find_children("*", "EditorPropertyClassName", true, false);
if (!fields.is_empty())
Expand Down
Loading

0 comments on commit 0333834

Please sign in to comment.