Skip to main content
StrongBeaver
Legend
March 20, 2016
Answered

OmniDialogMaker

  • March 20, 2016
  • 1 reply
  • 973 views

I was hoping someone can tell me where one puts the OmniDialogMaker script. I was hoping placing it into my scripts path, followed by restarting Photoshop then executing any script to which requires this Library script would work, unfortunately, no ?

This topic has been closed for replies.
Correct answer JJMack

It look like a file you would include in a script you write that will use the function in that included file.  All I see are some variables and functions not code to do anything.

Use a include statement

//@include "ominoDialogMaker.jsx"

var D_MARGIN = 4;

var D_CONTROLHEIGHT = 18;

var D_BUTTONWIDTH = 96;

var D_CONTROLLABELWIDTH = 84;

var D_CONTROLWIDTH = 100;

var D_DIALOG_WIDTH = 1 * D_MARGIN + D_CONTROLLABELWIDTH + D_CONTROLWIDTH;

var S2 = 1.41421356237309504880;

// create a rectangle for a new control, walking downwards.

function _odControlShared(label,name)

{

    od = this;

    var y = od.curYPos;

    var itemHeight = D_CONTROLHEIGHT;

    var itemBump = itemHeight + D_MARGIN;

    if(label != "")

        label += ":";

    var labelCtl = od.w.add('statictext',[D_MARGIN,y,D_MARGIN + D_CONTROLLABELWIDTH,y+itemHeight],label);

    labelCtl.justify = "right";

    var controlBox = new Object();

    controlBox.left = D_MARGIN + D_CONTROLLABELWIDTH + D_MARGIN;

    controlBox.top = y;

    controlBox.right = controlBox.left + D_CONTROLWIDTH;

    controlBox.bottom = controlBox.top + itemHeight;

    od.curYPos = controlBox.bottom + D_MARGIN;

    return controlBox;

}

function _odControlSharedFinish(control,tname,valueFieldName)

{

    oD = this;

    oD.items[tname] = control;

    oD.itemValueFieldNames[tname] = valueFieldName;

    oD.itemNames[oD.itemNames.length] = tname;

}

function _odNumber(label,tname,value)

{

        oD = this;

        var controlBox = oD._odControlShared(label,tname);

        var control = oD.w.add('edittext',controlBox,value);

        control.value = value;

        control.onChange = function(){this.value = (this.text) * 1.0; this.text = this.value;};  // make them all .value accessible

        oD._odControlSharedFinish(control,tname,"text");

        return control;

}

function _odText(label,tname,value)

{

        oD = this;

        var controlBox = oD._odControlShared(label,tname);

        var control = oD.w.add('edittext',controlBox,value);

        control.value = value;

        control.onChange = function(){this.value = this.text; };  // make them all .value accessible

        oD._odControlSharedFinish(control,tname,"text");

        return control;

}

function _setColorFromButton(victim,button)

{

            var g = victim.graphics;

            var n = button.value;

            var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, n);

            g.backgroundColor = myBrush;

}

/*

    color values are array of three floats, 0.0 .. 1.0.

    */

function _odColor(label,tname,color)

{

    oD = this;

    var controlBox = oD._odControlShared(label,tname);

    var swatchBox = [controlBox.left + 40,controlBox.top,controlBox.right,controlBox.bottom];

    var buttonBox = [controlBox.left,controlBox.top,controlBox.left + 30,controlBox.bottom];

    var swatch = oD.w.add('group',swatchBox);

    var button = oD.w.add('button',buttonBox);

    button.swatch = swatch;

    button.value = color;

    button.onClick = function(){

            var n = doColorPicker(this.value);

            this.value = n;

            _setColorFromButton(swatch,this);

            };

    _setColorFromButton(swatch,button);

    oD._odControlSharedFinish(button,tname,"value");

    return button;

}

/*

    Add a button and static text to the dialog;

    the button refers to the text "nameCtl",

    and has .filePrompt and .fileExtension.

    */

function _odFileCommon(label,tname,path,prompt,extension)

{

    var controlBox = oD._odControlShared(label,tname);

    var buttonWidth = 10;

    var buttonBox = [controlBox.left,controlBox.top,controlBox.left + buttonWidth,controlBox.bottom];

    var nameBox = [controlBox.left + buttonWidth + 10,controlBox.top,D_DIALOG_WIDTH,controlBox.bottom];

    var f = new File(path);

    var nameCtl = oD.w.add('statictext',nameBox);

    var button = oD.w.add('button',buttonBox,'...');

    button.nameCtl = nameCtl;

    nameCtl.text = f.name;

    button.value = f.fsName;

    button.file = f;

    button.filePrompt = prompt;

    button.fileExtension = extension;

    oD._odControlSharedFinish(button,tname,"value");

    button.onChange = function()

    {

        this.file = new File(this.value);

        this.nameCtl.text = this.file.name;

    }

    return button;

}

