[studio] Cleanup
This commit is contained in:
parent
7cab133127
commit
aad4b8a44c
@ -2,6 +2,8 @@
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <studio/imguiutil.hpp>
|
||||
|
||||
#include "makecopypopup.hpp"
|
||||
|
||||
namespace studio {
|
||||
@ -26,7 +28,7 @@ bool MakeCopyPopup::isOpen() const noexcept {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
void MakeCopyPopup::draw(StudioContext const &ctx) noexcept {
|
||||
void MakeCopyPopup::draw(StudioContext &ctx) noexcept {
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
|
@ -7,11 +7,12 @@
|
||||
#include <ox/std/string.hpp>
|
||||
|
||||
#include <studio/context.hpp>
|
||||
#include <studio/imguiutil.hpp>
|
||||
|
||||
#include <studio/widget.hpp>
|
||||
|
||||
namespace studio {
|
||||
|
||||
class MakeCopyPopup {
|
||||
class MakeCopyPopup: public Widget {
|
||||
private:
|
||||
enum class Stage {
|
||||
Closed,
|
||||
@ -36,7 +37,7 @@ class MakeCopyPopup {
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept;
|
||||
|
||||
void draw(StudioContext const &ctx) noexcept;
|
||||
void draw(StudioContext &ctx) noexcept override;
|
||||
|
||||
private:
|
||||
void accept(StudioContext const &ctx) noexcept;
|
||||
|
@ -159,15 +159,9 @@ void StudioUI::draw() noexcept {
|
||||
ImGui::SameLine();
|
||||
}
|
||||
drawTabBar();
|
||||
for (auto const&w : m_widgets) {
|
||||
for (auto const w : m_widgets) {
|
||||
w->draw(m_sctx);
|
||||
}
|
||||
for (auto const p : m_popups) {
|
||||
p->draw(m_sctx);
|
||||
}
|
||||
m_closeAppConfirm.draw(m_sctx);
|
||||
m_closeFileConfirm.draw(m_sctx);
|
||||
m_copyFilePopup.draw(m_sctx);
|
||||
}
|
||||
ImGui::End();
|
||||
handleKeyInput();
|
||||
@ -285,7 +279,6 @@ void StudioUI::drawTabs() noexcept {
|
||||
}
|
||||
if (!open) {
|
||||
if (e->unsavedChanges()) {
|
||||
m_closeAppConfirm.open();
|
||||
m_closeFileConfirm.open();
|
||||
++it;
|
||||
} else {
|
||||
@ -403,7 +396,6 @@ void StudioUI::handleKeyInput() noexcept {
|
||||
} else if (ImGui::IsKeyPressed(ImGuiKey_W)) {
|
||||
if (m_activeEditor) {
|
||||
if (m_activeEditor->unsavedChanges()) {
|
||||
m_closeAppConfirm.open();
|
||||
m_closeFileConfirm.open();
|
||||
} else {
|
||||
oxLogError(closeCurrentFile());
|
||||
|
@ -35,7 +35,6 @@ class StudioUI: public ox::SignalHandler {
|
||||
ox::UPtr<Project> m_project;
|
||||
TaskRunner m_taskRunner;
|
||||
ox::Vector<ox::UPtr<BaseEditor>> m_editors;
|
||||
ox::Vector<ox::UPtr<Widget>> m_widgets;
|
||||
ox::HashMap<ox::String, EditorMaker::Func> m_editorMakers;
|
||||
ProjectExplorer m_projectExplorer;
|
||||
ox::Vector<ox::String> m_openFiles;
|
||||
@ -57,6 +56,17 @@ class StudioUI: public ox::SignalHandler {
|
||||
RenameFile m_renameFile;
|
||||
NewProject m_newProject;
|
||||
AboutPopup m_aboutPopup;
|
||||
ox::Array<Widget*, 9> const m_widgets {
|
||||
&m_closeFileConfirm,
|
||||
&m_closeAppConfirm,
|
||||
&m_copyFilePopup,
|
||||
&m_newMenu,
|
||||
&m_newProject,
|
||||
&m_aboutPopup,
|
||||
&m_deleteConfirmation,
|
||||
&m_newDirDialog,
|
||||
&m_renameFile,
|
||||
};
|
||||
ox::Array<Popup*, 6> const m_popups = {
|
||||
&m_newMenu,
|
||||
&m_newProject,
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include <turbine/context.hpp>
|
||||
#include <studio/context.hpp>
|
||||
#include <studio/widget.hpp>
|
||||
|
||||
namespace studio::ig {
|
||||
|
||||
@ -303,7 +304,7 @@ class FilePicker {
|
||||
|
||||
};
|
||||
|
||||
class QuestionPopup {
|
||||
class QuestionPopup: public Widget {
|
||||
private:
|
||||
enum class Stage {
|
||||
Closed,
|
||||
@ -316,7 +317,7 @@ class QuestionPopup {
|
||||
ox::String m_question;
|
||||
|
||||
public:
|
||||
ox::Signal<ox::Error(ig::PopupResponse)> response;
|
||||
ox::Signal<ox::Error(PopupResponse)> response;
|
||||
|
||||
QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept;
|
||||
|
||||
@ -327,7 +328,7 @@ class QuestionPopup {
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept;
|
||||
|
||||
void draw(StudioContext &ctx, ImVec2 const &sz = {}) noexcept;
|
||||
void draw(StudioContext &ctx) noexcept;
|
||||
|
||||
};
|
||||
|
||||
|
@ -12,10 +12,12 @@
|
||||
|
||||
#include <turbine/context.hpp>
|
||||
|
||||
#include "widget.hpp"
|
||||
|
||||
namespace studio {
|
||||
|
||||
|
||||
class Popup {
|
||||
class Popup: public Widget {
|
||||
private:
|
||||
ox::Vec2 m_size;
|
||||
ox::String m_title;
|
||||
@ -32,8 +34,6 @@ class Popup {
|
||||
[[nodiscard]]
|
||||
virtual bool isOpen() const noexcept = 0;
|
||||
|
||||
virtual void draw(studio::StudioContext &ctx) noexcept = 0;
|
||||
|
||||
protected:
|
||||
constexpr void setSize(ox::Size sz) noexcept {
|
||||
m_size = {static_cast<float>(sz.width), static_cast<float>(sz.height)};
|
||||
|
@ -15,7 +15,7 @@ namespace studio {
|
||||
class Widget: public ox::SignalHandler {
|
||||
public:
|
||||
~Widget() noexcept override = default;
|
||||
virtual void draw(studio::StudioContext&) noexcept = 0;
|
||||
virtual void draw(StudioContext&) noexcept = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ bool QuestionPopup::isOpen() const noexcept {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
void QuestionPopup::draw(StudioContext &ctx, ImVec2 const &sz) noexcept {
|
||||
void QuestionPopup::draw(StudioContext &ctx) noexcept {
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
@ -255,7 +255,7 @@ void QuestionPopup::draw(StudioContext &ctx, ImVec2 const &sz) noexcept {
|
||||
[[fallthrough]];
|
||||
case Stage::Open:
|
||||
centerNextWindow(ctx.tctx);
|
||||
ImGui::SetNextWindowSize(static_cast<ImVec2>(sz));
|
||||
ImGui::SetNextWindowSize({});
|
||||
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
|
||||
if (ImGui::BeginPopupModal(m_title.c_str(), &m_open, modalFlags)) {
|
||||
ImGui::Text("%s", m_question.c_str());
|
||||
|
Loading…
x
Reference in New Issue
Block a user