dbaccess/source/ui/app/AppController.cxx | 2 include/unotools/historyoptions.hxx | 4 - sfx2/source/appl/newhelp.cxx | 3 - sfx2/source/appl/sfxpicklist.cxx | 3 - unotools/source/config/historyoptions.cxx | 68 ++++++++++++++++++++---------- 5 files changed, 51 insertions(+), 29 deletions(-)
New commits: commit 760c7a806ced3861086d5fdfbb7b4b1461948c27 Author: Andreas Heinisch <andreas.heini...@yahoo.de> AuthorDate: Thu Jun 15 19:48:18 2023 +0200 Commit: Andreas Heinisch <andreas.heini...@yahoo.de> CommitDate: Mon Jun 19 07:47:59 2023 +0200 tdf#38742 - Start Center: move last opened documents to the top Change-Id: If395b0784d9bdcdc1200c15fca60647da825ea1e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153150 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de> diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index 175f56b39724..ad18bff5892c 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -361,7 +361,7 @@ void SAL_CALL OApplicationController::disposing() aURL.GetURLNoPass( INetURLObject::DecodeMechanism::NONE ), aFilter, getStrippedDatabaseName(), - std::nullopt, std::nullopt, std::nullopt); + std::nullopt, std::nullopt); // add to recent document list if ( aURL.GetProtocol() == INetProtocol::File ) diff --git a/include/unotools/historyoptions.hxx b/include/unotools/historyoptions.hxx index 53b9fcdfa805..b2388de2ad4b 100644 --- a/include/unotools/historyoptions.hxx +++ b/include/unotools/historyoptions.hxx @@ -73,13 +73,11 @@ namespace SvtHistoryOptions @param sTitle document title to save in history @param sThumbnail base64 encoded thumbnail of the item @param oIsReadOnly item was opened editable or read-only - @param oIsPinned item is pinned in the user-interface */ UNOTOOLS_DLLPUBLIC void AppendItem(EHistoryType eHistory, const OUString& sURL, const OUString& sFilter, const OUString& sTitle, const std::optional<OUString>& sThumbnail, - std::optional<bool> oIsReadOnly, - std::optional<bool> oIsPinned); + std::optional<bool> oIsReadOnly); /** Delete item from the specified list. */ diff --git a/sfx2/source/appl/newhelp.cxx b/sfx2/source/appl/newhelp.cxx index 5c2d7cf6c0e1..e676bec19d4e 100644 --- a/sfx2/source/appl/newhelp.cxx +++ b/sfx2/source/appl/newhelp.cxx @@ -1175,8 +1175,7 @@ BookmarksTabPage_Impl::~BookmarksTabPage_Impl() for (sal_Int32 i = 0; i < nCount; ++i) { SvtHistoryOptions::AppendItem(EHistoryType::HelpBookmarks, m_xBookmarksBox->get_id(i), "", - m_xBookmarksBox->get_text(i), std::nullopt, std::nullopt, - std::nullopt); + m_xBookmarksBox->get_text(i), std::nullopt, std::nullopt); } m_xBookmarksBox.reset(); diff --git a/sfx2/source/appl/sfxpicklist.cxx b/sfx2/source/appl/sfxpicklist.cxx index 2451a8d0cad8..fb676d981d35 100644 --- a/sfx2/source/appl/sfxpicklist.cxx +++ b/sfx2/source/appl/sfxpicklist.cxx @@ -131,8 +131,7 @@ void SfxPickListImpl::AddDocumentToPickList( const SfxObjectShell* pDocSh ) aFilter, aTitle, aThumbnail, - oIsReadOnly, - std::nullopt); + oIsReadOnly); if ( aURL.GetProtocol() == INetProtocol::File ) Application::AddToRecentDocumentList( aURL.GetURLNoPass( INetURLObject::DecodeMechanism::NONE ), diff --git a/unotools/source/config/historyoptions.cxx b/unotools/source/config/historyoptions.cxx index 0b9e4d717b83..2cda950858d2 100644 --- a/unotools/source/config/historyoptions.cxx +++ b/unotools/source/config/historyoptions.cxx @@ -134,7 +134,8 @@ std::vector< HistoryItem > GetList( EHistoryType eHistory ) xSet->getPropertyValue(s_sPassword) >>= aItem.sPassword; xSet->getPropertyValue(s_sThumbnail) >>= aItem.sThumbnail; xSet->getPropertyValue(s_sReadOnly) >>= aItem.isReadOnly; - xSet->getPropertyValue(s_sPinned) >>= aItem.isPinned; + if (xSet->getPropertySetInfo()->hasPropertyByName(s_sPinned)) + xSet->getPropertyValue(s_sPinned) >>= aItem.isPinned; aRet.push_back(aItem); } @@ -160,7 +161,7 @@ std::vector< HistoryItem > GetList( EHistoryType eHistory ) void AppendItem(EHistoryType eHistory, const OUString& sURL, const OUString& sFilter, const OUString& sTitle, const std::optional<OUString>& sThumbnail, - ::std::optional<bool> const oIsReadOnly, ::std::optional<bool> const oIsPinned) + ::std::optional<bool> const oIsReadOnly) { try { @@ -194,17 +195,15 @@ void AppendItem(EHistoryType eHistory, const OUString& sURL, const OUString& sFi { xSet->setPropertyValue(s_sReadOnly, uno::Any(*oIsReadOnly)); } - if (oIsPinned) - { - xSet->setPropertyValue(s_sPinned, uno::Any(*oIsPinned)); - if (*oIsPinned) - PrependItem(xCfg, xOrderList, sURL); - else - MoveItemToUnpinned(xCfg, xOrderList, xItemList, sURL); - } + + // tdf#38742 - check the current pinned state of the item and move it accordingly + bool bIsItemPinned = false; + if (xSet->getPropertySetInfo()->hasPropertyByName(s_sPinned)) + xSet->getPropertyValue(s_sPinned) >>= bIsItemPinned; + if (bIsItemPinned) + PrependItem(xCfg, xOrderList, sURL); else MoveItemToUnpinned(xCfg, xOrderList, xItemList, sURL); - } else // The item to be appended does not exist yet { @@ -270,14 +269,13 @@ void AppendItem(EHistoryType eHistory, const OUString& sURL, const OUString& sFi { xSet->setPropertyValue(s_sReadOnly, uno::Any(*oIsReadOnly)); } - if (oIsPinned) - { - xSet->setPropertyValue(s_sPinned, uno::Any(*oIsPinned)); - if (*oIsPinned) - PrependItem(xCfg, xOrderList, sURL); - else - MoveItemToUnpinned(xCfg, xOrderList, xItemList, sURL); - } + + // tdf#38742 - check the current pinned state of the item and move it accordingly + bool bIsItemPinned = false; + if (xSet->getPropertySetInfo()->hasPropertyByName(s_sPinned)) + xSet->getPropertyValue(s_sPinned) >>= bIsItemPinned; + if (bIsItemPinned) + PrependItem(xCfg, xOrderList, sURL); else MoveItemToUnpinned(xCfg, xOrderList, xItemList, sURL); @@ -506,8 +504,8 @@ static void MoveItemToUnpinned(const uno::Reference<container::XNameAccess>& xCf if (aItem == sURL) { - // Move item to the unpinned document section - for (sal_Int32 j = i + 1; j < nLength - 1; j++) + // Move item to the unpinned document section to the right if it was previously pinned + for (sal_Int32 j = i + 1; j < nLength; j++) { uno::Reference<beans::XPropertySet> xNextSet; xOrderList->getByName(OUString::number(j)) >>= xNextSet; @@ -522,12 +520,40 @@ static void MoveItemToUnpinned(const uno::Reference<container::XNameAccess>& xCf xNextItemSet->getPropertyValue(s_sPinned) >>= bIsItemPinned; if (bIsItemPinned) { + xOrderList->getByName(OUString::number(j - 1)) >>= xSet; + xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem; xSet->setPropertyValue(s_sHistoryItemRef, uno::Any(aNextItem)); xNextSet->setPropertyValue(s_sHistoryItemRef, uno::Any(aItem)); } else break; } + + // Move item to the unpinned document section to the left if it was previously unpinned + for (sal_Int32 j = i - 1; j >= 0; --j) + { + uno::Reference<beans::XPropertySet> xPrevSet; + xOrderList->getByName(OUString::number(j)) >>= xPrevSet; + + OUString aPrevItem; + xPrevSet->getPropertyValue(s_sHistoryItemRef) >>= aPrevItem; + + uno::Reference<beans::XPropertySet> xPrevItemSet; + xItemList->getByName(aPrevItem) >>= xPrevItemSet; + bool bIsItemPinned = false; + if (xPrevItemSet->getPropertySetInfo()->hasPropertyByName(s_sPinned)) + xPrevItemSet->getPropertyValue(s_sPinned) >>= bIsItemPinned; + if (!bIsItemPinned) + { + xOrderList->getByName(OUString::number(j + 1)) >>= xSet; + xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem; + xSet->setPropertyValue(s_sHistoryItemRef, uno::Any(aPrevItem)); + xPrevSet->setPropertyValue(s_sHistoryItemRef, uno::Any(aItem)); + } + else + break; + } + ::comphelper::ConfigurationHelper::flush(xCfg); return; }