From a138f60feaad0c407b63463734cce9a68e4e0f14 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 28 May 2024 20:58:26 -0500 Subject: [PATCH] [studio] Add acceptsClipboardPayload to Editor --- src/olympic/studio/applib/src/studioapp.cpp | 2 +- src/olympic/studio/modlib/include/studio/context.hpp | 5 +++++ src/olympic/studio/modlib/include/studio/editor.hpp | 3 +++ src/olympic/studio/modlib/src/editor.cpp | 6 +++++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/olympic/studio/applib/src/studioapp.cpp b/src/olympic/studio/applib/src/studioapp.cpp index 5231b679..0cf5617b 100644 --- a/src/olympic/studio/applib/src/studioapp.cpp +++ b/src/olympic/studio/applib/src/studioapp.cpp @@ -209,7 +209,7 @@ void StudioUI::drawMenu() noexcept { if (ImGui::MenuItem("Cut", "Ctrl+X", false, m_activeEditor && m_activeEditor->cutEnabled())) { m_activeEditor->cut(); } - if (ImGui::MenuItem("Paste", "Ctrl+V", false, m_activeEditor && m_activeEditor->pasteEnabled()) && m_activeEditor) { + if (ImGui::MenuItem("Paste", "Ctrl+V", false, m_activeEditor && m_activeEditor->pasteEnabled())) { m_activeEditor->paste(); } ImGui::EndMenu(); diff --git a/src/olympic/studio/modlib/include/studio/context.hpp b/src/olympic/studio/modlib/include/studio/context.hpp index de15c8cd..3ffe9bb5 100644 --- a/src/olympic/studio/modlib/include/studio/context.hpp +++ b/src/olympic/studio/modlib/include/studio/context.hpp @@ -22,4 +22,9 @@ struct StudioContext { ui(pUi), tctx(pTctx) {} }; +[[nodiscard]] +constexpr keel::Context &keelCtx(StudioContext &ctx) noexcept { + return keelCtx(ctx.tctx); +} + } diff --git a/src/olympic/studio/modlib/include/studio/editor.hpp b/src/olympic/studio/modlib/include/studio/editor.hpp index 69cf082b..ab096b83 100644 --- a/src/olympic/studio/modlib/include/studio/editor.hpp +++ b/src/olympic/studio/modlib/include/studio/editor.hpp @@ -43,6 +43,9 @@ class BaseEditor: public Widget { virtual void paste(); + [[nodiscard]] + virtual bool acceptsClipboardPayload() const noexcept; + virtual void exportFile(); virtual void keyStateChanged(turbine::Key key, bool down); diff --git a/src/olympic/studio/modlib/src/editor.cpp b/src/olympic/studio/modlib/src/editor.cpp index 9bd199b8..4edc39c6 100644 --- a/src/olympic/studio/modlib/src/editor.cpp +++ b/src/olympic/studio/modlib/src/editor.cpp @@ -23,6 +23,10 @@ void BaseEditor::copy() { void BaseEditor::paste() { } +bool BaseEditor::acceptsClipboardPayload() const noexcept { + return {}; +} + void BaseEditor::exportFile() { } @@ -95,7 +99,7 @@ void BaseEditor::setPasteEnabled(bool v) { } bool BaseEditor::pasteEnabled() const noexcept { - return m_pasteEnabled; + return m_pasteEnabled && acceptsClipboardPayload(); } ox::Error BaseEditor::saveItem() noexcept {