commit fc7ca433adb54a90b441c9e32e700cf68fdc6544
Author: Koji Yokota <[email protected]>
Date:   Fri Aug 29 13:54:53 2025 +0900

    Amend dialog behaviour after import or removal of a theme
---
 src/frontends/qt/GuiPrefs.cpp | 34 +++++++++++++++++++++++++---------
 src/frontends/qt/GuiPrefs.h   |  2 +-
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/src/frontends/qt/GuiPrefs.cpp b/src/frontends/qt/GuiPrefs.cpp
index aad11c5cc5..48e6bbcb70 100644
--- a/src/frontends/qt/GuiPrefs.cpp
+++ b/src/frontends/qt/GuiPrefs.cpp
@@ -1094,8 +1094,7 @@ void PrefColors::applyRC(LyXRC & rc) const
        LyXRC oldrc = rc;
 
        for (unsigned int i = 0; i < lcolors_.size(); ++i)
-               if (curcolors_[i] != newcolors_[i])
-                       form_->setColor(lcolors_[i], newcolors_[i]);
+               form_->setColor(lcolors_[i], newcolors_[i]);
        rc.use_system_colors = syscolorsCB->isChecked();
 
        if (toqstr(rc.ui_theme) != theme_name_)
@@ -1556,14 +1555,21 @@ void PrefColors::importTheme()
        // copy to user theme dir
        import_file.copy(toqstr(target_file_path));
 
+       // list up all theme files in the themes directory in themesLW
        initializeThemesLW();
+       // cache all themes in themesLW
+       cacheAllThemes();
+       // update theme indicator
+       selectCurrentTheme(theme_name_, true);
+
        ColorNamePairs colors = readTheme(FileName(fromqstr(file_path)));
-       loadImportThemeCommon(colors);
        theme_colors_ = newcolors_ = colors;
        theme_filename_ = onlyFileName(toqstr(target_file_path));
        theme_name_ = removeExtension(theme_filename_).replace('_', ' ');
        initial_edit_ = true;
 
+       loadImportThemeCommon(colors);
+
        return;
 }
 
@@ -1674,11 +1680,12 @@ void PrefColors::removeTheme()
        msgBox.setDefaultButton(QMessageBox::No);
 
        if (msgBox.exec() == QMessageBox::Yes) {
+               dismissCurrentTheme();
                QFile file(theme_fullpaths_[cur_row]);
                file.remove();
                theme_name_ = "";
                initializeThemesLW();
-               dismissCurrentTheme();
+               cacheAllThemes();
                initial_edit_ = true;
        }
 }
@@ -1774,10 +1781,10 @@ void PrefColors::initializeThemesLW()
 }
 
 
-void PrefColors::selectCurrentTheme(QString theme_name_en)
+void PrefColors::selectCurrentTheme(QString theme_name_en, bool 
user_theme_only)
 {
        // note that themesLW->findItems() matches translated theme name
-       // whereas theme_name contains untranslated one
+       // whereas theme_name_en contains untranslated one
        ThemeNameDic::iterator dic_it = theme_name_dic_.find(theme_name_en);
        QString translated_name;
        if (dic_it != theme_name_dic_.end())
@@ -1787,10 +1794,19 @@ void PrefColors::selectCurrentTheme(QString 
theme_name_en)
 
        QList<QListWidgetItem *> selected_items =
                themesLW->findItems(translated_name, Qt::MatchExactly);
-       if (!selected_items.empty())
-               themesLW->setCurrentItem(selected_items.first());
-       else
+       if (selected_items.empty())
                dismissCurrentTheme();
+       else if (user_theme_only) {
+               bool found = false;
+               for (auto item : std::as_const(selected_items))
+                       if (isSysThemes_[themesLW->row(item)] == false) {
+                               themesLW->setCurrentItem(item);
+                               found = true;
+                               break;
+                       }
+               LATTEST(found);
+       } else
+               themesLW->setCurrentItem(selected_items.first());
 }
 
 
diff --git a/src/frontends/qt/GuiPrefs.h b/src/frontends/qt/GuiPrefs.h
index 3897ad641a..09a60febaf 100644
--- a/src/frontends/qt/GuiPrefs.h
+++ b/src/frontends/qt/GuiPrefs.h
@@ -346,7 +346,7 @@ private:
        void initializeColorsTV();
        /// Find a theme name of the current color set and indicates it in 
themesLW
        /// if there is a match.
-       void selectCurrentTheme(QString theme_name_en);
+       void selectCurrentTheme(QString theme_name_en, bool user_theme_only = 
false);
        ///
        void cacheAllThemes();
        ///
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to