diff --git a/src/nostalgia/studio/lib/editor.cpp b/src/nostalgia/studio/lib/editor.cpp index c38a6207..b4304e08 100644 --- a/src/nostalgia/studio/lib/editor.cpp +++ b/src/nostalgia/studio/lib/editor.cpp @@ -13,6 +13,9 @@ namespace nostalgia::studio { Editor::Editor(QWidget *parent): QWidget(parent) { } +void Editor::exportFile() { +} + void Editor::save() { saveItem(); setUnsavedChanges(false); @@ -20,13 +23,26 @@ void Editor::save() { void Editor::setUnsavedChanges(bool uc) { m_unsavedChanges = uc; - emit unsavedChangesUpdate(uc); + emit unsavedChangesChanged(uc); +} + +[[nodiscard]] bool Editor::unsavedChanges() noexcept { + return m_unsavedChanges; } QUndoStack *Editor::undoStack() { return &m_cmdStack; } +void Editor::setExportable(bool exportable) { + m_exportable = exportable; + emit exportableChanged(exportable); +} + +bool Editor::exportable() { + return m_exportable; +} + void Editor::saveItem() { } diff --git a/src/nostalgia/studio/lib/editor.hpp b/src/nostalgia/studio/lib/editor.hpp index 70c56514..e186bf77 100644 --- a/src/nostalgia/studio/lib/editor.hpp +++ b/src/nostalgia/studio/lib/editor.hpp @@ -21,6 +21,7 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget { private: QUndoStack m_cmdStack; bool m_unsavedChanges = false; + bool m_exportable = false; public: Editor(QWidget *parent); @@ -32,6 +33,8 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget { */ virtual QString itemName() = 0; + virtual void exportFile(); + /** * Save changes to item being edited. */ @@ -39,15 +42,21 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget { /** * Sets indication of item being edited has unsaved changes. Also emits - * unsavedChangesUpdate signal. + * unsavedChangesChanged signal. */ void setUnsavedChanges(bool); + [[nodiscard]] bool unsavedChanges() noexcept; + /** * Returns the undo stack holding changes to the item being edited. */ QUndoStack *undoStack(); + void setExportable(bool); + + bool exportable(); + protected: /** * Save changes to item being edited. @@ -55,7 +64,9 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget { virtual void saveItem(); signals: - void unsavedChangesUpdate(bool); + void unsavedChangesChanged(bool); + + void exportableChanged(bool); }; diff --git a/src/nostalgia/studio/mainwindow.cpp b/src/nostalgia/studio/mainwindow.cpp index cf36b385..a526dcc3 100644 --- a/src/nostalgia/studio/mainwindow.cpp +++ b/src/nostalgia/studio/mainwindow.cpp @@ -162,6 +162,16 @@ void MainWindow::setupMenu() { ); m_saveAction->setEnabled(false); + // Save Project + m_exportAction = addAction( + fileMenu, + tr("&Export File..."), + tr(""), + this, + SLOT(exportFile()) + ); + m_exportAction->setEnabled(false); + // Exit addAction( fileMenu, @@ -458,6 +468,10 @@ void MainWindow::saveFile() { m_currentEditor->save(); } +void MainWindow::exportFile() { + m_currentEditor->exportFile(); +} + void MainWindow::closeTab(int idx) { auto tab = static_cast(m_tabs->widget(idx)); m_undoGroup.removeStack(tab->undoStack()); @@ -480,13 +494,17 @@ void MainWindow::moveTab(int from, int to) { void MainWindow::changeTab(int idx) { auto tab = dynamic_cast(m_tabs->widget(idx)); if (m_currentEditor) { - disconnect(m_currentEditor, &Editor::unsavedChangesUpdate, m_saveAction, &QAction::setEnabled); - disconnect(m_currentEditor, &Editor::unsavedChangesUpdate, this, &MainWindow::markUnsavedChanges); + disconnect(m_currentEditor, &Editor::unsavedChangesChanged, m_saveAction, &QAction::setEnabled); + disconnect(m_currentEditor, &Editor::unsavedChangesChanged, this, &MainWindow::markUnsavedChanges); + disconnect(m_currentEditor, &Editor::exportableChanged, m_exportAction, &QAction::setEnabled); } m_currentEditor = tab; if (m_currentEditor) { - connect(m_currentEditor, &Editor::unsavedChangesUpdate, m_saveAction, &QAction::setEnabled); - connect(m_currentEditor, &Editor::unsavedChangesUpdate, this, &MainWindow::markUnsavedChanges); + m_saveAction->setEnabled(m_currentEditor->unsavedChanges()); + connect(m_currentEditor, &Editor::unsavedChangesChanged, m_saveAction, &QAction::setEnabled); + connect(m_currentEditor, &Editor::unsavedChangesChanged, this, &MainWindow::markUnsavedChanges); + m_exportAction->setEnabled(m_currentEditor->exportable()); + connect(m_currentEditor, &Editor::exportableChanged, m_exportAction, &QAction::setEnabled); m_undoGroup.setActiveStack(tab->undoStack()); } else { m_undoGroup.setActiveStack(nullptr); diff --git a/src/nostalgia/studio/mainwindow.hpp b/src/nostalgia/studio/mainwindow.hpp index 5c11123c..d3a1a08e 100644 --- a/src/nostalgia/studio/mainwindow.hpp +++ b/src/nostalgia/studio/mainwindow.hpp @@ -74,6 +74,7 @@ class MainWindow: public QMainWindow { NostalgiaStudioState m_state; QAction *m_importAction = nullptr; QAction *m_saveAction = nullptr; + QAction *m_exportAction = nullptr; Context m_ctx; QPointer m_viewMenu; QVector> m_dockWidgets; @@ -144,6 +145,8 @@ class MainWindow: public QMainWindow { void saveFile(); + void exportFile(); + void closeTab(int idx); void moveTab(int from, int to);