function _odOpenFile(label,tname,path,prompt,extension)

{

    oD = this;

    var buttonCtl = _odFileCommon(label,tname,path,prompt,extension);

    buttonCtl.onClick = function(){

        var f = this.file.openDlg(this.filePrompt);

        if(f)

        {

            this.file = f;

            this.value = f.fsName;

            this.nameCtl.text = f.name;

        }

    };

    return buttonCtl;

}

function _odSaveFile(label,tname,path,prompt,extension)

{

    oD = this;

    var buttonCtl = _odFileCommon(label,tname,path,prompt,extension);

    buttonCtl.onClick = function(){

        var f = this.file.saveDlg(this.filePrompt);

        if(f)

        {

            this.file = f;

            this.value = f.fsName;

            this.nameCtl.text = f.name;

        }

    };

    return buttonCtl;

}

function _odSelectFolder(label,tname,path,prompt,extension)

{

    oD = this;

    var buttonCtl = _odFileCommon(label,tname,path,prompt,extension);

    buttonCtl.folder = new Folder(path); // folder, pls, not file

    buttonCtl.nameCtl.text += "/";

    buttonCtl.onClick = function(){

        var f = this.folder.selectDlg(this.filePrompt);

        if(f)

        {

            this.folder = f;

            this.value = f.fsName;

            this.nameCtl.text = f.name + "/";

        }

    };

    return buttonCtl;

}

function _odCheckbox(label,tname,value,checkboxText)

{

        oD = this;

        var controlBox = oD._odControlShared(label,tname);

        var control = oD.w.add('checkbox',controlBox,checkboxText);

        control.value = value;

        //control.onChange = function(){this.value = this.text;};

        oD._odControlSharedFinish(control,tname,"value");

        return control;

}

function _odRadioButtons(label,tname,value,radioChoices)

{

    var oD = this;

    controlBox = oD ._odControlShared(label,tname);

    var itemHeight = controlBox.bottom - controlBox.top;

    result = oD.w.add('edittext',controlBox,value); // hidden text field to control it...

    result.onChange = function(){

        var i;

        this.value = this.text;

        for(i = 0; i < this.buttons.length; i++)

        {

            var button = this.buttons;

            button.value = (button.theChoice == this.text);

        }

    }

    result.hide();

    result.value = value;

    result.buttons = new Array();

    var i;

    for(i = 0; i < radioChoices.length; i++)

    {

        var choice = radioChoices;

        if(i > 0)

        {

            var bump = itemHeight + D_MARGIN;

            controlBox.top += bump;

            controlBox.bottom += bump;

            oD.curYPos += bump;

        }

        // each radiobutton object pokes its choice into the ersatz control,

        // so it looks like a simple value.

        // ("Grouping" appears to be by adjacent additions only. Nice!)

        var rb = oD.w.add('radiobutton',controlBox,choice);

        rb.value = choice == value;

        rb.theChoice = choice;

        rb.theGroupErsatzControl = result;

        rb.onClick = function(){this.theGroupErsatzControl.value = this.theChoice;};

        result.buttons[result.buttons.length] = rb;

    }

    oD._odControlSharedFinish(result,tname,"text");

    return result;

}

function _odMenu(label,tname,value,menuChoices)

{

    var oD = this;

    controlBox = oD ._odControlShared(label,tname);

    var itemHeight = controlBox.bottom - controlBox.top;

    var control = oD.w.add('dropdownlist',controlBox,menuChoices);

    // I couldnt discern how to get this from the "items" array, so I stash menuChoice for later. dvb08.

    control.menuChoices = menuChoices;

    control.value = value;

    // set the initial selection index

    var index = 0;

    for(var i = 0; i < menuChoices.length; i++)

    {

        if(value == menuChoices)

            index = i;

    }

    control.selection = index;

    control.onChange = function() {

        this.value = this.selection.text;

        } // make them all .value accessible

    oD._odControlSharedFinish(control,tname,"value");

}

function _odSectionLabel(label)

{

    var oD = this;

    var b2 = new Object();

    b2.left = D_MARGIN;

    b2.top = oD.curYPos;

    b2.right = b2.left + D_DIALOG_WIDTH;

    b2.bottom = b2.top + D_CONTROLHEIGHT;

    oD.curYPos += D_CONTROLHEIGHT + D_MARGIN;

    oD.w.add('statictext',b2,label + ':',{multiline:true});

}

function _odBoxedText(lines,text)

