Page 1 of 1

Why does the automatically generated code create the toolbars in differently?

Posted: 20 Nov 2013 11:36
by Ferenc Nagy
Hi,
The status line toolbar is generated simply.
The project toolbar is create in the brackets of a whenCreated call.
Place: generatedOnShow

Code: Select all

statusLine::create(getVPIWindow()),
Place: generatedInitialize

Code: Select all

whenCreated({ :- projectToolbar::create(getVPIWindow()) }),
Why?

Posted: 22 Nov 2013 20:32
by Thomas Linder Puls
getVPIWindow will raise an exception if the window is not actually created/shown.

whenCreated postpones the call until the window is created. If is is already created it just run the code.

In a show-handler the window is created, in the constructor/generatedInitialize the window is not yet created.

So in a show handler whenCreated is not necessary, but in the constructor/generatedInitialize it is necessary.

In a new project (created today) the toolbars are created in generatedInitialize like this:

Code: Select all

predicates     generatedInitialize : (). clauses     generatedInitialize():-         setText("testGUI"),         setDecoration(titlebar([closebutton(),maximizebutton(),minimizebutton()])),         setBorder(sizeBorder()),         setState([wsf_ClipSiblings]),         whenCreated({ :- projectToolbar::create(getVpiWindow()), statusLine::create(getVpiWindow()) }),         addSizeListener({ :- vpiToolbar::resize(getVpiWindow()) }),         setMdiProperty(mdiProperty),         menuSet(resMenu(resourceIdentifiers::id_TaskMenu)),         addShowListener(onShow),         addSizeListener(onSizeChanged),         addDestroyListener(onDestroy),         addMenuItemListener(resourceIdentifiers::id_help_about, onHelpAbout),         addMenuItemListener(resourceIdentifiers::id_file_exit, onFileExit).

WhenCreated vs. e_Create

Posted: 23 Nov 2013 14:32
by Ferenc Nagy
Thomas, I uderstand your answer.
Is this code equivalent

Code: Select all

whenCreated({ :- projectToolbar::create(getVpiWindow()), statusLine::create(getVpiWindow()) }
with the same predicate calls within the handling of the Create event?


Code: Select all

task_win_eh(_Win,e_Create(_),0):-!, projectToolbar::create(getVpiWindow()), statusLine::create(getVpiWindow(),         !.
Is the Show event sent to a window exactly once?

Posted: 23 Nov 2013 23:24
by Thomas Linder Puls
Yes, the show event is sent (exactly once) in the e_create handler.

What do you recommend to put in whenCreated(), onCreate() and onShow()?

Posted: 24 Nov 2013 10:23
by Ferenc Nagy
As I see the VIP team has changed the strategy of automatically created code since version 5.2,
and you have invented the whenCreated procedure which gathers the todolist for onCreate event handler.

Please give me some examples of actions for which the best / only place is
a) the actual parameters of whenCreated(....),
b) the clauses of the classic onCreate(...) event handler,
c) the clauses of the classic onShow(...) event handler,
respectively.

Posted: 24 Nov 2013 16:41
by Thomas Linder Puls
There are only whenCreated and show listeners, create belongs to the vpi world.

It is not possible to give best/only advices.

but in some cases you may consider the execution order: whenCreated actions are performed before the show listeners are invoked. (If you want something to take place after all show listeners you can use a postAction).