Make changes to Dialogs persistent

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Fernand
Posts: 9
Joined: Wed Dec 07, 2011 10:42 am

Make changes to Dialogs persistent

Post 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
Openoffice3.3 Windows XP
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Make changes to Dialogs persistent

Post 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
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
Fernand
Posts: 9
Joined: Wed Dec 07, 2011 10:42 am

Re: Make changes to Dialogs persistent

Post 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
Openoffice3.3 Windows XP
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Make changes to Dialogs persistent

Post 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.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
Fernand
Posts: 9
Joined: Wed Dec 07, 2011 10:42 am

Re: Make changes to Dialogs persistent

Post 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
Openoffice3.3 Windows XP
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Make changes to Dialogs persistent

Post 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.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
Post Reply