add MasterEditor::OpenProject, include .yaze in recent files

This commit is contained in:
scawful
2024-07-13 19:26:42 -04:00
parent b9ea84f581
commit 52f98c7dd7
2 changed files with 30 additions and 14 deletions

View File

@@ -2,6 +2,7 @@
#include <ImGuiColorTextEdit/TextEditor.h>
#include <ImGuiFileDialog/ImGuiFileDialog.h>
#include <abseil-cpp/absl/strings/match.h>
#include <imgui/backends/imgui_impl_sdl2.h>
#include <imgui/backends/imgui_impl_sdlrenderer2.h>
#include <imgui/imgui.h>
@@ -463,7 +464,11 @@ void MasterEditor::DrawFileMenu() {
} else {
for (const auto& filePath : manager.GetRecentFiles()) {
if (MenuItem(filePath.c_str())) {
status_ = rom()->LoadFromFile(filePath);
if (absl::StrContains(filePath, ".yaze")) {
status_ = current_project_.Open(filePath);
} else {
status_ = rom()->LoadFromFile(filePath);
}
}
}
}
@@ -494,18 +499,7 @@ void MasterEditor::DrawFileMenu() {
}
if (MenuItem("Open Project")) {
// Open an existing project
status_ =
current_project_.Open(FileDialogWrapper::ShowOpenFileDialog());
if (status_.ok()) {
status_ = rom()->LoadFromFile(current_project_.rom_filename_);
}
if (status_.ok()) {
if (!rom()->resource_label()->LoadLabels(
current_project_.labels_filename_)) {
status_ = absl::InternalError(
"Could not load labels file, update your project file.");
}
}
status_ = OpenProject();
}
if (MenuItem("Save Project")) {
// Save the current project
@@ -842,7 +836,8 @@ void MasterEditor::DrawHelpMenu() {
Text("Save the project to save the current state of the project.");
Text(
"To save a project, you need to first open a ROM and initialize your "
"code path and labels file. Label resource manager can be found in the "
"code path and labels file. Label resource manager can be found in "
"the "
"View menu. Code path is set in the Code editor after opening a "
"folder.");
@@ -903,6 +898,25 @@ void MasterEditor::SaveRom() {
status_ = rom()->SaveToFile(backup_rom_, save_new_auto_);
}
absl::Status MasterEditor::OpenProject() {
RETURN_IF_ERROR(
current_project_.Open(FileDialogWrapper::ShowOpenFileDialog()));
RETURN_IF_ERROR(rom()->LoadFromFile(current_project_.rom_filename_));
if (!rom()->resource_label()->LoadLabels(current_project_.labels_filename_)) {
return absl::InternalError(
"Could not load labels file, update your project file.");
}
static RecentFilesManager manager("recent_files.txt");
manager.Load();
manager.AddFile(current_project_.filepath + "/" + current_project_.name +
".yaze");
manager.Save();
return absl::OkStatus();
}
} // namespace editor
} // namespace app
} // namespace yaze

View File

@@ -83,6 +83,8 @@ class MasterEditor : public SharedRom,
void LoadRom();
void SaveRom();
absl::Status OpenProject();
bool quit_ = false;
bool about_ = false;
bool rom_info_ = false;