{

    var oD = this;

    var width = D_DIALOG_WIDTH;

    var height = lines * 15;

    var b2 = new Object();

    var b = new Object();

    b.top = oD.curYPos;

    b.bottom = b.top + height + 2 * D_MARGIN;

    b.left = D_MARGIN;

    b.right = b.left + width;

    oD.curYPos = b.bottom + D_MARGIN;

    var panel = oD.w.add('panel',b);

    b2.left = D_MARGIN;

    b2.top = D_MARGIN;

    b2.right = b2.left + width - 2 * D_MARGIN;

    b2.bottom = b2.top + height;

    panel.add('statictext',b2,text,{multiline:true});

}

function _odSeparator()

{

    var oD = this;

    var height = oD.groupGap;

    var barWidth = oD.ominoDialogWidth;

    if(barWidth)

    {

        var b = new Object();

        b.top = oD.curYPos + height / 2;

        b.bottom = b.top;

        b.left = D_MARGIN;

        b.right = b.left + barWidth;

        var barHeight = 2;

        b.top -= barHeight / 2;

        b.bottom = b.top + barHeight;

        oD.w.add('panel',b);

    }

    oD.curYPos += height;

}

function _odAppendGap()

{

    oD = this;

    oD.curYPos += oD.groupGap;

}

function appendOKCancel(oD)

{

    var y = oD.curYPos;

    var cancelRect = new Object();

    var okRect = new Object();

    cancelRect.left = D_MARGIN

    cancelRect.top = y;

    cancelRect.right = cancelRect.left + D_BUTTONWIDTH;

    cancelRect.bottom = cancelRect.top + D_CONTROLHEIGHT;

    okRect.left = cancelRect.right + D_MARGIN + D_MARGIN;

    okRect.top = y;

    okRect.right = okRect.left + D_BUTTONWIDTH;

    okRect.bottom = okRect.top + D_CONTROLHEIGHT;

    // Set up either Apply button, or OK/Cancel buttons

    if(oD.isPalette)

    {

        var applyBtn = oD.w.add('button',cancelRect,'Apply');

        applyBtn.oD = oD;

        applyBtn.onClick = function(){

            var oD = this.oD;

            var result = oD.get();

            oD.paletteCallback(result,oD.paletteCallbackArg2);

        };

    }

    else

    {

        var cancelBtn = oD.w.add('button',cancelRect,'Cancel',{name:'cancel'});

        var okBtn = oD.w.add('button',okRect,'OK',{name:'ok'});

        cancelBtn.oD = oD;

        cancelBtn.onClick = function(){this.oD.w.close(0);};  // 0 on cancel

        okBtn.theDialog = oD;

        okBtn.onClick = function(){this.theDialog.w.close(1);}; // 1 on ok

    }

    oD.curYPos = okRect.bottom + D_MARGIN;

}

function trimDialogBounds(oD)

{

    var xMax = 20;

    var yMax = 20;

    var n = oD.w.children.length;

    var i;

    for(i = 0; i < n; i++)

    {

        var aChild= od.w.children;

        var aChildBounds = aChild.bounds;

        if(aChildBounds.right > xMax)

            xMax = aChildBounds.right;

        if(aChildBounds.bottom > yMax)

            yMax = aChildBounds.bottom;

    }

    od.w.bounds.right = od.w.bounds.left + xMax + D_MARGIN;

    od.w.bounds.bottom = od.w.bounds.top + yMax + D_MARGIN;

    // actually... allow bottom gaps.

    od.w.bounds.bottom = od.curYPos + od.w.bounds.top;

}

/**

* The optional 2nd, 3rd, and 4th arguments make it a palette instead of a modal dialog. The callback

* is invoked every time Apply is clicked (you get an Apply button instead of OK/Cancel)

*/

function newOminoDialog(tname,existingPanel,paletteCallback,paletteCallbackArg2)

{

    // if you pass in something other than a panel, no can use.

    if(!(existingPanel instanceof Panel))

        existingPanel = null;

    var isPalette = (existingPanel || paletteCallback) ? 1 : 0;

    var kind = isPalette ? 'palette' : 'dialog';

    var oD = new Object();

    oD.w = existingPanel ? existingPanel : new Window(kind,tname,[100,100,500,500]);

    oD.isPalette = isPalette;

    oD.paletteCallback = paletteCallback;

    oD.paletteCallbackArg2 = paletteCallbackArg2;

    oD.curYPos = D_MARGIN;

    oD.groupGap = 12;

    oD.itemNames = new Array();

    oD.item

    oD.items = new Array();

    oD.itemValueFieldNames = new Object(); // to poke a value into the dialog, each control's appropriate field, like "text" or "value"

    oD.ominoDialogWidth = D_DIALOG_WIDTH;

    oD.gap = _odAppendGap;

    oD.number = _odNumber;

    oD.string = _odText;

    oD.radioButtons = _odRadioButtons;

    oD.checkbox = _odCheckbox;

    oD.sectionLabel = _odSectionLabel;

    oD.separator = _odSeparator;

    oD.boxedText = _odBoxedText;

    oD.color = _odColor;

    oD.openFile = _odOpenFile;

    oD.selectFolder = _odSelectFolder;

    oD.saveFile = _odSaveFile;

    oD.menu = _odMenu;

    oD.set = _odSet;

    oD.run = _odRun;

    oD.get = _odGet;

    oD._odControlShared = _odControlShared;

    oD._odControlSharedFinish = _odControlSharedFinish;

    return oD;

}

