Page 1 of 1
Make changes to Dialogs persistent
Posted: Wed Dec 07, 2011 10:45 am
by Fernand
When have made some changes to a Dialog (stored in a Librarie)using Basic and API I trye to make this changes persitent for future use.
The secrets are in the methods off the dialog.model
odialog.model.read( ???)
odialog.model.write(???)
found a confusing explaination in the DSK but nullware any examples how to use this read-write mechanism to make the changes persitent
Thanks for any hint !
Fernand
Re: Make changes to Dialogs persistent
Posted: Wed Dec 07, 2011 11:58 am
by hanya
Hi,
Welcome to the forum.
You can make your control model persistent as follows:
Code: Select all
Sub DialogPersistentTest
DialogLibraries.loadLibrary("Standard")
dlg = CreateUnoDIalog(DialogLibraries.Standard.Dialog15)
url = "file:///home/asuka/Desktop/list_model.out"
list = dlg.getControl("ListBox1")
list_model = list.getModel()
'PersistControl(list_model, url)
RestoreControl(list_model, url)
dlg.execute()
dlg.dispose()
End Sub
' store control properties to file.
Sub PersistControl(ctrl_model as Variant, url as string)
sfa = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
o = sfa.openFileWrite(url)
mos = CreateUnoService("com.sun.star.io.MarkableOutputStream")
oos = CreateUnoService("com.sun.star.io.ObjectOutputStream")
oos.setOutputStream(mos)
mos.setOutputStream(o)
ctrl_model.write(oos)
o.closeOutput()
End Sub
' restore control properties from file.
Sub RestoreControl(ctrl_model as Variant, url as string)
sfa = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
i = sfa.openFileRead(url)
mis = CreateUnoService("com.sun.star.io.MarkableInputStream")
ois = CreateUnoService("com.sun.star.io.ObjectInputStream")
ois.setInputStream(mis)
mis.setInputStream(i)
ctrl_model.read(ois)
i.closeInput()
End Sub
Re: Make changes to Dialogs persistent
Posted: Wed Dec 07, 2011 3:24 pm
by Fernand
hi Hanja,
Thanks for this code,
i tested, no error's but the changes to the control are not persistent even after i did the same procedure for the whole dialog.
for testing :
Code: Select all
Sub DialogPersistentTest
DialogLibraries.loadLibrary("Standard")
dlg = CreateUnoDIalog(DialogLibraries.Standard.Dialog15)
url = "file:///home/asuka/Desktop/list_model.out"
list = dlg.getControl("ListBox1")
list_model = list.getModel()
list_model.label = "Fernand"
PersistControl(list_model, url)
RestoreControl(list_model, url)
PersistControl(dlg.model url)
RestoreControl(dlg.model, url)
dlg.execute()
'here we sea the label is changed to "Fernand"
dlg.dispose()
nextopening
end sub
sub nextopening
DialogLibraries.loadLibrary("Standard")
dlg = CreateUnoDIalog(DialogLibraries.Standard.Dialog15)
dlg.execute
'here the label is no longer "Fernand"
dlg.dispose
End Sub
When executing the dialog we sea that the listbox is labeled "Fernand" but this change is not peristent afterwards ?
Do i have to save/restore the "library" also ?
thanks for any hint
Fernand
Re: Make changes to Dialogs persistent
Posted: Wed Dec 07, 2011 4:11 pm
by hanya
The exportDialogModel function which is used internally is not exported as any api. If you want to make the control persist with css.io.XPersist interface, you have to store and load yourself. Or modify xdl file of the dialog.
Re: Make changes to Dialogs persistent
Posted: Wed Dec 07, 2011 4:39 pm
by Fernand
Hanja,
Something is excaping me ?
If we not can make "changes" persistent to the dialogfile, waths then the purpose of "model.write/read" ?
and please can you explain a bit more how i can do what you propose "you have to store and load yourself"
Thanks any how
Re: Make changes to Dialogs persistent
Posted: Wed Dec 07, 2011 9:20 pm
by hanya
You can store the state of your control and you can load the state of the control from the file. Write your own higher level api than the office api using these methods.