Macro to store/load a dialogue

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Locked
ElFlamencoLoco
Posts: 20
Joined: Mon Dec 28, 2015 8:45 pm

Macro to store/load a dialogue

Post by ElFlamencoLoco »

Hi folks,

The StarBasic project I'm working on contains some macros to adapt an existing dialogue to a specific situation. The dialogue has been designed in the dialogue editor.

Exporting and importing dialogues is a piece of a cake from within the Basic IDE. But how to achieve the same effect by a macro? How to store a dialogue (in a .xdl file) and later to reload it (from that .xdl file) by a macro?

At this moment the code adapting the dialogue works fine but... a bit slowly. It takes 4-5 seconds before the dialogue pops up. Here some simplified code to illustrate:

Code: Select all

'Creating
oDia = createUnoDialog(DialogLibraries.MyLib.MyDialog)

'Adaption
for n = 1 to 100
  oCtrl = oDia.Model.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
  'Set position, size, text, textcolor, background color, listeners etc...
  ...
  'Add to dialogue
  oDia.Model.insertByName("Ctrl_" + cstr(n), oCtrl)
next n

'Running
  action = oDia.Execute
Now what I want to achieve (in pseudocode):

Code: Select all

IF dialogue doesn't (yet) exist THEN
  Create dialogue (cfr. supra)
  Export dialogue to .xdl file
ELSE
  Import dialogue from .xdl file
ENDIF
Run dialogue
Any suggestions? Thanks in advance.
Windows 10
OpenOffice 4.1.2
User avatar
RoryOF
Moderator
Posts: 35055
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro to store/load a dialogue

Post by RoryOF »

Some useful information relevant to this is at
https://openoffice-libreoffice.developp ... ogue-BASIC
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
ElFlamencoLoco
Posts: 20
Joined: Mon Dec 28, 2015 8:45 pm

Re: Macro to store/load a dialogue

Post by ElFlamencoLoco »

That site contains indeed some very usefull info. But it doesn't mention how to write a macro to save a dialogue as a .xdl file, nor how to load it from a .xdl file.

Other suggestions?
Windows 10
OpenOffice 4.1.2
User avatar
RoryOF
Moderator
Posts: 35055
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro to store/load a dialogue

Post by RoryOF »

Try
viewtopic.php?t=8020
to start with.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
ElFlamencoLoco
Posts: 20
Joined: Mon Dec 28, 2015 8:45 pm

Re: Macro to store/load a dialogue

Post by ElFlamencoLoco »

I think I didn't make myself clear enough. Sorry.

The problem is not a filepicker. I don't think I need a filepicker to export an existing, macrowise generated/adapted dialogue. In pseudocode, I don't need anything more than something like this:

Code: Select all

ExportDialog(oDia, "file:///C:/Users/user/Documents/MyProject/MyDialog.xdl")
And for importing the same dialogue something like this:

Code: Select all

oDia = ImportDialog("file:///C:/Users/user/Documents/MyProject/MyDialog.xdl")
I assume I'll have to search somewhere in the XStorable interface. But I cannot find out whether this interface is linked with the UnoControlDialog service.

I suppose this is somehow possible, since the Basic IDE itself can export and import dialogues. If the IDE can, we should be able to write a macro that also can import and export dialogues.
Windows 10
OpenOffice 4.1.2
User avatar
Villeroy
Volunteer
Posts: 31344
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macro to store/load a dialogue

Post by Villeroy »

The GUI copies the *.xdl file from some package, directory or document to some other package, directory or document and adds a registration to dialog.xlb of the respective library. The registration can point to any xdl file anywhere on the system. for instance, when you import an extension with a dialog the registration points to some file in a subdirectory of the uno_packages directory
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
User avatar
Villeroy
Volunteer
Posts: 31344
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macro to store/load a dialogue

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
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: Macro to store/load a dialogue

Post by hubert lambert »

Hello,

You can load a dialog directly from a xdl file using the DialogProvider or DialogProvider2 service :

Code: Select all

sub load_dlg
	dlg_provider = com.sun.star.awt.DialogProvider2.create()
	dlg_url = convertToURL("c:\path\to\the\dialog.xdl")
	dlg = dlg_provider.createDialog(dlg_url)
	dlg.execute()
end sub
Regards.
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
JmCornil
Posts: 3
Joined: Thu Dec 05, 2024 4:37 pm

Re: Macro to store/load a dialogue

Post by JmCornil »

Hello

Did you find a solution for your problem of storing/saving a modified dialog ?

I know that it is an old post but I find no information on this subject

Best Regards

J.M. CORNIL
OpenOffice 3.1 / Ubuntu
User avatar
RoryOF
Moderator
Posts: 35055
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro to store/load a dialogue

Post by RoryOF »

Try
https://wiki.openoffice.org/wiki/Docume ... ganization

If in any perplexity, try the works of Andrew Pitonyak which can be downloaded from
https://www.pitonyak.org/oo.php
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
JmCornil
Posts: 3
Joined: Thu Dec 05, 2024 4:37 pm

Re: Macro to store/load a dialogue

Post by JmCornil »

Thank you for your answer.

But I alredy read this papers and nowhere I found how to save a modified dialog.
OpenOffice 3.1 / Ubuntu
cwolan
Posts: 164
Joined: Sun Feb 07, 2021 3:44 pm

Re: Macro to store/load a dialogue

Post by cwolan »

@JmCornil
Are you the author of the Is it possible to save a modified dialog? topic on the Ask LibreOffice forum?
OpenOffice 1.1.5 – 4.1.15
LibreOffice 3.3.0.4 – 25.2
Windows 7,10,11 64-bit
JmCornil
Posts: 3
Joined: Thu Dec 05, 2024 4:37 pm

Re: Macro to store/load a dialogue

Post by JmCornil »

Yes, I am.
OpenOffice 3.1 / Ubuntu
User avatar
RoryOF
Moderator
Posts: 35055
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro to store/load a dialogue

Post by RoryOF »

I don't think there is a partial or incremental Save; I think you have to reSave the entire library and allow for the prompt that you are overwriting an existing library of the same name.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
JeJe
Volunteer
Posts: 3064
Joined: Wed Mar 09, 2016 2:40 pm

Re: Macro to store/load a dialogue

Post by JeJe »

Export the library eg

Code: Select all

url = converttourl("C:\tmp\") 
thiscomponent.DialogLibraries.exportLibrary( "Standard", url, nothing)
Then delete the files you don't want from the folder that's created.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Locked