function _odGet()

{

    var values = new Object();

    var tname;

    for(tname in this.items)

    {

        var value = this.items[tname].value;

        values[tname] = value;

    }

    return values;

}

function _odSet(values)

{

    var oD = this;

    if(!values)

        return;

    for(var p in values)

    {

        var value = values

;

        var item = oD.items

;

        if(!item)

            continue;

        var itemValueFieldName = oD.itemValueFieldNames

;

        if(itemValueFieldName)

        {

            item[itemValueFieldName] = value;

            if(item.onChange)

                item.onChange();

            item.notify('onChange'); // to get the refresh

        }

    }

}

/**

   * Can be run as a modal dialog, OR as an ongoing palette.

   * As a dialog, nothing happens until OK or Cancel is chosen; on OK,

   * the parameters are returned.

   * To be a palette, pass in a function and an arg. The function will

   * be called with (resultParams, yourArg).

   */

function _odRun()

{

    var oD = this;

    if(!oD.finishingTouches)

    {

        oD.separator(oD);

        //oD.gap();

        appendOKCancel(oD);

        //oD.gap();

        trimDialogBounds(oD);

        oD.finishingTouches = true;

    }

    if(oD.w instanceof Window)

    {

        var resultCode = oD.w.show();

        if(resultCode != 1) // cancel

            return null;

        var result = oD.get();

        return result;

    }

    else

        return null;

}

function objectToString(o)

{

    if(!o)

        return "";

    var s = "";

    var i;

    for(tname in o)

        s += tname + " = " + o[tname] + "\n";

    return s;

}

var gExampleSettings = null;

function example(thisObj)

{

    var host = app;

    // the last 2 args are to make it modeless, and give you an APPLY button instead of OK and CANCEL.

    // This works in AE and Illustrator, but on Photoshop. I havent tried the rest...

    var d = newOminoDialog("Omino Example Dialog: " + host.name,thisObj,function(a,b){alert("result\n" + objectToString(a));});

    // comment out the above, and use this one for photoshop, to be modal:

    //var d = newOminoDialog("Omino Example Dialog: " + host.name);

    d.boxedText(9, "This is an example of a dialog built with ominoDialogMaker.jsx\n"

    + "host: " + host.name + " " + host.version + "\n"

        + "\n"

        + "©2007-2012 poly@omino.com",

        D_DIALOG_WIDTH);

// d.separator();

//    d.sectionLabel("Kinds of Controls");

    d.number("Number H","h",11.23);

    d.checkbox("Checkbox X","x",true,"check this");

    d.string("Text","t","type here");

    d.openFile("A File","f","","open it","jpg");

    d.radioButtons("Choose One","r","red",["red","maroon","scarlet","crimson"]);

    var result;

    d.set(gExampleSettings);

    var result = d.run();

    if(result !=null)

    {

        gExampleSettings = result;

        var s = "Result Values\n";

          s += objectToString(result);

        alert(s);

    }

}

/*

    Easy to use progress bar for ExtendScript.

    Written by poly@omino.com, 2007

    Enjoy, but this credit must remain intact.

usage:

    var pb = progressBar("main title","subtitle");

    pb.setValue(valueFrom0to1);

    pb.setTitle2("new subtitle display!")

    if(pb.isCanceled())

        pb.close(); // they clicked cancel

*/

function progressBar(title1,title2)

{

    var result = new Object();

    result.running = true;

    result.p = new Window("palette");

    result.p.orientation = "column";

    result.p.alignChildren = "left";

    result.t1 = result.p.add("statictext",undefined,title1);

    result.t2 = result.p.add("statictext",undefined,title2);

    result.b = result.p.add("progressbar");

    result.c = result.p.add("button",undefined,"Cancel");

    result.c.onClick = function() {

        result.running = false;

        }

    result.isRunning = function() { return this.running; }

    result.isCanceled = function() { return !this.isRunning(); }

    result.setValue = function(x) { this.b.value = x * 100; this.p.update(); }

    result.setTitle1 = function(t1) { this.t1.text = t1; }

    result.setTitle2 = function(t2) { this.t2.text = t2; }

    result.close = function() { this.p.close(); }

    result.p.show();

    return result;

}

/*

    a foolish little routine to show all the insides of an object in al Alert.

    You know, for debugging.

    */

function alertObj(o,title)

{

    if(!title)

        title = "";

    var s = title + "\n";

    var k;

    if(!o)

        s += "(null object)";

    else

        s += objectToString(o);

    alert(s);

}

