Merge commit '7b7d59cf63d77cf7ab6daf6ed7122eef97954555'
This commit is contained in:
@ -2,8 +2,10 @@ add_library(
|
||||
StudioAppLib
|
||||
aboutpopup.cpp
|
||||
clawviewer.cpp
|
||||
deleteconfirmation.cpp
|
||||
filedialogmanager.cpp
|
||||
main.cpp
|
||||
newdir.cpp
|
||||
newmenu.cpp
|
||||
newproject.cpp
|
||||
projectexplorer.cpp
|
||||
|
55
src/olympic/studio/applib/src/deleteconfirmation.cpp
Normal file
55
src/olympic/studio/applib/src/deleteconfirmation.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <studio/imguiutil.hpp>
|
||||
|
||||
#include "deleteconfirmation.hpp"
|
||||
|
||||
namespace studio {
|
||||
|
||||
DeleteConfirmation::DeleteConfirmation() noexcept {
|
||||
setTitle("Delete Item");
|
||||
}
|
||||
|
||||
void DeleteConfirmation::openPath(ox::StringViewCR path) noexcept {
|
||||
open();
|
||||
m_path = path;
|
||||
}
|
||||
|
||||
void DeleteConfirmation::open() noexcept {
|
||||
m_path = "";
|
||||
m_stage = Stage::Opening;
|
||||
}
|
||||
|
||||
void DeleteConfirmation::close() noexcept {
|
||||
m_stage = Stage::Closed;
|
||||
m_open = false;
|
||||
}
|
||||
|
||||
bool DeleteConfirmation::isOpen() const noexcept {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
void DeleteConfirmation::draw(StudioContext &ctx) noexcept {
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
case Stage::Opening:
|
||||
ImGui::OpenPopup(title().c_str());
|
||||
m_stage = Stage::Open;
|
||||
m_open = true;
|
||||
[[fallthrough]];
|
||||
case Stage::Open:
|
||||
drawWindow(ctx.tctx, m_open, [this] {
|
||||
ImGui::Text("Are you sure you want to delete %s?", m_path.c_str());
|
||||
if (ig::PopupControlsOkCancel(m_open, "Yes", "No") != ig::PopupResponse::None) {
|
||||
deleteFile.emit(m_path);
|
||||
close();
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
43
src/olympic/studio/applib/src/deleteconfirmation.hpp
Normal file
43
src/olympic/studio/applib/src/deleteconfirmation.hpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/string.hpp>
|
||||
|
||||
#include <studio/context.hpp>
|
||||
#include <studio/popup.hpp>
|
||||
|
||||
namespace studio {
|
||||
|
||||
class DeleteConfirmation final: public Popup {
|
||||
private:
|
||||
enum class Stage {
|
||||
Closed,
|
||||
Opening,
|
||||
Open,
|
||||
};
|
||||
Stage m_stage = Stage::Closed;
|
||||
bool m_open{};
|
||||
ox::String m_path;
|
||||
|
||||
public:
|
||||
ox::Signal<ox::Error(ox::StringViewCR path)> deleteFile;
|
||||
|
||||
DeleteConfirmation() noexcept;
|
||||
|
||||
void openPath(ox::StringViewCR path) noexcept;
|
||||
|
||||
void open() noexcept override;
|
||||
|
||||
void close() noexcept override;
|
||||
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept override;
|
||||
|
||||
void draw(StudioContext &ctx) noexcept override;
|
||||
|
||||
};
|
||||
|
||||
}
|
63
src/olympic/studio/applib/src/newdir.cpp
Normal file
63
src/olympic/studio/applib/src/newdir.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <studio/imguiutil.hpp>
|
||||
|
||||
#include "newdir.hpp"
|
||||
|
||||
namespace studio {
|
||||
|
||||
NewDir::NewDir() noexcept {
|
||||
setTitle("New Directory");
|
||||
setSize({280, 0});
|
||||
}
|
||||
|
||||
void NewDir::openPath(ox::StringViewCR path) noexcept {
|
||||
open();
|
||||
m_path = path;
|
||||
}
|
||||
|
||||
void NewDir::open() noexcept {
|
||||
m_path = "";
|
||||
m_stage = Stage::Opening;
|
||||
}
|
||||
|
||||
void NewDir::close() noexcept {
|
||||
m_stage = Stage::Closed;
|
||||
m_open = false;
|
||||
}
|
||||
|
||||
bool NewDir::isOpen() const noexcept {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
void NewDir::draw(StudioContext &ctx) noexcept {
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
case Stage::Opening:
|
||||
ImGui::OpenPopup(title().c_str());
|
||||
m_open = true;
|
||||
[[fallthrough]];
|
||||
case Stage::Open:
|
||||
drawWindow(ctx.tctx, m_open, [this] {
|
||||
if (m_stage == Stage::Opening) {
|
||||
ImGui::SetKeyboardFocusHere();
|
||||
}
|
||||
ig::InputText("Name", m_str);
|
||||
if (ImGui::IsItemFocused() && ImGui::IsKeyPressed(ImGuiKey_Enter)) {
|
||||
newDir.emit(m_path + "/" + m_str);
|
||||
close();
|
||||
}
|
||||
if (ig::PopupControlsOkCancel(m_open) == ig::PopupResponse::OK) {
|
||||
newDir.emit(m_path + "/" + m_str);
|
||||
close();
|
||||
}
|
||||
});
|
||||
m_stage = Stage::Open;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
49
src/olympic/studio/applib/src/newdir.hpp
Normal file
49
src/olympic/studio/applib/src/newdir.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/string.hpp>
|
||||
|
||||
#include <studio/context.hpp>
|
||||
#include <studio/popup.hpp>
|
||||
|
||||
namespace studio {
|
||||
|
||||
class NewDir final: public Popup {
|
||||
private:
|
||||
enum class Stage {
|
||||
Closed,
|
||||
Opening,
|
||||
Open,
|
||||
};
|
||||
Stage m_stage = Stage::Closed;
|
||||
bool m_open{};
|
||||
ox::String m_path;
|
||||
ox::IString<255> m_str;
|
||||
|
||||
public:
|
||||
ox::Signal<ox::Error(ox::StringViewCR path)> newDir;
|
||||
|
||||
NewDir() noexcept;
|
||||
|
||||
void openPath(ox::StringViewCR path) noexcept;
|
||||
|
||||
void open() noexcept override;
|
||||
|
||||
void close() noexcept override;
|
||||
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept override;
|
||||
|
||||
void draw(StudioContext &ctx) noexcept override;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::CStringView value() const noexcept {
|
||||
return m_str;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -22,6 +22,12 @@ void NewMenu::open() noexcept {
|
||||
m_selectedType = 0;
|
||||
m_itemName = "";
|
||||
m_typeName = "";
|
||||
m_path = "";
|
||||
}
|
||||
|
||||
void NewMenu::openPath(ox::StringParam path) noexcept {
|
||||
open();
|
||||
m_path = std::move(path);
|
||||
}
|
||||
|
||||
void NewMenu::close() noexcept {
|
||||
@ -158,7 +164,7 @@ void NewMenu::finish(StudioContext &sctx) noexcept {
|
||||
oxLogError(ox::Error{1, "New file error: no file name"});
|
||||
return;
|
||||
}
|
||||
auto const&im = *m_types[static_cast<std::size_t>(m_selectedType)];
|
||||
auto const&im = *m_types[m_selectedType];
|
||||
if (sctx.project->exists(im.itemPath(m_itemName))) {
|
||||
oxLogError(ox::Error{1, "New file error: file already exists"});
|
||||
return;
|
||||
|
@ -30,6 +30,7 @@ class NewMenu final: public Popup {
|
||||
Stage m_stage = Stage::Closed;
|
||||
ox::String m_typeName;
|
||||
ox::IString<255> m_itemName;
|
||||
ox::String m_path;
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> m_types;
|
||||
size_t m_selectedType = 0;
|
||||
size_t m_selectedTemplate = 0;
|
||||
@ -38,6 +39,8 @@ class NewMenu final: public Popup {
|
||||
public:
|
||||
NewMenu() noexcept;
|
||||
|
||||
void openPath(ox::StringParam path) noexcept;
|
||||
|
||||
void open() noexcept override;
|
||||
|
||||
void close() noexcept override;
|
||||
|
@ -12,12 +12,12 @@ namespace studio {
|
||||
|
||||
static ox::Result<ox::UniquePtr<ProjectTreeModel>> buildProjectTreeModel(
|
||||
ProjectExplorer &explorer,
|
||||
ox::StringView name,
|
||||
ox::StringParam name,
|
||||
ox::StringView path,
|
||||
ProjectTreeModel *parent) noexcept {
|
||||
auto const fs = explorer.romFs();
|
||||
OX_REQUIRE(stat, fs->stat(path));
|
||||
auto out = ox::make_unique<ProjectTreeModel>(explorer, ox::String(name), parent);
|
||||
auto out = ox::make_unique<ProjectTreeModel>(explorer, std::move(name), parent);
|
||||
if (stat.fileType == ox::FileType::Directory) {
|
||||
OX_REQUIRE_M(children, fs->ls(path));
|
||||
std::sort(children.begin(), children.end());
|
||||
@ -37,7 +37,7 @@ static ox::Result<ox::UniquePtr<ProjectTreeModel>> buildProjectTreeModel(
|
||||
ProjectExplorer::ProjectExplorer(turbine::Context &ctx) noexcept: m_ctx(ctx) {
|
||||
}
|
||||
|
||||
void ProjectExplorer::draw(studio::StudioContext &ctx) noexcept {
|
||||
void ProjectExplorer::draw(StudioContext &ctx) noexcept {
|
||||
auto const viewport = ImGui::GetContentRegionAvail();
|
||||
ImGui::BeginChild("ProjectExplorer", ImVec2(300, viewport.y), true);
|
||||
ImGui::SetNextItemOpen(true);
|
||||
@ -54,7 +54,7 @@ void ProjectExplorer::setModel(ox::UPtr<ProjectTreeModel> &&model) noexcept {
|
||||
ox::Error ProjectExplorer::refreshProjectTreeModel(ox::StringViewCR) noexcept {
|
||||
OX_REQUIRE_M(model, buildProjectTreeModel(*this, "Project", "/", nullptr));
|
||||
setModel(std::move(model));
|
||||
return ox::Error(0);
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,27 +12,31 @@
|
||||
|
||||
namespace studio {
|
||||
|
||||
class ProjectExplorer: public studio::Widget {
|
||||
class ProjectExplorer: public Widget {
|
||||
private:
|
||||
ox::UPtr<ProjectTreeModel> m_treeModel;
|
||||
turbine::Context &m_ctx;
|
||||
|
||||
public:
|
||||
// slots
|
||||
ox::Signal<ox::Error(ox::StringViewCR)> fileChosen;
|
||||
ox::Signal<ox::Error(ox::StringViewCR)> addItem;
|
||||
ox::Signal<ox::Error(ox::StringViewCR)> addDir;
|
||||
ox::Signal<ox::Error(ox::StringViewCR)> deleteItem;
|
||||
|
||||
explicit ProjectExplorer(turbine::Context &ctx) noexcept;
|
||||
|
||||
void draw(studio::StudioContext &ctx) noexcept override;
|
||||
void draw(StudioContext &ctx) noexcept override;
|
||||
|
||||
void setModel(ox::UPtr<ProjectTreeModel> &&model) noexcept;
|
||||
|
||||
ox::Error refreshProjectTreeModel(ox::StringViewCR = {}) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
inline ox::FileSystem *romFs() noexcept {
|
||||
ox::FileSystem *romFs() noexcept {
|
||||
return rom(m_ctx);
|
||||
}
|
||||
|
||||
// slots
|
||||
public:
|
||||
ox::Signal<ox::Error(ox::StringView const&)> fileChosen;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -4,13 +4,18 @@
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include <studio/dragdrop.hpp>
|
||||
#include <studio/imguiutil.hpp>
|
||||
|
||||
#include "projectexplorer.hpp"
|
||||
#include "projecttreemodel.hpp"
|
||||
|
||||
namespace studio {
|
||||
|
||||
ProjectTreeModel::ProjectTreeModel(ProjectExplorer &explorer, ox::String name,
|
||||
ProjectTreeModel *parent) noexcept:
|
||||
ProjectTreeModel::ProjectTreeModel(
|
||||
ProjectExplorer &explorer,
|
||||
ox::StringParam name,
|
||||
ProjectTreeModel *parent) noexcept:
|
||||
m_explorer(explorer),
|
||||
m_parent(parent),
|
||||
m_name(std::move(name)) {
|
||||
@ -23,14 +28,18 @@ ProjectTreeModel::ProjectTreeModel(ProjectTreeModel &&other) noexcept:
|
||||
m_children(std::move(other.m_children)) {
|
||||
}
|
||||
|
||||
void ProjectTreeModel::draw(turbine::Context &ctx) const noexcept {
|
||||
void ProjectTreeModel::draw(turbine::Context &tctx) const noexcept {
|
||||
constexpr auto dirFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
||||
if (!m_children.empty()) {
|
||||
if (ImGui::TreeNodeEx(m_name.c_str(), dirFlags)) {
|
||||
drawDirContextMenu();
|
||||
for (auto const&child : m_children) {
|
||||
child->draw(ctx);
|
||||
child->draw(tctx);
|
||||
}
|
||||
ImGui::TreePop();
|
||||
} else {
|
||||
ig::IDStackItem const idStackItem{m_name};
|
||||
drawDirContextMenu();
|
||||
}
|
||||
} else {
|
||||
auto const path = fullPath();
|
||||
@ -39,7 +48,17 @@ void ProjectTreeModel::draw(turbine::Context &ctx) const noexcept {
|
||||
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) {
|
||||
m_explorer.fileChosen.emit(path);
|
||||
}
|
||||
if (ImGui::BeginPopupContextItem("FileMenu", ImGuiPopupFlags_MouseButtonRight)) {
|
||||
if (ImGui::MenuItem("Delete")) {
|
||||
m_explorer.deleteItem.emit(path);
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
ImGui::TreePop();
|
||||
std::ignore = ig::dragDropSource([this] {
|
||||
ImGui::Text("%s", m_name.c_str());
|
||||
return ig::setDragDropPayload("FileRef", FileRef{fullPath<ox::String>()});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -48,11 +67,19 @@ void ProjectTreeModel::setChildren(ox::Vector<ox::UPtr<ProjectTreeModel>> childr
|
||||
m_children = std::move(children);
|
||||
}
|
||||
|
||||
ox::BasicString<255> ProjectTreeModel::fullPath() const noexcept {
|
||||
if (m_parent) {
|
||||
return m_parent->fullPath() + "/" + ox::StringView(m_name);
|
||||
}
|
||||
return {};
|
||||
void ProjectTreeModel::drawDirContextMenu() const noexcept {
|
||||
if (ImGui::BeginPopupContextItem("DirMenu", ImGuiPopupFlags_MouseButtonRight)) {
|
||||
if (ImGui::MenuItem("Add Item")) {
|
||||
m_explorer.addItem.emit(fullPath());
|
||||
}
|
||||
if (ImGui::MenuItem("Add Directory")) {
|
||||
m_explorer.addDir.emit(fullPath());
|
||||
}
|
||||
if (ImGui::MenuItem("Delete")) {
|
||||
m_explorer.deleteItem.emit(fullPath());
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,19 +17,30 @@ class ProjectTreeModel {
|
||||
ProjectTreeModel *m_parent = nullptr;
|
||||
ox::String m_name;
|
||||
ox::Vector<ox::UPtr<ProjectTreeModel>> m_children;
|
||||
|
||||
public:
|
||||
explicit ProjectTreeModel(class ProjectExplorer &explorer, ox::String name,
|
||||
ProjectTreeModel *parent = nullptr) noexcept;
|
||||
explicit ProjectTreeModel(
|
||||
ProjectExplorer &explorer, ox::StringParam name,
|
||||
ProjectTreeModel *parent = nullptr) noexcept;
|
||||
|
||||
ProjectTreeModel(ProjectTreeModel &&other) noexcept;
|
||||
|
||||
void draw(turbine::Context &ctx) const noexcept;
|
||||
void draw(turbine::Context &tctx) const noexcept;
|
||||
|
||||
void setChildren(ox::Vector<ox::UPtr<ProjectTreeModel>> children) noexcept;
|
||||
|
||||
private:
|
||||
void drawDirContextMenu() const noexcept;
|
||||
|
||||
template<typename Str = ox::BasicString<255>>
|
||||
[[nodiscard]]
|
||||
ox::BasicString<255> fullPath() const noexcept;
|
||||
Str fullPath() const noexcept {
|
||||
if (m_parent) {
|
||||
return m_parent->fullPath<Str>() + "/" + m_name;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -52,6 +52,9 @@ StudioUI::StudioUI(turbine::Context &ctx, ox::StringParam projectDataDir) noexce
|
||||
m_aboutPopup(m_tctx) {
|
||||
turbine::setApplicationData(m_tctx, &m_sctx);
|
||||
m_projectExplorer.fileChosen.connect(this, &StudioUI::openFile);
|
||||
m_projectExplorer.addDir.connect(this, &StudioUI::addDir);
|
||||
m_projectExplorer.addItem.connect(this, &StudioUI::addFile);
|
||||
m_projectExplorer.deleteItem.connect(this, &StudioUI::deleteFile);
|
||||
m_newProject.finished.connect(this, &StudioUI::createOpenProject);
|
||||
m_newMenu.finished.connect(this, &StudioUI::openFile);
|
||||
ImGui::GetIO().IniFilename = nullptr;
|
||||
@ -342,6 +345,21 @@ void StudioUI::handleKeyInput() noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error StudioUI::addDir(ox::StringViewCR path) noexcept {
|
||||
m_newDirDialog.openPath(path);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error StudioUI::addFile(ox::StringViewCR path) noexcept {
|
||||
m_newMenu.openPath(path);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error StudioUI::deleteFile(ox::StringViewCR path) noexcept {
|
||||
m_deleteConfirmation.openPath(path);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error StudioUI::createOpenProject(ox::StringViewCR path) noexcept {
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(toStdStringView(path), ec);
|
||||
@ -356,9 +374,11 @@ ox::Error StudioUI::openProjectPath(ox::StringParam path) noexcept {
|
||||
OX_RETURN_ERROR(
|
||||
ox::make_unique_catch<Project>(keelCtx(m_tctx), std::move(path), m_projectDataDir)
|
||||
.moveTo(m_project));
|
||||
auto const sctx = applicationData<StudioContext>(m_tctx);
|
||||
sctx->project = m_project.get();
|
||||
m_sctx.project = m_project.get();
|
||||
turbine::setWindowTitle(m_tctx, ox::sfmt("{} - {}", keelCtx(m_tctx).appName, m_project->projectPath()));
|
||||
m_deleteConfirmation.deleteFile.connect(m_sctx.project, &Project::deleteItem);
|
||||
m_newDirDialog.newDir.connect(m_sctx.project, &Project::mkdir);
|
||||
m_project->dirAdded.connect(&m_projectExplorer, &ProjectExplorer::refreshProjectTreeModel);
|
||||
m_project->fileAdded.connect(&m_projectExplorer, &ProjectExplorer::refreshProjectTreeModel);
|
||||
m_project->fileDeleted.connect(&m_projectExplorer, &ProjectExplorer::refreshProjectTreeModel);
|
||||
m_openFiles.clear();
|
||||
|
@ -12,7 +12,10 @@
|
||||
#include <studio/module.hpp>
|
||||
#include <studio/project.hpp>
|
||||
#include <studio/task.hpp>
|
||||
|
||||
#include "aboutpopup.hpp"
|
||||
#include "deleteconfirmation.hpp"
|
||||
#include "newdir.hpp"
|
||||
#include "newmenu.hpp"
|
||||
#include "newproject.hpp"
|
||||
#include "projectexplorer.hpp"
|
||||
@ -38,12 +41,16 @@ class StudioUI: public ox::SignalHandler {
|
||||
BaseEditor *m_activeEditor = nullptr;
|
||||
BaseEditor *m_activeEditorUpdatePending = nullptr;
|
||||
NewMenu m_newMenu;
|
||||
DeleteConfirmation m_deleteConfirmation;
|
||||
NewDir m_newDirDialog;
|
||||
NewProject m_newProject;
|
||||
AboutPopup m_aboutPopup;
|
||||
ox::Array<Popup*, 3> const m_popups = {
|
||||
ox::Array<Popup*, 5> const m_popups = {
|
||||
&m_newMenu,
|
||||
&m_newProject,
|
||||
&m_aboutPopup
|
||||
&m_aboutPopup,
|
||||
&m_deleteConfirmation,
|
||||
&m_newDirDialog,
|
||||
};
|
||||
bool m_showProjectExplorer = true;
|
||||
|
||||
@ -83,6 +90,12 @@ class StudioUI: public ox::SignalHandler {
|
||||
|
||||
void handleKeyInput() noexcept;
|
||||
|
||||
ox::Error addDir(ox::StringViewCR path) noexcept;
|
||||
|
||||
ox::Error addFile(ox::StringViewCR path) noexcept;
|
||||
|
||||
ox::Error deleteFile(ox::StringViewCR path) noexcept;
|
||||
|
||||
ox::Error createOpenProject(ox::StringViewCR path) noexcept;
|
||||
|
||||
ox::Error openProjectPath(ox::StringParam path) noexcept;
|
||||
|
Reference in New Issue
Block a user