framework/source/uielement/recentfilesmenucontroller.cxx | 2 include/unotools/historyoptions.hxx | 5 sfx2/source/control/recentdocsview.cxx | 2 sfx2/source/dialog/backingwindow.cxx | 2 unotools/source/config/historyoptions.cxx | 88 ++++++++++----- 5 files changed, 65 insertions(+), 34 deletions(-)
New commits: commit 71cae3a219ff1629368b8f324d0de89afc9445e9 Author: Andreas Heinisch <andreas.heini...@yahoo.de> AuthorDate: Fri Sep 22 12:06:50 2023 +0200 Commit: Andreas Heinisch <andreas.heini...@yahoo.de> CommitDate: Mon Sep 25 14:15:37 2023 +0200 tdf#155698 - Start Center: Retain pinned items when clearing the list Change-Id: Ife54845e020977cdb80a7fcc1fa63333afc17b32 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157169 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de> diff --git a/framework/source/uielement/recentfilesmenucontroller.cxx b/framework/source/uielement/recentfilesmenucontroller.cxx index 75d13407ad93..9c8eea5ef694 100644 --- a/framework/source/uielement/recentfilesmenucontroller.cxx +++ b/framework/source/uielement/recentfilesmenucontroller.cxx @@ -383,7 +383,7 @@ void SAL_CALL RecentFilesMenuController::itemSelected( const css::awt::MenuEvent if ( aCommand == CMD_CLEAR_LIST ) { - SvtHistoryOptions::Clear( EHistoryType::PickList ); + SvtHistoryOptions::Clear( EHistoryType::PickList, false ); dispatchCommand( "vnd.org.libreoffice.recentdocs:ClearRecentFileList", css::uno::Sequence< css::beans::PropertyValue >() ); diff --git a/include/unotools/historyoptions.hxx b/include/unotools/historyoptions.hxx index b2388de2ad4b..3eb8162ee0b5 100644 --- a/include/unotools/historyoptions.hxx +++ b/include/unotools/historyoptions.hxx @@ -44,7 +44,7 @@ namespace SvtHistoryOptions @param eHistory select right history. */ - UNOTOOLS_DLLPUBLIC void Clear(EHistoryType eHistory); + UNOTOOLS_DLLPUBLIC void Clear(EHistoryType eHistory, const bool bClearPinnedItems = true); /** Return the complete specified history list. @@ -81,7 +81,8 @@ namespace SvtHistoryOptions /** Delete item from the specified list. */ - UNOTOOLS_DLLPUBLIC void DeleteItem(EHistoryType eHistory, const OUString& sURL); + UNOTOOLS_DLLPUBLIC void DeleteItem(EHistoryType eHistory, const OUString& sURL, + const bool bClearPinned = true); // tdf#38742 - toggle pinned state of an item UNOTOOLS_DLLPUBLIC void TogglePinItem(EHistoryType eHistory, const OUString& sURL); diff --git a/sfx2/source/control/recentdocsview.cxx b/sfx2/source/control/recentdocsview.cxx index f2c58cf6e12e..cc2e80de17e9 100644 --- a/sfx2/source/control/recentdocsview.cxx +++ b/sfx2/source/control/recentdocsview.cxx @@ -191,7 +191,7 @@ void RecentDocsView::clearUnavailableFiles(){ { const SvtHistoryOptions::HistoryItem& rPickListEntry = aHistoryList[i]; if ( !comphelper::DirectoryHelper::fileExists(rPickListEntry.sURL) ){ - SvtHistoryOptions::DeleteItem(EHistoryType::PickList,rPickListEntry.sURL); + SvtHistoryOptions::DeleteItem(EHistoryType::PickList,rPickListEntry.sURL, false); } } Reload(); diff --git a/sfx2/source/dialog/backingwindow.cxx b/sfx2/source/dialog/backingwindow.cxx index fbae5e1af221..553577a846df 100644 --- a/sfx2/source/dialog/backingwindow.cxx +++ b/sfx2/source/dialog/backingwindow.cxx @@ -647,7 +647,7 @@ IMPL_LINK (BackingWindow, MenuSelectHdl, const OUString&, rId, void) { if (rId == "clear_all") { - SvtHistoryOptions::Clear(EHistoryType::PickList); + SvtHistoryOptions::Clear(EHistoryType::PickList, false); mxAllRecentThumbnails->Reload(); return; } diff --git a/unotools/source/config/historyoptions.cxx b/unotools/source/config/historyoptions.cxx index 2cda950858d2..8361aa6bc358 100644 --- a/unotools/source/config/historyoptions.cxx +++ b/unotools/source/config/historyoptions.cxx @@ -68,27 +68,49 @@ static sal_uInt32 GetCapacity(const uno::Reference<container::XNameAccess>& xCom namespace SvtHistoryOptions { -void Clear( EHistoryType eHistory ) +void Clear(EHistoryType eHistory, const bool bClearPinnedItems) { try { uno::Reference<container::XNameAccess> xCfg = GetConfig(); uno::Reference<container::XNameAccess> xListAccess(GetListAccess(xCfg, eHistory)); - // clear ItemList - uno::Reference<container::XNameContainer> xNode; - xListAccess->getByName(s_sItemList) >>= xNode; - Sequence<OUString> aStrings(xNode->getElementNames()); + // Retrieve order and item lists using name access to check properties of individual items + uno::Reference<container::XNameAccess> xItemList; + uno::Reference<container::XNameAccess> xOrderList; + xListAccess->getByName(s_sItemList) >>= xItemList; + xListAccess->getByName(s_sOrderList) >>= xOrderList; - for (const auto& rString : std::as_const(aStrings)) - xNode->removeByName(rString); + // Retrieve order and item lists using name container to delete individual items + uno::Reference<container::XNameContainer> xOrderNode; + uno::Reference<container::XNameContainer> xItemNode; + xListAccess->getByName(s_sItemList) >>= xItemNode; + xListAccess->getByName(s_sOrderList) >>= xOrderNode; - // clear OrderList - xListAccess->getByName(s_sOrderList) >>= xNode; - aStrings = xNode->getElementNames(); + const sal_Int32 nLength = xOrderList->getElementNames().getLength(); + for (sal_Int32 nItem = 0; nItem < nLength; ++nItem) + { + // Retrieve single item from the order list + OUString sUrl; + uno::Reference<beans::XPropertySet> xSet; + xOrderList->getByName(OUString::number(nItem)) >>= xSet; + xSet->getPropertyValue(s_sHistoryItemRef) >>= sUrl; - for (const auto& rString : std::as_const(aStrings)) - xNode->removeByName(rString); + // tdf#155698 - check if pinned items should be cleared + bool bIsItemPinned = false; + if (!bClearPinnedItems) + { + xItemList->getByName(sUrl) >>= xSet; + if (xSet->getPropertySetInfo()->hasPropertyByName(s_sPinned)) + xSet->getPropertyValue(s_sPinned) >>= bIsItemPinned; + } + + if (!bIsItemPinned) + { + xItemNode->removeByName(sUrl); + xOrderNode->removeByName(OUString::number(nItem)); + } + } ::comphelper::ConfigurationHelper::flush(xCfg); } @@ -288,7 +310,7 @@ void AppendItem(EHistoryType eHistory, const OUString& sURL, const OUString& sFi } } -void DeleteItem(EHistoryType eHistory, const OUString& sURL) +void DeleteItem(EHistoryType eHistory, const OUString& sURL, const bool bClearPinned) { try { @@ -305,8 +327,8 @@ void DeleteItem(EHistoryType eHistory, const OUString& sURL) if (!xItemList->hasByName(sURL)) return; - // it's the last one, just clear the lists - if (nLength == 1) + // it's the last one and pinned items can be cleared, just clear the lists + if (nLength == 1 && bClearPinned) { Clear(eHistory); return; @@ -314,35 +336,43 @@ void DeleteItem(EHistoryType eHistory, const OUString& sURL) // find it in the OrderList sal_Int32 nFromWhere = 0; + bool bIsItemPinned = false; for (; nFromWhere < nLength - 1; ++nFromWhere) { uno::Reference<beans::XPropertySet> xSet; OUString aItem; xOrderList->getByName(OUString::number(nFromWhere)) >>= xSet; xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem; + // tdf#155698 - check if pinned item should be deleted + if (!bClearPinned && xSet->getPropertySetInfo()->hasPropertyByName(s_sPinned)) + xSet->getPropertyValue(s_sPinned) >>= bIsItemPinned; if (aItem == sURL) break; } - // and shift the rest of the items in OrderList accordingly - for (sal_Int32 i = nFromWhere; i < nLength - 1; ++i) + // tdf#155698 - check if pinned item should be deleted + if (!bIsItemPinned) { - uno::Reference<beans::XPropertySet> xPrevSet; - uno::Reference<beans::XPropertySet> xNextSet; - xOrderList->getByName(OUString::number(i)) >>= xPrevSet; - xOrderList->getByName(OUString::number(i + 1)) >>= xNextSet; + // 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::Any(sTemp)); - } - xOrderList->removeByName(OUString::number(nLength - 1)); + OUString sTemp; + xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp; + xPrevSet->setPropertyValue(s_sHistoryItemRef, uno::Any(sTemp)); + } + xOrderList->removeByName(OUString::number(nLength - 1)); - // and finally remove it from the ItemList - xItemList->removeByName(sURL); + // and finally remove it from the ItemList + xItemList->removeByName(sURL); - ::comphelper::ConfigurationHelper::flush(xCfg); + ::comphelper::ConfigurationHelper::flush(xCfg); + } } catch (const uno::Exception&) {