Changeset 57

Show
Ignore:
Timestamp:
07/16/08 00:15:59 (2 months ago)
Author:
bi..@lilyapp.org
Message:

Adding a patch properties dialog with the ability to defined the size of a patch when opened in a subpatch.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lily/lily/chrome/content/externals.js

    r42 r57  
    125125        */ 
    126126        includeAll:function() { 
     127                 
    127128                for(var i=0;i<this.objArray.length;i++) { //don't load patches 
    128129                        if(this.isLoadable(this.objArray[i].name) && this.objArray[i].path && typeof this.objLeaf[this.objArray[i].name]=="undefined") { 
    129                                 //log(this.objArray[i].name) 
    130130                                var extName = LilyUtils.stripExtension(this.objArray[i].name); 
    131131                                try { 
     
    135135                                        this.objArray[i].menuName=LilyUtils.getObjectMetaData(objName).textName; 
    136136                                        this.objArray[i].catName=LilyUtils.getObjectMetaData(objName).objectCategory; 
    137                                         this.objArray[i].objSummary=LilyUtils.getObjectMetaData(objName).objectSummary
     137                                        this.objArray[i].objSummary=(LilyUtils.getObjectMetaData(objName).objectSummary?LilyUtils.getObjectMetaData(objName).objectSummary:LilyUtils.extractPatchDesc(this.objArray[i].sourceCode))
    138138                                        this.objArray[i].objArguments=LilyUtils.getObjectMetaData(objName).objectArguments;                                                              
    139139                                        this.objDisplay[((this.objArray[i].menuName)?this.objArray[i].menuName:"tmp")]=objName; 
  • trunk/lily/lily/chrome/content/externals/patcher.js

    r47 r57  
    179179        function openPatch(data,file) { 
    180180                                                                 
    181                 var sizeArr=Lily.extractPatchSize(data); //get the patch size w/o having to eval the json. 
     181                var sizeArr=LilyUtils.extractPatchSize(data); //get the patch size w/o having to eval the json. 
    182182                var parentDir=(file.parent.isDirectory())?file.parent:null; //patch's parent dir. 
    183183                thisPatch.obj = new LilyPatch(pid,Lily,sizeArr[0],sizeArr[1],false,{type:"iframe",win:iframe,parent:thisPtr.parent.patchView.xulWin}); //call the patch constructor 
  • trunk/lily/lily/chrome/content/externals/subpatch.js

    r47 r57  
    4040        //inspector values 
    4141        var argsArr = LilyUtils.splitArgs(args); //split the args 
    42         this.fPath = argsArr.shift()||""; //path to patch or null 
     42         
     43        this.fPath = (argsArr.length>0)?argsArr.shift():""; //path to patch or null 
    4344        this.patchArgs = argsArr.join(" ")||""; //the remainder of the args as string 
     45         
     46        if(/##\w+##/.test(this.patchArgs)) { 
     47                //pull out the patch name and use that as the display 
     48                this.displayName = this.patchArgs.match(/##(\w+)##/)[1]; 
     49                //if there any additional args, strip out the classname and assign them to display args. otherwise displayargs = false. 
     50                this.displayArgs = (!/^##\w+##/.test(this.patchArgs))?this.patchArgs.replace(/##\w+##/,""):false; 
     51                this.loadsSubPatchByName = true; 
     52        }        
    4453         
    4554        //inlet/outlet arrays 
     
    4958        this.setInspectorConfig([ 
    5059                {name:"fPath",value:thisPtr.fPath,label:"Patch Path",type:"string",input:"file"}, 
    51                 {name:"patchArgs",value:this.patchArgs,label:"Patch Arguments",type:"string",input:"text"}             
     60                {name:"patchArgs",value:thisPtr.patchArgs,label:"Patch Arguments",type:"string",input:"text"}          
    5261        ]); 
    5362         
     
    7382        function replacePatchArgs(arg_str,data) { 
    7483                var patch_str = data; 
    75                 var tmp = LilyUtils.splitArgs(arg_str); 
     84                var tmp = LilyUtils.splitArgs(arg_str.replace(/##\w+##/,""));           
    7685                for(var i=0;i<tmp.length;i++) { 
    7786                        var re = new RegExp("\\#"+(i+1),"g"); 
     
    8695                        setTimeout(function(){ 
    8796                                //thisPatch = {obj:null,id:pid,file:null,json:null}; //reset the thispatch object 
    88                                 var o = thisPtr.parent.replaceObject(thisPtr,"subpatch",thisPtr.args); 
     97                                var o = thisPtr.parent.replaceObject(thisPtr,"subpatch",thisPtr.patchArgs.replace(/##\w+##/,"")); 
    8998                                o.setHeight(thisPtr.height); 
    9099                                o.setWidth(thisPtr.width); 
     
    177186        function openPatch(data,file) { 
    178187                                                 
    179                 var sizeArr=Lily.extractPatchSize(data); //get the patch size w/o having to eval the json. 
     188                var sizeArr=LilyUtils.extractPatchSize(data); //get the patch size w/o having to eval the json. 
    180189                var parentDir=(file.parent.isDirectory())?file.parent:null; //patch's parent dir. 
    181190                thisPatch.obj = new LilyPatch(pid,Lily,sizeArr[0],sizeArr[1],false,{type:"iframe",win:thisPtr.displayElement,parent:thisPtr.parent.patchView.xulWin}); //call the patch constructor 
     
    234243                         
    235244                        var parent_patch = thisPatch.obj.getTopPatch(); //get the top level patch 
    236                         parent_patch.patchController.patchLoaded(thisPtr.objID,thisPatch.obj); //tell the patch we're loaded.                    
    237                                                                                                                                                          
    238                 }                
     245                        parent_patch.patchController.patchLoaded(thisPtr.objID,thisPatch.obj); //tell the patch we're loaded. 
     246                                                                                                                                                                                                         
     247                        //size the subpatch to the size set in patch we're loading... 
     248                        if(parseInt(thisPatch.obj.heightInSubPatch) != 0 && parseInt(thisPatch.obj.widthInSubPatch) != 0)  
     249                                iframe.resize(parseInt(thisPatch.obj.widthInSubPatch), parseInt(thisPatch.obj.heightInSubPatch)); 
     250 
     251                } 
    239252                 
    240253        } 
     
    251264        function frameLoad() { 
    252265                thisPtr.displayElement.removeEventListener("load",frameLoad,true); //remove this so we don't loop 
    253                 if(thisPtr.fPath&&thisPatch.json&&thisPatch.file) { openPatch(thisPatch.json,thisPatch.file); }//open the patch if we've got the data 
     266                if(thisPtr.fPath&&thisPatch.json&&thisPatch.file) {  
     267                        openPatch(thisPatch.json,thisPatch.file);                        
     268                }//open the patch if we've got the data 
    254269        } 
    255270                 
  • trunk/lily/lily/chrome/content/externals/wow.js

    r1 r57  
    274274        function openPatch(data,file) { 
    275275                                                                 
    276                 var sizeArr=Lily.extractPatchSize(data); //get the patch size w/o having to eval the json. 
     276                var sizeArr=LilyUtils.extractPatchSize(data); //get the patch size w/o having to eval the json. 
    277277                var parentDir=(file.parent.isDirectory())?file.parent:null; //patch's parent dir. 
    278278                thisPatch.obj = new LilyPatch(pid,Lily,sizeArr[0],sizeArr[1],false,{type:"iframe",win:_iframe,parent:thisPtr.parent.patchView.xulWin}); //call the patch constructor 
  • trunk/lily/lily/chrome/content/lily.js

    r21 r57  
    591591                var hidden=hide||false; 
    592592                 
    593                 var sizeArr=this.extractPatchSize(data); //get the patch size w/o having to eval the json. 
     593                var sizeArr=LilyUtils.extractPatchSize(data); //get the patch size w/o having to eval the json. 
    594594                var patchID=this.newPatch(sizeArr[0],sizeArr[1],readonly,hidden); //patch constructor- opens blank window. 
    595595                var parentDir=(file.parent.isDirectory())?file.parent:null; //patch's parent dir. 
     
    643643                } else { 
    644644                         
    645                         var sizeArr=this.extractPatchSize(data); 
     645                        var sizeArr=LilyUtils.extractPatchSize(data); 
    646646                        var patchID=this.newPatch(sizeArr[0],sizeArr[1],readonly,false); 
    647647                                                 
     
    714714                var data=fileObj.data; 
    715715                 
    716                 var sizeArr=this.extractPatchSize(data); //get the patch size w/o having to eval the json. 
     716                var sizeArr=LilyUtils.extractPatchSize(data); //get the patch size w/o having to eval the json. 
    717717                 
    718718                document.getElementById("lilyContentSplitter").setAttribute("collapsed",false); 
     
    748748                         
    749749        },       
    750                  
    751         /* 
    752                 Method: extractPatchSize 
    753                         get the patch size without having to eval the patch JSON. 
    754                          
    755                 Arguments:  
    756                         data - JSON patch string. 
    757                          
    758                 Returns:  
    759                         An array of patch width & height.                                                                        
    760         */       
    761         extractPatchSize: function(data) { 
    762                 var wArr=data.match(/'width':(\d+)/); 
    763                 var hArr=data.match(/'height':(\d+)/);           
    764                  
    765                 if(wArr && hArr) 
    766                         return [wArr[1],hArr[1]]; 
    767                 else 
    768                         return [0,0]; 
    769         }, 
    770750         
    771751        /* 
     
    834814                var data=LilyUtils.readFile(file); 
    835815                 
    836                 var sizeArr=this.extractPatchSize(data); 
     816                var sizeArr=LilyUtils.extractPatchSize(data); 
    837817                var patchID=this.newPatch(sizeArr[0],sizeArr[1],false,false); 
    838818                 
     
    974954                        //update the patch name before we serialize 
    975955                        //yes, this is a mess 
    976                         this.patchObj[pID].obj.title=LilyUtils.stripExtension(file.leafName); 
    977                         this.patchObj[pID].obj.patchView.setPatchTitle(LilyUtils.stripExtension(file.leafName)); 
    978  
     956                        if(this.patchObj[pID].obj.title == "Untitled") { 
     957                                this.patchObj[pID].obj.title=LilyUtils.stripExtension(file.leafName); 
     958                                this.patchObj[pID].obj.patchView.setPatchTitle(LilyUtils.stripExtension(file.leafName));                                 
     959                        } 
     960                         
    979961                        //now we've updated the patch title, so serialize 
    980962                        var data=this.patchObj[pID].obj.patchModel.serializeDom(); 
     
    11981180                if(this.patchObj[id]&&this.patchObj[id].obj.patchController.getEditable()=="edit")               
    11991181                        this.patchObj[id].obj.patchController.selectAll(); 
     1182        }, 
     1183 
     1184        /* 
     1185                Method: openPatchProperties 
     1186                        dispatch menu command. 
     1187        */ 
     1188        openPatchProperties: function() { 
     1189                var p = this.patchObj[this.currPatch].obj; 
     1190                var win = p.patchView.xulWin; 
     1191                 
     1192                var initVals = {  
     1193                        title:  p.title, 
     1194                        color:  p.color,                         
     1195                        height: p.heightInSubPatch,  
     1196                        width:  p.widthInSubPatch, 
     1197                        desc:   LilyUtils.unescape(p.description)        
     1198                }; 
     1199                 
     1200                win.openDialog("chrome://lily/content/patch-properties.xul", "cWin","width=450,height=405,left=50,top=550,close=no,scrollbars=no,dialog=yes,resizable=no,toolbar=no,menubar=no,location=no,status=no,chrome=yes,alwaysRaised=yes",function(val){ 
     1201                        for(var x in val) { 
     1202                                switch(x) { 
     1203                                        case "title": 
     1204                                                p.patchView.setPatchTitle(val[x]); 
     1205                                        case "color": 
     1206                                                p.patchView.setPatchColor(val[x]); 
     1207                                        case "height": 
     1208                                                p.heightInSubPatch=val[x]; 
     1209                                        case "width": 
     1210                                                p.widthInSubPatch=val[x]; 
     1211                                        case "desc": 
     1212                                                p.description=LilyUtils.escape(val[x]); 
     1213                                }                                
     1214                        } 
     1215                },initVals); 
     1216                         
    12001217        }, 
    12011218 
  • trunk/lily/lily/chrome/content/model.js

    r14 r57  
    103103                j+="'height':"+this.patch.height+comma; 
    104104                j+="'color':"+quote+this.patch.color+quote+comma; 
    105                 j+="'mode':"+quote+this.patch.patchController.editable+quote+comma;              
     105                j+="'mode':"+quote+this.patch.patchController.editable+quote+comma;      
     106                j+="'description':"+quote+this.patch.description+quote+comma;    
     107                j+="'heightInSubPatch':"+quote+this.patch.heightInSubPatch+quote+comma;  
     108                j+="'widthInSubPatch':"+quote+this.patch.widthInSubPatch+quote+comma;                                                            
    106109                 
    107110                j+="'objArray':"+oBrace; 
  • trunk/lily/lily/chrome/content/patch.js

    r44 r57  
    3333        this.width=(width&&!hide)?width:(hide)?0:800; //width    
    3434        this.height=(height&&!hide)?height:(hide)?0:600; //height 
     35        this.heightInSubPatch=0; //height when loaded in a subpatch 
     36        this.widthInSubPatch=0;  //width when loaded in a subpatch 
     37        this.description="";    //patch description. 
    3538        this.color="#FFFFFF" //background color 
     39        this.desc="";           //patch description 
    3640        this.fontSize=LilyUtils.getDefaultFont()[1]; //font size in px 
    3741        this.fontFamily=LilyUtils.getDefaultFont()[0]; //font face 
     
    416420                        o.init(); //generic- user defined 
    417421                } else if(obj && typeof obj == "string") { 
    418                         return this.createObject("patcher",pID,t,l,id,(obj+" "+argStr+" ##"+className+"##")); 
     422                        var sizeArr = LilyUtils.extractSizeInSubPatch(LilyUtils.readFileFromPath(obj).data);             
     423                        if(sizeArr[0]||sizeArr[1]) { 
     424                                return this.createObject("subpatch",pID,t,l,id,(obj+" "+argStr+" ##"+className+"##"));                                   
     425                        } else { 
     426                                return this.createObject("patcher",pID,t,l,id,(obj+" "+argStr+" ##"+className+"##"));    
     427                        } 
     428                         
    419429                } 
    420430                 
     
    729739                        if(typeof patch.color!="undefined" && !subPatchID && !opID) 
    730740                                this.patchView.setPatchColor(patch.color); //update color 
     741                                 
     742                        if(typeof patch.description!="undefined" && !subPatchID && !opID) 
     743                                this.description=patch.description; //update color 
     744                                 
     745                        if(typeof patch.heightInSubPatch!="undefined" && !subPatchID && !opID) 
     746                                this.heightInSubPatch=parseInt(patch.heightInSubPatch); //update color   
     747                                 
     748                        if(typeof patch.widthInSubPatch!="undefined" && !subPatchID && !opID) 
     749                                this.widthInSubPatch=parseInt(patch.widthInSubPatch); //update color                                                     
    731750                         
    732751                        var oArray=patch.objArray; //top level 'patch' object defined in the patch json 
     
    16791698                var patchArr = thisPtr.patch.patchModel.subPatchArray; 
    16801699                for(var x  in patchArr) { 
    1681                         var p = patchArr[x].obj.patchView;                       
    1682                         try { 
    1683                                 var evt = p.document.createEvent("Event");                       
    1684                                 evt.initEvent(e, true, false);                           
    1685                                 p.document.dispatchEvent(evt);           
    1686                         } catch(e) {}                                    
     1700                        if(patchArr[x].obj && patchArr[x].obj.patchView) { 
     1701                                var p = patchArr[x].obj.patchView;                       
     1702                                try { 
     1703                                        var evt = p.document.createEvent("Event");                       
     1704                                        evt.initEvent(e, true, false);                           
     1705                                        p.document.dispatchEvent(evt);           
     1706                                } catch(e) {}    
     1707                        }                                        
    16871708                } 
    16881709        } 
  • trunk/lily/lily/chrome/content/patch.xul

    r23 r57  
    8383                    <menuitem id="patchEditOption" key="lilyToggleEditKey" label="&lily.Edit;" type="checkbox" autocheck="true" checked="false" option="patchEdit" oncommand="opener.Lily.toggleEdit()"/> 
    8484                                <menuitem id="menu_PatchColor" label="&lily.Color;" oncommand="opener.Lily.openColorPicker('patch')"/> 
     85                                <menuitem id="menu_PatchProperties" label="&lily.PatchProperties;..." oncommand="opener.Lily.openPatchProperties()"/> 
    8586                                <!--<menuitem id="menu_PatchZoomIn" label="&lily.ZoomIn;" oncommand="opener.Lily.zoomIn()"/> 
    8687                                <menuitem id="menu_PatchZoomOut" label="&lily.ZoomOut;" oncommand="opener.Lily.zoomOut()"/> 
  • trunk/lily/lily/chrome/content/utils.js

    r40 r57  
    441441        */ 
    442442        stripLTQuotes: function(str) { 
    443                 if(str && str.length) return str.replace(/^['"]|['"]$/ig, ''); 
     443                if(str && str.length) { 
     444                        return str.replace(/^['"]|['"]$/ig, ''); 
     445                } else { 
     446                        return ""; 
     447                }        
    444448        }, 
    445449         
     
    14011405        isPatchString: function(str) { 
    14021406                return (/var patch={/.test(str)); 
     1407        }, 
     1408         
     1409        /* 
     1410                Method: extractPatchDesc 
     1411                        get the patch size without having to eval the patch JSON. 
     1412                         
     1413                Arguments:  
     1414                        data - JSON patch string. 
     1415                         
     1416                Returns:  
     1417                        Patch description.                                                                       
     1418        */       
     1419        extractPatchDesc: function(data) { 
     1420                var desc=data.match(/'description':'([\S|\s]+)','heightInSubPatch'/);            
     1421                 
     1422                if(desc && desc.length>1) 
     1423                        return desc[1]; 
     1424                else 
     1425                        return ""; 
     1426        }, 
     1427         
     1428        /* 
     1429                Method: extractPatchSize 
     1430                        get the patch size without having to eval the patch JSON. 
     1431                         
     1432                Arguments:  
     1433                        data - JSON patch string. 
     1434                         
     1435                Returns:  
     1436                        An array of patch width & height.                                                                        
     1437        */       
     1438        extractPatchSize: function(data) { 
     1439                var wArr=data.match(/'width':(\d+)/); 
     1440                var hArr=data.match(/'height':(\d+)/);           
     1441                 
     1442                if(wArr && hArr) 
     1443                        return [wArr[1],hArr[1]]; 
     1444                else 
     1445                        return [0,0]; 
     1446        }, 
     1447         
     1448        /* 
     1449                Method: extractSizeInSubPatch 
     1450                        get the size in subpatch without having to eval the patch JSON. 
     1451                         
     1452                Arguments:  
     1453                        data - JSON patch string. 
     1454                         
     1455                Returns:  
     1456                        An array of patch width & height when opened in subpatch.                                                                        
     1457        */       
     1458        extractSizeInSubPatch: function(data) { 
     1459                                 
     1460                if(typeof data == "string") { 
     1461                        var wArr=data.match(/'widthInSubPatch':'(\d+)'/); 
     1462                        var hArr=data.match(/'heightInSubPatch':'(\d+)'/);       
     1463                         
     1464                        if(wArr && hArr){ 
     1465                                return [parseInt(wArr[1]),parseInt(hArr[1])]; 
     1466                        }else{ 
     1467                                return [0,0]; 
     1468                        } 
     1469                                 
     1470                } else { 
     1471                                return [0,0]; 
     1472                } 
    14031473        },       
    14041474         
     
    23312401        } 
    23322402         
     2403        this.resize=function(w,h) { 
     2404                parent.setHeight(h); 
     2405                parent.setWidth(w); 
     2406                frameCover.style.height=(h+5)+"px"; 
     2407                frameCover.style.width=(w+5)+"px";               
     2408        } 
     2409         
    23332410        //set the object size 
    23342411        if(h) 
     
    23412418        frameCover=parent.parent.patchView.displayHTML(""); 
    23422419        frameCover.id=parent.createElID("frameCover"); 
    2343 //      frameCover.style.backgroundColor='red';  
     2420//      frameCover.style.backgroundColor='red'; //debug 
    23442421        frameCover.style.position='absolute'; 
    23452422        frameCover.style.left=(parent.left)+"px"; 
  • trunk/lily/lily/chrome/locale/en-US/lily.dtd

    r20 r57  
    3232<!ENTITY  lily.Show                         "Show on Lock"> 
    3333<!ENTITY  lily.PatchFolder          "Open Patch Directory"> 
     34<!ENTITY  lily.PatchProperties      "Patch Properties"> 
    3435 
    3536<!ENTITY  lily.ObjectMenu           "Externals">