1 reply

JJMack
Community Expert
Community Expert
March 20, 2016

???

JJMack
StrongBeaver
Legend
March 20, 2016

This may be the only location the script is located at.

JJMack
Community Expert
JJMackCommunity ExpertCorrect answer
Community Expert
March 20, 2016

It look like a file you would include in a script you write that will use the function in that included file.  All I see are some variables and functions not code to do anything.

Use a include statement

//@include "ominoDialogMaker.jsx"

var D_MARGIN = 4;

var D_CONTROLHEIGHT = 18;

var D_BUTTONWIDTH = 96;

var D_CONTROLLABELWIDTH = 84;

var D_CONTROLWIDTH = 100;

var D_DIALOG_WIDTH = 1 * D_MARGIN + D_CONTROLLABELWIDTH + D_CONTROLWIDTH;

var S2 = 1.41421356237309504880;

// create a rectangle for a new control, walking downwards.

function _odControlShared(label,name)

{

    od = this;

    var y = od.curYPos;

    var itemHeight = D_CONTROLHEIGHT;

    var itemBump = itemHeight + D_MARGIN;

    if(label != "")

        label += ":";

    var labelCtl = od.w.add('statictext',[D_MARGIN,y,D_MARGIN + D_CONTROLLABELWIDTH,y+itemHeight],label);

    labelCtl.justify = "right";

    var controlBox = new Object();

    controlBox.left = D_MARGIN + D_CONTROLLABELWIDTH + D_MARGIN;

    controlBox.top = y;

    controlBox.right = controlBox.left + D_CONTROLWIDTH;

    controlBox.bottom = controlBox.top + itemHeight;

    od.curYPos = controlBox.bottom + D_MARGIN;

    return controlBox;

}

function _odControlSharedFinish(control,tname,valueFieldName)

{

    oD = this;

    oD.items[tname] = control;

    oD.itemValueFieldNames[tname] = valueFieldName;

    oD.itemNames[oD.itemNames.length] = tname;

}

function _odNumber(label,tname,value)

{

        oD = this;

        var controlBox = oD._odControlShared(label,tname);

        var control = oD.w.add('edittext',controlBox,value);

        control.value = value;

        control.onChange = function(){this.value = (this.text) * 1.0; this.text = this.value;};  // make them all .value accessible

        oD._odControlSharedFinish(control,tname,"text");

        return control;

}

function _odText(label,tname,value)

{

        oD = this;

        var controlBox = oD._odControlShared(label,tname);

        var control = oD.w.add('edittext',controlBox,value);

        control.value = value;

        control.onChange = function(){this.value = this.text; };  // make them all .value accessible

        oD._odControlSharedFinish(control,tname,"text");

        return control;

}

function _setColorFromButton(victim,button)

{

            var g = victim.graphics;

            var n = button.value;

            var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, n);

            g.backgroundColor = myBrush;

}

/*

    color values are array of three floats, 0.0 .. 1.0.

    */

function _odColor(label,tname,color)

{

    oD = this;

    var controlBox = oD._odControlShared(label,tname);

    var swatchBox = [controlBox.left + 40,controlBox.top,controlBox.right,controlBox.bottom];

    var buttonBox = [controlBox.left,controlBox.top,controlBox.left + 30,controlBox.bottom];

    var swatch = oD.w.add('group',swatchBox);

    var button = oD.w.add('button',buttonBox);

    button.swatch = swatch;

    button.value = color;

    button.onClick = function(){

            var n = doColorPicker(this.value);

            this.value = n;

            _setColorFromButton(swatch,this);

            };

    _setColorFromButton(swatch,button);

    oD._odControlSharedFinish(button,tname,"value");

    return button;

}

/*

    Add a button and static text to the dialog;

    the button refers to the text "nameCtl",

    and has .filePrompt and .fileExtension.

    */

function _odFileCommon(label,tname,path,prompt,extension)

{

    var controlBox = oD._odControlShared(label,tname);

    var buttonWidth = 10;

    var buttonBox = [controlBox.left,controlBox.top,controlBox.left + buttonWidth,controlBox.bottom];

    var nameBox = [controlBox.left + buttonWidth + 10,controlBox.top,D_DIALOG_WIDTH,controlBox.bottom];

    var f = new File(path);

    var nameCtl = oD.w.add('statictext',nameBox);

    var button = oD.w.add('button',buttonBox,'...');

    button.nameCtl = nameCtl;

    nameCtl.text = f.name;

    button.value = f.fsName;

    button.file = f;

    button.filePrompt = prompt;

    button.fileExtension = extension;

    oD._odControlSharedFinish(button,tname,"value");

    button.onChange = function()

    {

        this.file = new File(this.value);

        this.nameCtl.text = this.file.name;

    }

    return button;

}

