include/svx/Palette.hxx | 14 + include/svx/PaletteManager.hxx | 10 - include/svx/dialogs.hrc | 2 officecfg/registry/schema/org/openoffice/Office/Common.xcs | 29 +++ svx/source/tbxctrls/Palette.cxx | 15 + svx/source/tbxctrls/PaletteManager.cxx | 117 ++++++++++--- svx/source/tbxctrls/tbcontrl.cxx | 6 svx/source/tbxctrls/tbcontrl.src | 4 unotools/source/config/pathoptions.cxx | 17 + 9 files changed, 176 insertions(+), 38 deletions(-)
New commits: commit 172f1e2dfb039255cc10838dc7590d11a416d8c0 Author: Stephan Bergmann <[email protected]> Date: Tue Nov 29 15:01:21 2016 +0100 Allow extensions to provide color palettes Until now, .oxt extensions cannot provide additional color palettes (.soc files, see e.g. Draw's "Format - Area... - Area - Color - Colors - Palette:" drop-down list). There are two ways how this feature could be added: Either add a new file-entry media-type to extensions' META-INF/manifest.xml and add support for that in the code. Or leverage the existing code, which reads the configuration set /org.openoffice.Office.Paths/Paths/Palette/InternalPaths, where each set element denotes a directory, and scans those directories for .soc files. So an extension would include an .xcu file adding such a path (using %origin% to denote a directory within the .oxt file itself) and a directory with one or more .soc files. For simplicity, this commit uses the second way. The only problem with the existing code is that extension configuration data using %origin% is rewritten to vnd.sun.star.expand URIs which the palette-scanning code does not support. So extend SvtPathOptions_Impl::GetPath's PATH_PALETTE case to expand such URIs. (The choice of doing it in SvtPathOptions is somewhat arbitrary; there would be other, more generic places where it might make sense to do such expansion, but which would also carry a higher risk of regressions.) <https://github.com/stbergmann/palette-extension> contains an example of such an extension (with a LibreOffice-minimal-version of "LibreOffice 5.3", assuming this commit will be backported to upcoming LO 5.3). Some drawbacks of going this way are: * No control over where extension palettes appear in the palette drop-down lists. (But those lists appear to be sorted in some random order, anyway?) * Commit on future support of the .soc file format (which, however, is XML) and the /org.openoffice.Office.Paths/Paths/Palette/InternalPaths configuration set in a backward-compatible way. (But any other way of implementing this feature would also need a similar commitment.) * Somewhat odd, indirect approach where an extension specifies a directory filled with .soc files, instead of specifying the .soc files diretly. * With the current palette-management code, live extension addition/removal is not immediately reflected in all places that offer palette drop-down lists. (But this should be fixable, and would be an issue with other approaches, too.) Change-Id: I68b30127d61764d1b5349f1f2af9c712828bee3e (cherry picked from commit e2ea7bb3a6b681822a247e8c277694f921c92273) diff --git a/unotools/source/config/pathoptions.cxx b/unotools/source/config/pathoptions.cxx index 2a2c14bfff14..734ddcb050f3 100644 --- a/unotools/source/config/pathoptions.cxx +++ b/unotools/source/config/pathoptions.cxx @@ -32,6 +32,7 @@ #include <unotools/bootstrap.hxx> #include <unotools/ucbhelper.hxx> +#include <comphelper/getexpandeduri.hxx> #include <comphelper/processfactory.hxx> #include <com/sun/star/beans/XFastPropertySet.hpp> #include <com/sun/star/beans/XPropertySet.hpp> @@ -245,6 +246,22 @@ const OUString& SvtPathOptions_Impl::GetPath( SvtPathOptions::Paths ePath ) osl::FileBase::getSystemPathFromFileURL( aPathValue, aResult ); aPathValue = aResult; } + else if (ePath == SvtPathOptions::PATH_PALETTE) + { + auto ctx = comphelper::getProcessComponentContext(); + OUStringBuffer buf; + for (sal_Int32 i = 0;;) + { + buf.append( + comphelper::getExpandedUri( + ctx, aPathValue.getToken(0, ';', i))); + if (i == -1) { + break; + } + buf.append(';'); + } + aPathValue = buf.makeStringAndClear(); + } m_aPathArray[ ePath ] = aPathValue; return m_aPathArray[ ePath ]; commit 61dba7b0f4c827d30f1fca50c5ed9e43408999a5 Author: Stephan Bergmann <[email protected]> Date: Thu Sep 1 17:04:06 2016 +0200 GetPaletteName() may change pColorList ...since 571866eaba914742a48938abb6c8495e97868bf1 "[GSoC] Rework of color tab" (cherry picked from commit e11931da72eabd98f9ea49ae93bd76039b283268) Conflicts: svx/source/tbxctrls/PaletteManager.cxx Change-Id: Ia4ad8bf675abe6b279527eaed0b0e5ebc5b2f180 diff --git a/svx/source/tbxctrls/PaletteManager.cxx b/svx/source/tbxctrls/PaletteManager.cxx index d7f9fe8136ff..a2b54996b7b2 100644 --- a/svx/source/tbxctrls/PaletteManager.cxx +++ b/svx/source/tbxctrls/PaletteManager.cxx @@ -190,7 +190,8 @@ void PaletteManager::SetPalette( sal_Int32 nPos ) pColorList = XPropertyList::AsColorList( XPropertyList::CreatePropertyListFromURL( XCOLOR_LIST, GetSelectedPalettePath())); - pColorList->SetName(GetPaletteName()); + auto name = GetPaletteName(); // may change pColorList + pColorList->SetName(name); if(pColorList->Load()) { SfxObjectShell* pShell = SfxObjectShell::Current(); commit 6881233c5b03872af1c2ef634c443187c8ca07cb Author: Stephan Bergmann <[email protected]> Date: Fri Aug 19 16:49:42 2016 +0200 pShell can be null here ...e.g., when opening "Tools - Options... - LibreOffice - Colors" from the Start Center. Change-Id: Id83591996e03794dc7dc53ccda58df7d7624ff8d (cherry picked from commit e774d798f6734f3bcc10e74bf641efcce0dedc40) diff --git a/svx/source/tbxctrls/PaletteManager.cxx b/svx/source/tbxctrls/PaletteManager.cxx index e2dbe421c885..d7f9fe8136ff 100644 --- a/svx/source/tbxctrls/PaletteManager.cxx +++ b/svx/source/tbxctrls/PaletteManager.cxx @@ -194,8 +194,11 @@ void PaletteManager::SetPalette( sal_Int32 nPos ) if(pColorList->Load()) { SfxObjectShell* pShell = SfxObjectShell::Current(); - SvxColorListItem aColorItem(pColorList, SID_COLOR_TABLE); - pShell->PutItem( aColorItem ); + if (pShell != nullptr) + { + SvxColorListItem aColorItem(pColorList, SID_COLOR_TABLE); + pShell->PutItem( aColorItem ); + } } } std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_context)); commit 2f0f946c3ecb8e812a1cedac385edcb1c266bd85 Author: Rishabh Kumar <[email protected]> Date: Tue Aug 2 23:53:38 2016 +0530 Rework of color tab New Features - Remember the selected palette. Reviewed-on: https://gerrit.libreoffice.org/26868 Tested-by: Jenkins <[email protected]> Reviewed-by: Yousuf Philips <[email protected]> Tested-by: Yousuf Philips <[email protected]> Reviewed-by: Tomaž Vajngerl <[email protected]> Conflicts: officecfg/registry/schema/org/openoffice/Office/Common.xcs Change-Id: I36a438a0c282059ddcbda35f934fcd90337fd451 diff --git a/include/svx/Palette.hxx b/include/svx/Palette.hxx index 1cbb83e2c94a..ffbd529fbe2f 100644 --- a/include/svx/Palette.hxx +++ b/include/svx/Palette.hxx @@ -29,7 +29,7 @@ class SvFileStream; typedef std::pair<Color, OUString> NamedColor; typedef std::vector< NamedColor > ColorList; -class Palette +class SVX_DLLPUBLIC Palette { public: virtual ~Palette(); @@ -43,7 +43,7 @@ public: // ASE = Adobe Swatch Exchange -class PaletteASE : public Palette +class SVX_DLLPUBLIC PaletteASE : public Palette { bool mbValidPalette; OUString maFPath; @@ -64,7 +64,7 @@ public: // GPL - this is *not* GNU Public License, but is the Gimp PaLette -class PaletteGPL : public Palette +class SVX_DLLPUBLIC PaletteGPL : public Palette { bool mbLoadedPalette; bool mbValidPalette; @@ -89,7 +89,7 @@ public: // SOC - Star Office Color-table -class PaletteSOC : public Palette +class SVX_DLLPUBLIC PaletteSOC : public Palette { bool mbLoadedPalette; OUString maFPath; @@ -108,4 +108,4 @@ public: #endif // INCLUDED_SVX_PALETTE_HXX -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file diff --git a/include/svx/PaletteManager.hxx b/include/svx/PaletteManager.hxx index 09adc3653a92..ceeea5d5a5e8 100644 --- a/include/svx/PaletteManager.hxx +++ b/include/svx/PaletteManager.hxx @@ -36,7 +36,7 @@ #include <vector> #include <memory> -class PaletteManager +class SVX_DLLPUBLIC PaletteManager { const sal_uInt16 mnMaxRecentColors; @@ -52,17 +52,21 @@ class PaletteManager std::vector<std::unique_ptr<Palette>> m_Palettes; std::function<void(const OUString&, const Color&)> maColorSelectFunction; - + css::uno::Reference < css::uno::XComponentContext > m_context; public: PaletteManager(); ~PaletteManager(); + PaletteManager(const PaletteManager&) = delete; + PaletteManager& operator=(const PaletteManager&) = delete; void LoadPalettes(); void ReloadColorSet(SvxColorValueSet& rColorSet); void ReloadRecentColorSet(SvxColorValueSet& rColorSet); std::vector<OUString> GetPaletteList(); void SetPalette( sal_Int32 nPos ); sal_Int32 GetPalette(); + sal_Int32 GetPaletteCount() { return mnNumOfPalettes; } OUString GetPaletteName(); + OUString GetSelectedPalettePath(); long GetColorCount(); long GetRecentColorCount(); diff --git a/include/svx/dialogs.hrc b/include/svx/dialogs.hrc index c8f74acf0340..59260ae53f00 100644 --- a/include/svx/dialogs.hrc +++ b/include/svx/dialogs.hrc @@ -244,7 +244,7 @@ #define RID_SVXSTR_MORENUMBERING (RID_SVX_START + 204) #define RID_SVXSTR_MOREBULLETS (RID_SVX_START + 205) -#define RID_SVXSTR_DEFAULT_PAL (RID_SVX_START + 206) +#define RID_SVXSTR_CUSTOM_PAL (RID_SVX_START + 206) #define RID_SVXSTR_DOC_COLORS (RID_SVX_START + 207) #define RID_SVXSTR_DOC_COLOR_PREFIX (RID_SVX_START + 208) diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs index 60cd725aca03..fb96a51ec82f 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs @@ -3462,6 +3462,35 @@ </info> </prop> </group> + <group oor:name="UserColors"> + <info> + <desc>Contains selected color palette</desc> + </info> + <prop oor:name="RecentColor" oor:type="oor:int-list" oor:nillable="false"> + <info> + <desc>List of Recent colors</desc> + </info> + <value/> + </prop> + <prop oor:name="PaletteName" oor:type="xs:string" oor:nillable="false"> + <info> + <desc>Name of selected palette</desc> + </info> + <value>standard</value> + </prop> + <prop oor:name="CustomColor" oor:type="oor:int-list" oor:nillable="false"> + <info> + <desc>List of Custom colors</desc> + </info> + <value/> + </prop> + <prop oor:name="CustomColorName" oor:type="oor:string-list" oor:nillable="false"> + <info> + <desc>List of Custom colors</desc> + </info> + <value/> + </prop> + </group> <group oor:name="Help"> <info> <desc>Contains settings that specify the common help settings.</desc> diff --git a/svx/source/tbxctrls/PaletteManager.cxx b/svx/source/tbxctrls/PaletteManager.cxx index 55123aa002f8..e2dbe421c885 100644 --- a/svx/source/tbxctrls/PaletteManager.cxx +++ b/svx/source/tbxctrls/PaletteManager.cxx @@ -30,15 +30,18 @@ #include <vcl/settings.hxx> #include <stack> #include <set> +#include <cppu/unotype.hxx> +#include <officecfg/Office/Common.hxx> PaletteManager::PaletteManager() : mnMaxRecentColors(Application::GetSettings().GetStyleSettings().GetColorValueSetColumnCount()), - mnNumOfPalettes(1), + mnNumOfPalettes(2), mnCurrentPalette(0), mnColorCount(0), mpBtnUpdater(nullptr), mLastColor(COL_AUTO), - maColorSelectFunction(PaletteManager::DispatchColorCommand) + maColorSelectFunction(PaletteManager::DispatchColorCommand), + m_context(comphelper::getProcessComponentContext()) { SfxObjectShell* pDocSh = SfxObjectShell::Current(); if(pDocSh) @@ -117,7 +120,21 @@ void PaletteManager::ReloadColorSet(SvxColorValueSet &rColorSet) { SfxObjectShell* pDocSh = SfxObjectShell::Current(); - if( mnCurrentPalette == mnNumOfPalettes - 1 ) + if( mnCurrentPalette == 0) + { + rColorSet.Clear(); + css::uno::Sequence< sal_Int32 > CustomColorList( officecfg::Office::Common::UserColors::CustomColor::get() ); + css::uno::Sequence< OUString > CustomColorNameList( officecfg::Office::Common::UserColors::CustomColorName::get() ); + int nIx = 1; + for( int i = 0;i < CustomColorList.getLength();i++ ) + { + Color aColor( CustomColorList[i] ); + OUString aColorName( CustomColorNameList[i] ); + rColorSet.InsertItem( nIx, aColor, aColorName ); + ++nIx; + } + } + else if( mnCurrentPalette == mnNumOfPalettes - 1 ) { // Add doc colors to palette std::set<Color> aColors = pDocSh->GetDocColors(); @@ -127,13 +144,20 @@ void PaletteManager::ReloadColorSet(SvxColorValueSet &rColorSet) } else { - m_Palettes[mnCurrentPalette]->LoadColorSet( rColorSet ); + m_Palettes[mnCurrentPalette - 1]->LoadColorSet( rColorSet ); mnColorCount = rColorSet.GetItemCount(); } } void PaletteManager::ReloadRecentColorSet(SvxColorValueSet& rColorSet) { + maRecentColors.clear(); + css::uno::Sequence< sal_Int32 > Colorlist(officecfg::Office::Common::UserColors::RecentColor::get()); + for(int i = 0;i < Colorlist.getLength();i++) + { + Color aColor( Colorlist[i] ); + maRecentColors.push_back( aColor ); + } rColorSet.Clear(); int nIx = 1; for(std::deque<Color>::const_iterator it = maRecentColors.begin(); @@ -148,11 +172,11 @@ std::vector<OUString> PaletteManager::GetPaletteList() { std::vector<OUString> aPaletteNames; + aPaletteNames.push_back( SVX_RESSTR( RID_SVXSTR_CUSTOM_PAL ) ); for (auto const& it : m_Palettes) { aPaletteNames.push_back( (*it).GetName() ); } - aPaletteNames.push_back( SVX_RESSTR ( RID_SVXSTR_DOC_COLORS ) ); return aPaletteNames; @@ -160,12 +184,13 @@ std::vector<OUString> PaletteManager::GetPaletteList() void PaletteManager::SetPalette( sal_Int32 nPos ) { - if( nPos != mnNumOfPalettes - 1 ) + mnCurrentPalette = nPos; + if( nPos != mnNumOfPalettes - 1 && nPos != 0) { pColorList = XPropertyList::AsColorList( XPropertyList::CreatePropertyListFromURL( - XCOLOR_LIST, m_Palettes[nPos]->GetPath())); - pColorList->SetName(m_Palettes[nPos]->GetName()); + XCOLOR_LIST, GetSelectedPalettePath())); + pColorList->SetName(GetPaletteName()); if(pColorList->Load()) { SfxObjectShell* pShell = SfxObjectShell::Current(); @@ -173,7 +198,9 @@ void PaletteManager::SetPalette( sal_Int32 nPos ) pShell->PutItem( aColorItem ); } } - mnCurrentPalette = nPos; + std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_context)); + officecfg::Office::Common::UserColors::PaletteName::set(GetPaletteName(), batch); + batch->commit(); } sal_Int32 PaletteManager::GetPalette() @@ -183,7 +210,26 @@ sal_Int32 PaletteManager::GetPalette() OUString PaletteManager::GetPaletteName() { - return pColorList->GetName(); + std::vector<OUString> aNames(GetPaletteList()); + if(mnCurrentPalette != mnNumOfPalettes - 1 && mnCurrentPalette != 0) + { + SfxObjectShell* pDocSh = SfxObjectShell::Current(); + if(pDocSh) + { + const SfxPoolItem* pItem = nullptr; + if( nullptr != ( pItem = pDocSh->GetItem(SID_COLOR_TABLE) ) ) + pColorList = static_cast<const SvxColorListItem*>(pItem)->GetColorList(); + } + } + return aNames[mnCurrentPalette]; +} + +OUString PaletteManager::GetSelectedPalettePath() +{ + if(mnCurrentPalette != mnNumOfPalettes - 1 && mnCurrentPalette != 0) + return m_Palettes[mnCurrentPalette - 1]->GetPath(); + else + return OUString(); } long PaletteManager::GetColorCount() @@ -217,6 +263,14 @@ void PaletteManager::AddRecentColor(const Color& rRecentColor) maRecentColors.push_front( rRecentColor ); if( maRecentColors.size() > mnMaxRecentColors ) maRecentColors.pop_back(); + css::uno::Sequence< sal_Int32 > aColorList(maRecentColors.size()); + for(std::deque<Color>::size_type i = 0;i < maRecentColors.size();i++) + { + aColorList[i] = static_cast<sal_Int32>(maRecentColors[i].GetColor()); + } + std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_context)); + officecfg::Office::Common::UserColors::RecentColor::set(aColorList, batch); + batch->commit(); } void PaletteManager::SetBtnUpdater(svx::ToolboxButtonColorUpdater* pBtnUpdater) diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index fabe35b43cd3..859220e0cac9 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -95,6 +95,8 @@ #include <svx/xflclit.hxx> #include <svl/currencytable.hxx> #include <svtools/langtab.hxx> +#include <cppu/unotype.hxx> +#include <officecfg/Office/Common.hxx> #define MAX_MRU_FONTNAME_ENTRIES 5 @@ -1332,7 +1334,8 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand, { mpPaletteListBox->InsertEntry( *it ); } - mpPaletteListBox->SelectEntry(mrPaletteManager.GetPaletteName()); + OUString aPaletteName( officecfg::Office::Common::UserColors::PaletteName::get() ); + mpPaletteListBox->SelectEntry( aPaletteName ); SelectPaletteHdl( *mpPaletteListBox ); mpButtonAutoColor->SetClickHdl( LINK( this, SvxColorWindow_Impl, AutoColorClickHdl ) ); diff --git a/svx/source/tbxctrls/tbcontrl.src b/svx/source/tbxctrls/tbcontrl.src index c0a5bd4a3f53..b867c9da0660 100644 --- a/svx/source/tbxctrls/tbcontrl.src +++ b/svx/source/tbxctrls/tbcontrl.src @@ -207,9 +207,9 @@ String RID_SVXSTR_CHARFONTNAME_NOTAVAILABLE Text [ en-US ] = "Font Name. The current font is not available and will be substituted."; }; -String RID_SVXSTR_DEFAULT_PAL +String RID_SVXSTR_CUSTOM_PAL { - Text [ en-US ] = "Default palette"; + Text [ en-US ] = "custom"; }; String RID_SVXSTR_DOC_COLORS commit 34664ccceb4798356ef08b18535318e27c61e990 Author: Rishabh Kumar <[email protected]> Date: Sun Jul 24 17:23:40 2016 +0530 Fix palette selection in sidebar/toolbar color widget Remember palette selection after the popup is destroyed Change-Id: Iecd7fd4aa89cf9d2d6842c5b544d037df6818aaf Reviewed-on: https://gerrit.libreoffice.org/27474 Tested-by: Jenkins <[email protected]> Reviewed-by: Samuel Mehrbrodt <[email protected]> (cherry picked from commit db8ee318293da8967a8294dc558ffae898ba8e6b) diff --git a/include/svx/Palette.hxx b/include/svx/Palette.hxx index fa2c1798ff1e..1cbb83e2c94a 100644 --- a/include/svx/Palette.hxx +++ b/include/svx/Palette.hxx @@ -35,6 +35,7 @@ public: virtual ~Palette(); virtual const OUString& GetName() = 0; + virtual const OUString& GetPath() = 0; virtual void LoadColorSet( SvxColorValueSet& rColorSet ) = 0; virtual bool IsValid() = 0; @@ -55,6 +56,7 @@ public: virtual ~PaletteASE(); virtual const OUString& GetName() override; + virtual const OUString& GetPath() override; virtual void LoadColorSet( SvxColorValueSet& rColorSet ) override; virtual bool IsValid() override; @@ -79,6 +81,7 @@ public: virtual ~PaletteGPL(); virtual const OUString& GetName() override; + virtual const OUString& GetPath() override; virtual void LoadColorSet( SvxColorValueSet& rColorSet ) override; virtual bool IsValid() override; @@ -97,6 +100,7 @@ public: virtual ~PaletteSOC(); virtual const OUString& GetName() override; + virtual const OUString& GetPath() override; virtual void LoadColorSet( SvxColorValueSet& rColorSet ) override; virtual bool IsValid() override; diff --git a/include/svx/PaletteManager.hxx b/include/svx/PaletteManager.hxx index 2d4c528a1984..09adc3653a92 100644 --- a/include/svx/PaletteManager.hxx +++ b/include/svx/PaletteManager.hxx @@ -46,6 +46,7 @@ class PaletteManager long mnColorCount; svx::ToolboxButtonColorUpdater* mpBtnUpdater; + XColorListRef pColorList; Color mLastColor; std::deque<Color> maRecentColors; std::vector<std::unique_ptr<Palette>> m_Palettes; @@ -61,6 +62,7 @@ public: std::vector<OUString> GetPaletteList(); void SetPalette( sal_Int32 nPos ); sal_Int32 GetPalette(); + OUString GetPaletteName(); long GetColorCount(); long GetRecentColorCount(); diff --git a/svx/source/tbxctrls/Palette.cxx b/svx/source/tbxctrls/Palette.cxx index d5e2dd9b9505..4dceb783065e 100644 --- a/svx/source/tbxctrls/Palette.cxx +++ b/svx/source/tbxctrls/Palette.cxx @@ -53,6 +53,11 @@ const OUString& PaletteASE::GetName() return maASEPaletteName; } +const OUString& PaletteASE::GetPath() +{ + return maFPath; +} + bool PaletteASE::IsValid() { return mbValidPalette; @@ -186,6 +191,11 @@ const OUString& PaletteGPL::GetName() return maGPLPaletteName; } +const OUString& PaletteGPL::GetPath() +{ + return maFPath; +} + void PaletteGPL::LoadColorSet( SvxColorValueSet& rColorSet ) { LoadPalette(); @@ -327,6 +337,11 @@ const OUString& PaletteSOC::GetName() return maSOCPaletteName; } +const OUString& PaletteSOC::GetPath() +{ + return maFPath; +} + void PaletteSOC::LoadColorSet( SvxColorValueSet& rColorSet ) { if( !mbLoadedPalette ) diff --git a/svx/source/tbxctrls/PaletteManager.cxx b/svx/source/tbxctrls/PaletteManager.cxx index 535134f344de..55123aa002f8 100644 --- a/svx/source/tbxctrls/PaletteManager.cxx +++ b/svx/source/tbxctrls/PaletteManager.cxx @@ -33,13 +33,22 @@ PaletteManager::PaletteManager() : mnMaxRecentColors(Application::GetSettings().GetStyleSettings().GetColorValueSetColumnCount()), - mnNumOfPalettes(2), + mnNumOfPalettes(1), mnCurrentPalette(0), mnColorCount(0), mpBtnUpdater(nullptr), mLastColor(COL_AUTO), maColorSelectFunction(PaletteManager::DispatchColorCommand) { + SfxObjectShell* pDocSh = SfxObjectShell::Current(); + if(pDocSh) + { + const SfxPoolItem* pItem = nullptr; + if( nullptr != ( pItem = pDocSh->GetItem(SID_COLOR_TABLE) ) ) + pColorList = static_cast<const SvxColorListItem*>(pItem)->GetColorList(); + } + if(!pColorList.is()) + pColorList = XColorList::CreateStdColorList(); LoadPalettes(); mnNumOfPalettes += m_Palettes.size(); } @@ -82,19 +91,21 @@ void PaletteManager::LoadPalettes() if(aFileStat.isRegular() || aFileStat.isLink()) { OUString aFName = aFileStat.getFileName(); + INetURLObject aURLObj( aFileStat.getFileURL() ); + OUString aFNameWithoutExt = aURLObj.GetBase(); if (aNames.find(aFName) == aNames.end()) { std::unique_ptr<Palette> pPalette; if( aFName.endsWithIgnoreAsciiCase(".gpl") ) - pPalette.reset(new PaletteGPL(aFileStat.getFileURL(), aFName)); + pPalette.reset(new PaletteGPL(aFileStat.getFileURL(), aFNameWithoutExt)); else if( aFName.endsWithIgnoreAsciiCase(".soc") ) - pPalette.reset(new PaletteSOC(aFileStat.getFileURL(), aFName)); + pPalette.reset(new PaletteSOC(aFileStat.getFileURL(), aFNameWithoutExt)); else if ( aFName.endsWithIgnoreAsciiCase(".ase") ) - pPalette.reset(new PaletteASE(aFileStat.getFileURL(), aFName)); + pPalette.reset(new PaletteASE(aFileStat.getFileURL(), aFNameWithoutExt)); if( pPalette && pPalette->IsValid() ) m_Palettes.push_back( std::move(pPalette) ); - aNames.insert(aFName); + aNames.insert(aFNameWithoutExt); } } } @@ -106,29 +117,7 @@ void PaletteManager::ReloadColorSet(SvxColorValueSet &rColorSet) { SfxObjectShell* pDocSh = SfxObjectShell::Current(); - if( mnCurrentPalette == 0 ) - { - XColorListRef pColorList; - - if ( pDocSh ) - { - const SfxPoolItem* pItem = nullptr; - if ( nullptr != ( pItem = pDocSh->GetItem( SID_COLOR_TABLE ) ) ) - pColorList = static_cast<const SvxColorListItem*>(pItem)->GetColorList(); - } - - if ( !pColorList.is() ) - pColorList = XColorList::CreateStdColorList(); - - - if ( pColorList.is() ) - { - mnColorCount = pColorList->Count(); - rColorSet.Clear(); - rColorSet.addEntriesForXColorList(*pColorList); - } - } - else if( mnCurrentPalette == mnNumOfPalettes - 1 ) + if( mnCurrentPalette == mnNumOfPalettes - 1 ) { // Add doc colors to palette std::set<Color> aColors = pDocSh->GetDocColors(); @@ -138,7 +127,7 @@ void PaletteManager::ReloadColorSet(SvxColorValueSet &rColorSet) } else { - m_Palettes[mnCurrentPalette-1]->LoadColorSet( rColorSet ); + m_Palettes[mnCurrentPalette]->LoadColorSet( rColorSet ); mnColorCount = rColorSet.GetItemCount(); } } @@ -159,8 +148,6 @@ std::vector<OUString> PaletteManager::GetPaletteList() { std::vector<OUString> aPaletteNames; - aPaletteNames.push_back( SVX_RESSTR( RID_SVXSTR_DEFAULT_PAL ) ); - for (auto const& it : m_Palettes) { aPaletteNames.push_back( (*it).GetName() ); @@ -173,6 +160,19 @@ std::vector<OUString> PaletteManager::GetPaletteList() void PaletteManager::SetPalette( sal_Int32 nPos ) { + if( nPos != mnNumOfPalettes - 1 ) + { + pColorList = XPropertyList::AsColorList( + XPropertyList::CreatePropertyListFromURL( + XCOLOR_LIST, m_Palettes[nPos]->GetPath())); + pColorList->SetName(m_Palettes[nPos]->GetName()); + if(pColorList->Load()) + { + SfxObjectShell* pShell = SfxObjectShell::Current(); + SvxColorListItem aColorItem(pColorList, SID_COLOR_TABLE); + pShell->PutItem( aColorItem ); + } + } mnCurrentPalette = nPos; } @@ -181,6 +181,11 @@ sal_Int32 PaletteManager::GetPalette() return mnCurrentPalette; } +OUString PaletteManager::GetPaletteName() +{ + return pColorList->GetName(); +} + long PaletteManager::GetColorCount() { return mnColorCount; diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index 28684f4c4c93..fabe35b43cd3 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -1332,7 +1332,8 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand, { mpPaletteListBox->InsertEntry( *it ); } - mpPaletteListBox->SelectEntryPos(mrPaletteManager.GetPalette()); + mpPaletteListBox->SelectEntry(mrPaletteManager.GetPaletteName()); + SelectPaletteHdl( *mpPaletteListBox ); mpButtonAutoColor->SetClickHdl( LINK( this, SvxColorWindow_Impl, AutoColorClickHdl ) ); mpButtonPicker->SetClickHdl( LINK( this, SvxColorWindow_Impl, OpenPickerClickHdl ) );
_______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
