aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/mainwindow.cpp')
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/mainwindow.cpp129
1 files changed, 109 insertions, 20 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/mainwindow.cpp b/SQLiteStudio3/guiSQLiteStudio/mainwindow.cpp
index 57c7d35..b1f1f42 100644
--- a/SQLiteStudio3/guiSQLiteStudio/mainwindow.cpp
+++ b/SQLiteStudio3/guiSQLiteStudio/mainwindow.cpp
@@ -4,8 +4,6 @@
#include "dbtree/dbtreemodel.h"
#include "iconmanager.h"
#include "windows/editorwindow.h"
-#include "windows/tablewindow.h"
-#include "windows/viewwindow.h"
#include "windows/functionseditor.h"
#include "windows/collationseditor.h"
#include "windows/ddlhistorywindow.h"
@@ -13,8 +11,6 @@
#include "mdiarea.h"
#include "statusfield.h"
#include "uiconfig.h"
-#include "common/extaction.h"
-#include "dbobjectdialogs.h"
#include "services/notifymanager.h"
#include "dialogs/configdialog.h"
#include "services/pluginmanager.h"
@@ -35,12 +31,13 @@
#include "dialogs/aboutdialog.h"
#include "dialogs/newversiondialog.h"
#include "dialogs/quitconfirmdialog.h"
-#include "common/widgetcover.h"
#include "dialogs/cssdebugdialog.h"
#include "themetuner.h"
#include "style.h"
#include "services/codeformatter.h"
#include "common/compatibility.h"
+#include "windows/codesnippeteditor.h"
+#include "uiutils.h"
#include <QMdiSubWindow>
#include <QDebug>
#include <QStyleFactory>
@@ -51,6 +48,8 @@
#include <QStyle>
#include <QApplication>
#include <QToolTip>
+#include <QTimer>
+#include <QtGui>
CFG_KEYS_DEFINE(MainWindow)
MainWindow* MainWindow::instance = nullptr;
@@ -139,6 +138,30 @@ void MainWindow::init()
updateMultipleSessionsSetting();
fixFonts();
+ fixToolbars();
+ observeSessionChanges();
+
+ SQLITESTUDIO->installCrashHandler([this]()
+ {
+ saveSession();
+ });
+}
+
+void MainWindow::observeSessionChanges()
+{
+ saveSessionTimer = new QTimer(this);
+ saveSessionTimer->setSingleShot(true);
+ connect(saveSessionTimer, SIGNAL(timeout()), this, SLOT(saveSession()));
+
+ for (QDockWidget* dock : QList<QDockWidget*>({dbTree, statusField}))
+ {
+ connect(dock, SIGNAL(topLevelChanged(bool)), this, SLOT(scheduleSessionSave()));
+ connect(dock, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(scheduleSessionSave()));
+ connect(dock, SIGNAL(visibilityChanged(bool)), this, SLOT(scheduleSessionSave()));
+ }
+ connect(dbTree, SIGNAL(sessionValueChanged()), this, SLOT(scheduleSessionSave()));
+ connect(getMdiArea(), SIGNAL(sessionValueChanged()), this, SLOT(scheduleSessionSave()));
+ connect(this, SIGNAL(sessionValueChanged()), this, SLOT(scheduleSessionSave()));
}
void MainWindow::cleanUp()
@@ -186,6 +209,8 @@ void MainWindow::updateWindowActions()
actionMap[CLOSE_WINDOW]->setEnabled(hasActiveTask);
actionMap[CLOSE_OTHER_WINDOWS]->setEnabled(hasActiveTask);
actionMap[CLOSE_ALL_WINDOWS]->setEnabled(hasActiveTask);
+ actionMap[CLOSE_ALL_WINDOWS_LEFT]->setEnabled(hasActiveTask);
+ actionMap[CLOSE_ALL_WINDOWS_RIGHT]->setEnabled(hasActiveTask);
actionMap[RENAME_WINDOW]->setEnabled(hasActiveTask);
actionMap[RESTORE_WINDOW]->setEnabled(hasClosedWindowToRestore());
}
@@ -225,11 +250,13 @@ void MainWindow::closeEvent(QCloseEvent* event)
return;
}
+ saveSessionTimer->stop();
+ safe_delete(saveSessionTimer);
+
closingApp = true;
closeNonSessionWindows();
- MdiWindow* currWindow = ui->mdiArea->getCurrentWindow();
- hide();
- saveSession(currWindow);
+ saveSession(true);
+ SQLITESTUDIO->cleanUp();
QMainWindow::closeEvent(event);
}
@@ -238,6 +265,7 @@ void MainWindow::createActions()
createAction(OPEN_SQL_EDITOR, ICONS.OPEN_SQL_EDITOR, tr("Open SQL &editor"), this, SLOT(openSqlEditorSlot()), ui->mainToolBar);
createAction(OPEN_DDL_HISTORY, ICONS.DDL_HISTORY, tr("Open DDL &history"), this, SLOT(openDdlHistorySlot()), ui->mainToolBar);
createAction(OPEN_FUNCTION_EDITOR, ICONS.FUNCTION, tr("Open SQL &functions editor"), this, SLOT(openFunctionEditorSlot()), ui->mainToolBar);
+ createAction(OPEN_SNIPPETS_EDITOR, ICONS.CODE_SNIPPET, tr("Open code &snippets editor"), this, SLOT(openCodeSnippetsEditorSlot()), ui->mainToolBar);
createAction(OPEN_COLLATION_EDITOR, ICONS.CONSTRAINT_COLLATION, tr("Open &collations editor"), this, SLOT(openCollationEditorSlot()), ui->mainToolBar);
createAction(OPEN_EXTENSION_MANAGER, ICONS.EXTENSION, tr("Open ex&tension manager"), this, SLOT(openExtensionManagerSlot()), ui->mainToolBar);
createAction(IMPORT, ICONS.IMPORT, tr("&Import"), this, SLOT(importAnything()), ui->mainToolBar);
@@ -253,11 +281,13 @@ void MainWindow::createActions()
createAction(PREV_TASK, tr("Previous window"), ui->taskBar, SLOT(prevTask()), this);
createAction(HIDE_STATUS_FIELD, tr("Hide status field"), this, SLOT(hideStatusField()), this);
- createAction(CLOSE_WINDOW, ICONS.WIN_CLOSE, tr("Close selected &window"), this, SLOT(closeSelectedWindow()), this);
- createAction(CLOSE_OTHER_WINDOWS, ICONS.WIN_CLOSE_OTHER, tr("Close all windows &but selected"), this, SLOT(closeAllWindowsButSelected()), this);
+ createAction(CLOSE_WINDOW, ICONS.WIN_CLOSE, tr("Close current &window"), this, SLOT(closeSelectedWindow()), this);
+ createAction(CLOSE_OTHER_WINDOWS, ICONS.WIN_CLOSE_OTHER, tr("Close &other windows"), this, SLOT(closeAllWindowsButSelected()), this);
createAction(CLOSE_ALL_WINDOWS, ICONS.WIN_CLOSE_ALL, tr("Close &all windows"), this, SLOT(closeAllWindows()), this);
+ createAction(CLOSE_ALL_WINDOWS_LEFT, ICONS.WIN_CLOSE_ALL_LEFT, tr("Close windows on the &left"), this, SLOT(closeAllLeftWindows()), this);
+ createAction(CLOSE_ALL_WINDOWS_RIGHT, ICONS.WIN_CLOSE_ALL_RIGHT, tr("Close windows on the &right"), this, SLOT(closeAllRightWindows()), this);
createAction(RESTORE_WINDOW, ICONS.WIN_RESTORE, tr("Re&store recently closed window"), this, SLOT(restoreLastClosedWindow()), this);
- createAction(RENAME_WINDOW, ICONS.WIN_RENAME, tr("&Rename selected window"), this, SLOT(renameWindow()), this);
+ createAction(RENAME_WINDOW, ICONS.WIN_RENAME, tr("Re&name selected window"), this, SLOT(renameWindow()), this);
createAction(OPEN_DEBUG_CONSOLE, tr("Open Debug Console"), this, SLOT(openDebugConsole()), this);
createAction(OPEN_CSS_CONSOLE, tr("Open CSS Console"), this, SLOT(openCssConsole()), this);
@@ -352,8 +382,10 @@ void MainWindow::initMenuBar()
viewMenu->addAction(actionMap[MDI_CASCADE]);
viewMenu->addSeparator();
viewMenu->addAction(actionMap[CLOSE_WINDOW]);
- viewMenu->addAction(actionMap[CLOSE_OTHER_WINDOWS]);
viewMenu->addAction(actionMap[CLOSE_ALL_WINDOWS]);
+ viewMenu->addAction(actionMap[CLOSE_OTHER_WINDOWS]);
+ viewMenu->addAction(actionMap[CLOSE_ALL_WINDOWS_LEFT]);
+ viewMenu->addAction(actionMap[CLOSE_ALL_WINDOWS_RIGHT]);
viewMenu->addSeparator();
viewMenu->addAction(actionMap[RESTORE_WINDOW]);
viewMenu->addAction(actionMap[RENAME_WINDOW]);
@@ -369,6 +401,7 @@ void MainWindow::initMenuBar()
toolsMenu->addAction(actionMap[OPEN_SQL_EDITOR]);
toolsMenu->addAction(actionMap[OPEN_DDL_HISTORY]);
toolsMenu->addAction(actionMap[OPEN_FUNCTION_EDITOR]);
+ toolsMenu->addAction(actionMap[OPEN_SNIPPETS_EDITOR]);
toolsMenu->addAction(actionMap[OPEN_COLLATION_EDITOR]);
toolsMenu->addAction(actionMap[OPEN_EXTENSION_MANAGER]);
toolsMenu->addAction(actionMap[IMPORT]);
@@ -448,10 +481,16 @@ void MainWindow::restoreSession()
}
if (sessionValue.contains("style"))
- setStyle(sessionValue["style"].toString());
+ {
+ QString styleName = sessionValue["style"].toString();
+ setStyle(styleName);
+ }
else
THEME_TUNER->tuneCurrentTheme();
+ QString styleName = currentStyle();
+ CFG_UI.General.Style.set(styleName);
+
if (sessionValue.contains("geometry"))
restoreGeometry(sessionValue["geometry"].toByteArray());
@@ -533,22 +572,24 @@ MdiWindow* MainWindow::restoreWindowSession(const QVariant &windowSessions)
{
window->setCloseWithoutSessionSaving(true);
delete window;
+ return nullptr;
}
return window;
}
-void MainWindow::setStyle(const QString& styleName)
+bool MainWindow::setStyle(const QString& styleName)
{
QStyle* style = QStyleFactory::create(styleName);
if (!style)
{
notifyWarn(tr("Could not set style: %1", "main window").arg(styleName));
- return;
+ return false;
}
STYLE->setStyle(style, styleName);
statusField->refreshColors();
+ return true;
}
QString MainWindow::currentStyle() const
@@ -570,12 +611,33 @@ EditorWindow* MainWindow::openSqlEditor(Db* dbToSet, const QString& sql)
return win;
}
+void MainWindow::saveSession(bool hide)
+{
+ MdiWindow* currWindow = ui->mdiArea->getCurrentWindow();
+ if (hide)
+ this->hide();
+
+ saveSession(currWindow);
+}
+
+void MainWindow::saveSession()
+{
+ saveSession(false);
+}
+
+void MainWindow::scheduleSessionSave()
+{
+ if (saveSessionTimer)
+ saveSessionTimer->start(saveSessionDelayMs);
+}
+
void MainWindow::closeNonSessionWindows()
{
for (MdiWindow* window : ui->mdiArea->getWindows())
if (!window->restoreSessionNextTime())
window->close();
}
+
FormManager* MainWindow::getFormManager() const
{
return formManager;
@@ -607,6 +669,7 @@ void MainWindow::refreshMdiWindows()
for (const QString& name : actionNames)
mdiMenu->addAction(nameToAction[name]);
+ fixToolbarTooltips(ui->viewToolbar);
updateWindowActions();
}
@@ -632,6 +695,11 @@ void MainWindow::openFunctionEditorSlot()
openFunctionEditor();
}
+void MainWindow::openCodeSnippetsEditorSlot()
+{
+ openCodeSnippetEditor();
+}
+
void MainWindow::openCollationEditorSlot()
{
openCollationEditor();
@@ -679,6 +747,16 @@ void MainWindow::closeAllWindows()
ui->mdiArea->closeAllSubWindows();
}
+void MainWindow::closeAllLeftWindows()
+{
+ ui->mdiArea->closeAllLeftToActive();
+}
+
+void MainWindow::closeAllRightWindows()
+{
+ ui->mdiArea->closeAllRightToActive();
+}
+
void MainWindow::closeAllWindowsButSelected()
{
ui->mdiArea->closeAllButActive();
@@ -784,14 +862,12 @@ void MainWindow::quit()
void MainWindow::updateMultipleSessionsSetting(const QVariant& newValue)
{
- QSettings sett;
- sett.setValue(ALLOW_MULTIPLE_SESSIONS_SETTING, newValue);
+ Config::getSettings()->setValue(ALLOW_MULTIPLE_SESSIONS_SETTING, newValue);
}
void MainWindow::updateMultipleSessionsSetting()
{
- QSettings sett;
- sett.setValue(ALLOW_MULTIPLE_SESSIONS_SETTING, CFG_UI.General.AllowMultipleSessions.get());
+ Config::getSettings()->setValue(ALLOW_MULTIPLE_SESSIONS_SETTING, CFG_UI.General.AllowMultipleSessions.get());
}
#ifdef PORTABLE_CONFIG
@@ -859,6 +935,11 @@ FunctionsEditor* MainWindow::openFunctionEditor()
return openMdiWindow<FunctionsEditor>();
}
+CodeSnippetEditor* MainWindow::openCodeSnippetEditor()
+{
+ return openMdiWindow<CodeSnippetEditor>();
+}
+
CollationsEditor* MainWindow::openCollationEditor()
{
return openMdiWindow<CollationsEditor>();
@@ -876,10 +957,18 @@ void MainWindow::fixFonts()
{
typed = dynamic_cast<CfgTypedEntry<QFont>*>(cfg);
if (typed->get().pointSize() == 0)
- cfg->set(cfg->getDefultValue());
+ cfg->set(cfg->getDefaultValue());
}
}
+void MainWindow::fixToolbars()
+{
+ fixToolbarTooltips(ui->viewToolbar);
+ fixToolbarTooltips(ui->mainToolBar);
+ fixToolbarTooltips(ui->structureToolbar);
+ fixToolbarTooltips(ui->dbToolbar);
+}
+
bool MainWindow::confirmQuit(const QList<Committable*>& instances)
{
QuitConfirmDialog dialog(MAINWINDOW);