InDesign:检查是否在对话框上单击了取消按钮
InDesign: Check if cancel button is clicked on a dialog
我在 InDesign 中有一个脚本可以打开一个文件夹对话框。
如果用户按下“取消”按钮然后停止脚本,我如何显示警告?
有两个函数可以打开 File/Folder 选择对话框,它们的行为略有不同,但这两者是相同的:
• If the user clicks OK, returns a File object for the selected file, or an array of objects if multiple files are selected.
• If the user cancels, returns null.
所以你现在有一行
myFile = var myFolder.openDlg("Select a file", "*.*", false);
您可以在之后添加:
if (myFile == null)
{
alert ("You pressed Cancel!");
exit();
}
从用户界面的角度来看,我想补充一点 alert
可能 没有必要。如果据说脚本对选定的文件或文件夹执行某些操作 on/with,则在打开或保存对话框中按 "Cancel" 显然意味着用户改变了主意并且 想要 它停止。
这不是 ScriptUI,而是 InDesign 对话框对象。
这是文档中的一个片段…
var myDialog = app.dialogs.add({name:"Simple Dialog"});
//Add a dialog column.
with(myDialog.dialogColumns.add()){
staticTexts.add({staticLabel:"This is a very simple dialog box."});
}
//Show the dialog box.
var myResult = myDialog.show();
//If the user clicked OK, display one message;
//if they clicked Cancel, display a different message.
if(myResult == true){
alert("You clicked the OK button.");
}
else{
alert("You clicked the Cancel button.");
}
//Remove the dialog box from memory.
myDialog.destroy();
我在 InDesign 中有一个脚本可以打开一个文件夹对话框。
如果用户按下“取消”按钮然后停止脚本,我如何显示警告?
有两个函数可以打开 File/Folder 选择对话框,它们的行为略有不同,但这两者是相同的:
• If the user clicks OK, returns a File object for the selected file, or an array of objects if multiple files are selected.
• If the user cancels, returns null.
所以你现在有一行
myFile = var myFolder.openDlg("Select a file", "*.*", false);
您可以在之后添加:
if (myFile == null)
{
alert ("You pressed Cancel!");
exit();
}
从用户界面的角度来看,我想补充一点 alert
可能 没有必要。如果据说脚本对选定的文件或文件夹执行某些操作 on/with,则在打开或保存对话框中按 "Cancel" 显然意味着用户改变了主意并且 想要 它停止。
这不是 ScriptUI,而是 InDesign 对话框对象。
这是文档中的一个片段…
var myDialog = app.dialogs.add({name:"Simple Dialog"});
//Add a dialog column.
with(myDialog.dialogColumns.add()){
staticTexts.add({staticLabel:"This is a very simple dialog box."});
}
//Show the dialog box.
var myResult = myDialog.show();
//If the user clicked OK, display one message;
//if they clicked Cancel, display a different message.
if(myResult == true){
alert("You clicked the OK button.");
}
else{
alert("You clicked the Cancel button.");
}
//Remove the dialog box from memory.
myDialog.destroy();