[nostalgia/studio] Add Export menu item and hook

This commit is contained in:
Gary Talent 2020-03-24 21:42:42 -05:00
parent f90a6e30ea
commit 26747a6d0f
4 changed files with 55 additions and 7 deletions

View File

@ -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() {
}

View File

@ -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);
};

View File

@ -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<studio::Editor*>(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<studio::Editor*>(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);

View File

@ -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<QMenu> m_viewMenu;
QVector<QPointer<QDockWidget>> m_dockWidgets;
@ -144,6 +145,8 @@ class MainWindow: public QMainWindow {
void saveFile();
void exportFile();
void closeTab(int idx);
void moveTab(int from, int to);