mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
MainWindow: Make it possible to cancel closing of database file
When closing the database, either by using the menu item or by closing the window, the user is asked whether the changes he made shall be saved or not. Add a third button to this message box which makes it possible to cancel the action.
This commit is contained in:
@@ -373,7 +373,9 @@ void MainWindow::resetBrowser()
|
||||
|
||||
void MainWindow::fileClose()
|
||||
{
|
||||
db.close();
|
||||
if(!db.close())
|
||||
return;
|
||||
|
||||
setWindowTitle(QApplication::applicationName());
|
||||
resetBrowser();
|
||||
populateStructure();
|
||||
@@ -401,13 +403,17 @@ void MainWindow::fileClose()
|
||||
|
||||
void MainWindow::closeEvent( QCloseEvent* event )
|
||||
{
|
||||
db.close();
|
||||
PreferencesDialog::setSettingsValue("MainWindow", "geometry", saveGeometry());
|
||||
PreferencesDialog::setSettingsValue("MainWindow", "windowState", saveState());
|
||||
PreferencesDialog::setSettingsValue("SQLLogDock", "Log", ui->comboLogSubmittedBy->currentText());
|
||||
PreferencesDialog::setSettingsValue("PlotDock", "splitterSize", ui->splitterForPlot->saveState());
|
||||
clearCompleterModelsFields();
|
||||
QMainWindow::closeEvent(event);
|
||||
if(db.close())
|
||||
{
|
||||
PreferencesDialog::setSettingsValue("MainWindow", "geometry", saveGeometry());
|
||||
PreferencesDialog::setSettingsValue("MainWindow", "windowState", saveState());
|
||||
PreferencesDialog::setSettingsValue("SQLLogDock", "Log", ui->comboLogSubmittedBy->currentText());
|
||||
PreferencesDialog::setSettingsValue("PlotDock", "splitterSize", ui->splitterForPlot->saveState());
|
||||
clearCompleterModelsFields();
|
||||
QMainWindow::closeEvent(event);
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::addRecord()
|
||||
|
||||
@@ -191,16 +191,24 @@ bool DBBrowserDB::create ( const QString & db)
|
||||
}
|
||||
|
||||
|
||||
void DBBrowserDB::close (){
|
||||
if (_db)
|
||||
bool DBBrowserDB::close()
|
||||
{
|
||||
if(_db)
|
||||
{
|
||||
if (getDirty())
|
||||
{
|
||||
if (QMessageBox::question( 0,
|
||||
QApplication::applicationName(),
|
||||
QObject::tr("Do you want to save the changes "
|
||||
"made to the database file %1?").arg(curDBFilename),
|
||||
QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
|
||||
QMessageBox::StandardButton reply = QMessageBox::question(0,
|
||||
QApplication::applicationName(),
|
||||
QObject::tr("Do you want to save the changes "
|
||||
"made to the database file %1?").arg(curDBFilename),
|
||||
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
|
||||
|
||||
// If the user clicked the cancel button stop here and return false
|
||||
if(reply == QMessageBox::Cancel)
|
||||
return false;
|
||||
|
||||
// If he didn't it was either yes or no
|
||||
if(reply == QMessageBox::Yes)
|
||||
saveAll();
|
||||
else
|
||||
revertAll(); //not really necessary, I think... but will not hurt.
|
||||
@@ -211,6 +219,9 @@ void DBBrowserDB::close (){
|
||||
objMap.clear();
|
||||
savepointList.clear();
|
||||
if(mainWindow) mainWindow->dbState(getDirty());
|
||||
|
||||
// Return true to tell the calling function that the closing wasn't cancelled by the user
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DBBrowserDB::dump(const QString& filename)
|
||||
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
~DBBrowserDB (){}
|
||||
bool open ( const QString & db);
|
||||
bool create ( const QString & db);
|
||||
void close ();
|
||||
bool close();
|
||||
bool setRestorePoint(const QString& pointname = "RESTOREPOINT");
|
||||
bool save (const QString& pointname = "RESTOREPOINT");
|
||||
bool revert (const QString& pointname = "RESTOREPOINT");
|
||||
|
||||
Reference in New Issue
Block a user