Kaydet (Commit) 978ba69d authored tarafından Jan Holesovsky's avatar Jan Holesovsky

recent documents: Add possibility to remove individual documents.

Change-Id: Icf059ff9a911592ab09fc385aadbec9be8ed664a
üst e6ac6cbc
......@@ -82,12 +82,9 @@ public:
*/
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > GetList(EHistoryType eHistory) const;
/** Append a new item to specified list
/** Append a new item to the specified list.
You can append items to a list only - removing isn't allowed for a special item.
The oldest entry is deleted automatically if max size arrived or you can call Clear() ...
It exist two different overload methods to do this.
One for user which have an complete history item and another one for uncompletly data sets!
The oldest entry is deleted automatically when the size reaches the maximum.
@param eHistory select right history.
@param sURL URL to save in history
......@@ -99,6 +96,10 @@ public:
const OUString& sURL, const OUString& sFilter, const OUString& sTitle,
const OUString& sPassword, const OUString& sThumbnail);
/** Delete item from the specified list.
*/
void DeleteItem(EHistoryType eHistory, const OUString& sURL);
private:
/* Attention
......
......@@ -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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment