refactor: Restructure file dialog handling and introduce utility classes
- Updated file dialog references across the application to utilize a new `util::FileDialogWrapper` for consistent file handling. - Refactored existing code to replace direct calls to `core::FileDialogWrapper` with the new utility class, enhancing modularity and maintainability. - Introduced `util::PlatformPaths` for cross-platform directory management, ensuring consistent access to user directories and application data paths. - Added new utility functions for file operations, improving the overall file handling capabilities within the application. - Updated CMake configurations to include new utility source files, streamlining the build process.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/time/clock.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "app/core/platform/file_dialog.h"
|
||||
#include "util/file_util.h"
|
||||
#include "app/editor/agent/agent_chat_history_codec.h"
|
||||
#include "app/editor/system/proposal_drawer.h"
|
||||
#include "app/editor/system/toast_manager.h"
|
||||
@@ -48,7 +48,7 @@ std::filesystem::path ExpandUserPath(std::string path) {
|
||||
}
|
||||
|
||||
std::filesystem::path ResolveHistoryPath(const std::string& session_id = "") {
|
||||
std::filesystem::path base = ExpandUserPath(yaze::core::GetConfigDirectory());
|
||||
std::filesystem::path base = ExpandUserPath(yaze::util::GetConfigDirectory());
|
||||
if (base.empty()) {
|
||||
base = ExpandUserPath(".yaze");
|
||||
}
|
||||
@@ -1723,7 +1723,7 @@ void AgentChatWidget::RenderSystemPromptEditor() {
|
||||
// Save the current system prompt to project directory
|
||||
for (auto& tab : open_files_) {
|
||||
if (tab.is_system_prompt) {
|
||||
auto save_path = core::FileDialogWrapper::ShowSaveFileDialog(
|
||||
auto save_path = util::FileDialogWrapper::ShowSaveFileDialog(
|
||||
"custom_system_prompt", "txt");
|
||||
if (!save_path.empty()) {
|
||||
std::ofstream file(save_path);
|
||||
@@ -1760,7 +1760,7 @@ void AgentChatWidget::RenderSystemPromptEditor() {
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(ICON_MD_FOLDER_OPEN " Load Custom")) {
|
||||
auto filepath = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
auto filepath = util::FileDialogWrapper::ShowOpenFileDialog();
|
||||
if (!filepath.empty()) {
|
||||
std::ifstream file(filepath);
|
||||
if (file.is_open()) {
|
||||
@@ -1832,7 +1832,7 @@ void AgentChatWidget::RenderFileEditorTabs() {
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(ICON_MD_FOLDER_OPEN " Open File")) {
|
||||
auto filepath = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
auto filepath = util::FileDialogWrapper::ShowOpenFileDialog();
|
||||
if (!filepath.empty()) {
|
||||
OpenFileInEditor(filepath);
|
||||
}
|
||||
@@ -1890,7 +1890,7 @@ void AgentChatWidget::RenderFileEditorTabs() {
|
||||
toast_manager_->Show("Failed to save file", ToastType::kError);
|
||||
}
|
||||
} else {
|
||||
auto save_path = core::FileDialogWrapper::ShowSaveFileDialog(
|
||||
auto save_path = util::FileDialogWrapper::ShowSaveFileDialog(
|
||||
open_files_[i].filename, "");
|
||||
if (!save_path.empty()) {
|
||||
std::ofstream file(save_path);
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/strings/strip.h"
|
||||
#include "app/core/platform/file_dialog.h"
|
||||
#include "util/file_util.h"
|
||||
#include "util/macro.h"
|
||||
|
||||
namespace yaze {
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/match.h"
|
||||
#include "app/core/platform/file_dialog.h"
|
||||
#include "util/file_util.h"
|
||||
#include "app/gui/icons.h"
|
||||
#include "app/gui/modules/text_editor.h"
|
||||
|
||||
namespace yaze::editor {
|
||||
|
||||
using core::FileDialogWrapper;
|
||||
using util::FileDialogWrapper;
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -283,7 +283,7 @@ void AssemblyEditor::DrawFileTabView() {
|
||||
void AssemblyEditor::DrawFileMenu() {
|
||||
if (ImGui::BeginMenu("File")) {
|
||||
if (ImGui::MenuItem("Open", "Ctrl+O")) {
|
||||
auto filename = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
auto filename = util::FileDialogWrapper::ShowOpenFileDialog();
|
||||
ChangeActiveFile(filename);
|
||||
}
|
||||
if (ImGui::MenuItem("Save", "Ctrl+S")) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef YAZE_APP_EDITOR_CODE_MEMORY_EDITOR_H
|
||||
#define YAZE_APP_EDITOR_CODE_MEMORY_EDITOR_H
|
||||
|
||||
#include "app/core/platform/file_dialog.h"
|
||||
#include "util/file_util.h"
|
||||
#include "app/gui/input.h"
|
||||
#include "app/rom.h"
|
||||
#include "app/snes.h"
|
||||
@@ -25,7 +25,7 @@ struct MemoryEditorWithDiffChecker {
|
||||
static Rom comparison_rom;
|
||||
ImGui::Begin("Hex Editor", &show_memory_editor);
|
||||
if (ImGui::Button("Compare Rom")) {
|
||||
auto file_name = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
auto file_name = util::FileDialogWrapper::ShowOpenFileDialog();
|
||||
PRINT_IF_ERROR(comparison_rom.LoadFromFile(file_name));
|
||||
show_compare_rom = true;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "absl/strings/match.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/strings/str_split.h"
|
||||
#include "app/core/platform/file_dialog.h"
|
||||
#include "util/file_util.h"
|
||||
#include "app/editor/system/toast_manager.h"
|
||||
#include "app/gui/icons.h"
|
||||
#include "imgui/imgui.h"
|
||||
@@ -40,7 +40,7 @@ void ProjectFileEditor::Draw() {
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
if (ImGui::Button(absl::StrFormat("%s Open", ICON_MD_FOLDER_OPEN).c_str())) {
|
||||
auto file = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
auto file = util::FileDialogWrapper::ShowOpenFileDialog();
|
||||
if (!file.empty()) {
|
||||
auto status = LoadFile(file);
|
||||
if (!status.ok() && toast_manager_) {
|
||||
@@ -65,7 +65,7 @@ void ProjectFileEditor::Draw() {
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
if (ImGui::Button(absl::StrFormat("%s Save As", ICON_MD_SAVE_AS).c_str())) {
|
||||
auto file = core::FileDialogWrapper::ShowSaveFileDialog(
|
||||
auto file = util::FileDialogWrapper::ShowSaveFileDialog(
|
||||
filepath_.empty() ? "project" : filepath_, "yaze");
|
||||
if (!file.empty()) {
|
||||
auto status = SaveFileAs(file);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "absl/strings/match.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "app/core/features.h"
|
||||
#include "app/core/platform/file_dialog.h"
|
||||
#include "util/file_util.h"
|
||||
#include "app/core/project.h"
|
||||
#include "app/editor/code/assembly_editor.h"
|
||||
#include "app/editor/dungeon/dungeon_editor.h"
|
||||
@@ -62,7 +62,7 @@ namespace yaze {
|
||||
namespace editor {
|
||||
|
||||
using namespace ImGui;
|
||||
using core::FileDialogWrapper;
|
||||
using util::FileDialogWrapper;
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -1620,7 +1620,7 @@ void EditorManager::DrawMenuBar() {
|
||||
gui::kDefaultModalSize)) {
|
||||
// Use save file dialog for ROM files
|
||||
auto file_path =
|
||||
core::FileDialogWrapper::ShowSaveFileDialog(save_as_filename, "sfc");
|
||||
util::FileDialogWrapper::ShowSaveFileDialog(save_as_filename, "sfc");
|
||||
if (!file_path.empty()) {
|
||||
save_as_filename = file_path;
|
||||
}
|
||||
@@ -1698,7 +1698,7 @@ void EditorManager::DrawMenuBar() {
|
||||
.c_str(),
|
||||
gui::kDefaultModalSize)) {
|
||||
auto project_file_path =
|
||||
core::FileDialogWrapper::ShowSaveFileDialog(save_as_filename, "yaze");
|
||||
util::FileDialogWrapper::ShowSaveFileDialog(save_as_filename, "yaze");
|
||||
if (!project_file_path.empty()) {
|
||||
// Ensure .yaze extension
|
||||
if (project_file_path.find(".yaze") == std::string::npos) {
|
||||
@@ -1975,7 +1975,7 @@ absl::Status EditorManager::OpenRomOrProject(const std::string& filename) {
|
||||
}
|
||||
|
||||
absl::Status EditorManager::CreateNewProject(const std::string& template_name) {
|
||||
auto dialog_path = core::FileDialogWrapper::ShowOpenFolderDialog();
|
||||
auto dialog_path = util::FileDialogWrapper::ShowOpenFolderDialog();
|
||||
if (dialog_path.empty()) {
|
||||
return absl::OkStatus(); // User cancelled
|
||||
}
|
||||
@@ -1986,7 +1986,7 @@ absl::Status EditorManager::CreateNewProject(const std::string& template_name) {
|
||||
}
|
||||
|
||||
absl::Status EditorManager::OpenProject() {
|
||||
auto file_path = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
auto file_path = util::FileDialogWrapper::ShowOpenFileDialog();
|
||||
if (file_path.empty()) {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
@@ -2101,7 +2101,7 @@ absl::Status EditorManager::SaveProjectAs() {
|
||||
: "untitled_project";
|
||||
|
||||
auto file_path =
|
||||
core::FileDialogWrapper::ShowSaveFileDialog(default_name, "yaze");
|
||||
util::FileDialogWrapper::ShowSaveFileDialog(default_name, "yaze");
|
||||
if (file_path.empty()) {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
@@ -3195,7 +3195,7 @@ void EditorManager::DrawWelcomeScreen() {
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(ICON_MD_FOLDER_OPEN " Open Project", ImVec2(200, 40))) {
|
||||
auto file_name = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
auto file_name = util::FileDialogWrapper::ShowOpenFileDialog();
|
||||
if (!file_name.empty()) {
|
||||
status_ = OpenRomOrProject(file_name);
|
||||
if (!status_.ok()) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/status/statusor.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "app/core/platform/file_dialog.h"
|
||||
#include "util/file_util.h"
|
||||
#include "app/core/window.h"
|
||||
#include "app/gfx/arena.h"
|
||||
#include "app/gfx/bitmap.h"
|
||||
@@ -549,7 +549,7 @@ absl::Status GraphicsEditor::DrawCgxImport() {
|
||||
SameLine();
|
||||
|
||||
if (ImGui::Button("Open CGX")) {
|
||||
auto filename = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
auto filename = util::FileDialogWrapper::ShowOpenFileDialog();
|
||||
cgx_file_name_ = filename;
|
||||
cgx_file_path_ = std::filesystem::absolute(filename).string();
|
||||
is_open_ = true;
|
||||
@@ -578,7 +578,7 @@ absl::Status GraphicsEditor::DrawScrImport() {
|
||||
InputText("##ScrFile", &scr_file_name_);
|
||||
|
||||
if (ImGui::Button("Open SCR")) {
|
||||
auto filename = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
auto filename = util::FileDialogWrapper::ShowOpenFileDialog();
|
||||
scr_file_name_ = filename;
|
||||
scr_file_path_ = std::filesystem::absolute(filename).string();
|
||||
is_open_ = true;
|
||||
@@ -610,7 +610,7 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
|
||||
SameLine();
|
||||
|
||||
if (ImGui::Button("Open COL")) {
|
||||
auto filename = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
auto filename = util::FileDialogWrapper::ShowOpenFileDialog();
|
||||
col_file_name_ = filename;
|
||||
col_file_path_ = std::filesystem::absolute(filename).string();
|
||||
status_ = temp_rom_.LoadFromFile(col_file_path_,
|
||||
@@ -659,7 +659,7 @@ absl::Status GraphicsEditor::DrawObjImport() {
|
||||
SameLine();
|
||||
|
||||
if (ImGui::Button("Open OBJ")) {
|
||||
auto filename = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
auto filename = util::FileDialogWrapper::ShowOpenFileDialog();
|
||||
obj_file_path_ = std::filesystem::absolute(filename).string();
|
||||
status_ = temp_rom_.LoadFromFile(obj_file_path_);
|
||||
is_open_ = true;
|
||||
@@ -677,7 +677,7 @@ absl::Status GraphicsEditor::DrawTilemapImport() {
|
||||
SameLine();
|
||||
|
||||
if (ImGui::Button("Open Tilemap")) {
|
||||
auto filename = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
auto filename = util::FileDialogWrapper::ShowOpenFileDialog();
|
||||
tilemap_file_path_ = std::filesystem::absolute(filename).string();
|
||||
status_ = tilemap_rom_.LoadFromFile(tilemap_file_path_);
|
||||
status_ = tilemap_rom_.LoadFromFile(tilemap_file_path_);
|
||||
@@ -700,7 +700,7 @@ absl::Status GraphicsEditor::DrawFileImport() {
|
||||
SameLine();
|
||||
|
||||
if (ImGui::Button("Open BIN")) {
|
||||
auto filename = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
auto filename = util::FileDialogWrapper::ShowOpenFileDialog();
|
||||
file_path_ = filename;
|
||||
status_ = temp_rom_.LoadFromFile(file_path_);
|
||||
is_open_ = true;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "app/gfx/performance_profiler.h"
|
||||
#include "app/core/platform/file_dialog.h"
|
||||
#include "util/file_util.h"
|
||||
#include "app/core/window.h"
|
||||
#include "app/gfx/arena.h"
|
||||
#include "app/gfx/atlas_renderer.h"
|
||||
@@ -474,7 +474,7 @@ void ScreenEditor::DrawDungeonMapsEditor() {
|
||||
}
|
||||
|
||||
void ScreenEditor::LoadBinaryGfx() {
|
||||
std::string bin_file = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
std::string bin_file = util::FileDialogWrapper::ShowOpenFileDialog();
|
||||
if (!bin_file.empty()) {
|
||||
std::ifstream file(bin_file, std::ios::binary);
|
||||
if (file.is_open()) {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "app/gfx/performance_profiler.h"
|
||||
#include "app/core/platform/file_dialog.h"
|
||||
#include "util/file_util.h"
|
||||
#include "app/core/window.h"
|
||||
#include "app/gfx/bitmap.h"
|
||||
#include "app/gfx/snes_palette.h"
|
||||
@@ -243,7 +243,7 @@ void MessageEditor::DrawExpandedMessageSettings() {
|
||||
ImGui::Text("Expanded Messages");
|
||||
static std::string expanded_message_path = "";
|
||||
if (ImGui::Button("Load Expanded Message")) {
|
||||
expanded_message_path = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
expanded_message_path = util::FileDialogWrapper::ShowOpenFileDialog();
|
||||
if (!expanded_message_path.empty()) {
|
||||
if (!LoadExpandedMessages(expanded_message_path, parsed_messages_,
|
||||
expanded_messages_,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "sprite_editor.h"
|
||||
|
||||
#include "app/gfx/performance_profiler.h"
|
||||
#include "app/core/platform/file_dialog.h"
|
||||
#include "util/file_util.h"
|
||||
#include "app/editor/sprite/zsprite.h"
|
||||
#include "app/gfx/arena.h"
|
||||
#include "app/gui/icons.h"
|
||||
@@ -254,7 +254,7 @@ void SpriteEditor::DrawCustomSpritesMetadata() {
|
||||
// ZSprite Maker format open file dialog
|
||||
if (ImGui::Button("Open ZSprite")) {
|
||||
// Open ZSprite file
|
||||
std::string file_path = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
std::string file_path = util::FileDialogWrapper::ShowOpenFileDialog();
|
||||
if (!file_path.empty()) {
|
||||
zsprite::ZSprite zsprite;
|
||||
status_ = zsprite.Load(file_path);
|
||||
|
||||
Reference in New Issue
Block a user