Page 1 of 1
Save /back up Basic Libraries with macro, rename Libraries
Posted: Mon Nov 12, 2018 12:31 am
by JeJe
Attached extension makes it easy to back up libraries. Someone recommended starting all your libraries with a couple of letters so they can be distinguished from other peoples - hence the feature of selecting libraries this way.
Second dialog to edit exported libraries
-rename them
-rename modules - includes replacing calls to the module eg in dialog controls
-replace text in files eg to change location=document to location = application
-open files in Writer
Use with caution - don't work on your only copy of a library
See module AAUser
Simple script to export/back up your Basic Libraries. (I've noticed that information in libraries can sometimes be lost when using the organiser and backing them up individually via the dialog is tedious)
Code: Select all
sub test()
SaveBasicLibraries ConvertToUrl("C:\tmp\libraries" & "2" ' format(date,"ddmmyy"))
end sub
Sub SaveBasicLibraries(URL as string)
dim i as long,libnames,Blibs,Dlibs,Dlibnames
Blibs = GlobalScope.BasicLibraries
libnames= Blibs.getelementnames
for i = 0 to ubound(libnames)
Blibs.ExportLibrary libnames(i),URL,nothing
next
Dlibs = GlobalScope.DialogLibraries
Dlibnames= Dlibs.getelementnames
for i = 0 to ubound(Dlibnames)
Dlibs.ExportLibrary Dlibnames(i),URL,nothing
next
Msgbox "Libraries Exported"
End Sub
EDIT: MY ORIGINAL POST DIDN'T EXPORT DIALOGS - AMENDED.
EDIT2: Rename library code posted further on in thread
EDIT3: Added a dialog to the extension to Edit exported libraries
Re: Save /back up Basic Libraries with macro
Posted: Tue Nov 20, 2018 5:37 pm
by JeJe
UPDATED THREAD AS ORIGINAL VERSION JUST SAVED MODULES NOT DIALOGS.
Think okay now - but don't rely on for anything critical (eg creating your only copy of a library)
Re: Save /back up Basic Libraries with macro
Posted: Tue Nov 20, 2018 8:35 pm
by Zizi64
Re: Save /back up Basic Libraries with macro
Posted: Tue Nov 20, 2018 10:56 pm
by JeJe
Thanks, yeah. Another approach would be to save the User Profile.
This document from 2006 discusses implementing multiple library export:
... allowing multiple library export would cause considerable work as currently the library listbox at the “Organizer dialog/Libraries” tabpage does not support multi selection and none of the other functionality provided there (Edit, Password, Delete) supports it either. So the corresponding buttons would always have to be disabled in case of a multi selection. The bottom line is that the small advantage of multi library export does not seem to justify the additional work. So it will not be realised for now.
https://www.openoffice.org/specs/ide/Ba ... rtSpec.odt
The thing I like about OO is even though it doesn't have this feature - it allows access to the things necessary to implement it yourself if you want it - just with OOBasic. I don't know anything about the effort needed to code the above in the main program... but in Basic that dialog I wrote took very little time.
Re: Save /back up Basic Libraries with macro
Posted: Tue Nov 20, 2018 11:07 pm
by RoryOF
The problem with saving the User Profile is that, on occasions, it is necessary to delete the User Profile; the ability to restore one's selection of macros to a new (uncorrupted) User Profile could be very useful.
Re: Save /back up Basic Libraries with macro
Posted: Sat Nov 24, 2018 8:53 pm
by JeJe
Here is my rename code.
It exports a library, renames the folder,
then loads each document and does a find/replace for instances of the library name.
(NB: there may be some I've missed)
You can then import the modified library.
This is all tedious doing it manually. The code could also be modified to do a find/replace for location=document vs location=application
Again, take care if you use this code, examine the results and keep a backup of the original library just in case.
Code: Select all
sub test
dim URL as string,pth as string, STS() AS STRING,libname as string,newlibname as string
libname="JePickers"
newlibname="JePickers2"
oPathSettings = CreateUnoService( "com.sun.star.util.PathSettings" )
URL= oPathSettings.UserConfig
pth=convertfromURL( URL)
CreateRenamedLibrary pth, libname,newlibname
redim sts(5)
sts(0) = "quot;" & libname
sts(1) = "quot;" & newlibname
sts(2) = ":" & libname & "."
sts(3) = ":" & newlibname & "."
sts(4) = "library:name=" & chr(34) & libname
sts(5) = "library:name=" & chr(34) & newlibname
openFolderAndReplaceStrings pth,sts()
Msgbox "Done"
end sub
sub CreateRenamedLibrary(pth as string, libname as string,newlibname as string)
dim i as long,Blibs,Dlibs,URL as string
URL = convertToURL(pth)
Blibs = GlobalScope.BasicLibraries
if Blibs.hasbyname(libname) then
Blibs.ExportLibrary libname,URL,nothing
gotlib = true
end if
Dlibs = GlobalScope.DialogLibraries
if Dlibs.hasbyname(libname) then
Dlibs.ExportLibrary libname,URL,nothing
gotlib= true
end if
if gotlib = true then
Name (pth & GetPathSeparator() & libname) as (pth & GetPathSeparator() & newlibname)
pth = (pth & GetPathSeparator() & newlibname & GetPathSeparator())
end if
end sub
sub openFolderAndReplaceStrings(pth as string,sts() as string)
Dim NextFile As String,fpth as string
NextFile = Dir(pth, 0)
While NextFile <> ""
fpth = pth & nextfile
OpendocAndreplaceString pth & nextfile,STS()
NextFile = Dir
Wend
end sub
Sub OpendocAndreplaceString(pth as string,sts())
Dim oDoc
Dim oVal(2) As New com.sun.star.beans.PropertyValue
dim URL as string
Dim oRD as Object
oVal(0).Name = "Hidden"
oVal(0).Value = true
oVal(1).Name = "FilterName"
oVal(1).Value = "Text (encoded)"
oVal(2).Name = "FilterOptions"
oVal(2).Value = "UTF8,LF"
oDoc = StarDesktop.loadComponentFromURL(convertToURL(pth), "_blank", 0, oVal())
oRD = ODoc.createReplaceDescriptor
oRD.SearchCaseSensitive = True
for i = 0 to ubound(sts) step 2
oRD.SearchString = sts(i)
oRD.ReplaceString =sts(i+1)
oDoc.replaceAll(oRD)
next
oDoc.store
oDoc.close(TRUE)
End Sub
Re: Save /back up Basic Libraries with macro, rename Librari
Posted: Tue Dec 04, 2018 1:16 am
by JeJe
Added dialog to extension to edit exported dialogs.