﻿var YToolBox  = function YToolBox(thisObj)
{
    var resources =
    {
        icon : new File('../yScripts/yNet.png'),
        header : new File('../yScripts/header.png')
    }
    
    var info =
    {
        url : 'yorchnet.com',
        name :'yToolBox',
        ver :'0.4.2.1 alpha',
        description : 'Working tools so far...'
    }
    
    var gui =
    {
        buttonWidth : 126,
        buttonHeight : 30
    }
    
    var tools = [];
    
    #include "../yScripts/y_JSExtensions.jsx";
    
    this.addTool = function addTool(aTool)
    {
        alert("AddTool : Adding");
        alert("AddTool : there are " + this.tools.length + " tools right now");
        this.tools.push(aTool);
        alert("AddTool : there are " + this.tools.length + " tools right now");
    }
    
    //alert(thisObj);
    this.customize  = function customize()
    {
        /*
        g  = this.window.grp.main.graphics;
        myFont = ScriptUI.newFont('Cooper Std Black',ScriptUI.FontStyle.REGULAR ,14 );
        myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [1, .45, 0, 1]);    
        g.backgroundColor = myBrush;
        */
        alert();
    }

    this.resize = function resize()
    {
        this.layout.resize();
        this.customize;  
    }
    
    this.createGui = function createGui()
    {
         //MAIN WINDOW STRUCTURE.
        this.gui.header =
        "group\
        {\
            orientation:'column',\
            alignment:['fill','fill'],\
            margins:[0,0,0,0]\
            \
            header: Group\
            {\
                orientation:'column', \
                alignment:['center','top'],\
                margins:[0,0,0,0]\
                \
                title: Image\
                {\
                    icon:'"+this.resources.header.path+'/'+this.resources.header.name+"',\
                    preferredSize: [175, 35]},\
                    ver: StaticText { text:'"+this.info.ver+"',\
                    alignment:['center','center']}\
                desc: StaticText\
                {\
                    text:'"+this.info.description+"',\
                    alignment:['center','center']\
                },\
            },\
            main: Group {\
                orientation:'column',\
                alignment:['fill','fill'],\
                alignChildren:['center','center']\
                ,"
        this.gui.main= ""; //To be populated with the included Tools
        this.gui.footer ="}, \
            cmds: Group\
            {\
                alignment:['center','bottom'],\
                icn_app: Image\
                {\
                    icon:'"+ this.resources.icon.path+'/'+ this.resources.icon.name+"',\
                    preferredSize: [15, 18]\
                },\
                txt_info: StaticText\
                {\
                    text:'"+ this.info.url+"',\
                    alignment:['fill','center']\
                 },\
            },\
        }";
        
        alert(this.tools);
        this.window.grp = this.window.add( this.gui.header + this.gui.main + this.gui.footer );
        this.window.layout.layout(true);
        this.window.onResize = this.resize;

        this.window.onClose = function () {delete yToolBox;};
        
       //ASSIGN buttons to the activate function of each tool;
       var toolBtns = this.window.grp.main.children;
        for( var n = 0 ; n < toolBtns.length ; n++ ){
            toolBtns[n].onClick = this.tools[n].activate;
        }

    }
    
    this.init = function init()
    {
        this.resources = resources;
        this.info = info;
        this.gui = gui;
        this.tools = tools;
        
        this.window = (thisObj instanceof Panel) ? thisObj : new Window("palette", this.info , undefined, {resizeable:true});
        this.createGui();
    }
    
    this.init();
    return this
}

var ytb = new YToolBox(this);

#include "../yScripts/y_setStructure.jsx";

