diff --git a/CHANGELOG b/CHANGELOG index d5049af36..350635c8d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ Version 1.5.4 * - fixed FIL marker in LOG doesn't handle relative filepaths - parse port for GAMS Engine URL - fixed syntax highlighting for standard eolCom in table definition +- instantly follow macOS theme changes (delayed on visible settings dialog) Version 1.5.3 ================== diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b17e97127..65dda77fa 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -270,6 +270,7 @@ MainWindow::MainWindow(QWidget *parent) ViewHelper::changeAppearance(); connect(Theme::instance(), &Theme::changed, this, &MainWindow::invalidateTheme); invalidateTheme(); + ViewHelper::updateBaseTheme(); initGamsStandardPaths(); updateRunState(); @@ -448,10 +449,11 @@ bool MainWindow::event(QEvent *event) } else if (event->type() == QEvent::WindowActivate) { processFileEvents(); } else if (event->type() == QEvent::ApplicationPaletteChange) { -#ifdef __APPLE__ - // reload theme when switching OS theme - Theme::instance()->setActiveTheme(MacOSCocoaBridge::isDarkMode() ? 1 : 0); -#endif + if (!mSettingsDialog || !mSettingsDialog->preventThemeChaning()) + ViewHelper::updateBaseTheme(); + else { + mSettingsDialog->delayBaseThemeChange(true); + } } return QMainWindow::event(event); } @@ -3742,6 +3744,11 @@ void MainWindow::on_actionSettings_triggered() connect(mSettingsDialog, &SettingsDialog::editorLineWrappingChanged, this, &MainWindow::updateEditorLineWrapping); connect(mSettingsDialog, &SettingsDialog::finished, this, [this]() { updateAndSaveSettings(); + if (mSettingsDialog->hasDelayedBaseThemeChange()) { + mSettingsDialog->delayBaseThemeChange(false); + ViewHelper::updateBaseTheme(); + } + if (mSettingsDialog->miroSettingsEnabled()) updateMiroEnabled(); }); diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 7127792bd..887c46098 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -31,9 +31,6 @@ #include "themewidget.h" #include "viewhelper.h" -#ifdef __APPLE__ -#include "../platform/macos/macoscocoabridge.h" -#endif namespace gams { namespace studio { @@ -194,6 +191,17 @@ void SettingsDialog::setMiroSettingsEnabled(bool enabled) ui->miroBrowseButton->setEnabled(enabled); } +bool SettingsDialog::preventThemeChaning() +{ + if (isVisible()) return true; + return false; +} + +bool SettingsDialog::hasDelayedBaseThemeChange() +{ + return mDelayedBaseThemeChange; +} + // save settings from ui to qsettings void SettingsDialog::saveSettings() { @@ -377,6 +385,11 @@ bool SettingsDialog::eventFilter(QObject *watched, QEvent *event) return false; } +void SettingsDialog::delayBaseThemeChange(bool valid) +{ + mDelayedBaseThemeChange = valid; +} + SettingsDialog::~SettingsDialog() { mSettings->unblock(); diff --git a/src/settingsdialog.h b/src/settingsdialog.h index d7f533ed3..a43478c29 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -45,6 +45,8 @@ class SettingsDialog : public QDialog bool miroSettingsEnabled() const; void setMiroSettingsEnabled(bool enabled); + bool preventThemeChaning(); + bool hasDelayedBaseThemeChange(); protected: void closeEvent(QCloseEvent *event) override; @@ -55,6 +57,9 @@ class SettingsDialog : public QDialog void editorLineWrappingChanged(); void themeChanged(); +public slots: + void delayBaseThemeChange(bool valid); + private slots: void on_buttonBox_clicked(QAbstractButton *button); void on_tabWidget_currentChanged(int index); @@ -88,6 +93,7 @@ private slots: bool mInitializing = true; QList mColorWidgets; int mFixedThemeCount = 0; + bool mDelayedBaseThemeChange = false; bool mMiroSettingsEnabled = true; void saveSettings(); diff --git a/src/viewhelper.cpp b/src/viewhelper.cpp index 7d9a05873..5430bb01b 100644 --- a/src/viewhelper.cpp +++ b/src/viewhelper.cpp @@ -21,6 +21,10 @@ #include "colors/palettemanager.h" #include "settings.h" +#ifdef __APPLE__ +#include "../platform/macos/macoscocoabridge.h" +#endif + #include namespace gams { @@ -89,6 +93,19 @@ void ViewHelper::setLocation(QWidget *widget, QString location) } } +bool ViewHelper::updateBaseTheme() +{ + int currentTheme = Theme::instance()->activeTheme(); +#ifdef __APPLE__ + Theme::instance()->setActiveTheme(MacOSCocoaBridge::isDarkMode() ? 1 : 0); + if (currentTheme != Theme::instance()->activeTheme()) { + Settings::settings()->setInt(skEdAppearance, Theme::instance()->activeTheme()); + Settings::settings()->save(); + } +#endif + return currentTheme != Theme::instance()->activeTheme(); +} + /// /// \brief ViewHelper::setAppearance sets and saves the appearance /// \param appearance diff --git a/src/viewhelper.h b/src/viewhelper.h index da4f7147b..23fbfd96b 100644 --- a/src/viewhelper.h +++ b/src/viewhelper.h @@ -139,6 +139,7 @@ class ViewHelper << "Text files (*.txt)" << "All files (*.*)"; } + static bool updateBaseTheme(); static void setAppearance(int appearance = -1); static void changeAppearance(int appearance = -1);