Indesign 脚本 UI:在确定取消按钮之前动态添加文本编辑字段
Indesign Script UI: Dynamic Add Text Edit Fields before OK-Cancel Buttons
我正在尝试显示一个脚本 ui window 如果用户单击“添加另一个”按钮而不是“确定”或“取消”按钮,它将添加另一组输入字段...
我完成了某种工作...即我可以展示一个简单的两组,ui window
(第 1 组 = 1 个文本编辑字段和一个下拉列表以及添加另一个按钮
第 2 组 = 正常的确定-取消按钮)
如果用户在前 2 个输入字段中填写 in/chooses,然后忽略“添加另一个”按钮并使用“确定-取消”按钮,脚本将继续正常运行。
但是,如果用户单击“添加另一个”按钮,脚本会利用 call-back/event 处理函数 (add_AnotherInputline) 首先删除“确定-取消”按钮组,然后添加(通过 add_inputFields 函数)另一个一组文本编辑字段和下拉列表,然后重新添加确定-取消按钮... (我想不出另一种方法让确定-取消按钮移动或始终停留在底部window!)
但是删除-添加 OK-Cancel 按钮组是我的问题所在。当我这样做时,这些按钮在用户使用 add_AnotherInputLine 函数后不再起作用......这在数据浏览器中可以看到,因为此时在脚本中 cancelElement并且 defaultElement 现在等于 = 对象无效
这是 window/ui 代码...我希望这就足够了。我遗漏了以下代码中使用的大量先验(数组、变量)...如果您需要它们,它们是带有文本项的简单数组或询问我可以提供包含内容的 variables/arrays。
(是的,我有 G. Singelmann 脚本并对其进行了广泛研究......我还没有从中找出解决方案,以满足我的特殊需要......)
var myCSdialog = new Window("dialog", "Setup Color Coding");
dialogSetup();
//begin building dialog box myDialog
add_inputFields(myCSdialog);
if (myCSdialog.children.length <= 1) {
normalButtons(myCSdialog);
};
if (myCSdialog.show() == 1) {
userCancelled = false;
} else {
exit();
};
//function adds criteria input collection fields (text criteria and swatch choice)
function add_inputFields(myCSdialog) {
var myEnterCriteriaGroup = myCSdialog.add("group");
//title for first input
myEnterCriteriaGroup.add("statictext",undefined,"Criteria to Color Code");
//text entry field to enter criteria term
var myEnterCriteria = myEnterCriteriaGroup.add("edittext",undefined,"");//field for entering text criteria
myEnterCriteria.characters = 25;
myEnterCriteria.active = true;
var myListOfColors = myEnterCriteriaGroup.add("dropdownlist",undefined,mySwatchNames);//dropdown field for choosing swatch
//add button to add another row of fields to gather another set of user input
var addAnother_button = myEnterCriteriaGroup.add("button", undefined, "Add Another");
//event handler registered
addAnother_button.onClick = add_AnotherInputLine; //no passing parameters here! won't show button to be clicked!
//event handler...callback functions put input into arrays
myEnterCriteria.onChange = function() {
criteriaKeys.push(myEnterCriteria.text);
};
myListOfColors.onChange = function() {
if(myListOfColors.selection === null) {
myListOfColors.selection=myListOfColors.prevSel;
} else {
myListOfColors.prevSel=myListOfColors.selection.index
criteriaValues.push(myListOfColors.selection.text);
};
};
//if you don't add another group (add_AnotherInputLine() function...text edit field & dropdown) it hangs here... Ok or Cancel button do nothing...
};
//function adds another input row (text criteria and swatch choice) need to find a way NOT to remove OK/Cancel buttons...
function add_AnotherInputLine() {
myCSdialog.remove(myCSdialog.children[myCSdialog.children.length - 1]);
add_inputFields(myCSdialog);
if (myCSdialog.children.length >= 1) {
normalButtons(myCSdialog);
};
myCSdialog.layout.layout(true);
};
//function adds OK - Cancel buttons
function normalButtons(myCSdialog) {
var myDialogButtons = myCSdialog.add("group");
myDialogButtons.alignment = "right";
myDialogButtons.add("button", undefined, "OK");
myDialogButtons.add("button", undefined, "Cancel");
};
编辑:我在添加的行下方添加了注释,以使其更易于理解。如您所见,我删除了一些不必要的行。
var mySwatchNames = app.activeDocument.swatches.everyItem().name
var myCSdialog = new Window("dialog", "Setup Color Coding");
// dialogSetup();
//begin building dialog box myDialog
var maingroup = myCSdialog.add('panel')//Added line
// You need to put those InputFields into a container, to make sure
whenever you click on 'Add Another' button, the new fields will always
above the Yes/No button
add_inputFields(maingroup);
//So whenever you generate new fields, it will be always inside its
container 'maingroup',
//and the maingroup is the same level as YES/NO group, so YES/NO
will be always at the very end of the dialog.
normalButtons(myCSdialog);
myCSdialog.layout.layout(true)//Added line
// Why I put this line here? Because when the script renders the add_inputFields(maingroup)
//in the first time, there is another myCSdialog.layout.layout(true) at the end of the function dd_inputFields(maingroup).
// After this function, if you create OK/Cancel buttons, they won't show up, because the line myCSdialog.layout.layout(true) stop u generating those buttons.
// You need this line to re-render the dialog, to have OK/Cancel showed up.
myCSdialog.show()
//function adds criteria input collection fields (text criteria and swatch choice)
function add_inputFields(maingroup) {
var myEnterCriteriaGroup = maingroup.add("group");
//title for first input
myEnterCriteriaGroup.add("statictext",undefined,"Criteria to Color Code");
//text entry field to enter criteria term
var myEnterCriteria = myEnterCriteriaGroup.add("edittext",undefined,"");//field for entering text criteria
myEnterCriteria.characters = 25;
myEnterCriteria.active = true;
var myListOfColors = myEnterCriteriaGroup.add("dropdownlist",undefined,mySwatchNames);//dropdown field for choosing swatch
//add button to add another row of fields to gather another set of user input
var addAnother_button = myEnterCriteriaGroup.add("button", undefined, "Add Another");
//event handler registered
addAnother_button.onClick = add_AnotherInputLine; //no passing parameters here! won't show button to be clicked!
//event handler...callback functions put input into arrays
myEnterCriteria.onChange = function() {
criteriaKeys.push(myEnterCriteria.text);
};
myListOfColors.onChange = function() {
if(myListOfColors.selection === null) {
myListOfColors.selection=myListOfColors.prevSel;
} else {
myListOfColors.prevSel=myListOfColors.selection.index
criteriaValues.push(myListOfColors.selection.text);
};
};
myCSdialog.layout.layout(true)//Added line
//As I explained above, this line is just like you are asking the window to re-render the dialog, whenever you click 'Add Another' button.
//This line will stop you generate the OK/Cancel buttons, so the dialog won't render them. That is why I added extra line at the top.
//if you don't add another group (add_AnotherInputLine() function...text edit field & dropdown) it hangs here... Ok or Cancel button do nothing...
};
//function adds another input row (text criteria and swatch choice) need to find a way NOT to remove OK/Cancel buttons...
function add_AnotherInputLine() {
add_inputFields(maingroup);
};
//function adds OK - Cancel buttons
function normalButtons(myCSdialog) {
var myDialogButtons = myCSdialog.add("group");
myDialogButtons.alignment = "right";
myDialogButtons.add("button", undefined, "OK");
myDialogButtons.add("button", undefined, "Cancel");
};
我正在尝试显示一个脚本 ui window 如果用户单击“添加另一个”按钮而不是“确定”或“取消”按钮,它将添加另一组输入字段...
我完成了某种工作...即我可以展示一个简单的两组,ui window (第 1 组 = 1 个文本编辑字段和一个下拉列表以及添加另一个按钮 第 2 组 = 正常的确定-取消按钮)
如果用户在前 2 个输入字段中填写 in/chooses,然后忽略“添加另一个”按钮并使用“确定-取消”按钮,脚本将继续正常运行。 但是,如果用户单击“添加另一个”按钮,脚本会利用 call-back/event 处理函数 (add_AnotherInputline) 首先删除“确定-取消”按钮组,然后添加(通过 add_inputFields 函数)另一个一组文本编辑字段和下拉列表,然后重新添加确定-取消按钮... (我想不出另一种方法让确定-取消按钮移动或始终停留在底部window!) 但是删除-添加 OK-Cancel 按钮组是我的问题所在。当我这样做时,这些按钮在用户使用 add_AnotherInputLine 函数后不再起作用......这在数据浏览器中可以看到,因为此时在脚本中 cancelElement并且 defaultElement 现在等于 = 对象无效
这是 window/ui 代码...我希望这就足够了。我遗漏了以下代码中使用的大量先验(数组、变量)...如果您需要它们,它们是带有文本项的简单数组或询问我可以提供包含内容的 variables/arrays。
(是的,我有 G. Singelmann 脚本并对其进行了广泛研究......我还没有从中找出解决方案,以满足我的特殊需要......)
var myCSdialog = new Window("dialog", "Setup Color Coding");
dialogSetup();
//begin building dialog box myDialog
add_inputFields(myCSdialog);
if (myCSdialog.children.length <= 1) {
normalButtons(myCSdialog);
};
if (myCSdialog.show() == 1) {
userCancelled = false;
} else {
exit();
};
//function adds criteria input collection fields (text criteria and swatch choice)
function add_inputFields(myCSdialog) {
var myEnterCriteriaGroup = myCSdialog.add("group");
//title for first input
myEnterCriteriaGroup.add("statictext",undefined,"Criteria to Color Code");
//text entry field to enter criteria term
var myEnterCriteria = myEnterCriteriaGroup.add("edittext",undefined,"");//field for entering text criteria
myEnterCriteria.characters = 25;
myEnterCriteria.active = true;
var myListOfColors = myEnterCriteriaGroup.add("dropdownlist",undefined,mySwatchNames);//dropdown field for choosing swatch
//add button to add another row of fields to gather another set of user input
var addAnother_button = myEnterCriteriaGroup.add("button", undefined, "Add Another");
//event handler registered
addAnother_button.onClick = add_AnotherInputLine; //no passing parameters here! won't show button to be clicked!
//event handler...callback functions put input into arrays
myEnterCriteria.onChange = function() {
criteriaKeys.push(myEnterCriteria.text);
};
myListOfColors.onChange = function() {
if(myListOfColors.selection === null) {
myListOfColors.selection=myListOfColors.prevSel;
} else {
myListOfColors.prevSel=myListOfColors.selection.index
criteriaValues.push(myListOfColors.selection.text);
};
};
//if you don't add another group (add_AnotherInputLine() function...text edit field & dropdown) it hangs here... Ok or Cancel button do nothing...
};
//function adds another input row (text criteria and swatch choice) need to find a way NOT to remove OK/Cancel buttons...
function add_AnotherInputLine() {
myCSdialog.remove(myCSdialog.children[myCSdialog.children.length - 1]);
add_inputFields(myCSdialog);
if (myCSdialog.children.length >= 1) {
normalButtons(myCSdialog);
};
myCSdialog.layout.layout(true);
};
//function adds OK - Cancel buttons
function normalButtons(myCSdialog) {
var myDialogButtons = myCSdialog.add("group");
myDialogButtons.alignment = "right";
myDialogButtons.add("button", undefined, "OK");
myDialogButtons.add("button", undefined, "Cancel");
};
编辑:我在添加的行下方添加了注释,以使其更易于理解。如您所见,我删除了一些不必要的行。
var mySwatchNames = app.activeDocument.swatches.everyItem().name
var myCSdialog = new Window("dialog", "Setup Color Coding");
// dialogSetup();
//begin building dialog box myDialog
var maingroup = myCSdialog.add('panel')//Added line
// You need to put those InputFields into a container, to make sure
whenever you click on 'Add Another' button, the new fields will always
above the Yes/No button
add_inputFields(maingroup);
//So whenever you generate new fields, it will be always inside its
container 'maingroup',
//and the maingroup is the same level as YES/NO group, so YES/NO
will be always at the very end of the dialog.
normalButtons(myCSdialog);
myCSdialog.layout.layout(true)//Added line
// Why I put this line here? Because when the script renders the add_inputFields(maingroup)
//in the first time, there is another myCSdialog.layout.layout(true) at the end of the function dd_inputFields(maingroup).
// After this function, if you create OK/Cancel buttons, they won't show up, because the line myCSdialog.layout.layout(true) stop u generating those buttons.
// You need this line to re-render the dialog, to have OK/Cancel showed up.
myCSdialog.show()
//function adds criteria input collection fields (text criteria and swatch choice)
function add_inputFields(maingroup) {
var myEnterCriteriaGroup = maingroup.add("group");
//title for first input
myEnterCriteriaGroup.add("statictext",undefined,"Criteria to Color Code");
//text entry field to enter criteria term
var myEnterCriteria = myEnterCriteriaGroup.add("edittext",undefined,"");//field for entering text criteria
myEnterCriteria.characters = 25;
myEnterCriteria.active = true;
var myListOfColors = myEnterCriteriaGroup.add("dropdownlist",undefined,mySwatchNames);//dropdown field for choosing swatch
//add button to add another row of fields to gather another set of user input
var addAnother_button = myEnterCriteriaGroup.add("button", undefined, "Add Another");
//event handler registered
addAnother_button.onClick = add_AnotherInputLine; //no passing parameters here! won't show button to be clicked!
//event handler...callback functions put input into arrays
myEnterCriteria.onChange = function() {
criteriaKeys.push(myEnterCriteria.text);
};
myListOfColors.onChange = function() {
if(myListOfColors.selection === null) {
myListOfColors.selection=myListOfColors.prevSel;
} else {
myListOfColors.prevSel=myListOfColors.selection.index
criteriaValues.push(myListOfColors.selection.text);
};
};
myCSdialog.layout.layout(true)//Added line
//As I explained above, this line is just like you are asking the window to re-render the dialog, whenever you click 'Add Another' button.
//This line will stop you generate the OK/Cancel buttons, so the dialog won't render them. That is why I added extra line at the top.
//if you don't add another group (add_AnotherInputLine() function...text edit field & dropdown) it hangs here... Ok or Cancel button do nothing...
};
//function adds another input row (text criteria and swatch choice) need to find a way NOT to remove OK/Cancel buttons...
function add_AnotherInputLine() {
add_inputFields(maingroup);
};
//function adds OK - Cancel buttons
function normalButtons(myCSdialog) {
var myDialogButtons = myCSdialog.add("group");
myDialogButtons.alignment = "right";
myDialogButtons.add("button", undefined, "OK");
myDialogButtons.add("button", undefined, "Cancel");
};