[nostalgia/studio] Add Export menu item and hook
This commit is contained in:
parent
f90a6e30ea
commit
26747a6d0f
@ -13,6 +13,9 @@ namespace nostalgia::studio {
|
|||||||
Editor::Editor(QWidget *parent): QWidget(parent) {
|
Editor::Editor(QWidget *parent): QWidget(parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::exportFile() {
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::save() {
|
void Editor::save() {
|
||||||
saveItem();
|
saveItem();
|
||||||
setUnsavedChanges(false);
|
setUnsavedChanges(false);
|
||||||
@ -20,13 +23,26 @@ void Editor::save() {
|
|||||||
|
|
||||||
void Editor::setUnsavedChanges(bool uc) {
|
void Editor::setUnsavedChanges(bool uc) {
|
||||||
m_unsavedChanges = uc;
|
m_unsavedChanges = uc;
|
||||||
emit unsavedChangesUpdate(uc);
|
emit unsavedChangesChanged(uc);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool Editor::unsavedChanges() noexcept {
|
||||||
|
return m_unsavedChanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUndoStack *Editor::undoStack() {
|
QUndoStack *Editor::undoStack() {
|
||||||
return &m_cmdStack;
|
return &m_cmdStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::setExportable(bool exportable) {
|
||||||
|
m_exportable = exportable;
|
||||||
|
emit exportableChanged(exportable);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Editor::exportable() {
|
||||||
|
return m_exportable;
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::saveItem() {
|
void Editor::saveItem() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget {
|
|||||||
private:
|
private:
|
||||||
QUndoStack m_cmdStack;
|
QUndoStack m_cmdStack;
|
||||||
bool m_unsavedChanges = false;
|
bool m_unsavedChanges = false;
|
||||||
|
bool m_exportable = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Editor(QWidget *parent);
|
Editor(QWidget *parent);
|
||||||
@ -32,6 +33,8 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget {
|
|||||||
*/
|
*/
|
||||||
virtual QString itemName() = 0;
|
virtual QString itemName() = 0;
|
||||||
|
|
||||||
|
virtual void exportFile();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save changes to item being edited.
|
* 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
|
* Sets indication of item being edited has unsaved changes. Also emits
|
||||||
* unsavedChangesUpdate signal.
|
* unsavedChangesChanged signal.
|
||||||
*/
|
*/
|
||||||
void setUnsavedChanges(bool);
|
void setUnsavedChanges(bool);
|
||||||
|
|
||||||
|
[[nodiscard]] bool unsavedChanges() noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the undo stack holding changes to the item being edited.
|
* Returns the undo stack holding changes to the item being edited.
|
||||||
*/
|
*/
|
||||||
QUndoStack *undoStack();
|
QUndoStack *undoStack();
|
||||||
|
|
||||||
|
void setExportable(bool);
|
||||||
|
|
||||||
|
bool exportable();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* Save changes to item being edited.
|
* Save changes to item being edited.
|
||||||
@ -55,7 +64,9 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget {
|
|||||||
virtual void saveItem();
|
virtual void saveItem();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void unsavedChangesUpdate(bool);
|
void unsavedChangesChanged(bool);
|
||||||
|
|
||||||
|
void exportableChanged(bool);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -162,6 +162,16 @@ void MainWindow::setupMenu() {
|
|||||||
);
|
);
|
||||||
m_saveAction->setEnabled(false);
|
m_saveAction->setEnabled(false);
|
||||||
|
|
||||||
|
// Save Project
|
||||||
|
m_exportAction = addAction(
|
||||||
|
fileMenu,
|
||||||
|
tr("&Export File..."),
|
||||||
|
tr(""),
|
||||||
|
this,
|
||||||
|
SLOT(exportFile())
|
||||||
|
);
|
||||||
|
m_exportAction->setEnabled(false);
|
||||||
|
|
||||||
// Exit
|
// Exit
|
||||||
addAction(
|
addAction(
|
||||||
fileMenu,
|
fileMenu,
|
||||||
@ -458,6 +468,10 @@ void MainWindow::saveFile() {
|
|||||||
m_currentEditor->save();
|
m_currentEditor->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::exportFile() {
|
||||||
|
m_currentEditor->exportFile();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::closeTab(int idx) {
|
void MainWindow::closeTab(int idx) {
|
||||||
auto tab = static_cast<studio::Editor*>(m_tabs->widget(idx));
|
auto tab = static_cast<studio::Editor*>(m_tabs->widget(idx));
|
||||||
m_undoGroup.removeStack(tab->undoStack());
|
m_undoGroup.removeStack(tab->undoStack());
|
||||||
@ -480,13 +494,17 @@ void MainWindow::moveTab(int from, int to) {
|
|||||||
void MainWindow::changeTab(int idx) {
|
void MainWindow::changeTab(int idx) {
|
||||||
auto tab = dynamic_cast<studio::Editor*>(m_tabs->widget(idx));
|
auto tab = dynamic_cast<studio::Editor*>(m_tabs->widget(idx));
|
||||||
if (m_currentEditor) {
|
if (m_currentEditor) {
|
||||||
disconnect(m_currentEditor, &Editor::unsavedChangesUpdate, m_saveAction, &QAction::setEnabled);
|
disconnect(m_currentEditor, &Editor::unsavedChangesChanged, m_saveAction, &QAction::setEnabled);
|
||||||
disconnect(m_currentEditor, &Editor::unsavedChangesUpdate, this, &MainWindow::markUnsavedChanges);
|
disconnect(m_currentEditor, &Editor::unsavedChangesChanged, this, &MainWindow::markUnsavedChanges);
|
||||||
|
disconnect(m_currentEditor, &Editor::exportableChanged, m_exportAction, &QAction::setEnabled);
|
||||||
}
|
}
|
||||||
m_currentEditor = tab;
|
m_currentEditor = tab;
|
||||||
if (m_currentEditor) {
|
if (m_currentEditor) {
|
||||||
connect(m_currentEditor, &Editor::unsavedChangesUpdate, m_saveAction, &QAction::setEnabled);
|
m_saveAction->setEnabled(m_currentEditor->unsavedChanges());
|
||||||
connect(m_currentEditor, &Editor::unsavedChangesUpdate, this, &MainWindow::markUnsavedChanges);
|
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());
|
m_undoGroup.setActiveStack(tab->undoStack());
|
||||||
} else {
|
} else {
|
||||||
m_undoGroup.setActiveStack(nullptr);
|
m_undoGroup.setActiveStack(nullptr);
|
||||||
|
@ -74,6 +74,7 @@ class MainWindow: public QMainWindow {
|
|||||||
NostalgiaStudioState m_state;
|
NostalgiaStudioState m_state;
|
||||||
QAction *m_importAction = nullptr;
|
QAction *m_importAction = nullptr;
|
||||||
QAction *m_saveAction = nullptr;
|
QAction *m_saveAction = nullptr;
|
||||||
|
QAction *m_exportAction = nullptr;
|
||||||
Context m_ctx;
|
Context m_ctx;
|
||||||
QPointer<QMenu> m_viewMenu;
|
QPointer<QMenu> m_viewMenu;
|
||||||
QVector<QPointer<QDockWidget>> m_dockWidgets;
|
QVector<QPointer<QDockWidget>> m_dockWidgets;
|
||||||
@ -144,6 +145,8 @@ class MainWindow: public QMainWindow {
|
|||||||
|
|
||||||
void saveFile();
|
void saveFile();
|
||||||
|
|
||||||
|
void exportFile();
|
||||||
|
|
||||||
void closeTab(int idx);
|
void closeTab(int idx);
|
||||||
|
|
||||||
void moveTab(int from, int to);
|
void moveTab(int from, int to);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user