Page 1 of 1

Macro to store/load a dialogue

Posted: Sat Jan 27, 2018 7:19 pm
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.

Re: Macro to store/load a dialogue

Posted: Sat Jan 27, 2018 8:07 pm
by RoryOF
Some useful information relevant to this is at
https://openoffice-libreoffice.developp ... ogue-BASIC

Re: Macro to store/load a dialogue

Posted: Sat Jan 27, 2018 10:25 pm
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?

Re: Macro to store/load a dialogue

Posted: Sat Jan 27, 2018 10:48 pm
by RoryOF
Try
viewtopic.php?t=8020
to start with.

Re: Macro to store/load a dialogue

Posted: Sat Jan 27, 2018 11:18 pm
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.

Re: Macro to store/load a dialogue

Posted: Sat Jan 27, 2018 11:47 pm
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

Re: Macro to store/load a dialogue

Posted: Sun Jan 28, 2018 7:32 pm
by Villeroy

Re: Macro to store/load a dialogue

Posted: Mon Jan 29, 2018 7:09 pm
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.