diff options
author | Katarina Behrens <Katarina.Behrens@cib.de> | 2017-10-18 12:50:59 +0200 |
---|---|---|
committer | Katarina Behrens <Katarina.Behrens@cib.de> | 2017-10-21 15:02:50 +0200 |
commit | 23467fa5cfa2feffbeba2177c0d393f8ebe1a0a3 (patch) | |
tree | 71e3c86a862291530699fce94dcd90a61ab421c1 /sfx2 | |
parent | 0c46b3a9a384d5b70a708c3e9459a790dd815c63 (diff) |
tdf#67770: Read/writer LastActiveDeck bits
Change-Id: Id5e3c3cb4144b9fc56ab5e4a4e49f1fc69e70023
Reviewed-on: https://gerrit.libreoffice.org/43493
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/sidebar/ResourceManager.cxx | 49 | ||||
-rw-r--r-- | sfx2/source/sidebar/SidebarController.cxx | 14 |
2 files changed, 62 insertions, 1 deletions
diff --git a/sfx2/source/sidebar/ResourceManager.cxx b/sfx2/source/sidebar/ResourceManager.cxx index 1f8fb2863d4f..ead0ce7d7f11 100644 --- a/sfx2/source/sidebar/ResourceManager.cxx +++ b/sfx2/source/sidebar/ResourceManager.cxx @@ -20,9 +20,11 @@ #include <sfx2/sidebar/ResourceManager.hxx> #include <sfx2/sidebar/Tools.hxx> +#include <officecfg/Office/UI/Sidebar.hxx> #include <unotools/confignode.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/namedvaluecollection.hxx> +#include <comphelper/sequence.hxx> #include <comphelper/types.hxx> #include <rtl/ustrbuf.hxx> @@ -98,6 +100,7 @@ ResourceManager::ResourceManager() { ReadDeckList(); ReadPanelList(); + ReadLastActive(); } ResourceManager::~ResourceManager() @@ -243,6 +246,14 @@ const ResourceManager::PanelContextDescriptorContainer& ResourceManager::GetMatc return rPanelIds; } +const OUString& ResourceManager::GetLastActiveDeck( const Context& rContext ) +{ + if( maLastActiveDecks.find( rContext.msApplication ) == maLastActiveDecks.end()) + return maLastActiveDecks["any"]; + else + return maLastActiveDecks[rContext.msApplication]; +} + void ResourceManager::ReadDeckList() { const utl::OConfigurationTreeRoot aDeckRootNode( @@ -394,6 +405,21 @@ void ResourceManager::SaveDeckSettings(const DeckDescriptor* pDeckDesc) aPanelRootNode.commit(); } +void ResourceManager::SaveLastActiveDeck(const Context& rContext, const OUString& rActiveDeck) +{ + maLastActiveDecks[rContext.msApplication] = rActiveDeck; + + std::set<OUString> aLastActiveDecks; + for ( auto const & rEntry : maLastActiveDecks ) + aLastActiveDecks.insert( rEntry.first + "," + rEntry.second); + + std::shared_ptr<comphelper::ConfigurationChanges> cfgWriter( comphelper::ConfigurationChanges::create() ); + + officecfg::Office::UI::Sidebar::Content::LastActiveDeck::set(comphelper::containerToSequence(aLastActiveDecks), cfgWriter); + cfgWriter->commit(); + +} + void ResourceManager::ReadPanelList() { const utl::OConfigurationTreeRoot aPanelRootNode( @@ -435,6 +461,29 @@ void ResourceManager::ReadPanelList() } } +void ResourceManager::ReadLastActive() +{ + Sequence <OUString> aLastActive (officecfg::Office::UI::Sidebar::Content::LastActiveDeck::get()); + + for (auto& rDeckInfo : aLastActive) + { + sal_Int32 nCharIdx = rDeckInfo.lastIndexOf(','); + if ( nCharIdx <= 0 || (nCharIdx == rDeckInfo.getLength() - 1) ) + { + SAL_WARN("sfx.sidebar", "Expecting 2 values separated by comma"); + continue; + } + + const OUString sApplicationName = rDeckInfo.copy( 0, nCharIdx ); + vcl::EnumContext::Application eApplication (vcl::EnumContext::GetApplicationEnum(sApplicationName)); + const OUString sLastUsed = rDeckInfo.copy( nCharIdx + 1 ); + + // guard against garbage in place of application + if (eApplication != vcl::EnumContext::Application::NONE) + maLastActiveDecks.insert( std::make_pair(sApplicationName, sLastUsed ) ); + } +} + void ResourceManager::ReadContextList ( const utl::OConfigurationNode& rParentNode, ContextList& rContextList, diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx index e5cc4296b74a..fb50b264fb5b 100644 --- a/sfx2/source/sidebar/SidebarController.cxx +++ b/sfx2/source/sidebar/SidebarController.cxx @@ -140,7 +140,7 @@ rtl::Reference<SidebarController> SidebarController::create( if (instance->mxReadOnlyModeDispatch.is()) instance->mxReadOnlyModeDispatch->addStatusListener(instance.get(), aURL); - instance->SwitchToDeck(gsDefaultDeckId); + //first UpdateConfigurations call will SwitchToDeck return instance; } @@ -210,7 +210,10 @@ void SAL_CALL SidebarController::disposing() // so need to test if GetCurrentContext is still valid regarding msApplication if (GetCurrentContext().msApplication != "none") + { mpResourceManager->SaveDecksSettings(GetCurrentContext()); + mpResourceManager->SaveLastActiveDeck(GetCurrentContext(), msCurrentDeckId); + } // clear decks ResourceManager::DeckContextDescriptorContainer aDecks; @@ -437,6 +440,15 @@ void SidebarController::UpdateConfigurations() if (maCurrentContext.msApplication != "none") mpResourceManager->SaveDecksSettings(maCurrentContext); + // get last active deck for this application on first update + if (!maRequestedContext.msApplication.isEmpty() && + (maCurrentContext.msApplication != maRequestedContext.msApplication)) + { + OUString sLastActiveDeck = mpResourceManager->GetLastActiveDeck( maRequestedContext ); + if (!sLastActiveDeck.isEmpty()) + msCurrentDeckId = sLastActiveDeck; + } + maCurrentContext = maRequestedContext; mpResourceManager->InitDeckContext(GetCurrentContext()); |