📄 explorer.as
字号:
// Static variable used to define OS-specific root
// TODO: Allow server to introspect root location
public static var ROOT:String = "C:\\";
// Folder icon used by Tree for directory nodes that have no children
[Embed( "images/folder.gif" ) ]
private var imgFolder:String = null;
// Monitor service use to block rapid double clicking
// Hold a reference to the selected node during service calls
private var busy:Boolean = false;
private var node:Object = null;
// Called when a node is closed
// Removes child nodes in order to provide most recent display on subsequent requests
private function closed( event:Object ):Void {
event.node.removeAll();
}
// Initialize the application by triggering service calls for data
private function initApp( event ):Void {
svcFiles.directories( ROOT );
svcFiles.list( ROOT );
}
// Called when the directories service call has a result
// Manages display of directory nodes in Tree control
private function directories( list:Array ):Void {
var hold:Object = null;
// Loop over returned directory list
for( var f:Number = 0; f < list.length; f++ ) {
// If the tree has no data then this is the root directory structure
// Otherwise insert additional nodes as elements off selected node
if( node == null ) {
hold = treExplorer.addTreeNode( list[f] );
} else {
hold = node.addTreeNode( list[f] );
}
// Server checks for sub-directory structures and returns a boolean
// If children are present then show as branch
// If no chidren are present then create item node with folder icon
if( list[f].children ) {
treExplorer.setIsBranch( hold, true );
} else {
treExplorer.setIsBranch( hold, false );
treExplorer.setIcon( hold, imgFolder, imgFolder );
}
}
// Clear service usage
// Clear node selection
busy = false;
node = null;
}
// Label function used by DataGrid for formatting item data
// Does some basic file extension checking and manipulation
private function file( item:Object ):String {
var value:String = null;
var mark:Number = null;
if( item.file ) {
mark = item.name.indexOf( "." ) + 1;
value = item.name.slice( mark );
value = value.toUpperCase() + " File";
} else {
value = "File Folder";
}
return value;
}
// Called when Tree control gets a change event
// Triggers additional data call for sub-structure details
// Opens selected node to conveniently display incoming nodes
private function list( event:Object ):Void {
svcFiles.list( treExplorer.selectedNode.attributes.path );
if( !treExplorer.getIsOpen( treExplorer.selectedNode ) ) {
treExplorer.setIsOpen( treExplorer.selectedNode, true, false, true );
}
}
// Label function used by DataGrid for formatting item data
// Creates a Date from item data and leverages a formatter for Windows-esque display
private function modified( item:Object ):String {
var mod:Date = new Date();
mod.setTime( item.modified );
return fmtModified.format( mod );
}
// Called by Tree control when a node is expanded but not actually selected
// Stores reference to target node and triggers additional service call
private function open( event:Object ):Void {
if( !busy ) {
busy = true;
node = event.node;
svcFiles.directories( event.node.attributes.path );
}
}
// Label function used by DataGrid for formatting item data
// Displays size of data item in kilobytes
// TODO: Expand total method to allow for additional formatting
private function sizing( item:Object ):String {
var kb:Number = null;
var value:String = null;
if( item.size == 0 ) {
value = "";
} else {
kb = Math.ceil( item.size / 1024 )
value = fmtSize.format( kb ) + " KB";
}
return value;
}
// Called by DataGrid control when a change event is registered
// Reviews the selected item(s) and displays sizing information in status bar
private function selection():Void {
if( grdList.selectedItems.length == undefined ) {
lblSelection.text = grdList.dataProvider.length + " objects";
lblTotal.text = total( svcFiles.list.result, 3 );
} else {
lblSelection.text = grdList.selectedItems.length + " objects selected";
lblTotal.text = total( grdList.selectedItems, 3 );
}
}
// General formatting method used for item data display
// Takes an array of file items and tallies their sizes
// Can format tally based on number of digits to be displayed
private function total( list:Array, digits:Number ):String {
var bytes:Number = 0;
var div:Number = 0;
var value:String = null;
// Add up all the values
for( var i:Number = 0; i < list.length; i++ ) {
bytes += list[i].size;
}
// Look at total value as a string for length
value = bytes.toString();
// Compare length of tally against specified digit range
// Continue division on numeric tally until digit range matches argument
while( value.length > digits ) {
bytes = bytes / 1024;
value = Math.ceil( bytes ).toString();
div += 1;
}
// Leverage formatter class to provide thousands separator
value = fmtTotal.format( bytes );
// Add unit display based on the number of times division took place
switch( div ) {
case 0:
value = bytes + " bytes";
break;
case 1:
value = fmtTotal.format( bytes ) + " KB";
break;
case 2:
value = fmtTotal.format( bytes ) + " MB";
break;
case 3:
value = fmtTotal.format( bytes ) + " GB";
break;
}
return value;
}
// Called when general listing service has returned a result
// Performs additional tallying as required in status bar
// Results are also bound to DataGrid control directly
private function weigh( list:Array ):Void {
lblSelection.text = list.length + " objects";
lblTotal.text = total( list, 3 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -