Macro to store/load a dialogue

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
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: 34612
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.4 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: 34612
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.4 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: 31279
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: 31279
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
Post Reply