[Solved] Access to LibreOffice expert configuration

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
jeanmi2403
Posts: 29
Joined: Tue Jan 29, 2008 12:37 pm
Location: Sucy en Brie (France)

[Solved] Access to LibreOffice expert configuration

Post by jeanmi2403 »

Good evening,
The question comes to me from one of my correspondents who works on documents with a lot of images located in the same folder of each document.
He wants that when loading each document, the default loading folder (Insert/Image) is the document folder.
I manage (by macro) to modify the path of the images (Tools/Options/LibreOffice/Paths/Images)

Code: Select all

oPaths = CreateUnoService("com.sun.star.util.PathSettings")
oPaths.Graphic_user = "file:///I:/Projets/Images"
But that is not taken into account. In fact Writer keeps the last used path.
I ended up finding the setting in the expert configuration.
Preference name: org.openoffice.Office.Common->Misc>FilePickerLastDirectory->WriterInsertImage
There is a key here. : org.openoffice.Office.Common:LastDirectory['WriterInsertImage'] Property: LastPath then url of folder

It is therefore a property of the FilePicker, but I am not very comfortable with this concept, which I use with other UNO services.

THE question: can we access this property and can we modify it?
Cordially,
Last edited by Hagar Delest on Wed Jan 18, 2023 10:31 pm, edited 1 time in total.
Reason: tagged solved.
Jean-Michel
LibO 7.4.7 and AOO 4.1.14 on Windows 10 x64, Windows 11 & Ubuntu 22.04
LibO 7.5 on OpenSuse & Linux MX
JeJe
Volunteer
Posts: 2906
Joined: Wed Mar 09, 2016 2:40 pm

Re: Access to LibreOffice expert configuration

Post by JeJe »

Don't know but your can easily write a macro to call the filepicker with whatever directory yourself

Code: Select all

file_dialog = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
   file_dialog.SetDisplayDirectory(converttourl("C:\tmp"))
   file_dialog.execute
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Villeroy
Volunteer
Posts: 31319
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Access to LibreOffice expert configuration

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
ms777
Volunteer
Posts: 188
Joined: Mon Oct 08, 2007 1:33 am

Re: Access to LibreOffice expert configuration

Post by ms777 »

Hi,
below some code to change configuration settings as a starter.
In my configuration there was no "WriterInsertImage" setting. Maybe you have to create that setting from scratch.

Good luck,
ms777


Code: Select all

Sub Main
sNodePath = "org.openoffice.Office.Common/Misc/FilePickerLastDirectory"

Dim args(1) As new com.sun.star.beans.PropertyValue 
args(0).Name = "nodepath" 
args(0).Value = sNodePath
args(1).Name = "EnableAsync" 
args(1).Value = false 

aConfProv = createUnoService("com.sun.star.configuration.ConfigurationProvider") 
aSettings = aConfProv.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", args()) 
xray aSettings
xray aSettings.getByname("WriterSaveAs")
msgbox aSettings.hasByName("WriterInsertImage")
'aSettings.setHierarchicalPropertyValue(sNodePath & "/Size", "384,53") 
'aSettings.commitChanges()
end sub
User avatar
jeanmi2403
Posts: 29
Joined: Tue Jan 29, 2008 12:37 pm
Location: Sucy en Brie (France)

Re: Access to LibreOffice expert configuration

Post by jeanmi2403 »

Hello,
ms777 wrote: Tue Jan 17, 2023 7:19 pm In my configuration there was no "WriterInsertImage" setting. Maybe you have to create that setting from scratch.
Because you never insert an image in Writer ? or your version of LibreOffice is too old ?
Expert.PNG
Expert.PNG (23.18 KiB) Viewed 1977 times
Thanks to your indications, I found how to read these expert configuration parameters. Big thanks !!!
So long,
Jean-Michel
LibO 7.4.7 and AOO 4.1.14 on Windows 10 x64, Windows 11 & Ubuntu 22.04
LibO 7.5 on OpenSuse & Linux MX
JeJe
Volunteer
Posts: 2906
Joined: Wed Mar 09, 2016 2:40 pm

Re: Access to LibreOffice expert configuration

Post by JeJe »

jeanmi2403 wrote: Wed Jan 18, 2023 1:00 am Because you never insert an image in Writer ? or your version of LibreOffice is too old ?
I didn't have it either - you've got to open and insert an image first for that to appear in the registry.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Mountaineer
Posts: 334
Joined: Sun Sep 06, 2020 8:27 am

Re: Access to LibreOffice expert configuration

Post by Mountaineer »

jeanmi2403 wrote: Tue Jan 17, 2023 3:57 pm ...
But that is not taken into account. In fact Writer keeps the last used path.
...
Just a warning: As I had to switch some time ago between LibreOffice-Dialogue and Windows-Dialogue in the settings I remember they behaved differently concerning used paths. So, if anything is not working, check also this setting.

J.
LibreOffice 7.6 on Windows 10pro and other Versions parallel
User avatar
jeanmi2403
Posts: 29
Joined: Tue Jan 29, 2008 12:37 pm
Location: Sucy en Brie (France)

Re: Access to LibreOffice expert configuration

Post by jeanmi2403 »

Hi,
it works perfectly.
Regardless of the previous actions, when opening the file, the images loading folder will be that of the document.
The code :

Code: Select all

Sub InitialiseFilePicker
Dim oDocument as Object
Dim sURL as String, sNodePath as String
sNodePath = "org.openoffice.Office.Common/Misc/FilePickerLastDirectory"

oDocument = ThisComponent
sURL = Directory(oDocument.URL)

Dim args(1) As new com.sun.star.beans.PropertyValue 
args(0).Name = "nodepath" 
args(0).Value = sNodePath
args(1).Name = "EnableAsync" 
args(1).Value = false 

aConfProv = createUnoService("com.sun.star.configuration.ConfigurationProvider") 
aSettings = aConfProv.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", args()) 

aSettings.getByname("WriterInsertImage").LastPath = sURL
aSettings.commitChanges()
Msgbox (ConvertFromURL(sUrl),MB_ICONINFORMATION,"Folder for insert")
end sub

Function Directory(sURL As String) As String
Dim sPath() As String, sRep As String 
	sPath = Split(sURL,"/")
	sPath(Ubound(sPath())) = ""
	Directory = join(sPath, "/")
End Function
is connected to the Open Document event.
Works on Windows and Linux.
@Mountaineer : it works on System Dialogs and Office Dialogs.
 Edit: I don't understand what's the point :

Code: Select all

aSettings.setHierarchicalPropertyValue(sNodePath & "/Size", "384,53") 
 
Thanks,
Jean-Michel
LibO 7.4.7 and AOO 4.1.14 on Windows 10 x64, Windows 11 & Ubuntu 22.04
LibO 7.5 on OpenSuse & Linux MX
ms777
Volunteer
Posts: 188
Joined: Mon Oct 08, 2007 1:33 am

Re: Access to LibreOffice expert configuration

Post by ms777 »

jeanmi2403 wrote: Wed Jan 18, 2023 10:13 pm
 Edit: I don't understand what's the point :

Code: Select all

aSettings.setHierarchicalPropertyValue(sNodePath & "/Size", "384,53") 
 
... that was just a hint how to set a configuration value. I was setting some window size parameter. But your way

Code: Select all

aSettings.getByname("WriterInsertImage").LastPath = sURL
is much easier. I did not know that this is possible ...
Post Reply