function _odOpenFile(label,tname,path,prompt,extension)

{

    oD = this;

    var buttonCtl = _odFileCommon(label,tname,path,prompt,extension);

    buttonCtl.onClick = function(){

        var f = this.file.openDlg(this.filePrompt);

        if(f)

        {

            this.file = f;

            this.value = f.fsName;

            this.nameCtl.text = f.name;

        }

    };

    return buttonCtl;

}

function _odSaveFile(label,tname,path,prompt,extension)

{

    oD = this;

    var buttonCtl = _odFileCommon(label,tname,path,prompt,extension);

    buttonCtl.onClick = function(){

        var f = this.file.saveDlg(this.filePrompt);

        if(f)

        {

            this.file = f;

            this.value = f.fsName;

            this.nameCtl.text = f.name;

        }

    };

    return buttonCtl;

}

function _odSelectFolder(label,tname,path,prompt,extension)

{

    oD = this;

    var buttonCtl = _odFileCommon(label,tname,path,prompt,extension);

    buttonCtl.folder = new Folder(path); // folder, pls, not file

    buttonCtl.nameCtl.text += "/";

    buttonCtl.onClick = function(){

        var f = this.folder.selectDlg(this.filePrompt);

        if(f)

        {

            this.folder = f;

            this.value = f.fsName;

            this.nameCtl.text = f.name + "/";

        }

    };

    return buttonCtl;

}

function _odCheckbox(label,tname,value,checkboxText)

{

        oD = this;

        var controlBox = oD._odControlShared(label,tname);

        var control = oD.w.add('checkbox',controlBox,checkboxText);

        control.value = value;

        //control.onChange = function(){this.value = this.text;};

        oD._odControlSharedFinish(control,tname,"value");

        return control;

}

function _odRadioButtons(label,tname,value,radioChoices)

{

    var oD = this;

    controlBox = oD ._odControlShared(label,tname);

    var itemHeight = controlBox.bottom - controlBox.top;

    result = oD.w.add('edittext',controlBox,value); // hidden text field to control it...

    result.onChange = function(){

        var i;

        this.value = this.text;

        for(i = 0; i < this.buttons.length; i++)

        {

            var button = this.buttons;

            button.value = (button.theChoice == this.text);

        }

    }

    result.hide();

    result.value = value;

    result.buttons = new Array();

    var i;

    for(i = 0; i < radioChoices.length; i++)

    {

        var choice = radioChoices;

        if(i > 0)

        {

            var bump = itemHeight + D_MARGIN;

            controlBox.top += bump;

            controlBox.bottom += bump;

            oD.curYPos += bump;

        }

        // each radiobutton object pokes its choice into the ersatz control,

        // so it looks like a simple value.

        // ("Grouping" appears to be by adjacent additions only. Nice!)

        var rb = oD.w.add('radiobutton',controlBox,choice);

        rb.value = choice == value;

        rb.theChoice = choice;

        rb.theGroupErsatzControl = result;

        rb.onClick = function(){this.theGroupErsatzControl.value = this.theChoice;};

        result.buttons[result.buttons.length] = rb;

    }

    oD._odControlSharedFinish(result,tname,"text");

    return result;

}

function _odMenu(label,tname,value,menuChoices)

{

    var oD = this;

    controlBox = oD ._odControlShared(label,tname);

    var itemHeight = controlBox.bottom - controlBox.top;

    var control = oD.w.add('dropdownlist',controlBox,menuChoices);

    // I couldnt discern how to get this from the "items" array, so I stash menuChoice for later. dvb08.

    control.menuChoices = menuChoices;

    control.value = value;

    // set the initial selection index

    var index = 0;

    for(var i = 0; i < menuChoices.length; i++)

    {

        if(value == menuChoices)

            index = i;

    }

    control.selection = index;

    control.onChange = function() {

        this.value = this.selection.text;

        } // make them all .value accessible

    oD._odControlSharedFinish(control,tname,"value");

}

function _odSectionLabel(label)

{

    var oD = this;

    var b2 = new Object();

    b2.left = D_MARGIN;

    b2.top = oD.curYPos;

    b2.right = b2.left + D_DIALOG_WIDTH;

    b2.bottom = b2.top + D_CONTROLHEIGHT;

    oD.curYPos += D_CONTROLHEIGHT + D_MARGIN;

    oD.w.add('statictext',b2,label + ':',{multiline:true});

}

function _odBoxedText(lines,text)

{

    var oD = this;

    var width = D_DIALOG_WIDTH;

    var height = lines * 15;

    var b2 = new Object();

    var b = new Object();

    b.top = oD.curYPos;

    b.bottom = b.top + height + 2 * D_MARGIN;

    b.left = D_MARGIN;

    b.right = b.left + width;

    oD.curYPos = b.bottom + D_MARGIN;

    var panel = oD.w.add('panel',b);

    b2.left = D_MARGIN;

    b2.top = D_MARGIN;

    b2.right = b2.left + width - 2 * D_MARGIN;

    b2.bottom = b2.top + height;

    panel.add('statictext',b2,text,{multiline:true});

}

function _odSeparator()

{

    var oD = this;

    var height = oD.groupGap;

    var barWidth = oD.ominoDialogWidth;

    if(barWidth)

    {

        var b = new Object();

        b.top = oD.curYPos + height / 2;

        b.bottom = b.top;

        b.left = D_MARGIN;

        b.right = b.left + barWidth;

        var barHeight = 2;

        b.top -= barHeight / 2;

        b.bottom = b.top + barHeight;

        oD.w.add('panel',b);

    }

    oD.curYPos += height;

}

function _odAppendGap()

{

    oD = this;

    oD.curYPos += oD.groupGap;

}

function appendOKCancel(oD)

{

    var y = oD.curYPos;

    var cancelRect = new Object();

    var okRect = new Object();

    cancelRect.left = D_MARGIN

    cancelRect.top = y;

    cancelRect.right = cancelRect.left + D_BUTTONWIDTH;

    cancelRect.bottom = cancelRect.top + D_CONTROLHEIGHT;

    okRect.left = cancelRect.right + D_MARGIN + D_MARGIN;

    okRect.top = y;

    okRect.right = okRect.left + D_BUTTONWIDTH;

    okRect.bottom = okRect.top + D_CONTROLHEIGHT;

    // Set up either Apply button, or OK/Cancel buttons

    if(oD.isPalette)

    {

        var applyBtn = oD.w.add('button',cancelRect,'Apply');

        applyBtn.oD = oD;

        applyBtn.onClick = function(){

            var oD = this.oD;

            var result = oD.get();

            oD.paletteCallback(result,oD.paletteCallbackArg2);

        };

    }

    else

    {

        var cancelBtn = oD.w.add('button',cancelRect,'Cancel',{name:'cancel'});

        var okBtn = oD.w.add('button',okRect,'OK',{name:'ok'});

        cancelBtn.oD = oD;

        cancelBtn.onClick = function(){this.oD.w.close(0);};  // 0 on cancel

        okBtn.theDialog = oD;

        okBtn.onClick = function(){this.theDialog.w.close(1);}; // 1 on ok

    }

    oD.curYPos = okRect.bottom + D_MARGIN;

}

function trimDialogBounds(oD)

{

    var xMax = 20;

    var yMax = 20;

    var n = oD.w.children.length;

    var i;

    for(i = 0; i < n; i++)

    {

        var aChild= od.w.children;

        var aChildBounds = aChild.bounds;

        if(aChildBounds.right > xMax)

            xMax = aChildBounds.right;

        if(aChildBounds.bottom > yMax)

            yMax = aChildBounds.bottom;

    }

    od.w.bounds.right = od.w.bounds.left + xMax + D_MARGIN;

    od.w.bounds.bottom = od.w.bounds.top + yMax + D_MARGIN;

    // actually... allow bottom gaps.

    od.w.bounds.bottom = od.curYPos + od.w.bounds.top;

}

/**

* The optional 2nd, 3rd, and 4th arguments make it a palette instead of a modal dialog. The callback

* is invoked every time Apply is clicked (you get an Apply button instead of OK/Cancel)

*/

function newOminoDialog(tname,existingPanel,paletteCallback,paletteCallbackArg2)

{

    // if you pass in something other than a panel, no can use.

    if(!(existingPanel instanceof Panel))

        existingPanel = null;

    var isPalette = (existingPanel || paletteCallback) ? 1 : 0;

    var kind = isPalette ? 'palette' : 'dialog';

    var oD = new Object();

    oD.w = existingPanel ? existingPanel : new Window(kind,tname,[100,100,500,500]);

    oD.isPalette = isPalette;

    oD.paletteCallback = paletteCallback;

    oD.paletteCallbackArg2 = paletteCallbackArg2;

    oD.curYPos = D_MARGIN;

    oD.groupGap = 12;

    oD.itemNames = new Array();

    oD.item

    oD.items = new Array();

    oD.itemValueFieldNames = new Object(); // to poke a value into the dialog, each control's appropriate field, like "text" or "value"

    oD.ominoDialogWidth = D_DIALOG_WIDTH;

    oD.gap = _odAppendGap;

    oD.number = _odNumber;

    oD.string = _odText;

    oD.radioButtons = _odRadioButtons;

    oD.checkbox = _odCheckbox;

    oD.sectionLabel = _odSectionLabel;

    oD.separator = _odSeparator;

    oD.boxedText = _odBoxedText;

    oD.color = _odColor;

    oD.openFile = _odOpenFile;

    oD.selectFolder = _odSelectFolder;

    oD.saveFile = _odSaveFile;

    oD.menu = _odMenu;

    oD.set = _odSet;

    oD.run = _odRun;

    oD.get = _odGet;

    oD._odControlShared = _odControlShared;

    oD._odControlSharedFinish = _odControlSharedFinish;

    return oD;

}

