How can you do this without using a reference?

-----Original Message-----
From: Dan Stowell [mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 18, 2006 11:51 AM
To: William Krick; [email protected]
Subject: RE: [Laszlo-user] modal dialogs are non-blocking?possible bug?


> I simplified the code a little by overriding close and passing the 
> button name.
> I think it makes it clearer.

I agree, this code is tighter and clearer. The one thing I did in 
creating the handleClose() method below that I would try to avoid in 
production code is using a reference (to dlg, in this case). Using too 
many references makes it difficult to discern control flow - as I've 
found when returning to code I wrote in the past.

> <?xml version="1.0" encoding="UTF-8" ?>
> <canvas debug="true">
>
>   <class name="okcanceldialog" extends="modaldialog">
>
>     <method name="close" args="buttonHit">
>       if ( this['onclose'] ) {
>         onclose.sendEvent( buttonHit );
>       }
>       super.close();
>     </method>
>
>     <reverselayout axis="y" />
>
>     <view layout="axis:x" >
>       <button onclick="classroot.close(this.name)" name="ok" text="OK" 
> isdefault="true" />
>       <button onclick="classroot.close(this.name)" name="cancel" 
> text="Cancel" />
>     </view>
>
>   </class>
>
>   <method name="handleClose" args="buttonHit" event="onclose" 
> reference="dlg">
>     switch ( buttonHit ) {
>       case 'ok':     Debug.write( 'Dialog returned ok' ); break;
>       case 'cancel': Debug.write( 'Dialog returned cancel' ); break;
>       default:       Debug.warn( 'Dialog returned ', result ); break;
>     }
>   </method>
>
>   <okcanceldialog name="dlg">
>     <text>Hello World!</text>
>   </okcanceldialog>
>
>   <button x="20" y="20" text="click me" onclick="canvas.dlg.open()" />
>
> </canvas>
>
>
>
>
>
>
> -----Original Message-----
> From: Dan Stowell [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, January 17, 2006 11:58 AM
> To: William Krick; [email protected]
> Subject: RE: [Laszlo-user] modal dialogs are non-blocking?possible 
> bug?
>
>
>> Have any bigger (more complete) examples?
>
> The overarching theme here is that code has to be broken apart in 
> asynchronous settings. Here's your original dialog example using 
> events:
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <canvas debug="true">
>
>      <class name="okcanceldialog" extends="modaldialog">
>          <attribute name="buttonHit"/>
>
>          <method name="ok">
>              this.buttonHit = "ok";
>              this.close();
>          </method>
>
>          <method name="cancel">
>              this.buttonHit = "cancel";
>              this.close();
>          </method>
>
>          <reverselayout axis="y" />
>
>          <view layout="axis:x" >
>              <button text="OK" isdefault="true">
>                  <method name="ok" event="onclick">
>                      if ( classroot['onclose'] ) {
>                          classroot.onclose.sendEvent( 'ok' );
>                      }
>                      classroot.close();
>                  </method>
>              </button>
>              <button text="Cancel">
>                  <method name="cancel" event="onclick">
>                      if ( classroot['onclose'] ) {
>                          classroot.onclose.sendEvent( 'cancel' );
>                      }
>                      classroot.close();
>                  </method>
>              </button>
>          </view>
>      </class>
>
>      <method name="handleClose" args="result" event="onclose" 
> reference="dlg">
>          switch ( result ) {
>              case 'ok':     Debug.write( 'Dialog returned ok' ); 
> break;
>              case 'cancel': Debug.write( 'Dialog returned cancel' ); 
> break;
>              default:       Debug.warn( 'Dialog returned ', result ); 
> break;
>          }
>      </method>
>
>      <okcanceldialog name="dlg">
>          <text>Hello World!</text>
>      </okcanceldialog>
>
>      <button x="20" y="20" text="click me">
>          <method name="showDialog" event="onclick">
>              canvas.dlg.open();
>          </method>
>      </button>
>
> </canvas>
>
> Dan Stowell
> Software Engineer
> Laszlo Studios
>
>
>
>
> _______________________________________________
> Laszlo-user mailing list
> [email protected]
> http://www.openlaszlo.org/mailman/listinfo/laszlo-user


Dan Stowell
Software Engineer
Laszlo Studios




_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user

Reply via email to