Copy link to clipboard
Copied
Is "cancel" a keyword or reserved word?
My simple dialog box:
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.
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?
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")
...
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.
Copy link to clipboard
Copied
Any other "self-defined" or Photoshop only reserved words that may have eluded me?
Copy link to clipboard
Copied
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