Is "cancel" a keyword or reserved word in Photoshop?

Explorer ,
May 23, 2022 May 23, 2022

Copy link to clipboard

Copied

Is "cancel" a keyword or reserved word?

 

My simple dialog box:

ui.png

 

var dlg = new Window("dialog"); 
    dlg.text = "Proceed?"; 
    dlg.preferredSize.width = 160; 

// GROUP1
// ======
var group1 = dlg.add("group", undefined, {name: "group1"}); 
    group1.preferredSize.width = 160; 

// add buttons
var button1 = group1.add ("button", undefined);
    button1.text = "OK";
var button2 = group1.add ("button", undefined);
    button2.text = "Cancel";


var myReturn = dlg.show();

if (myReturn == 1)
{
   // code here
}

 

 

Works fine. All is well. However replace the string "Cancel" with "Can" and the button no longer functions.

 

can.png

 

 

You need to add extra code in order to regain functionality.

 

button2.onClick = function()
{
  // alert("Byas!");
  dlg.close();
  dialogResponse = "cancel";
}

 

 

So, what's going on, is "cancel" a keyword?

 

TOPICS
Actions and scripting , Windows

Views

44

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , May 23, 2022 May 23, 2022
Yes, in ScriptUI – OK and Cancel are "self-defined": From the Bible "Beginning ScriptUI", by Peter Kahrel, page 15:
Responding to button presses The behaviour of buttons other than OK and Cancel must be coded explicitely. You do this with a so-called callback, in this case onClick. Here is an example:
var w = new Window ("dialog"); var e = w.add ("edittext", undefined, "Abcdefg"); var convert_button = w.add ("button", undefined, "Convert to upper case"); w.add ("button", undefined, "OK")...

Likes

Translate

Translate
Adobe Community Professional ,
May 23, 2022 May 23, 2022

Copy link to clipboard

Copied

Yes, in ScriptUI – OK and Cancel are "self-defined":

 

From the Bible "Beginning ScriptUI", by Peter Kahrel, page 15:

 


Responding to button presses

The behaviour of buttons other than OK and Cancel must be coded explicitely.

You do this with a so-called callback, in this case onClick. Here is an example:


 

var w = new Window ("dialog");
var e = w.add ("edittext", undefined, "Abcdefg");
var convert_button = w.add ("button", undefined, "Convert to upper case");
w.add ("button", undefined, "OK");
convert_button.onClick = function () {e.text = e.text.toUpperCase();}
w.show ();

 

Clicking Convert to upper case converts the text in the edit field to upper

case. This is a simple example, but the functions called by onClick can be of any

complexity. (There are several other types of callback, which we will deal with

later.)

 

Callbacks such as onClick can be combined with other callbacks in one

statement. The following script displays a small panel that we can use to check

the status of the state of the No break attribute.


 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2022 May 23, 2022

Copy link to clipboard

Copied

Any other "self-defined" or Photoshop only reserved words that may have eluded me?

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

LATEST

I don't know, I avoid ScriptUI as much as possible!

 

As for JavaScript/Extendscript, there are of course case sensitive reserved words such as var or function etc.

 

https://www.w3schools.com/js/js_reserved.asp

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines