2006-06-15 22:35:48 +00:00
////////////////////////////////////////////////////////////////////////////////
///
/// ItemTreeView
/// -- handles the link between an individual tree and the data layer
/// -- displays only items (no collections, no hierarchy)
///
////////////////////////////////////////////////////////////////////////////////
/ *
* Constructor the the ItemTreeView object
* /
2006-05-31 20:29:46 +00:00
Scholar . ItemTreeView = function ( itemGroup )
2006-05-30 16:37:51 +00:00
{
2006-06-09 14:42:53 +00:00
this . _itemGroup = itemGroup ;
2006-05-30 16:37:51 +00:00
this . _treebox = null ;
2006-06-27 20:37:02 +00:00
this . _savedSelection = null ;
2006-06-01 17:54:41 +00:00
this . refresh ( ) ;
2006-06-01 20:03:53 +00:00
this . _unregisterID = Scholar . Notifier . registerItemTree ( this ) ;
2006-06-01 18:50:16 +00:00
}
2006-06-15 22:35:48 +00:00
/ *
* Called by the tree itself
* /
2006-06-09 14:42:53 +00:00
Scholar . ItemTreeView . prototype . setTree = function ( treebox )
{
if ( this . _treebox )
return ;
this . _treebox = treebox ;
2006-06-12 12:43:20 +00:00
if ( ! this . isSorted ( ) )
{
this . cycleHeader ( this . _treebox . columns . getNamedColumn ( 'firstCreator' ) ) ;
}
else
{
this . sort ( ) ;
}
2006-06-09 14:42:53 +00:00
}
2006-06-15 22:35:48 +00:00
/ *
* Reload the rows from the data access methods
* ( doesn ' t call the tree . invalidate methods , etc . )
* /
2006-06-01 18:50:16 +00:00
Scholar . ItemTreeView . prototype . refresh = function ( )
{
this . _dataItems = new Array ( ) ;
this . rowCount = 0 ;
var newRows = this . _itemGroup . getChildItems ( ) ;
for ( var i = 0 ; i < newRows . length ; i ++ )
2006-06-06 20:33:49 +00:00
if ( newRows [ i ] )
2006-06-27 22:47:17 +00:00
this . _showItem ( new Scholar . ItemTreeView . TreeRow ( newRows [ i ] , 0 , false ) , i + 1 ) ; //item ref, before row
2006-06-01 18:50:16 +00:00
this . _refreshHashMap ( ) ;
}
2006-06-15 22:35:48 +00:00
/ *
* Called by Scholar . Notifier on any changes to items in the data layer
* /
2006-06-09 14:42:53 +00:00
Scholar . ItemTreeView . prototype . notify = function ( action , type , ids )
2006-06-01 18:50:16 +00:00
{
2006-06-09 14:42:53 +00:00
var madeChanges = false ;
this . selection . selectEventsSuppressed = true ;
this . saveSelection ( ) ;
if ( ( action == 'remove' && ! this . _itemGroup . isLibrary ( ) ) || ( action == 'delete' && this . _itemGroup . isLibrary ( ) ) )
{
ids = Scholar . flattenArguments ( ids ) ;
//Since a remove involves shifting of rows, we have to do it in order
//sort the ids by row
var rows = new Array ( ) ;
for ( var i = 0 , len = ids . length ; i < len ; i ++ )
if ( action == 'delete' || ! this . _itemGroup . ref . hasItem ( ids [ i ] ) )
rows . push ( this . _itemRowMap [ ids [ i ] ] ) ;
if ( rows . length > 0 )
{
rows . sort ( function ( a , b ) { return a - b } ) ;
for ( var i = 0 , len = rows . length ; i < len ; i ++ )
{
var row = rows [ i ] ;
2006-07-05 15:35:15 +00:00
if ( row != null )
{
this . _hideItem ( row - i ) ;
this . _treebox . rowCountChanged ( row - i , - 1 ) ;
}
2006-06-09 14:42:53 +00:00
}
madeChanges = true ;
}
}
else if ( action == 'modify' ) //must check for null because it could legitimately be 0
{
2006-06-26 17:51:18 +00:00
var row = this . _itemRowMap [ ids ] ;
if ( row != null )
2006-06-09 14:42:53 +00:00
{
2006-06-26 17:51:18 +00:00
if ( this . isContainer ( row ) && this . isContainerOpen ( row ) )
{
this . toggleOpenState ( row ) ;
this . toggleOpenState ( row ) ;
}
else
{
this . _treebox . invalidateRow ( row ) ;
}
2006-06-09 14:42:53 +00:00
madeChanges = true ;
}
}
else if ( action == 'add' )
{
var item = Scholar . Items . get ( ids ) ;
2006-07-27 18:08:09 +00:00
if ( ( this . _itemGroup . isLibrary ( ) || item . inCollection ( this . _itemGroup . ref . getID ( ) ) ) //if the item belongs in this collection
&& this . _itemRowMap [ ids ] == null //if we haven't already added it to our hash map
&& ( item . isRegularItem ( ) || ! item . getSource ( ) ) ) //if it's stand-alone
2006-06-09 14:42:53 +00:00
{
2006-06-27 22:47:17 +00:00
this . _showItem ( new Scholar . ItemTreeView . TreeRow ( item , 0 , false ) , this . rowCount ) ;
2006-06-09 14:42:53 +00:00
this . _treebox . rowCountChanged ( this . rowCount - 1 , 1 ) ;
madeChanges = true ;
}
}
if ( madeChanges )
{
if ( this . isSorted ( ) )
{
this . sort ( ) ; //this also refreshes the hash map
this . _treebox . invalidate ( ) ;
}
else if ( action != 'modify' ) //no need to update this if we just modified
{
this . _refreshHashMap ( ) ;
}
if ( action == 'add' )
2006-06-17 00:57:50 +00:00
{
2006-06-09 14:42:53 +00:00
this . selection . select ( this . _itemRowMap [ item . getID ( ) ] ) ;
2006-06-17 00:57:50 +00:00
this . _treebox . ensureRowIsVisible ( this . _itemRowMap [ item . getID ( ) ] ) ;
}
2006-06-09 14:42:53 +00:00
else
2006-06-17 00:57:50 +00:00
{
2006-06-09 14:42:53 +00:00
this . rememberSelection ( ) ;
2006-06-17 00:57:50 +00:00
}
2006-06-09 14:42:53 +00:00
}
this . selection . selectEventsSuppressed = false ;
2006-05-30 16:37:51 +00:00
}
2006-06-15 22:35:48 +00:00
/ *
* Unregisters view from Scholar . Notifier ( called on window close )
* /
2006-06-09 14:42:53 +00:00
Scholar . ItemTreeView . prototype . unregister = function ( )
2006-05-30 16:37:51 +00:00
{
2006-06-09 14:42:53 +00:00
Scholar . Notifier . unregisterItemTree ( this . _unregisterID ) ;
2006-05-30 16:37:51 +00:00
}
2006-06-15 22:35:48 +00:00
////////////////////////////////////////////////////////////////////////////////
///
/// nsITreeView functions
/// http://www.xulplanet.com/references/xpcomref/ifaces/nsITreeView.html
///
////////////////////////////////////////////////////////////////////////////////
2006-05-30 16:37:51 +00:00
Scholar . ItemTreeView . prototype . getCellText = function ( row , column )
{
var obj = this . _getItemAtRow ( row ) ;
2006-06-12 12:43:20 +00:00
var val ;
2006-06-16 15:27:22 +00:00
if ( column . id == "numNotes" )
{
var c = obj . numNotes ( ) ;
if ( c ) //don't display '0'
val = c ;
}
2006-06-26 17:51:18 +00:00
else if ( column . id == "typeIcon" )
{
val = Scholar . getString ( 'itemTypes.' + Scholar . ItemTypes . getName ( obj . getType ( ) ) ) ;
}
else
2006-06-16 15:27:22 +00:00
{
2006-06-12 12:43:20 +00:00
val = obj . getField ( column . id ) ;
2006-06-16 15:27:22 +00:00
}
2006-05-31 17:50:33 +00:00
if ( column . id == 'dateAdded' || column . id == 'dateModified' ) //this is not so much that we will use this format for date, but a simple template for later revisions.
{
2006-06-06 19:53:27 +00:00
val = new Date ( Date . parse ( val . replace ( /-/g , "/" ) ) ) . toLocaleString ( ) ;
2006-05-31 17:50:33 +00:00
}
return val ;
2006-05-30 16:37:51 +00:00
}
2006-06-09 16:36:18 +00:00
Scholar . ItemTreeView . prototype . getImageSrc = function ( row , col )
{
2006-06-26 17:51:18 +00:00
if ( col . id == 'title' )
2006-06-09 16:36:18 +00:00
{
2006-06-27 20:37:02 +00:00
var itemType = Scholar . ItemTypes . getName ( this . _getItemAtRow ( row ) . getType ( ) ) ;
2006-06-26 17:51:18 +00:00
2006-06-09 16:36:18 +00:00
return "chrome://scholar/skin/treeitem-" + itemType + ".png" ;
}
}
2006-06-26 17:51:18 +00:00
Scholar . ItemTreeView . prototype . isContainer = function ( row )
{
2006-07-27 18:08:09 +00:00
return this . _getItemAtRow ( row ) . isRegularItem ( ) ;
2006-06-26 17:51:18 +00:00
}
Scholar . ItemTreeView . prototype . isContainerOpen = function ( row )
{
return this . _dataItems [ row ] . isOpen ;
}
Scholar . ItemTreeView . prototype . isContainerEmpty = function ( row )
{
2006-07-27 18:08:09 +00:00
return ( this . _getItemAtRow ( row ) . numNotes ( ) == 0 && this . _getItemAtRow ( row ) . numFiles ( ) == 0 ) ;
2006-06-26 17:51:18 +00:00
}
Scholar . ItemTreeView . prototype . getLevel = function ( row )
{
return this . _getItemAtRow ( row ) . level ;
}
Scholar . ItemTreeView . prototype . getParentIndex = function ( row )
{
var thisLevel = this . getLevel ( row ) ;
if ( thisLevel == 0 ) return - 1 ;
for ( var i = row - 1 ; i >= 0 ; i -- )
if ( this . getLevel ( i ) < thisLevel )
return i ;
return - 1 ;
}
Scholar . ItemTreeView . prototype . hasNextSibling = function ( row , afterIndex )
{
var thisLevel = this . getLevel ( row ) ;
for ( var i = afterIndex + 1 ; i < this . rowCount ; i ++ )
{
var nextLevel = this . getLevel ( i ) ;
if ( nextLevel == thisLevel ) return true ;
else if ( nextLevel < thisLevel ) return false ;
}
}
Scholar . ItemTreeView . prototype . toggleOpenState = function ( row )
{
var count = 0 ; //used to tell the tree how many rows were added/removed
var thisLevel = this . getLevel ( row ) ;
if ( this . isContainerOpen ( row ) )
{
while ( ( row + 1 < this . _dataItems . length ) && ( this . getLevel ( row + 1 ) > thisLevel ) )
{
this . _hideItem ( row + 1 ) ;
count -- ; //count is negative when closing a container because we are removing rows
}
}
else
{
var item = this . _getItemAtRow ( row ) . ref ;
2006-07-27 18:08:09 +00:00
//Get children
var files = item . getFiles ( ) ;
var notes = item . getNotes ( ) ;
var newRows ;
if ( files && notes )
newRows = files . concat ( notes ) ;
else if ( files )
newRows = files ;
else if ( notes )
newRows = notes ;
newRows = Scholar . Items . get ( newRows ) ;
2006-06-26 17:51:18 +00:00
for ( var i = 0 ; i < newRows . length ; i ++ )
{
count ++ ;
2006-06-27 22:47:17 +00:00
this . _showItem ( new Scholar . ItemTreeView . TreeRow ( newRows [ i ] , thisLevel + 1 , false ) , row + i + 1 ) ; //item ref, before row
2006-07-27 18:08:09 +00:00
}
2006-06-26 17:51:18 +00:00
}
this . _treebox . beginUpdateBatch ( ) ;
this . _dataItems [ row ] . isOpen = ! this . _dataItems [ row ] . isOpen ;
this . _treebox . rowCountChanged ( row + 1 , count ) ; //tell treebox to repaint these
this . _treebox . invalidateRow ( row ) ;
this . _treebox . endUpdateBatch ( ) ;
this . _refreshHashMap ( ) ;
}
2006-06-05 15:49:11 +00:00
Scholar . ItemTreeView . prototype . isSorted = function ( )
{
for ( var i = 0 , len = this . _treebox . columns . count ; i < len ; i ++ )
if ( this . _treebox . columns . getColumnAt ( i ) . element . getAttribute ( 'sortActive' ) )
return true ;
return false ;
}
2006-05-30 16:37:51 +00:00
Scholar . ItemTreeView . prototype . cycleHeader = function ( column )
{
2006-06-05 15:49:11 +00:00
for ( var i = 0 , len = this . _treebox . columns . count ; i < len ; i ++ )
{
col = this . _treebox . columns . getColumnAt ( i ) ;
if ( column != col )
{
col . element . removeAttribute ( 'sortActive' ) ;
col . element . removeAttribute ( 'sortDirection' ) ;
}
else
{
col . element . setAttribute ( 'sortActive' , true ) ;
col . element . setAttribute ( 'sortDirection' , col . element . getAttribute ( 'sortDirection' ) == 'descending' ? 'ascending' : 'descending' ) ;
}
}
2006-06-06 22:43:58 +00:00
this . selection . selectEventsSuppressed = true ;
this . saveSelection ( ) ;
2006-06-05 15:49:11 +00:00
this . sort ( ) ;
2006-06-06 22:43:58 +00:00
this . rememberSelection ( ) ;
this . selection . selectEventsSuppressed = false ;
this . _treebox . invalidate ( ) ;
2006-06-05 15:49:11 +00:00
}
2006-06-15 22:35:48 +00:00
/ *
* Sort the items by the currently sorted column .
* Simply uses Array . sort ( ) function , and refreshes the hash map .
* /
2006-06-05 15:49:11 +00:00
Scholar . ItemTreeView . prototype . sort = function ( )
{
var column = this . _treebox . columns . getSortedColumn ( )
var order = column . element . getAttribute ( 'sortDirection' ) == 'descending' ;
2006-06-12 12:43:20 +00:00
if ( column . id == 'typeIcon' )
2006-05-30 16:37:51 +00:00
{
function columnSort ( a , b )
{
2006-06-25 04:35:11 +00:00
var typeA = Scholar . getString ( 'itemTypes.' + Scholar . ItemTypes . getName ( a . getType ( ) ) ) ;
var typeB = Scholar . getString ( 'itemTypes.' + Scholar . ItemTypes . getName ( b . getType ( ) ) ) ;
2006-06-12 12:43:20 +00:00
return ( typeA > typeB ) ? - 1 : ( typeA < typeB ) ? 1 : 0 ;
2006-05-30 16:37:51 +00:00
}
}
2006-06-16 16:30:03 +00:00
else if ( column . id == 'numNotes' )
{
function columnSort ( a , b )
{
return b . numNotes ( ) - a . numNotes ( ) ;
}
}
2006-05-30 16:37:51 +00:00
else
{
function columnSort ( a , b )
{
2006-06-20 14:36:49 +00:00
var fieldA = a . getField ( column . id ) ;
var fieldB = b . getField ( column . id ) ;
if ( typeof fieldA == 'string' )
{
fieldA = fieldA . toLowerCase ( ) ;
fieldB = fieldB . toLowerCase ( ) ;
}
return ( fieldA > fieldB ) ? - 1 : ( fieldA < fieldB ) ? 1 : 0 ;
2006-05-30 16:37:51 +00:00
}
}
2006-06-16 16:30:03 +00:00
function doSort ( a , b )
{
var s = columnSort ( a , b ) ;
if ( s )
return s ;
else
return secondarySort ( a , b ) ;
}
2006-06-15 22:35:48 +00:00
function oppositeSort ( a , b )
2006-06-12 12:43:20 +00:00
{
2006-06-16 16:30:03 +00:00
return ( doSort ( a , b ) * - 1 ) ;
}
function secondarySort ( a , b )
{
return ( a . getField ( 'dateModified' ) > b . getField ( 'dateModified' ) ) ? - 1 : ( a . getField ( 'dateModified' ) < b . getField ( 'dateModified' ) ) ? 1 : 0 ;
2006-06-12 12:43:20 +00:00
}
2006-06-26 17:51:18 +00:00
var openRows = new Array ( ) ;
for ( var i = 0 ; i < this . _dataItems . length ; i ++ )
{
if ( this . isContainer ( i ) && this . isContainerOpen ( i ) )
{
openRows . push ( this . _getItemAtRow ( i ) . ref . getID ( ) ) ;
this . toggleOpenState ( i ) ;
}
}
2006-06-12 12:43:20 +00:00
if ( order )
2006-06-15 22:35:48 +00:00
this . _dataItems . sort ( oppositeSort ) ;
2006-06-12 12:43:20 +00:00
else
2006-06-16 16:30:03 +00:00
this . _dataItems . sort ( doSort ) ;
2006-06-12 12:43:20 +00:00
2006-05-30 16:37:51 +00:00
this . _refreshHashMap ( ) ;
2006-06-05 15:49:11 +00:00
2006-06-26 17:51:18 +00:00
for ( var i = 0 ; i < openRows . length ; i ++ )
this . toggleOpenState ( this . _itemRowMap [ openRows [ i ] ] ) ;
2006-05-30 16:37:51 +00:00
}
2006-06-15 22:35:48 +00:00
////////////////////////////////////////////////////////////////////////////////
///
/// Additional functions for managing data in the tree
///
////////////////////////////////////////////////////////////////////////////////
/ *
* Delete the selection
* /
2006-05-30 16:37:51 +00:00
Scholar . ItemTreeView . prototype . deleteSelection = function ( )
{
if ( this . selection . count == 0 )
return ;
2006-06-26 17:51:18 +00:00
//collapse open items
for ( var i = 0 ; i < this . rowCount ; i ++ )
if ( this . selection . isSelected ( i ) && this . isContainer ( i ) && this . isContainerOpen ( i ) )
this . toggleOpenState ( i ) ;
this . _refreshHashMap ( ) ;
2006-05-30 16:37:51 +00:00
//create an array of selected items
2006-06-02 15:27:52 +00:00
var items = new Array ( ) ;
2006-05-30 16:37:51 +00:00
var start = new Object ( ) ;
var end = new Object ( ) ;
for ( var i = 0 , len = this . selection . getRangeCount ( ) ; i < len ; i ++ )
{
this . selection . getRangeAt ( i , start , end ) ;
for ( var j = start . value ; j <= end . value ; j ++ )
2006-06-02 15:27:52 +00:00
items . push ( this . _getItemAtRow ( j ) ) ;
2006-05-30 16:37:51 +00:00
}
//iterate and erase...
this . _treebox . beginUpdateBatch ( ) ;
2006-06-02 15:27:52 +00:00
for ( var i = 0 ; i < items . length ; i ++ )
2006-05-30 16:37:51 +00:00
{
2006-07-27 18:08:09 +00:00
if ( this . _itemGroup . isLibrary ( ) || ! items [ i ] . isRegularItem ( ) ) //erase item from DB
2006-06-27 20:37:02 +00:00
items [ i ] . ref . erase ( ) ;
else if ( this . _itemGroup . isCollection ( ) )
this . _itemGroup . ref . removeItem ( items [ i ] . ref . getID ( ) ) ;
2006-05-30 16:37:51 +00:00
}
this . _treebox . endUpdateBatch ( ) ;
}
2006-06-15 22:35:48 +00:00
/ *
* Set the search filter on the view
* /
2006-06-01 16:40:43 +00:00
Scholar . ItemTreeView . prototype . searchText = function ( search )
{
2006-06-06 22:43:58 +00:00
this . selection . selectEventsSuppressed = true ;
this . saveSelection ( ) ;
2006-06-06 20:33:49 +00:00
this . _itemGroup . setSearch ( search ) ;
var oldCount = this . rowCount ;
this . refresh ( ) ;
this . _treebox . rowCountChanged ( 0 , this . rowCount - oldCount ) ;
2006-06-06 22:43:58 +00:00
this . sort ( ) ;
this . rememberSelection ( ) ;
this . selection . selectEventsSuppressed = false ;
2006-06-06 20:33:49 +00:00
this . _treebox . invalidate ( ) ;
2006-06-01 16:40:43 +00:00
}
2006-06-15 22:35:48 +00:00
/ *
* Called by various view functions to show a row
*
* item : reference to the Item
* beforeRow : row index to insert new row before
* /
2006-06-09 14:42:53 +00:00
Scholar . ItemTreeView . prototype . _showItem = function ( item , beforeRow )
{
2006-06-26 17:51:18 +00:00
this . _dataItems . splice ( beforeRow , 0 , item ) ;
this . rowCount ++ ;
2006-06-01 17:54:41 +00:00
}
2006-06-15 22:35:48 +00:00
/ *
* Called by view to hide specified row
* /
2006-06-09 14:42:53 +00:00
Scholar . ItemTreeView . prototype . _hideItem = function ( row )
2006-06-01 17:54:41 +00:00
{
2006-06-26 17:51:18 +00:00
this . _dataItems . splice ( row , 1 ) ;
this . rowCount -- ;
2006-06-01 17:54:41 +00:00
}
2006-06-15 22:35:48 +00:00
/ *
* Returns a reference to the item at row ( see Scholar . Item in data _access . js )
* /
2006-06-09 14:42:53 +00:00
Scholar . ItemTreeView . prototype . _getItemAtRow = function ( row )
2006-06-01 17:54:41 +00:00
{
2006-06-09 14:42:53 +00:00
return this . _dataItems [ row ] ;
}
2006-06-07 16:19:56 +00:00
2006-06-09 15:52:40 +00:00
/ *
2006-06-15 22:35:48 +00:00
* Create hash map of item ids to row indexes
2006-06-09 15:52:40 +00:00
* /
2006-06-09 14:42:53 +00:00
Scholar . ItemTreeView . prototype . _refreshHashMap = function ( )
2006-06-09 15:52:40 +00:00
{
2006-06-09 14:42:53 +00:00
this . _itemRowMap = new Array ( ) ;
for ( var i = 0 ; i < this . rowCount ; i ++ )
2006-06-26 17:51:18 +00:00
{
var row = this . _getItemAtRow ( i ) ;
2006-06-27 20:37:02 +00:00
this . _itemRowMap [ row . ref . getID ( ) ] = i ;
2006-06-26 17:51:18 +00:00
}
2006-06-02 12:59:58 +00:00
}
2006-06-15 22:35:48 +00:00
/ *
* Saves the ids of currently selected items for later
* /
2006-06-06 22:43:58 +00:00
Scholar . ItemTreeView . prototype . saveSelection = function ( )
{
2006-06-27 20:37:02 +00:00
this . _savedSelection = new Array ( ) ;
2006-06-06 22:43:58 +00:00
var start = new Object ( ) ;
var end = new Object ( ) ;
for ( var i = 0 , len = this . selection . getRangeCount ( ) ; i < len ; i ++ )
{
this . selection . getRangeAt ( i , start , end ) ;
for ( var j = start . value ; j <= end . value ; j ++ )
2006-06-26 17:51:18 +00:00
{
2006-06-27 20:37:02 +00:00
this . _savedSelection . push ( this . _getItemAtRow ( j ) . ref . getID ( ) ) ;
2006-06-26 17:51:18 +00:00
}
2006-06-06 22:43:58 +00:00
}
}
2006-06-15 22:35:48 +00:00
/ *
* Sets the selection based on saved selection ids ( see above )
* /
2006-06-06 22:43:58 +00:00
Scholar . ItemTreeView . prototype . rememberSelection = function ( )
{
this . selection . clearSelection ( ) ;
2006-06-27 20:37:02 +00:00
for ( var i = 0 ; i < this . _savedSelection . length ; i ++ )
2006-06-26 17:51:18 +00:00
{
2006-06-27 20:37:02 +00:00
if ( this . _itemRowMap [ this . _savedSelection [ i ] ] != null )
this . selection . toggleSelect ( this . _itemRowMap [ this . _savedSelection [ i ] ] ) ;
2006-06-06 22:43:58 +00:00
}
}
2006-06-15 22:35:48 +00:00
////////////////////////////////////////////////////////////////////////////////
2006-07-28 13:28:50 +00:00
///
/// Command Controller:
/// for Select All, etc.
///
////////////////////////////////////////////////////////////////////////////////
Scholar . ItemTreeCommandController = function ( tree )
{
this . tree = tree ;
}
Scholar . ItemTreeCommandController . prototype . supportsCommand = function ( cmd )
{
return ( cmd == 'cmd_selectAll' || cmd == 'cmd_delete' ) ;
}
Scholar . ItemTreeCommandController . prototype . isCommandEnabled = function ( cmd )
{
return ( cmd == 'cmd_selectAll' || ( cmd == 'cmd_delete' && this . tree . view . selection . count > 0 ) ) ;
}
Scholar . ItemTreeCommandController . prototype . doCommand = function ( cmd )
{
if ( cmd == 'cmd_selectAll' )
this . tree . view . selection . selectAll ( ) ;
else if ( cmd == 'cmd_delete' )
ScholarPane . deleteSelectedItem ( ) ;
}
Scholar . ItemTreeCommandController . prototype . onEvent = function ( evt )
{
}
////////////////////////////////////////////////////////////////////////////////
2006-06-15 22:35:48 +00:00
///
/// Drag-and-drop functions:
/// for nsDragAndDrop.js + nsTransferable.js
///
////////////////////////////////////////////////////////////////////////////////
2006-06-09 14:42:53 +00:00
2006-06-15 22:35:48 +00:00
/ *
* Begin a drag
* /
2006-06-08 18:42:55 +00:00
Scholar . ItemTreeView . prototype . onDragStart = function ( evt , transferData , action )
{
transferData . data = new TransferData ( ) ;
this . saveSelection ( ) ;
2006-06-27 20:37:02 +00:00
transferData . data . addDataForFlavour ( "scholar/item" , this . _savedSelection ) ;
2006-06-08 18:42:55 +00:00
}
2006-06-15 22:35:48 +00:00
/ *
* Called by nsDragAndDrop . js for any sort of drop on the tree
* /
2006-06-08 18:42:55 +00:00
Scholar . ItemTreeView . prototype . getSupportedFlavours = function ( )
{
var flavors = new FlavourSet ( ) ;
flavors . appendFlavour ( "scholar/item" ) ;
2006-06-14 15:51:05 +00:00
flavors . appendFlavour ( "text/x-moz-url" ) ;
2006-06-08 18:42:55 +00:00
return flavors ;
}
2006-06-15 22:35:48 +00:00
/ *
* Called by nsDragAndDrop . js for any sort of drop on the tree
* /
2006-06-14 15:51:05 +00:00
Scholar . ItemTreeView . prototype . onDrop = function ( evt , data , session )
{
var dataType = data . flavour . contentType ;
if ( dataType == 'scholar/item' )
{
2006-06-15 22:35:48 +00:00
var ids = data . data . split ( ',' ) ;
2006-06-14 15:51:05 +00:00
for ( var i = 0 ; i < ids . length ; i ++ )
this . _itemGroup . ref . addItem ( ids [ i ] ) ;
}
else if ( dataType == 'text/x-moz-url' )
{
2006-06-15 22:35:48 +00:00
var url = data . data . split ( "\n" ) [ 0 ] ;
/ * W A I T I N G F O R I N G E S T E R S U P P O R T
var newItem = Scholar . Ingester . scrapeURL ( url ) ;
if ( newItem )
this . _itemGroup . ref . addItem ( newItem . getID ( ) ) ;
* /
2006-06-14 15:51:05 +00:00
}
}
2006-06-08 18:42:55 +00:00
Scholar . ItemTreeView . prototype . onDragOver = function ( evt , dropdata , session ) { }
2006-06-09 14:42:53 +00:00
2006-06-15 22:35:48 +00:00
////////////////////////////////////////////////////////////////////////////////
///
/// Functions for nsITreeView that we have to stub out.
///
////////////////////////////////////////////////////////////////////////////////
2006-06-09 14:42:53 +00:00
Scholar . ItemTreeView . prototype . isSeparator = function ( row ) { return false ; }
Scholar . ItemTreeView . prototype . getRowProperties = function ( row , prop ) { }
Scholar . ItemTreeView . prototype . getColumnProperties = function ( col , prop ) { }
2006-06-26 17:51:18 +00:00
Scholar . ItemTreeView . prototype . getCellProperties = function ( row , col , prop ) { }
2006-06-27 22:47:17 +00:00
Scholar . ItemTreeView . TreeRow = function ( ref , level , isOpen )
2006-06-26 17:51:18 +00:00
{
2006-07-27 18:08:09 +00:00
this . ref = ref ; //the item associated with this
2006-06-26 17:51:18 +00:00
this . level = level ;
this . isOpen = isOpen ;
}
Scholar . ItemTreeView . TreeRow . prototype . isNote = function ( )
{
2006-06-27 20:37:02 +00:00
return this . ref . isNote ( ) ;
2006-06-26 17:51:18 +00:00
}
2006-07-27 18:08:09 +00:00
Scholar . ItemTreeView . TreeRow . prototype . isFile = function ( )
{
return this . ref . isFile ( ) ;
}
Scholar . ItemTreeView . TreeRow . prototype . isRegularItem = function ( )
{
return this . ref . isRegularItem ( ) ;
}
2006-06-26 17:51:18 +00:00
Scholar . ItemTreeView . TreeRow . prototype . getField = function ( field )
{
2006-06-27 20:37:02 +00:00
if ( this . isNote ( ) && field == 'title' )
2006-06-26 17:51:18 +00:00
{
2006-06-27 20:37:02 +00:00
var t = this . ref . getNote ( ) ;
2006-06-27 22:47:17 +00:00
if ( t )
{
var n = t . indexOf ( "\n" ) ;
if ( n > - 1 )
t = t . substring ( 0 , n ) ;
return t ;
}
2006-06-26 17:51:18 +00:00
}
else
{
return this . ref . getField ( field ) ;
}
}
Scholar . ItemTreeView . TreeRow . prototype . getType = function ( )
{
2006-06-27 20:37:02 +00:00
return this . ref . getType ( ) ;
2006-06-26 17:51:18 +00:00
}
Scholar . ItemTreeView . TreeRow . prototype . numNotes = function ( )
{
2006-07-27 18:08:09 +00:00
if ( this . isRegularItem ( ) )
return this . ref . numNotes ( ) ;
else
2006-06-26 17:51:18 +00:00
return 0 ;
2006-07-27 18:08:09 +00:00
}
Scholar . ItemTreeView . TreeRow . prototype . numFiles = function ( )
{
if ( this . isRegularItem ( ) )
return this . ref . numFiles ( ) ;
2006-06-26 17:51:18 +00:00
else
2006-07-27 18:08:09 +00:00
return 0 ;
2006-06-26 17:51:18 +00:00
}