function _odGet()

{

    var values = new Object();

    var tname;

    for(tname in this.items)

    {

        var value = this.items[tname].value;

        values[tname] = value;

    }

    return values;

}

function _odSet(values)

{

    var oD = this;

    if(!values)

        return;

    for(var p in values)

    {

        var value = values

;

        var item = oD.items

;

        if(!item)

            continue;

        var itemValueFieldName = oD.itemValueFieldNames

;

        if(itemValueFieldName)

        {

            item[itemValueFieldName] = value;

            if(item.onChange)

                item.onChange();

            item.notify('onChange'); // to get the refresh

        }

    }

}

/**

   * Can be run as a modal dialog, OR as an ongoing palette.

   * As a dialog, nothing happens until OK or Cancel is chosen; on OK,

   * the parameters are returned.

   * To be a palette, pass in a function and an arg. The function will

   * be called with (resultParams, yourArg).

   */

function _odRun()

{

    var oD = this;

    if(!oD.finishingTouches)

    {

        oD.separator(oD);

        //oD.gap();

        appendOKCancel(oD);

        //oD.gap();

        trimDialogBounds(oD);

        oD.finishingTouches = true;

    }

    if(oD.w instanceof Window)

    {

        var resultCode = oD.w.show();

        if(resultCode != 1) // cancel

            return null;

        var result = oD.get();

        return result;

    }

    else

        return null;

}

function objectToString(o)

{

    if(!o)

        return "";

    var s = "";

    var i;

    for(tname in o)

        s += tname + " = " + o[tname] + "\n";

    return s;

}

var gExampleSettings = null;

function example(thisObj)

{

    var host = app;

    // the last 2 args are to make it modeless, and give you an APPLY button instead of OK and CANCEL.

    // This works in AE and Illustrator, but on Photoshop. I havent tried the rest...

    var d = newOminoDialog("Omino Example Dialog: " + host.name,thisObj,function(a,b){alert("result\n" + objectToString(a));});

    // comment out the above, and use this one for photoshop, to be modal:

    //var d = newOminoDialog("Omino Example Dialog: " + host.name);

    d.boxedText(9, "This is an example of a dialog built with ominoDialogMaker.jsx\n"

    + "host: " + host.name + " " + host.version + "\n"

        + "\n"

        + "©2007-2012 poly@omino.com",

        D_DIALOG_WIDTH);

// d.separator();

//    d.sectionLabel("Kinds of Controls");

    d.number("Number H","h",11.23);

    d.checkbox("Checkbox X","x",true,"check this");

    d.string("Text","t","type here");

    d.openFile("A File","f","","open it","jpg");

    d.radioButtons("Choose One","r","red",["red","maroon","scarlet","crimson"]);

    var result;

    d.set(gExampleSettings);

    var result = d.run();

    if(result !=null)

    {

        gExampleSettings = result;

        var s = "Result Values\n";

          s += objectToString(result);

        alert(s);

    }

}

/*

    Easy to use progress bar for ExtendScript.

    Written by poly@omino.com, 2007

    Enjoy, but this credit must remain intact.

usage:

    var pb = progressBar("main title","subtitle");

    pb.setValue(valueFrom0to1);

    pb.setTitle2("new subtitle display!")

    if(pb.isCanceled())

        pb.close(); // they clicked cancel

*/

function progressBar(title1,title2)

{

    var result = new Object();

    result.running = true;

    result.p = new Window("palette");

    result.p.orientation = "column";

    result.p.alignChildren = "left";

    result.t1 = result.p.add("statictext",undefined,title1);

    result.t2 = result.p.add("statictext",undefined,title2);

    result.b = result.p.add("progressbar");

    result.c = result.p.add("button",undefined,"Cancel");

    result.c.onClick = function() {

        result.running = false;

        }

    result.isRunning = function() { return this.running; }

    result.isCanceled = function() { return !this.isRunning(); }

    result.setValue = function(x) { this.b.value = x * 100; this.p.update(); }

    result.setTitle1 = function(t1) { this.t1.text = t1; }

    result.setTitle2 = function(t2) { this.t2.text = t2; }

    result.close = function() { this.p.close(); }

    result.p.show();

    return result;

}

/*

    a foolish little routine to show all the insides of an object in al Alert.

    You know, for debugging.

    */

function alertObj(o,title)

{

    if(!title)

        title = "";

    var s = title + "\n";

    var k;

    if(!o)

        s += "(null object)";

    else

        s += objectToString(o);

    alert(s);

}

JJMack