From 34664ccceb4798356ef08b18535318e27c61e990 Mon Sep 17 00:00:00 2001 From: Rishabh Kumar Date: Sun, 24 Jul 2016 17:23:40 +0530 Subject: 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 Reviewed-by: Samuel Mehrbrodt (cherry picked from commit db8ee318293da8967a8294dc558ffae898ba8e6b) --- svx/source/tbxctrls/Palette.cxx | 15 ++++++++ svx/source/tbxctrls/PaletteManager.cxx | 67 ++++++++++++++++++---------------- svx/source/tbxctrls/tbcontrl.cxx | 3 +- 3 files changed, 53 insertions(+), 32 deletions(-) (limited to 'svx') 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(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 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(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 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 PaletteManager::GetPaletteList() { std::vector 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 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 ) ); -- cgit