include/svx/Palette.hxx | 4 + include/svx/PaletteManager.hxx | 2 svx/source/tbxctrls/Palette.cxx | 15 +++++++ svx/source/tbxctrls/PaletteManager.cxx | 67 +++++++++++++++++---------------- svx/source/tbxctrls/tbcontrl.cxx | 3 - 5 files changed, 59 insertions(+), 32 deletions(-)
New commits: commit db8ee318293da8967a8294dc558ffae898ba8e6b Author: Rishabh Kumar <kris.kr...@gmail.com> Date: Sun Jul 24 17:23:40 2016 +0530 [GSoC] 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 <c...@libreoffice.org> Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> diff --git a/include/svx/Palette.hxx b/include/svx/Palette.hxx index fa2c179..1cbb83e 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 2d4c528..09adc36 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 9a5c76a..82789e9 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 535134f..55123aa 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 9846500..2851dfa 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -1331,7 +1331,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 libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits