chore: Refactor file_dialog.cc and file_dialog.h to use namespace aliases

This commit is contained in:
scawful
2024-08-13 23:56:17 -04:00
parent e72ae83d48
commit 9bbb6c6114
10 changed files with 38 additions and 17 deletions

View File

@@ -206,7 +206,8 @@
}
- (void)openFileAction:(id)sender {
if (!yaze::app::SharedRom::shared_rom_->LoadFromFile(FileDialogWrapper::ShowOpenFileDialog())
if (!yaze::app::SharedRom::shared_rom_
->LoadFromFile(yaze::app::core::FileDialogWrapper::ShowOpenFileDialog())
.ok()) {
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:@"Error"];

View File

@@ -1,5 +1,9 @@
#include "file_dialog.h"
namespace yaze {
namespace app {
namespace core {
#if defined(__linux__)
std::string FileDialogWrapper::ShowOpenFileDialog() {
@@ -20,4 +24,8 @@ std::vector<std::string> FileDialogWrapper::GetFilesInFolder(
return {"Linux: Files in folder"};
}
#endif
#endif
} // namespace core
} // namespace app
} // namespace yaze

View File

@@ -4,6 +4,10 @@
#include <string>
#include <vector>
namespace yaze {
namespace app {
namespace core {
#ifdef _WIN32
// Include Windows-specific headers
#include <shobjidl.h>
@@ -83,7 +87,7 @@ class FileDialogWrapper {
}
static std::vector<std::string> GetSubdirectoriesInFolder(
const std::string& folder_path) {
const std::string &folder_path) {
std::vector<std::string> subdirectories;
WIN32_FIND_DATA findFileData;
HANDLE hFind = FindFirstFile((folder_path + "\\*").c_str(), &findFileData);
@@ -102,7 +106,7 @@ class FileDialogWrapper {
}
static std::vector<std::string> GetFilesInFolder(
const std::string& folder_path) {
const std::string &folder_path) {
std::vector<std::string> files;
WIN32_FIND_DATA findFileData;
HANDLE hFind = FindFirstFile((folder_path + "\\*").c_str(), &findFileData);
@@ -135,4 +139,8 @@ class FileDialogWrapper {
#endif
} // namespace core
} // namespace app
} // namespace yaze
#endif // YAZE_APP_CORE_PLATFORM_FILE_DIALOG_H

View File

@@ -56,7 +56,7 @@ std::vector<std::string> FileDialogWrapper::GetSubdirectoriesInFolder(const std:
#import <Cocoa/Cocoa.h>
std::string FileDialogWrapper::ShowOpenFileDialog() {
std::string yaze::app::core::FileDialogWrapper::ShowOpenFileDialog() {
NSOpenPanel* openPanel = [NSOpenPanel openPanel];
[openPanel setCanChooseFiles:YES];
[openPanel setCanChooseDirectories:NO];
@@ -71,7 +71,7 @@ std::string FileDialogWrapper::ShowOpenFileDialog() {
return "";
}
std::string FileDialogWrapper::ShowOpenFolderDialog() {
std::string yaze::app::core::FileDialogWrapper::ShowOpenFolderDialog() {
NSOpenPanel* openPanel = [NSOpenPanel openPanel];
[openPanel setCanChooseFiles:NO];
[openPanel setCanChooseDirectories:YES];
@@ -86,7 +86,8 @@ std::string FileDialogWrapper::ShowOpenFolderDialog() {
return "";
}
std::vector<std::string> FileDialogWrapper::GetFilesInFolder(const std::string& folder) {
std::vector<std::string> yaze::app::core::FileDialogWrapper::GetFilesInFolder(
const std::string& folder) {
std::vector<std::string> filenames;
NSFileManager* fileManager = [NSFileManager defaultManager];
NSDirectoryEnumerator* enumerator =
@@ -101,7 +102,8 @@ std::vector<std::string> FileDialogWrapper::GetFilesInFolder(const std::string&
return filenames;
}
std::vector<std::string> FileDialogWrapper::GetSubdirectoriesInFolder(const std::string& folder) {
std::vector<std::string> yaze::app::core::FileDialogWrapper::GetSubdirectoriesInFolder(
const std::string& folder) {
std::vector<std::string> subdirectories;
NSFileManager* fileManager = [NSFileManager defaultManager];
NSDirectoryEnumerator* enumerator =
@@ -125,4 +127,4 @@ std::vector<std::string> FileDialogWrapper::GetSubdirectoriesInFolder(const std:
// Unsupported platform
#endif // TARGET_OS_MAC
#endif // __APPLE__ && __MACH__
#endif // __APPLE__ && __MACH__

View File

@@ -1,7 +1,6 @@
#include "assembly_editor.h"
#include "ImGuiColorTextEdit/TextEditor.h"
#include "app/core/platform/file_dialog.h"
#include "app/gui/icons.h"
#include "app/gui/input.h"
@@ -11,6 +10,8 @@ namespace yaze {
namespace app {
namespace editor {
using core::FileDialogWrapper;
namespace {
std::vector<std::string> RemoveIgnoredFiles(

View File

@@ -46,7 +46,7 @@ struct MemoryEditorWithDiffChecker : public SharedRom {
static Rom comparison_rom;
ImGui::Begin("Hex Editor", &show_memory_editor);
if (ImGui::Button("Compare Rom")) {
auto file_name = FileDialogWrapper::ShowOpenFileDialog();
auto file_name = core::FileDialogWrapper::ShowOpenFileDialog();
PRINT_IF_ERROR(comparison_rom.LoadFromFile(file_name));
show_compare_rom = true;
}

View File

@@ -39,6 +39,7 @@ namespace app {
namespace editor {
using namespace ImGui;
using core::FileDialogWrapper;
namespace {
@@ -484,8 +485,8 @@ void EditorManager::DrawYazeMenuBar() {
}
if (MenuItem("Open Project")) {
// Open an existing project
status_ =
current_project_.Open(FileDialogWrapper::ShowOpenFileDialog());
status_ = current_project_.Open(
core::FileDialogWrapper::ShowOpenFileDialog());
if (status_.ok()) {
status_ = OpenProject();
}

View File

@@ -370,10 +370,10 @@ absl::Status GraphicsEditor::UpdatePaletteColumn() {
RETURN_IF_ERROR(
rom()
->mutable_gfx_sheets()
->at(current_sheet_)
->data()[current_sheet_]
.ApplyPaletteWithTransparent(palette, edit_palette_sub_index_));
Renderer::GetInstance().UpdateBitmap(
&rom()->mutable_gfx_sheets()->at(current_sheet_), true);
&rom()->mutable_gfx_sheets()->data()[current_sheet_], true);
refresh_graphics_ = false;
}
}

View File

@@ -243,7 +243,7 @@ void SpriteEditor::DrawCustomSpritesMetadata() {
// ZSprite Maker format open file dialog
if (ImGui::Button("Open ZSprite")) {
// Open ZSprite file
std::string file_path = FileDialogWrapper::ShowOpenFileDialog();
std::string file_path = core::FileDialogWrapper::ShowOpenFileDialog();
if (!file_path.empty()) {
zsprite::ZSprite zsprite;
status_ = zsprite.Load(file_path);

View File

@@ -246,7 +246,7 @@ void Emulator::RenderNavBar() {
}
if (open_file) {
auto file_name = FileDialogWrapper::ShowOpenFileDialog();
auto file_name = core::FileDialogWrapper::ShowOpenFileDialog();
if (!file_name.empty()) {
std::ifstream file(file_name, std::ios::binary);
// Load the data directly into rom_data