/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// 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;
// 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;
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;
// 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));
}
}
aRet.push_back(aItem);
} catch(const uno::Exception&)
{ // <https://bugs.libreoffice.org/show_bug.cgi?id=46074> // "FILEOPEN: No Recent Documents..." discusses a problem // with corrupted /org.openoffice.Office/Histories/Histories // configuration items; to work around that problem, simply // ignore such corrupted individual items here, so that at // least newly added items are successfully reported back // from this function:
DBG_UNHANDLED_EXCEPTION("unotools.config");
}
}
} catch(const uno::Exception&)
{
DBG_UNHANDLED_EXCEPTION("unotools.config");
} return aRet;
}
// The item to be appended already exists if (xItemList->hasByName(sURL))
{
uno::Reference<beans::XPropertySet> xSet;
xItemList->getByName(sURL) >>= xSet; if (sThumbnail)
{ // update the thumbnail
xSet->setPropertyValue(s_sThumbnail, uno::Any(*sThumbnail));
} if (oIsReadOnly)
{
xSet->setPropertyValue(s_sReadOnly, uno::Any(*oIsReadOnly));
}
// 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
{
uno::Reference<beans::XPropertySet> xSet;
uno::Reference<lang::XSingleServiceFactory> xFac;
uno::Reference<uno::XInterface> xInst;
uno::Reference<beans::XPropertySet> xPrevSet;
uno::Reference<beans::XPropertySet> xNextSet;
// Append new item to OrderList. if ( nLength == nMaxSize )
{
OUString sRemove;
xOrderList->getByName(OUString::number(nLength-1)) >>= xSet;
xSet->getPropertyValue(s_sHistoryItemRef) >>= sRemove; try
{
xItemList->removeByName(sRemove);
} catch (container::NoSuchElementException &)
{ // <https://bugs.libreoffice.org/show_bug.cgi?id=46074> // "FILEOPEN: No Recent Documents..." discusses a problem // with corrupted /org.openoffice.Office/Histories/Histories // configuration items; to work around that problem, simply // ignore such corrupted individual items here, so that at // least newly added items are successfully added: if (!sRemove.isEmpty())
{ throw;
}
}
} if (nLength != nMaxSize)
{
xFac.set(xOrderList, uno::UNO_QUERY);
xInst = xFac->createInstance();
OUString sPush = OUString::number(nLength++);
xOrderList->insertByName(sPush, uno::Any(xInst));
} for (sal_Int32 j=nLength-1; j>0; --j)
{
xOrderList->getByName( OUString::number(j) ) >>= xPrevSet;
xOrderList->getByName( OUString::number(j-1) ) >>= xNextSet;
OUString sTemp;
xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp;
xPrevSet->setPropertyValue(s_sHistoryItemRef, uno::Any(sTemp));
}
xOrderList->getByName( OUString::number(0) ) >>= xSet;
xSet->setPropertyValue(s_sHistoryItemRef, uno::Any(sURL));
// Append the item to ItemList.
xFac.set(xItemList, uno::UNO_QUERY);
xInst = xFac->createInstance();
xItemList->insertByName(sURL, uno::Any(xInst));
// 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);
// if it does not exist, nothing to do if (!xItemList->hasByName(sURL)) return;
// it's the last one and pinned items can be cleared, just clear the lists if (nLength == 1 && bClearPinned)
{
Clear(eHistory); return;
}
// 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;
}
// tdf#155698 - check if pinned item should be deleted if (!bIsItemPinned)
{ // 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;
// Shift item to the beginning of the document list if is not pinned now if (bIsItemPinned)
MoveItemToUnpinned(xCfg, xOrderList, xItemList, sURL); else
PrependItem(xCfg, xOrderList, sURL);
}
} catch (const uno::Exception&)
{
DBG_UNHANDLED_EXCEPTION("unotools.config");
}
}
staticvoid MoveItemToUnpinned(const uno::Reference<container::XNameAccess>& xCfg, const uno::Reference<container::XNameContainer>& xOrderList, const uno::Reference<container::XNameContainer>& xItemList,
std::u16string_view sURL)
{
uno::Reference<beans::XPropertySet> xSet; const sal_Int32 nLength = xOrderList->getElementNames().getLength(); // Search for item in the ordered list list for (sal_Int32 i = 0; i < nLength; i++)
{
OUString aItem;
xOrderList->getByName(OUString::number(i)) >>= xSet;
xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem;
if (aItem == sURL)
{ // 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;
// 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;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.