关闭按钮故障(Extendscript)

问题描述 投票:0回答:1

这是整个脚本。

    UI();

    function UI() {

    var window = new Window ('dialog', 'Settings', undefined, {closeButton: true});
    window.orientation = 'column';

    var iFolderC = loadSettings (['I','F',0]);
    for (i = 1; i <= iFolderC; i++)
    eval('var ' + "iFolder" + i + " = loadSettings (['I','F'," + i + "]);");

    var inputGroup = window.add ('group');
    inputGroup.add('panel', undefined, 'Input Folders', {borderStyle:'raised'});
    inputGroup.orientation = 'column';
    //inputGroup.alignment = 'left';

    for (i = 1; i <= iFolderC; i++) {
    eval('var ' + "inputFolder" + i + "= inputGroup.add ('group');");
    eval("inputFolder" + i + ".add('panel', [0, 0, 300, 20], iFolder"+ i +", {borderStyle:'raised'});");
    eval('var ' + "removeButton" + i + "= inputFolder" + i + ".add ('button', undefined, 'Remove');");}

    var newFolder = inputGroup.add ('group');
    //var folderButton = newFolder.add("iconbutton", undefined, "#FolderOpened");
    var newIFolder = newFolder.add('edittext',[0, 0, 300, 20]);
    var addButton =  newFolder.add ('button', undefined, 'Add');
    addButton.onClick = function () {window.close(); saveSettings (['N', 'F', 0], newIFolder.text);}

    for (i = 1; i <= iFolderC; i++) {
    eval("removeButton" + i + ".onClick = function() {window.close(); saveSettings (['R', 'F'," + i + "], '');}");}

    var closeButton = window.add ('button', undefined, 'Close');
    window.cancelElement = closeButton

    window.center();
    window.show();
    }

    function saveSettings (Identity, Fixture) {
    var file = '~/Documents/Read and write text102323210.txt';
    var str = read (file);
    var arr = str.split('\n');
    var c = Math.floor(arr[0]);

    if (Identity[0] == 'N') {
        if (Identity[1] == 'F') {
            arr[c+1] = Fixture;
            arr[0] = c + 1;
            str = arr.toString().replace(/,/g, '\n');
            write (file, str);           
            UI();}}

        if (Identity[0] == 'R') {
        if (Identity[1] == 'F') {
            if (Identity[2] == c) {
                arr[c] = '';
                arr[0] = c - 1;
                str = arr.toString().replace(/,/g, '\n');
                write (file, str);           
                UI();}}}
                    if (Identity[2] < c) {
                        for ( i = 0; i <= c - Identity[2]; i++)
                            arr[Identity[2]] = arr[Identity[2]+1];
                        arr[c] = '';
                        arr[0] = c - 1;
                        str = arr.toString().replace(/,/g, '\n');
                        write (file, str);           
                        UI();}}

    function loadSettings (Identity) {
    var file = '~/Documents/Read and write text102323210.txt';
    var str = read (file);
    var arr = str.split('\n');
    
    if (Identity[0] == 'I')
        if (Identity[1] == 'F')
            if (Identity[2] == 0)
                return Math.floor(arr[Identity[2]]);
                    else return arr[Identity[2]];}

    function read (filePath) {
    var file = new File (filePath);    
    file.open('r');
    file.encoding = 'UTF8';
    var text = file.read();
    file.close(); 
    return text;}

    function write (filePath, textContent) {  
    var file = new File( filePath );   
    file.open('w');
    file.encoding = 'UTF8';
    file.write( textContent );
    file.close();}`

添加/删除按钮工作正常。当我单击关闭按钮而不是关闭窗口时,它开始删除文件夹,有时一次删除两个文件夹。当没有更多文件夹时,它将关闭。右上角的关闭按钮会立即删除所有文件夹。

我尝试过:窗口和调色板,窗口的作用相同,调色板只是变成了横幅。 转动 ...{closeButton: true});,打开和关闭。

closeButton.onClick = function () {window.close();}
closeButton.onClick = function () {window.close(); break;}
closeButton.onClick = function () {window.close(); return;}
closeButton.onClick = function () {window.close(); return 1;}
closeButton.onClick = function () {window.close(); exit();}

..还尝试调用函数并返回 window.close;

..就像它只是继续并不断点击删除按钮:(

请提前帮忙并致谢

extendscript
1个回答
0
投票
// Define the close button
var closeButton = window.add('button', undefined, 'Close');
window.cancelElement = closeButton;

// Define the onClick event handler for the close button
closeButton.onClick = function() {
    // Close the window
    window.close();
};
© www.soinside.com 2019 - 2024. All rights reserved.