summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/unotools/historyoptions.hxx11
-rw-r--r--unotools/source/config/historyoptions.cxx73
2 files changed, 79 insertions, 5 deletions
diff --git a/include/unotools/historyoptions.hxx b/include/unotools/historyoptions.hxx
index 165b98876856..d3617704ed15 100644
--- a/include/unotools/historyoptions.hxx
+++ b/include/unotools/historyoptions.hxx
@@ -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
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: */