Cambiar un control ScriptUI después de que ya se muestra su ventana

So I have a (hopefully) simple one this time. I have a ScriptUI window programmed in ExtendScript for Adobe InDesign CS6. It contains a StaticText control. 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. 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.

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. If this is simply a limitation of ScriptUI, just let me know and I'll deal with it. 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. Thanks!

preguntado el 27 de noviembre de 13 a las 18:11

2 Respuestas

Intenta configurar multiline a 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:

t.text = "Good\revening"

respondido 28 nov., 13:05

I'm sorry, but that's not doing it. Besides, I don't really want the text to be multiline, anyway. - Tormenta

The only other solution would be to make the static text (and/or the window) wider so that the text is not pushed onto a second line. - justin putney

That's not really a worry I have. Having the text be pushed onto a second line. A second line is never created. In my real script, the window that contains this line of text is mucho wide; it's just the width of the text itself that remains fixed at creation time. Thus, there's lots of space that remains to the left and right of the text, even though longer lines of text get truncated, still leaving that space. If I can manage a screen grab, I'll post it here to illustrate. - Tormenta

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
}

Respondido el 28 de diciembre de 13 a las 07:12

I'm on another project currently, but I'll get back to this one soon. I especially need to wrap my head around your code, first, as well. - Tormenta

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.