cui/source/options/optchart.cxx |   65 ++++++++++++++++++++++++++++------------
 1 file changed, 47 insertions(+), 18 deletions(-)

New commits:
commit 7c836d8722a032ebc586a709659dffb15cbf84a6
Author:     Jim Raykowski <[email protected]>
AuthorDate: Tue Dec 9 11:12:48 2025 -0900
Commit:     Jim Raykowski <[email protected]>
CommitDate: Thu Dec 11 16:38:40 2025 +0100

    related tdf#163347 Improve sync color table to chart colors list
    
    ...entry selection
    
    * 'Custom', 'Theme colors', and 'Document colors' palettes are included
    in the search.
    * When no palette is found having the chart colors list entry selection
    color, the palette combobox text is set empty and the color valueset is
    cleared. This can happen when a chart colors list entry selection color
    was made from the 'Theme colors' palette and the SvxDefaultColorOptPage
    is opened from the start center backing window.
    
    Change-Id: I8ad9956c0bb9ee7de5fdcff77a250e81d7a58a9b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195335
    Reviewed-by: Jim Raykowski <[email protected]>
    Tested-by: Jenkins

diff --git a/cui/source/options/optchart.cxx b/cui/source/options/optchart.cxx
index e90b7289c31c..bd99a339d2cf 100644
--- a/cui/source/options/optchart.cxx
+++ b/cui/source/options/optchart.cxx
@@ -99,26 +99,55 @@ IMPL_LINK_NOARG(SvxDefaultColorOptPage, 
LbChartColorsSelectionChangedHdl, weld::
     Color& rColor(aColorList[nIndex]);
 
     XColorListRef xColorList;
-    for (size_t i = 0, nSize = aPaletteManager.GetPaletteList().size(); i < 
nSize; ++i)
+    for (sal_uInt16 nPalettePos = 0, nPaletteCount = 
aPaletteManager.GetPaletteCount();
+         nPalettePos < nPaletteCount; ++nPalettePos)
     {
-        aPaletteManager.SetPalette(i, true/*bPosOnly*/);
-
-        xColorList = 
XPropertyList::AsColorList(XPropertyList::CreatePropertyListFromURL(
-            XPropertyListType::Color, 
aPaletteManager.GetSelectedPalettePath()));
-        if (!xColorList->Load())
-            continue;
-
-        auto nPos = xColorList->GetIndexOfColor(rColor);
-        if (nPos == -1)
-            continue;
-
-        
m_xLbPaletteSelector->set_active_text(aPaletteManager.GetPaletteName());
-        SelectPaletteLbHdl(*m_xLbPaletteSelector);
-
-        m_xValSetColorBox->SelectItem(m_xValSetColorBox->GetItemId(nPos));
-
-        return;
+        aPaletteManager.SetPalette(nPalettePos, true /*bPosOnly*/);
+
+        if (/*custom palette*/ nPalettePos == 0 ||
+            /*theme colors palette*/ aPaletteManager.IsThemePaletteSelected() 
||
+            /*document colors palette*/ nPalettePos == 
aPaletteManager.GetPaletteCount() - 1)
+        {
+            aPaletteManager.ReloadColorSet(*m_xValSetColorBox);
+
+            for (size_t nItemPos = 0, nItemCount = 
m_xValSetColorBox->GetItemCount();
+                 nItemPos < nItemCount; nItemPos++)
+            {
+                auto nItemId = m_xValSetColorBox->GetItemId(nItemPos);
+                if (m_xValSetColorBox->GetItemColor(nItemId) == rColor)
+                {
+                    
m_xLbPaletteSelector->set_active_text(aPaletteManager.GetPaletteName());
+                    SelectPaletteLbHdl(*m_xLbPaletteSelector);
+
+                    m_xValSetColorBox->SelectItem(nItemId);
+
+                    return;
+                }
+            }
+        }
+        else
+        {
+            xColorList = 
XPropertyList::AsColorList(XPropertyList::CreatePropertyListFromURL(
+                XPropertyListType::Color, 
aPaletteManager.GetSelectedPalettePath()));
+            if (!xColorList->Load())
+                continue;
+
+            auto nPos = xColorList->GetIndexOfColor(rColor);
+            if (nPos == -1)
+                continue;
+
+            
m_xLbPaletteSelector->set_active_text(aPaletteManager.GetPaletteName());
+            SelectPaletteLbHdl(*m_xLbPaletteSelector);
+
+            m_xValSetColorBox->SelectItem(m_xValSetColorBox->GetItemId(nPos));
+
+            return;
+        }
     }
+
+    // color not found in any palette
+    m_xLbPaletteSelector->set_active_text(OUString());
+    m_xValSetColorBox->Clear();
 }
 
 SvxDefaultColorOptPage::SvxDefaultColorOptPage(weld::Container* pPage, 
weld::DialogController* pController, const SfxItemSet& rInAttrs)

Reply via email to