[studio] Add support for deleting files
All checks were successful
Build / build (push) Successful in 3m16s
All checks were successful
Build / build (push) Successful in 3m16s
This commit is contained in:
parent
66229de77f
commit
4e5c749918
@ -12,12 +12,12 @@ namespace studio {
|
|||||||
|
|
||||||
static ox::Result<ox::UniquePtr<ProjectTreeModel>> buildProjectTreeModel(
|
static ox::Result<ox::UniquePtr<ProjectTreeModel>> buildProjectTreeModel(
|
||||||
ProjectExplorer &explorer,
|
ProjectExplorer &explorer,
|
||||||
ox::StringView name,
|
ox::StringParam name,
|
||||||
ox::StringView path,
|
ox::StringView path,
|
||||||
ProjectTreeModel *parent) noexcept {
|
ProjectTreeModel *parent) noexcept {
|
||||||
auto const fs = explorer.romFs();
|
auto const fs = explorer.romFs();
|
||||||
OX_REQUIRE(stat, fs->stat(path));
|
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) {
|
if (stat.fileType == ox::FileType::Directory) {
|
||||||
OX_REQUIRE_M(children, fs->ls(path));
|
OX_REQUIRE_M(children, fs->ls(path));
|
||||||
std::sort(children.begin(), children.end());
|
std::sort(children.begin(), children.end());
|
||||||
@ -37,12 +37,14 @@ static ox::Result<ox::UniquePtr<ProjectTreeModel>> buildProjectTreeModel(
|
|||||||
ProjectExplorer::ProjectExplorer(turbine::Context &ctx) noexcept: m_ctx(ctx) {
|
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();
|
auto const viewport = ImGui::GetContentRegionAvail();
|
||||||
ImGui::BeginChild("ProjectExplorer", ImVec2(300, viewport.y), true);
|
ImGui::BeginChild("ProjectExplorer", ImVec2(300, viewport.y), true);
|
||||||
ImGui::SetNextItemOpen(true);
|
ImGui::SetNextItemOpen(true);
|
||||||
if (m_treeModel) {
|
if (m_treeModel) {
|
||||||
m_treeModel->draw(ctx.tctx);
|
if (m_treeModel->draw(ctx.tctx)) {
|
||||||
|
oxLogError(refreshProjectTreeModel());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
}
|
}
|
||||||
|
@ -12,27 +12,28 @@
|
|||||||
|
|
||||||
namespace studio {
|
namespace studio {
|
||||||
|
|
||||||
class ProjectExplorer: public studio::Widget {
|
class ProjectExplorer: public Widget {
|
||||||
private:
|
private:
|
||||||
ox::UPtr<ProjectTreeModel> m_treeModel;
|
ox::UPtr<ProjectTreeModel> m_treeModel;
|
||||||
turbine::Context &m_ctx;
|
turbine::Context &m_ctx;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
// slots
|
||||||
|
ox::Signal<ox::Error(ox::StringView const&)> fileChosen;
|
||||||
|
|
||||||
explicit ProjectExplorer(turbine::Context &ctx) noexcept;
|
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;
|
void setModel(ox::UPtr<ProjectTreeModel> &&model) noexcept;
|
||||||
|
|
||||||
ox::Error refreshProjectTreeModel(ox::StringViewCR = {}) noexcept;
|
ox::Error refreshProjectTreeModel(ox::StringViewCR = {}) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline ox::FileSystem *romFs() noexcept {
|
ox::FileSystem *romFs() noexcept {
|
||||||
return rom(m_ctx);
|
return rom(m_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// slots
|
|
||||||
public:
|
|
||||||
ox::Signal<ox::Error(ox::StringView const&)> fileChosen;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
|
|
||||||
namespace studio {
|
namespace studio {
|
||||||
|
|
||||||
ProjectTreeModel::ProjectTreeModel(ProjectExplorer &explorer, ox::String name,
|
ProjectTreeModel::ProjectTreeModel(
|
||||||
|
ProjectExplorer &explorer,
|
||||||
|
ox::StringParam name,
|
||||||
ProjectTreeModel *parent) noexcept:
|
ProjectTreeModel *parent) noexcept:
|
||||||
m_explorer(explorer),
|
m_explorer(explorer),
|
||||||
m_parent(parent),
|
m_parent(parent),
|
||||||
@ -23,12 +25,13 @@ ProjectTreeModel::ProjectTreeModel(ProjectTreeModel &&other) noexcept:
|
|||||||
m_children(std::move(other.m_children)) {
|
m_children(std::move(other.m_children)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectTreeModel::draw(turbine::Context &ctx) const noexcept {
|
bool ProjectTreeModel::draw(turbine::Context &ctx) const noexcept {
|
||||||
|
bool updated = false;
|
||||||
constexpr auto dirFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
constexpr auto dirFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
||||||
if (!m_children.empty()) {
|
if (!m_children.empty()) {
|
||||||
if (ImGui::TreeNodeEx(m_name.c_str(), dirFlags)) {
|
if (ImGui::TreeNodeEx(m_name.c_str(), dirFlags)) {
|
||||||
for (auto const&child : m_children) {
|
for (auto const&child : m_children) {
|
||||||
child->draw(ctx);
|
updated = child->draw(ctx) || updated;
|
||||||
}
|
}
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
@ -39,9 +42,16 @@ void ProjectTreeModel::draw(turbine::Context &ctx) const noexcept {
|
|||||||
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) {
|
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) {
|
||||||
m_explorer.fileChosen.emit(path);
|
m_explorer.fileChosen.emit(path);
|
||||||
}
|
}
|
||||||
|
if (ImGui::BeginPopupContextItem("FileMenu", ImGuiPopupFlags_MouseButtonRight)) {
|
||||||
|
if (ImGui::MenuItem("Delete")) {
|
||||||
|
updated = m_explorer.romFs()->remove(path).errCode == 0 || updated;
|
||||||
|
}
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectTreeModel::setChildren(ox::Vector<ox::UPtr<ProjectTreeModel>> children) noexcept {
|
void ProjectTreeModel::setChildren(ox::Vector<ox::UPtr<ProjectTreeModel>> children) noexcept {
|
||||||
|
@ -17,19 +17,23 @@ class ProjectTreeModel {
|
|||||||
ProjectTreeModel *m_parent = nullptr;
|
ProjectTreeModel *m_parent = nullptr;
|
||||||
ox::String m_name;
|
ox::String m_name;
|
||||||
ox::Vector<ox::UPtr<ProjectTreeModel>> m_children;
|
ox::Vector<ox::UPtr<ProjectTreeModel>> m_children;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ProjectTreeModel(class ProjectExplorer &explorer, ox::String name,
|
explicit ProjectTreeModel(
|
||||||
|
ProjectExplorer &explorer, ox::StringParam name,
|
||||||
ProjectTreeModel *parent = nullptr) noexcept;
|
ProjectTreeModel *parent = nullptr) noexcept;
|
||||||
|
|
||||||
ProjectTreeModel(ProjectTreeModel &&other) noexcept;
|
ProjectTreeModel(ProjectTreeModel &&other) noexcept;
|
||||||
|
|
||||||
void draw(turbine::Context &ctx) const noexcept;
|
[[nodiscard]]
|
||||||
|
bool draw(turbine::Context &ctx) const noexcept;
|
||||||
|
|
||||||
void setChildren(ox::Vector<ox::UPtr<ProjectTreeModel>> children) noexcept;
|
void setChildren(ox::Vector<ox::UPtr<ProjectTreeModel>> children) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
ox::BasicString<255> fullPath() const noexcept;
|
ox::BasicString<255> fullPath() const noexcept;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user