add NewProjectMenu for create, save, open

This commit is contained in:
scawful
2024-07-13 18:54:51 -04:00
parent 0d551722f7
commit 7021b64c80
3 changed files with 41 additions and 6 deletions

View File

@@ -37,11 +37,9 @@ struct Project {
* @return An absl::Status indicating the success or failure of the project * @return An absl::Status indicating the success or failure of the project
* creation. * creation.
*/ */
absl::Status Create(const std::string &project_name, absl::Status Create(const std::string &project_name) {
const std::string &project_path) {
name = project_name; name = project_name;
filepath = project_path;
return absl::OkStatus(); return absl::OkStatus();
} }

View File

@@ -441,6 +441,7 @@ void MasterEditor::DrawYazeMenu() {
void MasterEditor::DrawFileMenu() { void MasterEditor::DrawFileMenu() {
static bool save_as_menu = false; static bool save_as_menu = false;
static bool new_project_menu = false;
if (BeginMenu("File")) { if (BeginMenu("File")) {
if (MenuItem("Open", "Ctrl+O")) { if (MenuItem("Open", "Ctrl+O")) {
@@ -479,6 +480,24 @@ void MasterEditor::DrawFileMenu() {
ImGui::Separator(); ImGui::Separator();
if (BeginMenu("Project")) {
if (MenuItem("Create New Project")) {
// Create a new project
new_project_menu = true;
}
if (MenuItem("Open Project")) {
// Open an existing project
status_ =
current_project_.Open(FileDialogWrapper::ShowOpenFileDialog());
}
if (MenuItem("Save Project")) {
// Save the current project
status_ = current_project_.Save();
}
ImGui::EndMenu();
}
if (BeginMenu("Options")) { if (BeginMenu("Options")) {
MenuItem("Backup ROM", "", &backup_rom_); MenuItem("Backup ROM", "", &backup_rom_);
MenuItem("Save New Auto", "", &save_new_auto_); MenuItem("Save New Auto", "", &save_new_auto_);
@@ -554,6 +573,22 @@ void MasterEditor::DrawFileMenu() {
} }
ImGui::End(); ImGui::End();
} }
if (new_project_menu) {
ImGui::Begin("New Project", &new_project_menu,
ImGuiWindowFlags_AlwaysAutoResize);
static std::string save_as_filename = "";
ImGui::InputText("Project Name", &save_as_filename);
if (ImGui::Button("Create", gui::kDefaultModalSize)) {
new_project_menu = false;
status_ = current_project_.Create(save_as_filename);
}
ImGui::SameLine();
if (ImGui::Button("Cancel", gui::kDefaultModalSize)) {
new_project_menu = false;
}
ImGui::End();
}
} }
void MasterEditor::DrawEditMenu() { void MasterEditor::DrawEditMenu() {

View File

@@ -12,6 +12,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/project.h"
#include "app/editor/code/assembly_editor.h" #include "app/editor/code/assembly_editor.h"
#include "app/editor/context/gfx_context.h" #include "app/editor/context/gfx_context.h"
#include "app/editor/dungeon_editor.h" #include "app/editor/dungeon_editor.h"
@@ -97,6 +98,8 @@ class MasterEditor : public SharedRom,
emu::Emulator emulator_; emu::Emulator emulator_;
Project current_project_;
AssemblyEditor assembly_editor_; AssemblyEditor assembly_editor_;
DungeonEditor dungeon_editor_; DungeonEditor dungeon_editor_;
GraphicsEditor graphics_editor_; GraphicsEditor graphics_editor_;
@@ -106,9 +109,8 @@ class MasterEditor : public SharedRom,
ScreenEditor screen_editor_; ScreenEditor screen_editor_;
SpriteEditor sprite_editor_; SpriteEditor sprite_editor_;
std::vector<Editor*> active_editors_;
ImVector<int> active_tabs_; ImVector<int> active_tabs_;
std::vector<Editor*> active_editors_;
Editor* current_editor_ = nullptr; Editor* current_editor_ = nullptr;
}; };