Adobe 65009333 Scripting Guide - Page 65

Localization and menu names,

Page 65 highlights

Menus Understanding the menu model 65 var myMenu; //Open a new text file. var myTextFile = File.saveDialog("Save Menu Action Names As", undefined); //If the user clicked the Cancel button, the result is null. if(myTextFile != null){ //Open the file with write access. myTextFile.open("w"); for(var myMenuCounter = 0;myMenuCounter< app.menus.length; myMenuCounter++){ myMenu = app.menus.item(myMenuCounter); myTextFile.writeln(myMenu.name); myProcessMenu(myMenu, myTextFile); } myTextFile.close(); alert("done!"); } function myProcessMenu(myMenu, myTextFile){ var myMenuElement; var myIndent = myGetIndent(myMenu); for(var myCounter = 0; myCounter < myMenu.menuElements.length; myCounter++){ myMenuElement = myMenu.menuElements.item(myCounter); if(myMenuElement.getElements()[0].constructor.name != "MenuSeparator"){ myTextFile.writeln(myIndent + myMenuElement.name); if(myMenuElement.getElements()[0].constructor.name == "Submenu"){ if(myMenuElement.menuElements.length > 0){ myProcessMenu(myMenuElement, myTextFile); } } } } } function myGetIndent(myObject){ var myString = "\t"; var myDone = false; do{ if((myObject.parent.constructor.name == "Menu")|| (myObject.parent.constructor.name == "Application")){ myDone = true; } else{ myString = myString + "\t"; myObject = myObject.parent; } }while(myDone == false) return myString; } Localization and menu names in InCopy scripting, menuItems, menus, menuActions,and submenus are all referred to by name. Because of this, scripts need a method of locating these objects that is independent of the installed locale of the application. To do this, you can use an internal database of strings that refer to a specific item, regardless of the locale. For example, to get the locale-independent name of a menu action, you can use the following script fragment (for the complete script, see GetKeyStrings):

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88

Menus
Understanding the menu model
65
var myMenu;
//Open a new text file.
var myTextFile = File.saveDialog("Save Menu Action Names As", undefined);
//If the user clicked the Cancel button, the result is null.
if(myTextFile != null){
//Open the file with write access.
myTextFile.open("w");
for(var myMenuCounter = 0;myMenuCounter< app.menus.length; myMenuCounter++){
myMenu = app.menus.item(myMenuCounter);
myTextFile.writeln(myMenu.name);
myProcessMenu(myMenu, myTextFile);
}
myTextFile.close();
alert("done!");
}
function myProcessMenu(myMenu, myTextFile){
var myMenuElement;
var myIndent = myGetIndent(myMenu);
for(var myCounter = 0; myCounter < myMenu.menuElements.length; myCounter++){
myMenuElement = myMenu.menuElements.item(myCounter);
if(myMenuElement.getElements()[0].constructor.name != "MenuSeparator"){
myTextFile.writeln(myIndent + myMenuElement.name);
if(myMenuElement.getElements()[0].constructor.name == "Submenu"){
if(myMenuElement.menuElements.length > 0){
myProcessMenu(myMenuElement, myTextFile);
}
}
}
}
}
function myGetIndent(myObject){
var myString = "\t";
var myDone = false;
do{
if((myObject.parent.constructor.name == "Menu")||
(myObject.parent.constructor.name == "Application")){
myDone = true;
}
else{
myString = myString + "\t";
myObject = myObject.parent;
}
}while(myDone == false)
return myString;
}
Localization and menu names
in InCopy scripting,
menuItems
,
menus
,
menuActions
,and
submenus
are all referred to by name. Because of
this, scripts need a method of locating these objects that is independent of the installed locale of the
application. To do this, you can use an internal database of strings that refer to a specific item, regardless of
the locale. For example, to get the locale-independent name of a menu action, you can use the following
script fragment (for the complete script, see GetKeyStrings):