chore: Refactor EditorManager to improve code organization and readability

This commit is contained in:
scawful
2024-08-16 17:06:59 -04:00
parent 941a184bb8
commit e1fda49d91
2 changed files with 15 additions and 14 deletions

View File

@@ -261,7 +261,6 @@ void EditorManager::ManageKeyboardShortcuts() {
manager.Load(); manager.Load();
if (!manager.GetRecentFiles().empty()) { if (!manager.GetRecentFiles().empty()) {
auto front = manager.GetRecentFiles().front(); auto front = manager.GetRecentFiles().front();
std::cout << "Reloading: " << front << std::endl;
OpenRomOrProject(front); OpenRomOrProject(front);
} }
} }
@@ -427,17 +426,6 @@ void EditorManager::DrawYazeMenu() {
} }
} }
void EditorManager::OpenRomOrProject(const std::string& filename) {
if (absl::StrContains(filename, ".yaze")) {
status_ = current_project_.Open(filename);
if (status_.ok()) {
status_ = OpenProject();
}
} else {
status_ = rom()->LoadFromFile(filename);
}
}
void EditorManager::DrawYazeMenuBar() { void EditorManager::DrawYazeMenuBar() {
static bool save_as_menu = false; static bool save_as_menu = false;
static bool new_project_menu = false; static bool new_project_menu = false;
@@ -805,6 +793,17 @@ void EditorManager::SaveRom() {
status_ = rom()->SaveToFile(backup_rom_, save_new_auto_); status_ = rom()->SaveToFile(backup_rom_, save_new_auto_);
} }
void EditorManager::OpenRomOrProject(const std::string& filename) {
if (absl::StrContains(filename, ".yaze")) {
status_ = current_project_.Open(filename);
if (status_.ok()) {
status_ = OpenProject();
}
} else {
status_ = rom()->LoadFromFile(filename);
}
}
absl::Status EditorManager::OpenProject() { absl::Status EditorManager::OpenProject() {
RETURN_IF_ERROR(rom()->LoadFromFile(current_project_.rom_filename_)); RETURN_IF_ERROR(rom()->LoadFromFile(current_project_.rom_filename_));

View File

@@ -8,6 +8,7 @@
#include "absl/status/status.h" #include "absl/status/status.h"
#include "app/core/common.h" #include "app/core/common.h"
#include "app/core/constants.h" #include "app/core/constants.h"
#include "app/core/message.h"
#include "app/core/project.h" #include "app/core/project.h"
#include "app/editor/code/assembly_editor.h" #include "app/editor/code/assembly_editor.h"
#include "app/editor/code/memory_editor.h" #include "app/editor/code/memory_editor.h"
@@ -18,9 +19,9 @@
#include "app/editor/message/message_editor.h" #include "app/editor/message/message_editor.h"
#include "app/editor/music/music_editor.h" #include "app/editor/music/music_editor.h"
#include "app/editor/overworld/overworld_editor.h" #include "app/editor/overworld/overworld_editor.h"
#include "app/editor/system/settings_editor.h"
#include "app/editor/sprite/sprite_editor.h" #include "app/editor/sprite/sprite_editor.h"
#include "app/editor/system/extension_manager.h" #include "app/editor/system/extension_manager.h"
#include "app/editor/system/settings_editor.h"
#include "app/editor/utils/gfx_context.h" #include "app/editor/utils/gfx_context.h"
#include "app/emu/emulator.h" #include "app/emu/emulator.h"
#include "app/gfx/snes_palette.h" #include "app/gfx/snes_palette.h"
@@ -81,7 +82,6 @@ class EditorManager : public SharedRom,
private: private:
void ManageActiveEditors(); void ManageActiveEditors();
void ManageKeyboardShortcuts(); void ManageKeyboardShortcuts();
void OpenRomOrProject(const std::string& filename);
void DrawFileDialog(); void DrawFileDialog();
void DrawStatusPopup(); void DrawStatusPopup();
@@ -94,6 +94,7 @@ class EditorManager : public SharedRom,
void LoadRom(); void LoadRom();
void SaveRom(); void SaveRom();
void OpenRomOrProject(const std::string& filename);
absl::Status OpenProject(); absl::Status OpenProject();
bool quit_ = false; bool quit_ = false;
@@ -112,6 +113,7 @@ class EditorManager : public SharedRom,
Project current_project_; Project current_project_;
yaze_editor_context editor_context_; yaze_editor_context editor_context_;
ExtensionManager extension_manager_; ExtensionManager extension_manager_;
core::MessageDispatcher dispatcher_;
AssemblyEditor assembly_editor_; AssemblyEditor assembly_editor_;
DungeonEditor dungeon_editor_; DungeonEditor dungeon_editor_;