@@ -1 +1,145 @@
# include "../yScripts/y_JSExtensions.jsx" ; ␍ function yFlattenSelectedFolderContentsTool ( ) ␍ { ␍ this . info = ␍ { ␍ name : "yFlatten" , ␍ version : 0.11 , ␍ stage : "alpha" , ␍ description : "Set the Folder Structure for a new Project" , ␍ url : "yorchnet.com" ␍ } ; ␍ this . appearence = ␍ { ␍ buttonHeight : 30 , ␍ buttonWidth : 126 ␍ } ; ␍ this . resources = ␍ { ␍ icon : new File ( 'yNet.png' ) , ␍ } ; ␍ this . init = function init ( ) ␍ { ␍ / /alert("my name is:" + this.info.name);␍ this.btnLauyout = ␍ "button\␍ {\␍ preferredSize: ['" + this.appearence.buttonWidth + "','" + this.appearence.buttonHeight + "'],\␍ text:'" + this.info.name + "',\␍ helpTip:'" + this.info.description + "'\␍ }";␍ ␍ this. res = ␍ "window\␍ {\␍ type:'palette',\␍ text:'" + this.info.name + ' ' + this.info.ver + ' ' + this.info.stage + "',\␍ info: Group \␍ {\␍ alignment:['center','bottom'],\␍ icon: Image \␍ {\␍ icon:'" + this.resources.icon.path + '/ ' + this.resources.icon.name + "' , \ ␍ preferredSize : [ 15 , 18 ] \ ␍ } , \ ␍ website : StaticText \ ␍ { \ ␍ text : '" + this.info.url + "' , \ ␍ alignment : [ 'fill' , 'center' ] \ ␍ } , \ ␍ } \ ␍ } ";␍ }␍ this.createUI = function createUI()␍ {␍ ␍ ␍ this.window = new Window ( this.res );␍ this.window.show() ;␍ }␍ ␍ this.getSelectedProjectItems = function getSelectedProjectItems (){␍ var items = [];␍ var p = app.project;␍ for ( var i = 1 ; i <= p.numItems ; i ++ ){␍ var item = p.item(i);␍ if ( item.selected ){␍ items.push(item);␍ }␍ }␍ return items;␍ }␍ this.getAllItems = function getAllItems( folderItem ){␍ ␍ var items = [];␍ var folders = [];␍ ␍ for ( var i = 1 ; i <= folderItem.numItems ; i ++ ){␍ var item = folderItem.item(i);␍ ␍ if ( (item.typeName != " Folder ") ){␍ //if ( (isInArray( items ,item )) == false ){␍ items.push( item );␍ //}␍ }else{␍ var new_items = yFlattenSelectedFolderContentsTool().getAllItems(item);␍ for ( var j = 0 ; j < new_items.length ; j ++ ){␍ new_item = new_items[j];␍ //if ( (isInArray ( new_item )) == false ){␍ items.push ( new_item );␍ //}␍ }␍ }␍ }␍ return items␍ }␍ this.flatten = function flatten( items, root ){␍ app.beginUndoGroup(" Flatten Selected Folder Contents ")␍ for ( var i = 0; i < items.length ; i ++){␍ item = items[i];␍ item.parentFolder = root;␍ }␍ app.endUndoGroup()␍ purgeEmptyFolders();␍ return␍ }␍ this.purgeEmptyFolders = function purgeEmptyFolders(){␍ app.beginUndoGroup(" Purge Empty Folders ")␍ var emptyFolders = [];␍ ␍ var p = app.project;␍ for ( var i = p.numItems ; i >= 1 ; i -- ){␍ item = p.item(i);␍ if ( item.typeName == " Folder " ){␍ if ( item.numItems <= 0 ){␍ item.remove();␍ }␍ }␍ }␍ ␍ app.endUndoGroup()␍ }␍ this.yFlattenSelectedFolderContents = function yFlattenSelectedFolderContents()␍ {␍ //alert(" is this working " ) ; ␍ app . beginUndoGroup ( yFlattenSelectedFolderContentsTool ( ) . info . description ) ; ␍ yFlattenSelectedFolderContentsTool ( ) . flatten ( yFlattenSelectedFolderContentsTool ( ) . getAllItems ( yFlattenSelectedFolderContentsTool ( ) . getSelectedProjectItems ( ) [ 0 ] ) , yFlattenSelectedFolderContentsTool ( ) . getSelectedProjectItems ( ) [ 0 ] ) ; ␍ app . endUndoGroup ( ) ; ␍ } ␍ ␍ this . activate = this . yFlattenSelectedFolderContents ; ␍ ␍ this . init ( ) ; ␍ return this ; ␍ } ␍ ␍ / / C H E C K S t h a t t h e t o o l b o x e x i s t s , a n d i f i t d o e s n ´ t i t r u n s t h e s c r i p t o n i t s o w n . ␍ i f ( t y p e o f ( Y T B ) = = ' u n d e f i n e d ' ) ␍ { ␍ y F l a t t e n S e l e c t e d F o l d e r C o n t e n t s T o o l = n e w y F l a t t e n S e l e c t e d F o l d e r C o n t e n t s T o o l ( ) ; ␍ y F l a t t e n S e l e c t e d F o l d e r C o n t e n t s T o o l . a c t i v a t e ( ) ; ␍ } ␍ e l s e ␍ { ␍ y F l a t t e n S e l e c t e d F o l d e r C o n t e n t s T o o l = Y T B . a d d T o o l ( n e w y F l a t t e n S e l e c t e d F o l d e r C o n t e n t s T o o l ( ) ) ; ␍ } ␍
# include "../yScripts/y_JSExtensions.jsx" ;
function yFlattenSelectedFolderContentsTool ( )
{
this . info =
{
name : "yFlatten" ,
version : 0.11 ,
stage : "alpha" ,
description : "Set the Folder Structure for a new Project" ,
url : "yorchnet.com"
} ;
this . appearence =
{
buttonHeight : 30 ,
buttonWidth : 126
} ;
this . resources =
{
icon : new File ( 'yNet.png' ) ,
} ;
this . init = function init ( )
{
//alert("my name is:" + this.info.name);
this . btnLauyout =
"button\
{\
preferredSize: ['" + this . appearence . buttonWidth + "','" + this . appearence . buttonHeight + "'],\
text:'" + this . info . name + "',\
helpTip:'" + this . info . description + "'\
}" ;
this . res =
"window\
{\
type:'palette',\
text:'" + this . info . name + ' ' + this . info . ver + ' ' + this . info . stage + "',\
info: Group \
{\
alignment:['center','bottom'],\
icon: Image \
{\
icon:'" + this . resources . icon . path + '/' + this . resources . icon . name + "',\
preferredSize: [15, 18]\
},\
website: StaticText\
{\
text:'" + this . info . url + "',\
alignment:['fill','center']\
},\
}\
}" ;
}
this . createUI = function createUI ( )
{
this . window = new Window ( this . res ) ;
this . window . show ( ) ;
}
this . getSelectedProjectItems = function getSelectedProjectItems ( ) {
var items = [ ] ;
var p = app . project ;
for ( var i = 1 ; i <= p . numItems ; i ++ ) {
var item = p . item ( i ) ;
if ( item . selected ) {
items . push ( item ) ;
}
}
return items ;
}
this . getAllItems = function getAllItems ( folderItem ) {
var items = [ ] ;
var folders = [ ] ;
for ( var i = 1 ; i <= folderItem . numItems ; i ++ ) {
var item = folderItem . item ( i ) ;
if ( ( item . typeName != "Folder" ) ) {
//if ( (isInArray( items ,item )) == false ){
items . push ( item ) ;
//}
} else {
var new _items = yFlattenSelectedFolderContentsTool ( ) . getAllItems ( item ) ;
for ( var j = 0 ; j < new _items . length ; j ++ ) {
new _item = new _items [ j ] ;
//if ( (isInArray ( new_item )) == false ){
items . push ( new _item ) ;
//}
}
}
}
return items
}
this . flatten = function flatten ( items , root ) {
app . beginUndoGroup ( "Flatten Selected Folder Contents" )
for ( var i = 0 ; i < items . length ; i ++ ) {
item = items [ i ] ;
item . parentFolder = root ;
}
app . endUndoGroup ( )
purgeEmptyFolders ( ) ;
return
}
this . purgeEmptyFolders = function purgeEmptyFolders ( ) {
//app.beginUndoGroup("Purge Empty Folders")
var emptyFolders = [ ] ;
var p = app . project ;
for ( var i = p . numItems ; i >= 1 ; i -- ) {
item = p . item ( i ) ;
if ( item . typeName == "Folder" ) {
if ( item . numItems <= 0 ) {
item . remove ( ) ;
}
}
}
//app.endUndoGroup()
}
this . yFlattenSelectedFolderContents = function yFlattenSelectedFolderContents ( )
{
//alert("is this working");
//app.beginUndoGroup(yFlattenSelectedFolderContentsTool().info.description);
yFlattenSelectedFolderContentsTool ( ) . flatten ( yFlattenSelectedFolderContentsTool ( ) . getAllItems ( yFlattenSelectedFolderContentsTool ( ) . getSelectedProjectItems ( ) [ 0 ] ) , yFlattenSelectedFolderContentsTool ( ) . getSelectedProjectItems ( ) [ 0 ] ) ;
//app.endUndoGroup();
}
this . activate = this . yFlattenSelectedFolderContents ;
this . init ( ) ;
return this ;
}
//CHECKS that the toolbox exists, and if it doesn´ t it runs the script on its own.
if ( typeof ( YTB ) == 'undefined' )
{
yFlattenSelectedFolderContentsTool = new yFlattenSelectedFolderContentsTool ( ) ;
yFlattenSelectedFolderContentsTool . activate ( ) ;
}
else
{
yFlattenSelectedFolderContentsTool = YTB . addTool ( new yFlattenSelectedFolderContentsTool ( ) ) ;
}