Is it possible to save a modified dialog?

Hello Guys

I have a Dialog that I loaded with loadDialog and modified with a BASIC macro (it’s a color palette with 120 controls that I put into with a loop, see below).

I would like to be able to save this modified dialog so that I don’t have to recalculate it every time I use it. But I don’t find the symmetrical of loadDialog. Can I achieve with StoreDocument? But I don’t see which parameters to use.

Any hint ?

Thank you in advance

J.M. CORNIL

< < < < < < My Macro, that constructs the dialog and open it > > > > > >

Sub Macro2

	BasicLibraries.LoadLibrary("XrayTool")  ' Pour charger xray qui permet l'instrospection
	BasicLibraries.LoadLibrary("Tools")  ' Pour charger xray qui permet l'instrospection

	Dim dialog As Object
	dialog = LoadDialog("Standard","www_Dialog_test") 
	
	xray dialog

	Dim colorTable 	As Object
	Dim colorNames	As Object
	Dim color				 As String
	colorTable = createUnoService("com.sun.star.drawing.ColorTable")
	' obtenir un tableau des couleurs de la palette
	colorNames = colorTable.ElementNames
	Const ORG_X = 30, ORG_Y = 10, DELTA_X = 2, DELTA_Y = 4, NBR_COL=12 
	Dim posX, posY, numCol, numLgn As Integer
	Dim mdl As Object	
	posX = ORG_X
	posY = ORG_Y 
	numCol = 0
	numLgn =0
	for each color in colorNames    ' Boucle sur les couleurs 
		'mdl = dialog.Model.createInstance("com.sun.star.awt.UnoControlButtonModel")
		mdl = dialog.Model.createInstance("com.sun.star.awt.UnoControlFixedTextModel")		
		'xray mdl
		mdl.Width 	= 10
		mdl.Height 	= 12
		mdl.PositionX = posX			
		mdl.PositionY = posY
		mdl.Name = color
		mdl.backGroundColor =  colorTable.getByName(color)
		'mdl.TabIndex = 5 + 3*i +j
		'mdl.label =  cstr(i) & cstr(j)
		'insérer le modèle du contrôle dans le modèle du dialogue
		mdl.HelpText = color
		dialog.Model.insertByName(mdl.Name, mdl)
		posX = posX + mdl.Width + DELTA_X
		numCol = numCol+1
		if numCol = NBR_COL then
			numCol = 0
			posX = ORG_X
			posY = posY + mdl.Height + DELTA_Y
		End If
	'	print color
	next color
	
	dialog.execute

End Sub

The www_Dialog_test.xdl file is attached in zip format
www_Dialog_test.xdl.zip (620 Bytes)

would need some sort of serializer,
maybe this … xmldlg_export.cxx (revision ed0b12f4) - OpenGrok cross reference for /core/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx

Thank you for this link but I am not very familiar with C++ at this level.

What intrigues me the most is that the function to save a dialog in.xdl format exists since the dialogs built with the IDE are well saved but I can’t find any trace of them anywhere.

maybe .uno:ExportDialog

see https://wiki.documentfoundation.org/Development/DispatchCommands

If we are talking about dialogs that are saved inside the document, then the path inside the archive is:
\Dialogs\MyLibrary\MyDialog.xml

No, it is not the problem of finding the file where is written the description of the dialog.

My problem is to find the function which permits to save a modified dialog.

I am looking at the com.sun.star.frame.DispatchHelper but it is not evident to make it work …

The dialog exists in two “stages”:

  1. Dialog definition (can be in a file or created dynamically)
  2. Executable dialog (in a window)

I don’t know of any way to save dialogs to a file after you’ve loaded the dialog (using CreateUnoDialog or calling the appropriate UNO services). You can modify the executable dialog, show it modally or non-modally, etc.


However, it is probably possible to use the dialog model to define a new dialog and save it.

Unfortunately this is only tip instead of solution, and maybe bad tip.
Every .Model in dialog has the method .write(), so maybe it could be possible to write the object to some binary file.
I tried simple code but without success.

	'your code
	'dialog.execute

	dim oService as object, oStream as object, oObjectStream as object, oSfa as object
	oObjectStream=createUnoService("com.sun.star.io.ObjectOutputStream")
	oSfa = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
	oStream=oSfa.openFileWrite("d:\dialog.txt") 'path to saved file
	oObjectStream.setOutputStream(oStream)
	'oObjectStream.writeObject(dialog)
	dialog.Model.write(oObjectStream) 'ERROR
	oObjectStream.closeOutput
	oStream.closeOutput

There is chapter 8.9.5. Pipes in the A. Pitonyak’s macro book that has the example for Successor and Predecessor, so maybe try to set the Successor for com.sun.star.io.ObjectOutputStream like in Pipes example?


Unfotunately I have neckache in these days so I can’t spend more time with programming experiments.

Hello, @KamilLanda!
I’m in a period of extreme busyness at work, so we can return to the experiments later.

I came across the topic Make changes to Dialogs persistent.

Do the macros and opinions presented in it have any significance for LibreOffice?

1 Like

Hello @fpy

I tried your hint (which looked very promising) using the indicated page. So I tested:

Sub Macro
	BasicLibraries.LoadLibrary("Tools")  ' Pour charger xray qui permet l'instrospection

	dialog = LoadDialog("Standard","www_Dialog_test") 
	dialog.model.name ="www_Dialog_test_new"

 	Set oDispatch = CreateUnoService("com.sun.star.frame.DispatchHelper")
    Dim args(3) As New com.sun.star.beans.PropertyValue
    oDispatch.executeDispatch(dialog,  ".uno:ExportDialog ", "", 0,args)

End Sub

But this leads to the error message.
Mess_Error

I tried dialog.model instead of dialog but I have the same problem.

From what I understand, it would be enough to transform the dialog object into "
com.sun.star.frame but I don’t see how?

Any idea ?

Thank you @cwolan

Interesting link. I will dive in it tomorrow

uno:ExportDialog is the actual call from File > Export dialog menu,
which actually saves the currently edited dialog;
not sure if your LoadDialog() may cope in parallel with it.

otherwise, need to find your way down the callstack …
ultimately (c++ again, sorry) : exportdialog.cxx (revision 61dea439) - OpenGrok cross reference for /core/svtools/source/filter/exportdialog.cxx

maybe try to shake tdf#97268 to raise interest of more skilled people :wink:

maybe also a ping to Development/Mailing List - The Document Foundation Wiki

You only have to calculate it once. You can use the generated dialog multiple times once generated.
On my 7 year old PC it takes < 1 second to generate the dialog. Is time saving your final goal in saving the dialog?
Regards,
ms777

1 Like

There may be a desire to use the design editor for manual editing including the dialog controls that are not accessible through the “tool box” toolbar. In this case, I would use the dialog editor leaving some space for the tree controls and color pickers to be added on runtime.