简体   繁体   English

在其窗口已显示后更改 ScriptUI 控件

[英]Changing a ScriptUI control after its window is already shown

So I have a (hopefully) simple one this time.所以这次我有一个(希望)简单的。 I have a ScriptUI window programmed in ExtendScript for Adobe InDesign CS6.我有一个在 ExtendScript 中为 Adob​​e InDesign CS6 编程的 ScriptUI 窗口。 It contains a StaticText control.它包含一个 StaticText 控件。 After this dialog window is shown to the user, I would like to change the text of that StaticText control based upon some action the user takes.在向用户显示此对话框窗口后,我想根据用户采取的某些操作更改该 StaticText 控件的文本。 Here is a very simplified version of my problem:这是我的问题的一个非常简化的版本:

var w = new Window("dialog");
    var t = w.add("statictext", undefined, "Hello");

w.show();

t.text = "Good evening";

In the above example, "Hello" never changes to "Good evening".在上面的例子中,“你好”永远不会变成“晚安”。 I have discovered, however, that if I add a Progress Bar control to this window and update it periodically along with the StaticText control, it WILL allow the text to change, but then the text gets truncated if the second line is longer than the original text.然而,我发现如果我向这个窗口添加一个 Progress Bar 控件并与 StaticText 控件一起定期更新它,它将允许文本更改,但如果第二行比原始文本长,则文本会被截断文本。

It's as though the width of the StaticText control is set at creation time and can never ever be changed after its window is shown.就好像 StaticText 控件的宽度是在创建时设置的,并且在其窗口显示后永远无法更改。 If this is simply a limitation of ScriptUI, just let me know and I'll deal with it.如果这只是 ScriptUI 的一个限制,请告诉我,我会处理它。 Otherwise, please tell me if there's anything I can do to have that StaticText change dynamically and accept longer lines of text without getting truncated.否则,请告诉我是否有什么办法可以让 StaticText 动态更改并接受更长的文本行而不会被截断。 Thanks!谢谢!

Try setting multiline to true :尝试将multiline设置为true

var w = new Window("dialog");
    var t = w.add("statictext", undefined, "Hello", {multiline:true});

w.show();

t.text = "Good evening";

That should prevent the text from getting truncated after the first line.这应该可以防止文本在第一行之后被截断。

You can test it by adding return characters ( \\r or \\n ) to your text string:您可以通过向文本字符串添加返回字符( \\r\\n )来测试它:

t.text = "Good\revening"

This is the structure I usually use [EDIT: Actually, this shows it off a little better]:这是我通常使用的结构[编辑:实际上,这显示得更好]:

//global:
var n=1;
//////////////////////////

function doTextChange(target, newText) {
    target.text = newText;
}

var win = new Window('dialog', 'dialog',[300,100,645,396]);
var w = buildUI();
if (w != null) {
    w.show();
}

function buildUI() {
    if (win != null) {
         win.t = win.add("statictext", [14,15,314,37], "Hello");
         win.closeBtn = win.add('button', [240,210,320,232], 'Close', {name:'Cancel'});
         win.changeBtn = win.add('button', [240,210+33,320,232+33], 'Change', {name:'Cancel'});
         win.closeBtn.onClick = function () { this.parent.close(1) };
         win.changeBtn.onClick = function () { n++;doTextChange(  win.t, "Good evening " + n);};
    }
    return win
}

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

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