diff options
author | Rishabh Kumar <kris.kr296@gmail.com> | 2016-07-24 17:23:40 +0530 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2016-07-25 09:22:12 +0000 |
commit | db8ee318293da8967a8294dc558ffae898ba8e6b (patch) | |
tree | ffec9bb5b79aaebabc6c1e0ef02bf89806481aa8 /svx/source | |
parent | 57c8915376dbb580760486071cac6533e05427bf (diff) |
[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 <ci@libreoffice.org>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'svx/source')
-rw-r--r-- | svx/source/tbxctrls/Palette.cxx | 15 | ||||
-rw-r--r-- | svx/source/tbxctrls/PaletteManager.cxx | 67 | ||||
-rw-r--r-- | svx/source/tbxctrls/tbcontrl.cxx | 3 |
3 files changed, 53 insertions, 32 deletions
diff --git a/svx/source/tbxctrls/Palette.cxx b/svx/source/tbxctrls/Palette.cxx index 9a5c76a7e610..82789e99e193 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 984650021ff1..2851dfa1f2b4 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 ) ); |