Skip to content

Commit

Permalink
Enable save button when not auto-saving non-data changes (#9634)
Browse files Browse the repository at this point in the history
* Fix #9501 
* Also fix bug where context menu did not update when entry moved to very top or bottom of list
  • Loading branch information
droidmonkey committed Aug 7, 2023
1 parent e1482de commit 5fb26d6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ void Database::markAsClean()
void Database::markNonDataChange()
{
m_hasNonDataChange = true;
emit databaseNonDataChanged();
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/core/Database.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public slots:
void databaseSaved();
void databaseDiscarded();
void databaseFileChanged();
void databaseNonDataChanged();
void tagListUpdated();

private:
Expand Down
10 changes: 10 additions & 0 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,8 @@ void DatabaseWidget::connectDatabaseSignals()
connect(m_db.data(), &Database::modified, this, &DatabaseWidget::onDatabaseModified);
connect(m_db.data(), &Database::databaseSaved, this, &DatabaseWidget::databaseSaved);
connect(m_db.data(), &Database::databaseFileChanged, this, &DatabaseWidget::reloadDatabaseFile);
connect(m_db.data(), &Database::databaseNonDataChanged, this, &DatabaseWidget::databaseNonDataChanged);
connect(m_db.data(), &Database::databaseNonDataChanged, this, &DatabaseWidget::onDatabaseNonDataChanged);
}

void DatabaseWidget::loadDatabase(bool accepted)
Expand Down Expand Up @@ -1571,6 +1573,14 @@ void DatabaseWidget::triggerAutosaveTimer()
QMetaObject::invokeMethod(m_autosaveTimer, "timeout");
}

void DatabaseWidget::onDatabaseNonDataChanged()
{
// Force mark the database modified if we are not auto-saving non-data changes
if (!config()->get(Config::AutoSaveNonDataChanges).toBool()) {
m_db->markAsModified();
}
}

QString DatabaseWidget::getCurrentSearch()
{
return m_lastSearchText;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/DatabaseWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class DatabaseWidget : public QStackedWidget
// relayed Database signals
void databaseFilePathChanged(const QString& oldPath, const QString& newPath);
void databaseModified();
void databaseNonDataChanged();
void databaseSaved();
void databaseUnlocked();
void databaseLockRequested();
Expand Down Expand Up @@ -254,6 +255,7 @@ private slots:
void onEntryChanged(Entry* entry);
void onGroupChanged();
void onDatabaseModified();
void onDatabaseNonDataChanged();
void onAutosaveDelayTimeout();
void connectDatabaseSignals();
void loadDatabase(bool accepted);
Expand Down
1 change: 1 addition & 0 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ MainWindow::MainWindow()
SIGNAL(currentModeChanged(DatabaseWidget::Mode)), this, SLOT(setMenuActionState(DatabaseWidget::Mode)));
m_actionMultiplexer.connect(SIGNAL(groupChanged()), this, SLOT(setMenuActionState()));
m_actionMultiplexer.connect(SIGNAL(entrySelectionChanged()), this, SLOT(setMenuActionState()));
m_actionMultiplexer.connect(SIGNAL(databaseNonDataChanged()), this, SLOT(setMenuActionState()));
m_actionMultiplexer.connect(SIGNAL(groupContextMenuRequested(QPoint)), this, SLOT(showGroupContextMenu(QPoint)));
m_actionMultiplexer.connect(SIGNAL(entryContextMenuRequested(QPoint)), this, SLOT(showEntryContextMenu(QPoint)));
m_actionMultiplexer.connect(SIGNAL(groupChanged()), this, SLOT(updateEntryCountLabel()));
Expand Down

0 comments on commit 5fb26d6

Please sign in to comment.