diff options
author | Jan Holesovsky <kendy@collabora.com> | 2014-04-26 19:33:54 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2014-04-27 01:28:55 +0200 |
commit | 978ba69d33cf31cd334f18af5215166dd3926402 (patch) | |
tree | 22aa6b02aaad3705a7dc73e0ff92f936c7a0a360 /unotools | |
parent | e6ac6cbccf0e26b860b2a8c276fea258091d9da3 (diff) |
recent documents: Add possibility to remove individual documents.
Change-Id: Icf059ff9a911592ab09fc385aadbec9be8ed664a
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/source/config/historyoptions.cxx | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/unotools/source/config/historyoptions.cxx b/unotools/source/config/historyoptions.cxx index 4f5dc38156c9..ea87bed3a71d 100644 --- a/unotools/source/config/historyoptions.cxx +++ b/unotools/source/config/historyoptions.cxx @@ -89,6 +89,8 @@ public: const OUString& sURL, const OUString& sFilter, const OUString& sTitle, const OUString& sPassword, const OUString& sThumbnail); + void DeleteItem(EHistoryType eHistory, const OUString& sURL); + private: /// Return the appropriate list of recent documents (based on eHistory). uno::Reference<container::XNameAccess> GetListAccess(EHistoryType eHistory) const; @@ -473,6 +475,70 @@ void SvtHistoryOptions_Impl::AppendItem(EHistoryType eHistory, } } +void SvtHistoryOptions_Impl::DeleteItem(EHistoryType eHistory, const OUString& sURL) +{ + uno::Reference<container::XNameAccess> xListAccess(GetListAccess(eHistory)); + if (!xListAccess.is()) + return; + + uno::Reference<container::XNameContainer> xItemList; + uno::Reference<container::XNameContainer> xOrderList; + uno::Reference<beans::XPropertySet> xSet; + + try + { + xListAccess->getByName(s_sItemList) >>= xItemList; + xListAccess->getByName(s_sOrderList) >>= xOrderList; + sal_Int32 nLength = xOrderList->getElementNames().getLength(); + + // if it does not exist, nothing to do + if (!xItemList->hasByName(sURL)) + return; + + // it's the last one, just clear the lists + if (nLength == 1) + { + Clear(eHistory); + return; + } + + // find it in the OrderList + sal_Int32 nFromWhere = 0; + for (; nFromWhere < nLength - 1; ++nFromWhere) + { + OUString aItem; + xOrderList->getByName(OUString::number(nFromWhere)) >>= xSet; + xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem; + + if (aItem == sURL) + break; + } + + // and shift the rest of the items in OrderList accordingly + for (sal_Int32 i = nFromWhere; i < nLength - 1; ++i) + { + uno::Reference<beans::XPropertySet> xPrevSet; + uno::Reference<beans::XPropertySet> xNextSet; + xOrderList->getByName(OUString::number(i)) >>= xPrevSet; + xOrderList->getByName(OUString::number(i + 1)) >>= xNextSet; + + OUString sTemp; + xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp; + xPrevSet->setPropertyValue(s_sHistoryItemRef, uno::makeAny(sTemp)); + } + xOrderList->removeByName(OUString::number(nLength - 1)); + + // and finally remove it from the ItemList + xItemList->removeByName(sURL); + + ::comphelper::ConfigurationHelper::flush(m_xCfg); + } + catch (const uno::Exception& ex) + { + SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message); + } +} + // initialize static member // DON'T DO IT IN YOUR HEADER! // see definition for further information @@ -544,4 +610,11 @@ void SvtHistoryOptions::AppendItem(EHistoryType eHistory, m_pDataContainer->AppendItem(eHistory, sURL, sFilter, sTitle, sPassword, sThumbnail); } +void SvtHistoryOptions::DeleteItem(EHistoryType eHistory, const OUString& sURL) +{ + MutexGuard aGuard(theHistoryOptionsMutex::get()); + + m_pDataContainer->DeleteItem(eHistory, sURL); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |