[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libreoffice-users] Macro to autoload first recent doc


Let's improve the code a bit...

When we open the registry key we do not need it to be editable so let's open it as read only. By default GetRegistryKeyContent opens it as such. For some reason LibreOffice complains about named arguments not supported for the object, as Jon pointed out to me.

I've changed the key as well to correspond exactly with the key in registry. You can search for the key in the registrymodifications.xcu file (with the path %appdata%\LibreOffice\4\user\registrymodifications.xcu on windows).

I've added a new sub which opens the file and sets some open arguments according to what is saved in the registry and if the file is a template it should be opened in edit mode. I do not think that the password part works at the moment, so that part of the code probably needs some love. ;)

Sub Load1st()
Dim oCUA, oList, oItem As Object
If Not BasicLibraries.isLibraryLoaded("Tools") Then BasicLibraries.LoadLibrary("Tools")
REM use GetRegistryKeyContent function from the module Tools.Misc
oList = GetRegistryKeyContent("/org.openoffice.Office.Histories/Histories/org.openoffice.Office.Histories:HistoryInfo['PickList']/OrderList")
If oList.hasByName("0") Then
oItem = oList.getByName("0")
OpenRecentFile(oItem.HistoryItemRef)
End If
End Sub

Sub OpenRecentFile(sFileURL as String)
Dim oPickList As Object, oPickListArgs As Object
Dim loadArgs(2) As New com.sun.star.beans.PropertyValue
If Not BasicLibraries.isLibraryLoaded("Tools") Then BasicLibraries.LoadLibrary("Tools")
oPickList = GetRegistryKeyContent("/org.openoffice.Office.Histories/Histories/org.openoffice.Office.Histories:HistoryInfo['PickList']/ItemList")
If oPickList.hasByName(sFileURL) Then
oPickListArgs = oPickList.getByName(sFileURL)
If FileExists(sFileURL) Then
loadArgs(0).Name = "AsTemplate" 'We never want to open a recent file as template
loadArgs(0).Value = false
loadArgs(1).Name = "Filter"
loadArgs(1).Value = oPickListArgs.getByName("Filter")
loadArgs(2).Name = "Password"
loadArgs(2).Value = oPickListArgs.getByName("Password")
REM use OpenDocument function from the module Tools.Misc
OpenDocument(sFileURL, loadArgs())
End If
End If
End Sub


'I loosely took inspiration from the LibreOffice code http://opengrok.libreoffice.org/xref/core/unotools/source/config/historyoptions.cxx

Regards,
Niklas Johansson


--
To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Follow-Ups:
Re: [libreoffice-users] Macro to autoload first recent docJon Harringdon <jonathan.harringdon@virgin.net>
References:
[libreoffice-users] Macro to autoload first recent docJon Harringdon <jonathan.harringdon@virgin.net>
Re: [libreoffice-users] Macro to autoload first recent doc<sleeping.pillow@gmail.com>
Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.