mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-05-11 14:30:17 -05:00
Closable main tabs and saving automatically open tabs and order
Main tabs are made closable, so they can be closed by the user. New entries are added to the View menu for toggling their open/closed state. Spartan users can closed all tabs but their preferred, and then the tab bar is hidden saving some space. The set of open tabs and their order is automatically saved in the settings on application exit and restored on application start. Tab labels are stored in the statusTip attribute in order to restore them, since those labels are not stored anywhere else. See issues #1675 and #459
This commit is contained in:
@@ -222,6 +222,19 @@ void MainWindow::init()
|
||||
restoreGeometry(Settings::getValue("MainWindow", "geometry").toByteArray());
|
||||
restoreState(Settings::getValue("MainWindow", "windowState").toByteArray());
|
||||
|
||||
// Restore open tab order if the openTabs setting is saved.
|
||||
// Clear the tabs and then add them in the order specified by the setting.
|
||||
// Use the statusTip attribute for restoring the tab label.
|
||||
if (!Settings::getValue("MainWindow", "openTabs").toString().isEmpty()) {
|
||||
ui->mainTab->clear();
|
||||
for (QString objectName : Settings::getValue("MainWindow", "openTabs").toString().split(' ')) {
|
||||
for (QWidget* widget : {ui->structure, ui->browser, ui->pragmas, ui->query})
|
||||
if (widget->objectName() == objectName) {
|
||||
ui->mainTab->addTab(widget, widget->statusTip());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Restore dock state settings
|
||||
ui->comboLogSubmittedBy->setCurrentIndex(ui->comboLogSubmittedBy->findText(Settings::getValue("SQLLogDock", "Log").toString()));
|
||||
|
||||
@@ -335,6 +348,25 @@ void MainWindow::init()
|
||||
// Add separator between docks and toolbars
|
||||
ui->viewMenu->insertSeparator(ui->viewDBToolbarAction);
|
||||
|
||||
// Connect the tabCloseRequested to the actual closeTab function.
|
||||
// This must be done before the connections for checking the actions in the View menu so
|
||||
// they are updated accordingly.
|
||||
connect(ui->mainTab, &QTabWidget::tabCloseRequested, this, &MainWindow::closeTab);
|
||||
|
||||
// Add entries for toggling the visibility of main tabs
|
||||
for (QWidget* widget : {ui->structure, ui->browser, ui->pragmas, ui->query}) {
|
||||
QAction* action = ui->viewMenu->addAction(QIcon(":/icons/tab"), widget->statusTip());
|
||||
action->setCheckable(true);
|
||||
action->setChecked(ui->mainTab->indexOf(widget) != -1);
|
||||
connect(action, &QAction::toggled, [=](bool show) { toggleTabVisible(widget, show); });
|
||||
// Connect tabCloseRequested for setting checked the appropiate menu entry.
|
||||
// Note these are called after the actual tab is closed only because they are connected
|
||||
// after connecting closeTab.
|
||||
connect(ui->mainTab, &QTabWidget::tabCloseRequested, [=](int index) {
|
||||
action->setChecked(ui->mainTab->indexOf(widget) != -1);
|
||||
});
|
||||
}
|
||||
|
||||
// If we're not compiling in SQLCipher, hide its FAQ link in the help menu
|
||||
#ifndef ENABLE_SQLCIPHER
|
||||
ui->actionSqlCipherFaq->setVisible(false);
|
||||
@@ -896,6 +928,12 @@ void MainWindow::closeEvent( QCloseEvent* event )
|
||||
{
|
||||
Settings::setValue("MainWindow", "geometry", saveGeometry());
|
||||
Settings::setValue("MainWindow", "windowState", saveState());
|
||||
|
||||
QString openTabs;
|
||||
for (int i=0; i < ui->mainTab->count(); i++)
|
||||
openTabs.append(ui->mainTab->widget(i)->objectName() + ' ');
|
||||
Settings::setValue("MainWindow", "openTabs", openTabs);
|
||||
|
||||
Settings::setValue("SQLLogDock", "Log", ui->comboLogSubmittedBy->currentText());
|
||||
Settings::setValue("SchemaDock", "dropQualifiedNames", ui->actionDropQualifiedCheck->isChecked());
|
||||
Settings::setValue("SchemaDock", "dropEnquotedNames", ui->actionEnquoteNamesCheck->isChecked());
|
||||
@@ -3694,3 +3732,17 @@ void MainWindow::updateDatabaseBusyStatus(bool busy, const QString& user)
|
||||
statusBusyLabel->setVisible(busy);
|
||||
statusStopButton->setVisible(busy);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::closeTab(int index)
|
||||
{
|
||||
ui->mainTab->removeTab(index);
|
||||
}
|
||||
|
||||
void MainWindow::toggleTabVisible(QWidget* tabWidget, bool show)
|
||||
{
|
||||
if (show)
|
||||
ui->mainTab->addTab(tabWidget, tabWidget->statusTip());
|
||||
else
|
||||
ui->mainTab->removeTab(ui->mainTab->indexOf(tabWidget));
|
||||
}
|
||||
|
||||
@@ -187,6 +187,7 @@ private:
|
||||
sqlb::ObjectIdentifier currentlyBrowsedTableName() const;
|
||||
|
||||
void applyBrowseTableSettings(BrowseDataTableSettings storedData, bool skipFilters = false);
|
||||
void toggleTabVisible(QWidget* tabWidget, bool show);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *) override;
|
||||
@@ -298,6 +299,7 @@ private slots:
|
||||
void printDbStructure();
|
||||
void updateDatabaseBusyStatus(bool busy, const QString& user);
|
||||
void openPreferences();
|
||||
void closeTab(int index);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+21
-2
@@ -24,10 +24,19 @@
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="tabsClosable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="movable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="tabBarAutoHide">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="structure">
|
||||
<property name="statusTip">
|
||||
<string extracomment="This has to be equal to the tab title in all the main tabs">Database Structure</string>
|
||||
</property>
|
||||
<attribute name="title">
|
||||
<string>Database Structure</string>
|
||||
</attribute>
|
||||
@@ -93,6 +102,9 @@ You can drag SQL statements from an object row and drop them into other applicat
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="browser">
|
||||
<property name="statusTip">
|
||||
<string extracomment="This has to be equal to the tab title in all the main tabs">Browse Data</string>
|
||||
</property>
|
||||
<attribute name="title">
|
||||
<string>Browse Data</string>
|
||||
</attribute>
|
||||
@@ -431,6 +443,9 @@ You can drag SQL statements from an object row and drop them into other applicat
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="pragmas">
|
||||
<property name="statusTip">
|
||||
<string extracomment="This has to be equal to the tab title in all the main tabs">Edit Pragmas</string>
|
||||
</property>
|
||||
<attribute name="title">
|
||||
<string>Edit Pragmas</string>
|
||||
</attribute>
|
||||
@@ -445,8 +460,8 @@ You can drag SQL statements from an object row and drop them into other applicat
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>601</width>
|
||||
<height>484</height>
|
||||
<width>572</width>
|
||||
<height>510</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
@@ -946,6 +961,9 @@ You can drag SQL statements from an object row and drop them into other applicat
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="query">
|
||||
<property name="statusTip">
|
||||
<string extracomment="This has to be equal to the tab title in all the main tabs">Execute SQL</string>
|
||||
</property>
|
||||
<attribute name="title">
|
||||
<string>Execute SQL</string>
|
||||
</attribute>
|
||||
@@ -1056,6 +1074,7 @@ You can drag SQL statements from an object row and drop them into other applicat
|
||||
<addaction name="viewDBToolbarAction"/>
|
||||
<addaction name="viewExtraDBToolbarAction"/>
|
||||
<addaction name="viewProjectToolbarAction"/>
|
||||
<addaction name="separator"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="helpMenu">
|
||||
<property name="title">
|
||||
|
||||
@@ -138,6 +138,10 @@ QVariant Settings::getDefaultValue(const QString& group, const QString& name)
|
||||
if(group == "MainWindow" && name == "windowState")
|
||||
return "";
|
||||
|
||||
// MainWindow/openTabs?
|
||||
if(group == "MainWindow" && name == "openTabs")
|
||||
return "";
|
||||
|
||||
// SQLLogDock/Log?
|
||||
if(group == "SQLLogDock" && name == "Log")
|
||||
return "Application";
|
||||
|
||||
@@ -71,5 +71,6 @@
|
||||
<file alias="cancel">cancel.png</file>
|
||||
<file alias="comment_block">comment_block.png</file>
|
||||
<file alias="hourglass">hourglass.png</file>
|
||||
<file alias="tab">tab.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 323 B |
Reference in New Issue
Block a user