mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-05-01 01:19:15 -05:00
"Save Project" to remember filename and new "Save Project As" action
"Save Project" remembers used filename, at second and successive calls the user is not asked for the filename. Ellipsis are removed, since it only opens a dialog the first time. A Wait Cursor is set while saving so the user does not get the impression that pressing "Save Project" does nothing. "Save Project As" action is added, so the user can still save to another filename when saved for the first time. Added icon combining package.png and textfield_rename.png from the Silk icon set. The base filename for a new project does not include the DB suffix. Problems saving the project file are detected and the user warned. See issue #1706
This commit is contained in:
+36
-4
@@ -590,6 +590,7 @@ bool MainWindow::fileOpen(const QString& fileName, bool dontAddToRecentFiles, bo
|
||||
statusEncryptionLabel->setVisible(db.encrypted());
|
||||
statusReadOnlyLabel->setVisible(db.readOnly());
|
||||
setCurrentFile(wFile);
|
||||
currentProjectFilename.clear();
|
||||
if(!dontAddToRecentFiles)
|
||||
addToRecentFilesMenu(wFile);
|
||||
openSqlTab(true);
|
||||
@@ -1961,6 +1962,7 @@ void MainWindow::activateFields(bool enable)
|
||||
ui->actionLoadExtension->setEnabled(enable);
|
||||
ui->actionSqlExecuteLine->setEnabled(enable);
|
||||
ui->actionSaveProject->setEnabled(enable && !tempDb);
|
||||
ui->actionSaveProjectAs->setEnabled(enable && !tempDb);
|
||||
ui->actionEncryption->setEnabled(enable && write && !tempDb);
|
||||
ui->actionIntegrityCheck->setEnabled(enable);
|
||||
ui->actionQuickCheck->setEnabled(enable);
|
||||
@@ -2766,6 +2768,8 @@ bool MainWindow::loadProject(QString filename, bool readOnly)
|
||||
}
|
||||
|
||||
file.close();
|
||||
currentProjectFilename = filename;
|
||||
|
||||
return !xml.hasError();
|
||||
} else {
|
||||
// No project was opened
|
||||
@@ -2865,14 +2869,22 @@ static void saveBrowseDataTableSettings(const BrowseDataTableSettings& object, Q
|
||||
xml.writeEndElement();
|
||||
}
|
||||
|
||||
void MainWindow::saveProject()
|
||||
QString MainWindow::saveProject(const QString& currentFilename)
|
||||
{
|
||||
QString filename = FileDialog::getSaveFileName(
|
||||
QString filename;
|
||||
if(currentFilename.isEmpty()) {
|
||||
QString basePathName = db.currentFile();
|
||||
// Remove database suffix
|
||||
basePathName.chop(QFileInfo(basePathName).suffix().size()+1);
|
||||
filename = FileDialog::getSaveFileName(
|
||||
CreateProjectFile,
|
||||
this,
|
||||
tr("Choose a filename to save under"),
|
||||
tr("DB Browser for SQLite project file (*.sqbpro)"),
|
||||
db.currentFile());
|
||||
basePathName);
|
||||
} else
|
||||
filename = currentFilename;
|
||||
|
||||
if(!filename.isEmpty())
|
||||
{
|
||||
// Make sure the file has got a .sqbpro ending
|
||||
@@ -2880,7 +2892,14 @@ void MainWindow::saveProject()
|
||||
filename.append(".sqbpro");
|
||||
|
||||
QFile file(filename);
|
||||
file.open(QFile::WriteOnly | QFile::Text);
|
||||
bool opened = file.open(QFile::WriteOnly | QFile::Text);
|
||||
if(!opened) {
|
||||
QMessageBox::warning(this, qApp->applicationName(),
|
||||
tr("Could not open project file for writing.\nReason: %1").arg(file.errorString()));
|
||||
return QString();
|
||||
}
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
QXmlStreamWriter xml(&file);
|
||||
xml.writeStartDocument();
|
||||
xml.writeStartElement("sqlb_project");
|
||||
@@ -2979,8 +2998,21 @@ void MainWindow::saveProject()
|
||||
xml.writeEndElement();
|
||||
xml.writeEndDocument();
|
||||
file.close();
|
||||
|
||||
addToRecentFilesMenu(filename);
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
void MainWindow::saveProject()
|
||||
{
|
||||
currentProjectFilename = saveProject(currentProjectFilename);
|
||||
}
|
||||
|
||||
void MainWindow::saveProjectAs()
|
||||
{
|
||||
currentProjectFilename = saveProject(QString());
|
||||
}
|
||||
|
||||
void MainWindow::fileAttach()
|
||||
|
||||
@@ -166,6 +166,8 @@ private:
|
||||
QString defaultOpenTabs;
|
||||
QByteArray defaultWindowState;
|
||||
|
||||
QString currentProjectFilename;
|
||||
|
||||
void init();
|
||||
void clearCompleterModelsFields();
|
||||
|
||||
@@ -185,6 +187,7 @@ private:
|
||||
void toggleTabVisible(QWidget* tabWidget, bool show);
|
||||
void restoreOpenTabs(QString tabs);
|
||||
QString saveOpenTabs();
|
||||
QString saveProject(const QString& currentFilename);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *) override;
|
||||
@@ -265,6 +268,7 @@ private slots:
|
||||
void updateBrowseDataColumnWidth(int section, int /*old_size*/, int new_size);
|
||||
bool loadProject(QString filename = QString(), bool readOnly = false);
|
||||
void saveProject();
|
||||
void saveProjectAs();
|
||||
void fileAttach();
|
||||
void updateFilter(int column, const QString& value);
|
||||
void addCondFormat(int column, const QString& value);
|
||||
|
||||
+30
-1
@@ -1052,6 +1052,7 @@ You can drag SQL statements from an object row and drop them into other applicat
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionOpenProject"/>
|
||||
<addaction name="actionSaveProject"/>
|
||||
<addaction name="actionSaveProjectAs"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="fileExitAction"/>
|
||||
</widget>
|
||||
@@ -1880,7 +1881,7 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
|
||||
<normaloff>:/icons/project_save</normaloff>:/icons/project_save</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Sa&ve Project...</string>
|
||||
<string>Sa&ve Project</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Save the current session to a file</string>
|
||||
@@ -2443,6 +2444,18 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
|
||||
<string>Stop the currently running SQL script</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSaveProjectAs">
|
||||
<property name="icon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
<normaloff>:/icons/project_save_as</normaloff>:/icons/project_save_as</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Save Project As...</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Save the project in a file selected in a dialog</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
@@ -4176,6 +4189,22 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>actionSaveProjectAs</sender>
|
||||
<signal>triggered()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>saveProjectAs()</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>
|
||||
|
||||
@@ -72,5 +72,6 @@
|
||||
<file alias="comment_block">comment_block.png</file>
|
||||
<file alias="hourglass">hourglass.png</file>
|
||||
<file alias="tab">tab.png</file>
|
||||
<file alias="project_save_as">package_rename.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 637 B |
Reference in New Issue
Block a user