[nostalgia/studio] Cleanup save hooks and add unsaved changes marker to tabs
This commit is contained in:
parent
bf00ff0e41
commit
6ada347ec4
@ -13,15 +13,12 @@ namespace nostalgia::studio {
|
||||
Editor::Editor(QWidget *parent): QWidget(parent) {
|
||||
}
|
||||
|
||||
void Editor::saveItem() {
|
||||
}
|
||||
|
||||
QUndoStack *Editor::undoStack() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Editor::save() {
|
||||
save();
|
||||
saveItem();
|
||||
setUnsavedChanges(false);
|
||||
}
|
||||
|
||||
@ -30,4 +27,7 @@ void Editor::setUnsavedChanges(bool uc) {
|
||||
emit unsavedChangesUpdate(uc);
|
||||
}
|
||||
|
||||
void Editor::saveItem() {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace nostalgia::studio {
|
||||
class NOSTALGIASTUDIO_EXPORT Editor: public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
private:
|
||||
bool m_unsavedChanges = false;
|
||||
|
||||
public:
|
||||
@ -31,11 +31,6 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget {
|
||||
*/
|
||||
virtual QString itemName() = 0;
|
||||
|
||||
/**
|
||||
* Save changes to item being edited.
|
||||
*/
|
||||
virtual void saveItem();
|
||||
|
||||
/**
|
||||
* Returns the undo stack holding changes to the item being edited.
|
||||
*/
|
||||
@ -52,6 +47,12 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget {
|
||||
*/
|
||||
void setUnsavedChanges(bool);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Save changes to item being edited.
|
||||
*/
|
||||
virtual void saveItem();
|
||||
|
||||
signals:
|
||||
void unsavedChangesUpdate(bool);
|
||||
|
||||
|
@ -303,7 +303,11 @@ void MainWindow::openProject(QString projectPath) {
|
||||
// reopen tabs
|
||||
auto openTabs = readTabs();
|
||||
for (auto t : openTabs) {
|
||||
openFile(t, true);
|
||||
try {
|
||||
openFile(t, true);
|
||||
} catch (ox::Error err) {
|
||||
oxTrace("nostalgia::studio::MainWindow::openProject") << "Error opening tab:" << err;
|
||||
}
|
||||
}
|
||||
qInfo() << "Open project:" << projectPath;
|
||||
}
|
||||
@ -316,7 +320,7 @@ void MainWindow::closeProject() {
|
||||
m_tabs->removeTab(0);
|
||||
delete tab;
|
||||
}
|
||||
|
||||
|
||||
if (m_ctx.project) {
|
||||
disconnect(m_ctx.project, SIGNAL(updated(QString)), m_oxfsView, SLOT(updateFile(QString)));
|
||||
|
||||
@ -471,14 +475,32 @@ void MainWindow::moveTab(int from, int to) {
|
||||
|
||||
void MainWindow::changeTab(int idx) {
|
||||
auto tab = dynamic_cast<studio::Editor*>(m_tabs->widget(idx));
|
||||
disconnect(m_currentEditor, &Editor::unsavedChangesUpdate, m_saveAction, &QAction::setEnabled);
|
||||
m_currentEditor = tab;
|
||||
connect(m_currentEditor, &Editor::unsavedChangesUpdate, m_saveAction, &QAction::setEnabled);
|
||||
if (!tab) {
|
||||
m_undoGroup.setActiveStack(nullptr);
|
||||
return;
|
||||
if (m_currentEditor) {
|
||||
disconnect(m_currentEditor, &Editor::unsavedChangesUpdate, m_saveAction, &QAction::setEnabled);
|
||||
disconnect(m_currentEditor, &Editor::unsavedChangesUpdate, this, &MainWindow::markUnsavedChanges);
|
||||
}
|
||||
m_currentEditor = tab;
|
||||
if (m_currentEditor) {
|
||||
connect(m_currentEditor, &Editor::unsavedChangesUpdate, m_saveAction, &QAction::setEnabled);
|
||||
connect(m_currentEditor, &Editor::unsavedChangesUpdate, this, &MainWindow::markUnsavedChanges);
|
||||
m_undoGroup.setActiveStack(tab->undoStack());
|
||||
} else {
|
||||
m_undoGroup.setActiveStack(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::markUnsavedChanges(bool unsavedChanges) {
|
||||
auto idx = m_tabs->indexOf(m_currentEditor);
|
||||
if (idx > -1) {
|
||||
const auto path = m_currentEditor->itemName();
|
||||
const auto lastSlash = path.lastIndexOf('/') + 1;
|
||||
const auto tabName = path.mid(lastSlash);
|
||||
if (unsavedChanges) {
|
||||
m_tabs->setTabText(idx, tabName + "*");
|
||||
} else {
|
||||
m_tabs->setTabText(idx, tabName);
|
||||
}
|
||||
}
|
||||
m_undoGroup.setActiveStack(tab->undoStack());
|
||||
}
|
||||
|
||||
void MainWindow::showImportWizard() {
|
||||
|
@ -150,6 +150,8 @@ class MainWindow: public QMainWindow {
|
||||
|
||||
void changeTab(int idx);
|
||||
|
||||
void markUnsavedChanges(bool);
|
||||
|
||||
void showNewWizard();
|
||||
|
||||
void showImportWizard();
|
||||
|
Loading…
Reference in New Issue
Block a user