From 0b2b6a0dc700c86ca6af30d4a9c3d9445acca9fb Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 27 May 2017 15:40:06 +0200 Subject: [PATCH] Only one instance of the settings dialog should be open at once --- widgets/notebook.cpp | 4 +--- widgets/notebookbutton.h | 1 + widgets/settingsdialog.cpp | 12 +++++++++++- widgets/settingsdialog.h | 2 ++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/widgets/notebook.cpp b/widgets/notebook.cpp index ceb348c46..93b9930f1 100644 --- a/widgets/notebook.cpp +++ b/widgets/notebook.cpp @@ -181,9 +181,7 @@ void Notebook::resizeEvent(QResizeEvent *) void Notebook::settingsButtonClicked() { - SettingsDialog *a = new SettingsDialog(); - - a->show(); + SettingsDialog::showDialog(); } void Notebook::usersButtonClicked() diff --git a/widgets/notebookbutton.h b/widgets/notebookbutton.h index 3a3fa6186..22ecb86e0 100644 --- a/widgets/notebookbutton.h +++ b/widgets/notebookbutton.h @@ -33,6 +33,7 @@ private: bool _mouseDown = false; QPoint _mousePos; }; + } // namespace widgets } // namespace chatterino diff --git a/widgets/settingsdialog.cpp b/widgets/settingsdialog.cpp index 21c175d40..ff475cd8b 100644 --- a/widgets/settingsdialog.cpp +++ b/widgets/settingsdialog.cpp @@ -1,6 +1,6 @@ #include "widgets/settingsdialog.h" -#include "twitch/twitchaccount.h" #include "accountmanager.h" +#include "twitch/twitchaccount.h" #include "widgets/settingsdialogtab.h" #include "windowmanager.h" @@ -299,6 +299,16 @@ void SettingsDialog::select(SettingsDialogTab *tab) _selectedTab = tab; } +void SettingsDialog::showDialog() +{ + static SettingsDialog *instance = new SettingsDialog(); + + instance->show(); + instance->activateWindow(); + instance->raise(); + instance->setFocus(); +} + /// Widget creation helpers QCheckBox *SettingsDialog::createCheckbox(const QString &title, Setting &setting) { diff --git a/widgets/settingsdialog.h b/widgets/settingsdialog.h index edd74b6e0..4ad7e4649 100644 --- a/widgets/settingsdialog.h +++ b/widgets/settingsdialog.h @@ -26,6 +26,8 @@ public: void select(SettingsDialogTab *tab); + static void showDialog(); + private: SettingsSnapshot _snapshot;