Macro to store/load a dialogue

Creating a macro - Writing a Script - Using the API

Macro to store/load a dialogue

Postby ElFlamencoLoco » Sat Jan 27, 2018 7:19 pm

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   Expand viewCollapse view
'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   Expand viewCollapse view
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
ElFlamencoLoco
 
Posts: 20
Joined: Mon Dec 28, 2015 8:45 pm

Re: Macro to store/load a dialogue

Postby RoryOF » Sat Jan 27, 2018 8:07 pm

Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28548
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro to store/load a dialogue

Postby ElFlamencoLoco » Sat Jan 27, 2018 10:25 pm

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
ElFlamencoLoco
 
Posts: 20
Joined: Mon Dec 28, 2015 8:45 pm

Re: Macro to store/load a dialogue

Postby RoryOF » Sat Jan 27, 2018 10:48 pm

Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28548
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro to store/load a dialogue

Postby ElFlamencoLoco » Sat Jan 27, 2018 11:18 pm

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   Expand viewCollapse view
ExportDialog(oDia, "file:///C:/Users/user/Documents/MyProject/MyDialog.xdl")
And for importing the same dialogue something like this:
Code: Select all   Expand viewCollapse view
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
ElFlamencoLoco
 
Posts: 20
Joined: Mon Dec 28, 2015 8:45 pm

Re: Macro to store/load a dialogue

Postby Villeroy » Sat Jan 27, 2018 11:47 pm

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, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26542
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macro to store/load a dialogue

Postby Villeroy » Sun Jan 28, 2018 7:32 pm

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26542
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macro to store/load a dialogue

Postby hubert lambert » Mon Jan 29, 2018 7:09 pm

Hello,

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

Code: Select all   Expand viewCollapse view
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
hubert lambert
 
Posts: 118
Joined: Mon Jun 13, 2016 10:50 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 3 guests