Skip to content

Commit

Permalink
New action "Save All"
Browse files Browse the repository at this point in the history
New action "Save All" for saving all the files currently opened by the
application: DB file, SQL files and project file. Can be activated through
shortcut (Ctrl+Shift+S) and File menu.

Icon composed from package.png and database_save.png.

See issues sqlitebrowser#871 and sqlitebrowser#1706
  • Loading branch information
mgrojo committed Jan 18, 2019
1 parent f08cdb1 commit a149399
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2156,10 +2156,6 @@ bool MainWindow::askSaveSqlTab(int index, bool& ignoreUnattachedBuffers)
break;
}
} else if(!sqlExecArea->fileName().isEmpty()) {
// Set the tab as current. This is both for user feedback as well as for saveSqlFile(),
// which requires the file to be saved to be in the current tab.
ui->tabSqlAreas->setCurrentIndex(index);

QMessageBox::StandardButton reply =
QMessageBox::question(nullptr,
QApplication::applicationName(),
Expand All @@ -2168,7 +2164,7 @@ bool MainWindow::askSaveSqlTab(int index, bool& ignoreUnattachedBuffers)
QMessageBox::Save | QMessageBox::No | QMessageBox::Cancel);
switch(reply) {
case QMessageBox::Save:
saveSqlFile();
saveSqlFile(index);
break;
case QMessageBox::Cancel:
return false;
Expand Down Expand Up @@ -2285,9 +2281,9 @@ void MainWindow::openSqlFile()
}
}

void MainWindow::saveSqlFile()
void MainWindow::saveSqlFile(int tabIndex)
{
SqlExecutionArea* sqlarea = qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->currentWidget());
SqlExecutionArea* sqlarea = qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->widget(tabIndex));
if(!sqlarea)
return;

Expand All @@ -2310,6 +2306,11 @@ void MainWindow::saveSqlFile()
}
}

void MainWindow::saveSqlFile()
{
saveSqlFile(ui->tabSqlAreas->currentIndex());
}

void MainWindow::saveSqlFileAs()
{
SqlExecutionArea* sqlarea = qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->currentWidget());
Expand Down Expand Up @@ -3901,3 +3902,16 @@ void MainWindow::showStatusMessage5s(QString message)
{
ui->statusbar->showMessage(message, 5000);
}

void MainWindow::saveAll()
{
for(int i=0; i<ui->tabSqlAreas->count(); i++) {
SqlExecutionArea* sqlExecArea = qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->widget(i));
if(sqlExecArea->getEditor()->isModified() && !sqlExecArea->fileName().isEmpty())
saveSqlFile(i);
}
if(!currentProjectFilename.isEmpty())
saveProject();
fileSave();

}
2 changes: 2 additions & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ private slots:
void openPreferences();
void closeTab(int index);
void showStatusMessage5s(QString message);
void saveSqlFile(int tabIndex);
void saveAll();
};

#endif
45 changes: 45 additions & 0 deletions src/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,8 @@ You can drag SQL statements from an object row and drop them into other applicat
<addaction name="actionSaveProject"/>
<addaction name="actionSaveProjectAs"/>
<addaction name="separator"/>
<addaction name="actionSaveAll"/>
<addaction name="separator"/>
<addaction name="fileExitAction"/>
</widget>
<widget class="QMenu" name="editMenu">
Expand Down Expand Up @@ -2455,6 +2457,33 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
<property name="toolTip">
<string>Save the project in a file selected in a dialog</string>
</property>
<property name="statusTip">
<string>Save the project in a file selected in a dialog</string>
</property>
<property name="whatsThis">
<string>Save the project in a file selected in a dialog</string>
</property>
</action>
<action name="actionSaveAll">
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/save_all</normaloff>:/icons/save_all</iconset>
</property>
<property name="text">
<string>Save A&amp;ll</string>
</property>
<property name="toolTip">
<string>Save DB file, project file and opened SQL files</string>
</property>
<property name="statusTip">
<string>Save DB file, project file and opened SQL files</string>
</property>
<property name="whatsThis">
<string>Save DB file, project file and opened SQL files</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+S</string>
</property>
</action>
</widget>
<customwidgets>
Expand Down Expand Up @@ -4205,6 +4234,22 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
</hint>
</hints>
</connection>
<connection>
<sender>actionSaveAll</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>saveAll()</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>
Expand Down
1 change: 1 addition & 0 deletions src/icons/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@
<file alias="tab">tab.png</file>
<file alias="project_save_as">package_rename.png</file>
<file alias="field_fk">page_foreign_key.png</file>
<file alias="save_all">save_all.png</file>
</qresource>
</RCC>
Binary file added src/icons/save_all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a149399

Please sign in to comment.