简体   繁体   English

将关闭窗口的自定义 ScriptUI 按钮

[英]Custom ScriptUI buttons that will close the window

For those knowledgeable in ExtendScript & InDesign, I have a ScriptUI question: How can I have a window close properly after the user picks one button or the other when the buttons are custom choices .对于那些熟悉 ExtendScript 和 InDesign 的人,我有一个 ScriptUI 问题:当按钮是自定义选项时,如何在用户选择一个或另一个按钮后正确关闭窗口。 See the code below:请参阅下面的代码:

$.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();
    }
}

Fairly simple, no?相当简单,不是吗? Well, so far, the buttons don't do anything and you have to hit [ESC] in order to cancel the window.好吧,到目前为止,按钮没有做任何事情,您必须按 [ESC] 才能取消窗口。 How can I get this to work?我怎样才能让它发挥作用?

EDIT: got the right answer:编辑:得到正确答案:

$.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() was right. close() 是对的。 But not using it within the if(win.show() == 1)else{} block.但不在 if(win.show() == 1)else{} 块中使用它。 Instead use it within the onClick function of one of the buttons.而是在其中一个按钮的 onClick 函数中使用它。

for this you can also try getOyoWindow.hide() inside your close button.onClick function.为此,您还可以在关闭 button.onClick 函数中尝试 getOyoWindow.hide()。 You can also try this in your else statement.您也可以在 else 语句中尝试此操作。 Hope this helps.希望这可以帮助。 Thanks.谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM