Code: Select all
Sub CleanUpHistory()
Dim oCP As Object
Dim oCUA As Object
Dim aProps(0) As New com.sun.star.beans.PropertyValue
' get configuration of the file history
oCP = GetProcessServiceManager().createInstanceWithContext( _
"com.sun.star.configuration.ConfigurationProvider", GetDefaultContext() )
aProps(0).Name = "nodepath"
aProps(0).Value = "/org.openoffice.Office.Common/History"
oCUA = oCP.createInstanceWithArguments( _
"com.sun.star.configuration.ConfigurationUpdateAccess", aProps )
' clean up PickList
CleanUpList( "PickList", "PickListSize", "p", oCUA )
' clean up List
CleanUpList( "List", "Size", "h", oCUA )
oCUA.commitChanges()
End Sub
' sListName: PickList or List
' sSizeName: PickListSize or Size
' sPrefix: p or h
Sub CleanUpList( sListName As String, sSizeName As String, _
sPrefix As String, oAccess As Object)
Dim oList As Object
Dim oItem As Object
Dim nSize As Long
Dim sName As String
Dim nCounter As Integer
oList = oAccess.getPropertyValue( sListName )
nSize = oAccess.getPropertyValue( sSizeName )
nCounter = 0 'existing items
For i = 0 To nSize - 1 step 1
sName = sPrefix & CStr(i)
If oList.hasByName( sName ) Then
oItem = oList.getByName( sName )
If FileExists( oItem.URL ) Then
CreateAsNewItem( oList, oItem, sPrefix & CStr(nCounter) )
If nCounter <> i Then
oList.removeByName( sName )
End If
nCounter = nCounter + 1
Else
oList.removeByName( sName )
End If
End If
Next
End Sub
' make new item and insert/replace it in the sName position
Sub CreateAsNewItem( oList As Object, oItem As Object, sName As String )
oNewItem = oList.createInstance()
With oNewItem
.URL = oItem.URL
.Filter = oItem.Filter
.Title = oItem.Title
.Password = oItem.Password
End With
If oList.hasByName( sName ) Then
oList.replaceByName( sName, oNewItem )
Else
oList.insertByName( sName, oNewItem )
End If
End Sub