[nostalgia] Split studio::Editor into Editor and BaseEditor

This commit is contained in:
2022-04-09 16:20:39 -05:00
parent 56964e197a
commit edf4571ff7
8 changed files with 64 additions and 55 deletions

View File

@@ -8,27 +8,27 @@
namespace nostalgia::studio {
const ox::String &Editor::itemDisplayName() const {
const ox::String &BaseEditor::itemDisplayName() const noexcept {
return itemName();
}
void Editor::cut() {
void BaseEditor::cut() {
}
void Editor::copy() {
void BaseEditor::copy() {
}
void Editor::paste() {
void BaseEditor::paste() {
}
void Editor::exportFile() {
void BaseEditor::exportFile() {
}
void Editor::close() {
void BaseEditor::close() {
this->closed.emit(itemName());
}
void Editor::save() noexcept {
void BaseEditor::save() noexcept {
const auto err = saveItem();
if (!err) {
setUnsavedChanges(false);
@@ -37,52 +37,61 @@ void Editor::save() noexcept {
}
}
void Editor::setUnsavedChanges(bool uc) {
void BaseEditor::setUnsavedChanges(bool uc) {
m_unsavedChanges = uc;
unsavedChangesChanged.emit(uc);
}
bool Editor::unsavedChanges() const noexcept {
bool BaseEditor::unsavedChanges() const noexcept {
return m_unsavedChanges;
}
void Editor::setExportable(bool exportable) {
void BaseEditor::setExportable(bool exportable) {
m_exportable = exportable;
exportableChanged.emit(exportable);
}
bool Editor::exportable() const {
bool BaseEditor::exportable() const {
return m_exportable;
}
void Editor::setCutEnabled(bool v) {
void BaseEditor::setCutEnabled(bool v) {
m_cutEnabled = v;
cutEnabledChanged.emit(v);
}
bool Editor::cutEnabled() const {
bool BaseEditor::cutEnabled() const {
return m_cutEnabled;
}
void Editor::setCopyEnabled(bool v) {
void BaseEditor::setCopyEnabled(bool v) {
m_copyEnabled = v;
copyEnabledChanged.emit(v);
}
bool Editor::copyEnabled() const {
bool BaseEditor::copyEnabled() const {
return m_copyEnabled;
}
void Editor::setPasteEnabled(bool v) {
void BaseEditor::setPasteEnabled(bool v) {
m_pasteEnabled = v;
pasteEnabledChanged.emit(v);
}
bool Editor::pasteEnabled() const {
bool BaseEditor::pasteEnabled() const {
return m_pasteEnabled;
}
ox::Error Editor::saveItem() noexcept {
ox::Error BaseEditor::saveItem() noexcept {
return OxError(0);
}
Editor::Editor() noexcept {
m_undoStack.changeTriggered.connect(this, &Editor::markUnsavedChanges);
}
ox::Error Editor::markUnsavedChanges(int) noexcept {
setUnsavedChanges(true);
return OxError(0);
}

View File

@@ -17,7 +17,7 @@ class StudioUI;
namespace nostalgia::studio {
class NOSTALGIASTUDIO_EXPORT Editor: public Widget {
class NOSTALGIASTUDIO_EXPORT BaseEditor: public Widget {
friend StudioUI;
@@ -29,16 +29,16 @@ class NOSTALGIASTUDIO_EXPORT Editor: public Widget {
bool m_pasteEnabled = false;
public:
~Editor() override = default;
~BaseEditor() override = default;
/**
* Returns the name of item being edited.
*/
[[nodiscard]]
virtual const ox::String &itemName() const = 0;
virtual const ox::String &itemName() const noexcept = 0;
[[nodiscard]]
virtual const ox::String &itemDisplayName() const;
virtual const ox::String &itemDisplayName() const noexcept;
virtual void cut();
@@ -109,4 +109,20 @@ class NOSTALGIASTUDIO_EXPORT Editor: public Widget {
};
class Editor: public studio::BaseEditor {
private:
studio::UndoStack m_undoStack;
public:
Editor() noexcept;
UndoStack *undoStack() noexcept final {
return &m_undoStack;
}
private:
ox::Error markUnsavedChanges(int) noexcept;
};
}

View File

@@ -14,7 +14,7 @@
namespace nostalgia::studio {
struct EditorMaker {
using Func = std::function<ox::Result<class Editor*>(const ox::String&)>;
using Func = std::function<ox::Result<class BaseEditor*>(const ox::String&)>;
ox::Vector<ox::String> fileTypes;
Func make;
};

View File

@@ -24,13 +24,13 @@ class StudioUI: public ox::SignalHandler {
ox::UniquePtr<studio::Project> m_project;
studio::TaskRunner m_taskRunner;
core::Context *m_ctx = nullptr;
ox::Vector<ox::UniquePtr<studio::Editor>> m_editors;
ox::Vector<ox::UniquePtr<studio::BaseEditor>> m_editors;
ox::Vector<ox::UniquePtr<studio::Widget>> m_widgets;
ox::HashMap<ox::String, studio::EditorMaker::Func> m_editorMakers;
ProjectExplorer *m_projectExplorer = nullptr;
ox::Vector<ox::String> m_openFiles;
studio::Editor *m_activeEditor = nullptr;
studio::Editor *m_activeEditorUpdatePending = nullptr;
studio::BaseEditor *m_activeEditor = nullptr;
studio::BaseEditor *m_activeEditorUpdatePending = nullptr;
bool m_saveEnabled = false;
bool m_aboutEnabled = false;
bool m_showProjectExplorer = true;