[studio] Add popup to warn about UUID duplication

This commit is contained in:
2025-05-06 22:22:26 -05:00
parent d4329981e7
commit ff1e8f260b
4 changed files with 152 additions and 34 deletions

View File

@ -17,6 +17,12 @@
#include "font.hpp"
#include "studioui.hpp"
#ifdef OX_OS_Darwin
#define STUDIO_CTRL "Cmd"
#else
#define STUDIO_CTRL "Ctrl"
#endif
namespace studio {
static bool shutdownHandler(turbine::Context &ctx) {
@ -174,45 +180,64 @@ bool StudioUI::handleShutdown() noexcept {
void StudioUI::drawMenu() noexcept {
if (ImGui::BeginMainMenuBar()) {
if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("New...", "Ctrl+N", false, m_project)) {
if (ImGui::MenuItem("New...", STUDIO_CTRL "+N", false, m_project)) {
m_newMenu.open();
}
if (ImGui::MenuItem("New Project...", "Ctrl+Shift+N")) {
if (ImGui::MenuItem("New Project...", STUDIO_CTRL "+Shift+N")) {
m_newProject.open();
}
if (ImGui::MenuItem("Open Project...", "Ctrl+O")) {
if (ImGui::MenuItem("Open Project...", STUDIO_CTRL "+O")) {
m_taskRunner.add(*ox::make<FileDialogManager>(this, &StudioUI::openProjectPath));
}
if (ImGui::MenuItem("Save", "Ctrl+S", false, m_activeEditor && m_activeEditor->unsavedChanges())) {
if (ImGui::MenuItem(
"Save",
STUDIO_CTRL "+S",
false,
m_activeEditor && m_activeEditor->unsavedChanges())) {
m_activeEditor->save();
}
if (ImGui::MenuItem("Quit", "Ctrl+Q")) {
if (ImGui::MenuItem("Quit", STUDIO_CTRL "+Q")) {
turbine::requestShutdown(m_tctx);
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Edit")) {
auto undoStack = m_activeEditor ? m_activeEditor->undoStack() : nullptr;
if (ImGui::MenuItem("Undo", "Ctrl+Z", false, undoStack && undoStack->canUndo())) {
if (ImGui::MenuItem(
"Undo", STUDIO_CTRL "+Z", false, undoStack && undoStack->canUndo())) {
oxLogError(undoStack->undo());
}
if (ImGui::MenuItem("Redo", "Ctrl+Y", false, undoStack && undoStack->canRedo())) {
if (ImGui::MenuItem(
"Redo", STUDIO_CTRL "+Y", false, undoStack && undoStack->canRedo())) {
oxLogError(undoStack->redo());
}
ImGui::Separator();
if (ImGui::MenuItem("Copy", "Ctrl+C", false, m_activeEditor && m_activeEditor->copyEnabled())) {
if (ImGui::MenuItem(
"Copy",
STUDIO_CTRL "+C",
false,
m_activeEditor && m_activeEditor->copyEnabled())) {
m_activeEditor->copy();
}
if (ImGui::MenuItem("Cut", "Ctrl+X", false, m_activeEditor && m_activeEditor->cutEnabled())) {
if (ImGui::MenuItem(
"Cut",
STUDIO_CTRL "+X",
false,
m_activeEditor && m_activeEditor->cutEnabled())) {
m_activeEditor->cut();
}
if (ImGui::MenuItem("Paste", "Ctrl+V", false, m_activeEditor && m_activeEditor->pasteEnabled())) {
if (ImGui::MenuItem(
"Paste",
STUDIO_CTRL "+V",
false,
m_activeEditor && m_activeEditor->pasteEnabled())) {
m_activeEditor->paste();
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("View")) {
if (ImGui::MenuItem("Project Explorer", "Ctrl+Shift+1", m_showProjectExplorer)) {
if (ImGui::MenuItem(
"Project Explorer", STUDIO_CTRL "+Shift+1", m_showProjectExplorer)) {
toggleProjectExplorer();
}
ImGui::EndMenu();
@ -278,12 +303,8 @@ void StudioUI::drawTabs() noexcept {
if (m_activeEditor == (*it).get()) {
m_activeEditor = nullptr;
}
try {
OX_THROW_ERROR(m_editors.erase(it).moveTo(it));
} catch (ox::Exception const&ex) {
oxErrf("Editor tab deletion failed: {} ({}:{})\n", ex.what(), ex.src.file_name(), ex.src.line());
} catch (std::exception const&ex) {
oxErrf("Editor tab deletion failed: {}\n", ex.what());
if (auto const err = m_editors.erase(it).moveTo(it)) {
oxErrf("Editor tab deletion failed: {} ({}:{})\n", toStr(err), err.src.file_name(), err.src.line());
}
}
} else {
@ -478,12 +499,25 @@ ox::Error StudioUI::createOpenProject(ox::StringViewCR path) noexcept {
ox::Error StudioUI::openProjectPath(ox::StringParam path) noexcept {
OX_REQUIRE_M(fs, keel::loadRomFs(path.view()));
OX_RETURN_ERROR(keel::setRomFs(keelCtx(m_tctx), std::move(fs)));
keel::DuplicateSet ds;
OX_RETURN_ERROR(keel::setRomFs(keelCtx(m_tctx), std::move(fs), ds));
if (ds.size()) {
ox::String msg;
msg += "Multiple files have the same UUID:\n";
for (auto const &k : ds.keys()) {
msg += ox::sfmt("\n\t{}:\n", k.toString());
for (auto const &v : ds[k]) {
msg += ox::sfmt("\t\t - {}\n", v);
}
}
m_messagePopup.show(msg);
}
OX_RETURN_ERROR(
ox::make_unique_catch<Project>(keelCtx(m_tctx), std::move(path), m_projectDataDir)
.moveTo(m_project));
m_sctx.project = m_project.get();
turbine::setWindowTitle(m_tctx, ox::sfmt("{} - {}", keelCtx(m_tctx).appName, m_project->projectPath()));
turbine::setWindowTitle(
m_tctx, ox::sfmt("{} - {}", keelCtx(m_tctx).appName, m_project->projectPath()));
m_deleteConfirmation.deleteFile.connect(m_sctx.project, &Project::deleteItem);
m_copyFilePopup.makeCopy.connect(m_sctx.project, &Project::copyItem);
m_newDirDialog.newDir.connect(m_sctx.project, &Project::mkdir);

View File

@ -52,11 +52,12 @@ class StudioUI: public ox::SignalHandler {
"Close Application?",
"There are files with unsaved changes. Close?"
};
ig::MessagePopup m_messagePopup{"Message", ""};
MakeCopyPopup m_copyFilePopup;
RenameFile m_renameFile;
NewProject m_newProject;
AboutPopup m_aboutPopup;
ox::Array<Widget*, 9> const m_widgets {
ox::Array<Widget*, 10> const m_widgets {
&m_closeFileConfirm,
&m_closeAppConfirm,
&m_copyFilePopup,
@ -66,6 +67,7 @@ class StudioUI: public ox::SignalHandler {
&m_deleteConfirmation,
&m_newDirDialog,
&m_renameFile,
&m_messagePopup,
};
bool m_showProjectExplorer = true;
struct NavAction {