自定义ScriptUI按钮将关闭窗口

时间:2013-06-13 15:28:44

标签: javascript button window extendscript

对于那些熟悉ExtendScript&在InDesign中,我有一个ScriptUI问题:如何在用户选择一个按钮后正确关闭窗口,或者当按钮是自定义选项时,如何关闭。请参阅以下代码:

$.writeln("The user pressed " + chooseOyo("123456"));

function chooseOyo(jobNumber) {
    var machine;
    var getOyoWindow = new Window ("dialog", "Which Imagesetter?");
        var textGroup = getOyoWindow.add("group");
            textGroup.orientation = "column";
            textGroup.add("statictext", undefined, "The current job is " + jobNumber);
            textGroup.add("statictext", undefined, "Please choose an imagesetter for this job:");
        var buttonGroup = getOyoWindow.add("group");
            var o1 = buttonGroup.add("button", undefined, "OYO 1");
            var o2 = buttonGroup.add("button", undefined, "OYO 2");
                o1.onClick = function () {machine = "OYO1";}
                o2.onClick = function () {machine = "OYO2";}

    if (getOyoWindow.show() == 1) {
        return machine;
    } else {
        exit();
    }
}

相当简单,不是吗?好吧,到目前为止,按钮没有做任何事情,你必须按[ESC]才能取消窗口。我怎样才能让它发挥作用?

2 个答案:

答案 0 :(得分:1)

编辑:得到了正确答案:

$.writeln("The user pressed " + chooseOyo("123456"));
function chooseOyo(jobNumber) {
    var machine;
    var getOyoWindow = new Window ("dialog", "Which Imagesetter?");
        var textGroup = getOyoWindow.add("group");
            textGroup.orientation = "column";
            textGroup.add("statictext", undefined, "The current job is " + jobNumber);
            textGroup.add("statictext", undefined, "Please choose an imagesetter for this job:");
        var buttonGroup = getOyoWindow.add("group");
            var o1 = buttonGroup.add("button", undefined, "OYO 1");
            var o2 = buttonGroup.add("button", undefined, "OYO 2");
                o1.onClick = function () {
                    machine = "OYO1";

                    getOyoWindow.close(); // thats the trick!

                    }
                o2.onClick = function () {
                    machine = "OYO2";
                    }
    if (getOyoWindow.show() == 1) {
    return machine;

    } else {
    return;
    }
}

close()是对的。但是在if(win.show()== 1)else {}块中没有使用它。而是在其中一个按钮的onClick函数中使用它。

答案 1 :(得分:0)

为此,您还可以在关闭 button.onClick 函数中尝试 getOyoWindow.hide()。您也可以在 else 语句中尝试此操作。 希望这可以帮助。谢谢。