2014-11-03 90 views
1

編輯:我也接受其他建議,我可以做些什麼。Indesign腳本更新窗口?

如何使用onChange事件更新我的窗口?我的解決方案有效,但我需要這些組在不可見時摺疊。

w.DD.onChange = function() { 
    switch (this.selection.text){ 
     case 'Headline': 
       if(w.visiblegroup) 
       w.visiblegroup.visible = false; 
       w.visiblegroup = w.texted; 
       w.texted.visible = true; 
      break; 
    } 
} 

我已經嘗試添加在case本身的元素後使用w.showw.update(與文檔,還不能確定什麼.update實際上沒有)。但我無法弄清楚這一點。

w.DD.onChange = function() { 
    switch (this.selection.text){ 
     case 'Headline': 
       w.add('checkbox', undefined, 'User-Color'); 
       //w.show(); 
       w.update(); 
      break; 
    } 
} 

有沒有人有一個線索這可能工作?

+0

這是關於InDesign中的腳本,沒有HTML。 – 2014-11-19 08:09:20

+0

對不起,沒有看到標籤 – 2014-11-19 11:11:17

回答

0

要摺疊組和窗口,您將需要使用窗口的layout()方法。這將加載控制窗口或容器的自動佈局行爲的LayoutManagerLayoutManager也有一個名爲layout()的方法,該方法調用自動佈局行爲並在第一次顯示窗口時自動調用。此後,腳本必須顯式調用它像這樣:

window.layout().layout(); 

的如何使用由傑拉爾德Singelmann佈局管理器的一個例子:

function main() { 
    var win = new Window("dialog"); 

    var maingroup = win.add("panel"); 
    maingroup.orientation = "column"; 
    add_group(maingroup); 

    var show_btn = win.add("button", undefined, "show"); 
    show_btn.onClick = function() { 
     var txt = ""; 
     for (var n = 0; n < maingroup.children.length; n++) { 
      txt += maingroup.children[n].edit.text + "\n"; 
     } 
     alert("Da steht: \n" + txt); 
    } 

    win.show(); 

    function add_group(maingroup) { 
     var group = maingroup.add("group"); 
     group.edit = group.add("edittext", [undefined, undefined, 200, 20], maingroup.children.length); 
     group.plus = group.add("button", undefined, "+"); 
     group.plus.onClick = add_btn; 
     group.minus = group.add("button", undefined, "-"); 
     group.minus.onClick = minus_btn; 
     group.index = maingroup.children.length - 1; 
     win.layout.layout(true); 
     return group; 
    } 
    function add_btn (e) { 
     add_group(maingroup); 
    } 
    function minus_btn (e) { 
     var ix = this.parent.index; 
     maingroup.remove(maingroup.children[ix]); 
     win.layout.layout(true); 
    } 
} 

source

1

我一般避免使用的LayoutManager和做所有我自己的數學,我相信更好,但這是我的愚見...

var w = new Window("dialog"); 
 
w.preferredSize = [200,200]; 
 
w.DD = w.add('dropdownlist', undefined, ["A","B"]); 
 
w.DD.selection = 0; 
 
w.DD.alignment = ["fill","top"]; 
 

 
//Setting a stacked group to items overlay 
 
w.gp = w.add('group'); 
 
w.gp.orientation = 'stack'; 
 
w.gp.alignment = ["fill","top"]; 
 
w.gp.alignChildren = ["fill","top"]; 
 
w.gp.p1 = w.gp.add('panel',undefined, "A"); 
 
w.gp.p2 = w.gp.add('panel',undefined, "B"); 
 

 
//dummy text to show "collapsing" 
 
w.st = w.add('statictext',undefined, "Collapse ?"); 
 

 
w.DD.onChange = function() { 
 
    w.gp.p1.visible = w.DD.selection==0; 
 
    w.gp.p2.visible = !w.gp.p1.visible; 
 
    w.gp.p2.size.height =100; 
 
    w.gp.size.height = w.gp.p1.visible? 50 : 100; 
 
    w.st.location.y = w.gp.location.y+w.gp.size.height+10; 
 
} 
 

 
w.onShow = function() { 
 
    w.gp.p2.visible=false; 
 
    w.gp.size.height = w.gp.p1.size.height = 50; 
 
    w.st.location.y = w.gp.location.y+w.gp.size.height+10; 
 
} 
 

 
w.show();

enter image description here

enter image description here

盧瓦克