0

我正在尝试显示一个脚本 ui 窗口,如果用户单击“添加另一个”按钮而不是“确定”或“取消”按钮,它将添加另一组输入字段...

我得到它的一种工作...即我可以显示一个简单的,两组,ui 窗口(组 1 = 1 个文本编辑字段和一个下拉列表和添加另一个按钮组 2 = 正常的 OK-Cancel 按钮)

如果用户填写/选择前 2 个输入字段,然后忽略 Add Another 按钮并使用 OK-Cancel 按钮,则脚本会正常进行。但是,如果用户单击“添加另一个”按钮,该脚本会利用回调/事件处理函数(add_AnotherInputline)首先删除“确定-取消”按钮组,然后(通过 add_inputFields 函数)添加另一组文本编辑字段和下拉菜单,然后重新添加 OK-Cancel 按钮... (我想不出另一种方法让 OK-Cancel 按钮移动或始终停留在窗口底部!) 但是,删除-添加 OK-Cancel 按钮组是我的问题所在。当我这样做时,这些按钮在用户使用 add_AnotherInputLine 函数后不再起作用......这在数据浏览器中可以看到,因为此时脚本中的cancelElementdefaultElement现在等于 = Object 无效

这是窗口/用户界面代码......我希望这已经足够了。我遗漏了以下代码中使用的许多先验(数组、变量)……如果您需要它们,它们是带有文本项的简单数组或询问,我可以提供包含内容的变量/数组。

(是的,我有 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");
};
4

1 回答 1

0

试试这个:

    var mySwatchNames = app.activeDocument.swatches.everyItem().name
    var w = new Window("dialog", "Setup Color Coding");
    // dialogSetup();
    var maingroup = w.add('panel')
    //begin building dialog box myDialog
    add_inputFields(maingroup);
    normalButtons()
    w.layout.layout(true);
  
    
     w.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);
                    };
                };

      //if you don't add another group (add_AnotherInputLine() function...text edit field & dropdown) it hangs here... Ok or Cancel button do nothing...
     w.layout.layout(true);

};


 //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() {
        var myDialogButtons = w.add("group");
        myDialogButtons.alignment = "right";   
        myDialogButtons.add("button", undefined, "OK");
        myDialogButtons.add("button", undefined, "Cancel");

};
于 2022-03-02T07:42:09.967 回答