mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-02-11 06:08:33 -06:00
Add new action to close project file and return to initial state
This will close all SQL tabs, asking if they have to be saved and close the database file. Fixed a bug when switching between two project files from the Recent Files list. If the first project had a pending change and it was saved at that very moment, the database was already closed and the project file was saved without DB file. See issue #2289
This commit is contained in:
@@ -519,16 +519,17 @@ bool MainWindow::fileOpen(const QString& fileName, bool openFromProject, bool re
|
||||
// catch situation where user has canceled file selection from dialog
|
||||
if(!wFile.isEmpty() && QFile::exists(wFile) )
|
||||
{
|
||||
// Close the database. If the user didn't want to close it, though, stop here
|
||||
if (db.isOpen())
|
||||
if(!fileClose())
|
||||
return false;
|
||||
|
||||
// Try opening it as a project file first
|
||||
// Try opening it as a project file first. If confirmed, this will include closing current
|
||||
// database and project files.
|
||||
if(loadProject(wFile, readOnly))
|
||||
{
|
||||
retval = true;
|
||||
} else {
|
||||
// Close the database. If the user didn't want to close it, though, stop here
|
||||
if (db.isOpen())
|
||||
if(!fileClose())
|
||||
return false;
|
||||
|
||||
// No project file; so it should be a database file
|
||||
if(db.open(wFile, readOnly))
|
||||
{
|
||||
@@ -743,10 +744,17 @@ bool MainWindow::closeFiles()
|
||||
{
|
||||
bool ignoreUnattachedBuffers = false;
|
||||
// Ask for saving all modified open SQL files in their files and all the unattached tabs in a project file.
|
||||
for(int i=0; i<ui->tabSqlAreas->count(); i++)
|
||||
for(int i=0; i<ui->tabSqlAreas->count(); i++) {
|
||||
// Ask for saving and comply with cancel answer.
|
||||
if(!askSaveSqlTab(i, ignoreUnattachedBuffers))
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now all tabs can be closed at once without asking user.
|
||||
// Close tabs in reverse order (so indexes are not changed in the process).
|
||||
for(int i=ui->tabSqlAreas->count()-1; i>=0; i--)
|
||||
closeSqlTab(i, /* force */ true, /* askSaving */ false);
|
||||
|
||||
return closeProject();
|
||||
}
|
||||
|
||||
@@ -770,7 +778,7 @@ bool MainWindow::closeProject()
|
||||
}
|
||||
}
|
||||
currentProjectFilename.clear();
|
||||
return db.close();
|
||||
return fileClose();
|
||||
}
|
||||
|
||||
void MainWindow::attachPlot(ExtendedTableWidget* tableWidget, SqliteTableModel* model, BrowseDataTableSettings* settings, bool keepOrResetSelection)
|
||||
@@ -1914,14 +1922,15 @@ bool MainWindow::askSaveSqlTab(int index, bool& ignoreUnattachedBuffers)
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWindow::closeSqlTab(int index, bool force)
|
||||
void MainWindow::closeSqlTab(int index, bool force, bool askSaving)
|
||||
{
|
||||
// Check if we're still executing statements from this tab and stop them before proceeding
|
||||
if(ui->tabSqlAreas->tabBar()->tabData(index).toBool())
|
||||
{
|
||||
if(QMessageBox::warning(this, qApp->applicationName(), tr("The statements in this tab are still executing. Closing the tab will stop the "
|
||||
"execution. This might leave the database in an inconsistent state. Are you sure "
|
||||
"you want to close the tab?"),
|
||||
if(QMessageBox::warning(this, qApp->applicationName(),
|
||||
tr("The statements in the tab '%1' are still executing. Closing the tab will stop the "
|
||||
"execution. This might leave the database in an inconsistent state. Are you sure "
|
||||
"you want to close the tab?").arg(ui->tabSqlAreas->tabBar()->tabText(index)),
|
||||
QMessageBox::Yes,
|
||||
QMessageBox::Cancel | QMessageBox::Default | QMessageBox::Escape) == QMessageBox::Cancel)
|
||||
return;
|
||||
@@ -1931,7 +1940,7 @@ void MainWindow::closeSqlTab(int index, bool force)
|
||||
}
|
||||
// Ask for saving and comply with cancel answer.
|
||||
bool ignoreUnattachedBuffers = false;
|
||||
if (!askSaveSqlTab(index, ignoreUnattachedBuffers))
|
||||
if (askSaving && !askSaveSqlTab(index, ignoreUnattachedBuffers))
|
||||
return;
|
||||
// Remove the tab and delete the widget
|
||||
QWidget* w = ui->tabSqlAreas->widget(index);
|
||||
@@ -2462,7 +2471,7 @@ bool MainWindow::loadProject(QString filename, bool readOnly)
|
||||
|
||||
// We are going to open a new project, so close the possible current one before opening another.
|
||||
// Stop the opening process here if the user pressed the cancel button in there.
|
||||
if(!closeProject())
|
||||
if(!closeFiles())
|
||||
return false;
|
||||
|
||||
addToRecentFilesMenu(filename, readOnly);
|
||||
|
||||
@@ -111,7 +111,6 @@ private:
|
||||
void restoreOpenTabs(QString tabs);
|
||||
QString saveOpenTabs();
|
||||
void saveProject(const QString& currentFilename);
|
||||
bool closeFiles();
|
||||
bool closeProject();
|
||||
bool askSaveSqlTab(int index, bool& ignoreUnattachedBuffers);
|
||||
void focusSqlEditor();
|
||||
@@ -131,6 +130,7 @@ public slots:
|
||||
void switchToBrowseDataTab(sqlb::ObjectIdentifier tableToBrowse = sqlb::ObjectIdentifier());
|
||||
void populateStructure(const QString& old_table = QString());
|
||||
void reloadSettings();
|
||||
bool closeFiles();
|
||||
|
||||
private slots:
|
||||
void createTreeContextMenu(const QPoint & qPoint);
|
||||
@@ -165,7 +165,7 @@ private slots:
|
||||
void savePragmas();
|
||||
void mainTabSelected( int tabindex );
|
||||
int openSqlTab(bool resetCounter = false);
|
||||
void closeSqlTab(int index, bool force = false);
|
||||
void closeSqlTab(int index, bool force = false, bool askSaving = true);
|
||||
void changeSqlTab(int index);
|
||||
void openSqlFile();
|
||||
void saveSqlFile();
|
||||
|
||||
@@ -788,6 +788,7 @@ You can drag SQL statements from an object row and drop them into other applicat
|
||||
<addaction name="actionOpenProject"/>
|
||||
<addaction name="actionSaveProject"/>
|
||||
<addaction name="actionSaveProjectAs"/>
|
||||
<addaction name="actionCloseProject"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionSaveAll"/>
|
||||
<addaction name="separator"/>
|
||||
@@ -2176,6 +2177,17 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
|
||||
<string>Browse Table</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCloseProject">
|
||||
<property name="text">
|
||||
<string>Close Pro&ject</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Close project and database files and return to the initial state</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Shift+F4</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
@@ -3572,6 +3584,22 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>actionCloseProject</sender>
|
||||
<signal>triggered()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>closeFiles()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>-1</x>
|
||||
<y>-1</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>518</x>
|
||||
<y>314</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>fileOpen()</slot>
|
||||
|
||||
Reference in New Issue
Block a user