Getting Program Control Closing A Script Dialog

dave_galera

Well-known member
Hi,

When a user clicks the RED X close icon in the top left hand corner of a script dialog how do you get program control so the same process can be executed as for a user clicking the normal Close/Exit/Dismiss button located on the bottom button line?

Any help would be appreciated........

Screenshot 2020-05-14 at 19.00.32.png


OK I have done it.....forget I ever asked LOL
 
Last edited:
Hi Dave,

Anyway, for future reference of other users, the solution to this problem is to implement the Control.onClose() event handler for the Dialog in question. Example script:

JavaScript:
#include <pjsr/StdButton.jsh>
#include <pjsr/StdIcon.jsh>

function FooBarDialog()
{
   this.__base__ = Dialog;
   this.__base__();

   this.info_Label = new Label( this );
   this.info_Label.text = "This is a FooBar dialog.";

   //

   this.ok_Button = new PushButton( this );
   this.ok_Button.text = "OK";
   this.ok_Button.icon = this.scaledResource( ":/icons/ok.png" );
   this.ok_Button.onClick = function()
   {
      this.dialog.ok();
   };

   this.cancel_Button = new PushButton( this );
   this.cancel_Button.text = "Cancel";
   this.cancel_Button.icon = this.scaledResource( ":/icons/cancel.png" );
   this.cancel_Button.onClick = function()
   {
      this.dialog.cancel();
   };

   this.buttons_Sizer = new HorizontalSizer;
   this.buttons_Sizer.spacing = 8;
   this.buttons_Sizer.addStretch();
   this.buttons_Sizer.add( this.ok_Button );
   this.buttons_Sizer.add( this.cancel_Button );

   //

   this.sizer = new VerticalSizer;
   this.sizer.margin = 8;
   this.sizer.spacing = 8;
   this.sizer.add( this.info_Label );
   this.sizer.addSpacing( 8 );
   this.sizer.add( this.buttons_Sizer );

   this.windowTitle = "FooBar";
   this.adjustToContents();
   this.setFixedSize();

   /*
    * Event received when the dialog window is closed.
    * Returns true if the dialog can be closed; false to ignore the event.
    */
   this.onClose = function()
   {
      return (new MessageBox( "Do you really want to exit FooBar?",
           "FooBar Dialog", StdIcon_Question, StdButton_No, StdButton_Yes )).execute() == StdButton_Yes;
   };
}

FooBarDialog.prototype = new Dialog;

function main()
{
   console.show();
   console.writeln( "The FooBar dialog returned: ", (new FooBarDialog).execute() );
}

main();
 
Back
Top