www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 379674191130640138f412c19b42f94cc21d8bdc
parent 560864ad6bda7e1e3dff56ca8dc6511f2770aa2e
Author: David Norton <david@nortoncrew.com>
Date:   Mon,  5 Jun 2006 18:01:53 +0000

Changed all references of 'folder' to 'collection' in code to correspond to database / dataacess nomenclature.

Diffstat:
Achrome/chromeFiles/content/scholar/collectionTreeView.js | 296+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dchrome/chromeFiles/content/scholar/folderTreeView.js | 296-------------------------------------------------------------------------------
Mchrome/chromeFiles/content/scholar/itemTreeView.js | 6+-----
Mchrome/chromeFiles/content/scholar/overlay.js | 28++++++++++++++--------------
Mchrome/chromeFiles/content/scholar/overlay.xul | 6+++---
Mchrome/chromeFiles/skin/default/scholar/overlay.css | 2+-
6 files changed, 315 insertions(+), 319 deletions(-)

diff --git a/chrome/chromeFiles/content/scholar/collectionTreeView.js b/chrome/chromeFiles/content/scholar/collectionTreeView.js @@ -0,0 +1,295 @@ +Scholar.CollectionTreeView = function() +{ + this._treebox = null; + this._dataItems = new Array(); + this.rowCount = 0; + this._showItem(new Scholar.ItemGroup('library',null),0,1); + this._unregisterID = Scholar.Notifier.registerColumnTree(this); +} + +/* + * Unregisters itself from Scholar.Notifier (called on window close) + */ +Scholar.CollectionTreeView.prototype.unregister = function() +{ + Scholar.Notifier.unregisterColumnTree(this._unregisterID); +} + +/* + * Is called by Scholar.Notifier on any changes to the data layer + */ +Scholar.CollectionTreeView.prototype.notify = function(action, type, ids) +{ + ids = Scholar.flattenArguments(ids); + var madeChanges = false; + + if(action == 'remove') + { + //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(this._collectionRowMap[ids[i]] != null) + rows.push(this._collectionRowMap[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]; + this._hideItem(row-i); + this._treebox.rowCountChanged(row-i,-1); + } + + madeChanges = true; + } + + } + else + { + for (var i=0, len=ids.length; i<len; i++) + { + + var row = this._collectionRowMap[ids[i]]; + if(action == 'modify' && row != null) //must check for null because it could legitimately be 0 + { + this._treebox.invalidateRow(row) + } + else if(action == 'add' && row == null) + { + var item = Scholar.Collections.get(ids[i]); + + this._showItem(new Scholar.ItemGroup('collection',item), 0, this.rowCount); + this._treebox.rowCountChanged(this.rowCount-1,1); + + madeChanges = true; + } + + } + } + + if(madeChanges) + this._refreshHashMap(); +} + +Scholar.CollectionTreeView.prototype.setTree = function(treebox) +{ + if(this._treebox) + return; + this._treebox = treebox; + + var newRows = Scholar.getCollections(); + for(var i = 0; i < newRows.length; i++) + this._showItem(new Scholar.ItemGroup('collection',newRows[i]), 0, this._dataItems.length); //item ref, level, beforeRow + + this._refreshHashMap(); +} + +Scholar.CollectionTreeView.prototype.getCellText = function(row, column) +{ + var obj = this._getItemAtRow(row); + + if(column.id == "name_column") + return obj.getName(); + else + return ""; +} + +Scholar.CollectionTreeView.prototype.isContainer = function(row) +{ + return this._getItemAtRow(row).isCollection(); +} + +Scholar.CollectionTreeView.prototype.isContainerOpen = function(row) +{ + return this._dataItems[row][1]; +} + +Scholar.CollectionTreeView.prototype.isContainerEmpty = function(row) +{ + var itemGroup = this._getItemAtRow(row); + if(itemGroup.isCollection()) + return !itemGroup.ref.hasChildCollections(); + else + return true; +} + +Scholar.CollectionTreeView.prototype.getLevel = function(row) { return this._dataItems[row][2]; } + +Scholar.CollectionTreeView.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.CollectionTreeView.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.CollectionTreeView.prototype.toggleOpenState = function(row) +{ + var count = 0; //used to tell the tree how many rows were added/removed + var thisLevel = this.getLevel(row); + + this._treebox.beginUpdateBatch(); + 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 newRows = Scholar.getCollections(this._getItemAtRow(row).ref.getID()); //Get children + + for(var i = 0; i < newRows.length; i++) + { + count++; + this._showItem(new Scholar.ItemGroup('collection',newRows[i]), thisLevel+1, row+i+1); //insert new row + } + } + this._dataItems[row][1] = !this._dataItems[row][1]; //toggle container open value + + this._treebox.rowCountChanged(row+1, count); //tell treebox to repaint these + this._treebox.invalidateRow(row); + this._treebox.endUpdateBatch(); + this._refreshHashMap(); +} + +Scholar.CollectionTreeView.prototype._showItem = function(item, level, beforeRow) { this._dataItems.splice(beforeRow, 0, [item, false, level]); this.rowCount++; } + +Scholar.CollectionTreeView.prototype._hideItem = function(row) { this._dataItems.splice(row,1); this.rowCount--; } + +Scholar.CollectionTreeView.prototype._getItemAtRow = function(row) { return this._dataItems[row][0]; } +Scholar.CollectionTreeView.prototype.isSorted = function() { return false; } +Scholar.CollectionTreeView.prototype.isSeparator = function(row) { return false; } +Scholar.CollectionTreeView.prototype.isEditable = function(row, idx) { return false; } +Scholar.CollectionTreeView.prototype.getRowProperties = function(row, prop) { } +Scholar.CollectionTreeView.prototype.getColumnProperties = function(col, prop) { } +Scholar.CollectionTreeView.prototype.getCellProperties = function(row, col, prop) { } +Scholar.CollectionTreeView.prototype.getImageSrc = function(row, col) { } +Scholar.CollectionTreeView.prototype.performAction = function(action) { } +Scholar.CollectionTreeView.prototype.performActionOnCell = function(action, row, col) { } +Scholar.CollectionTreeView.prototype.getProgressMode = function(row, col) { } +Scholar.CollectionTreeView.prototype.cycleHeader = function(column) { } + +Scholar.CollectionTreeView.prototype.deleteSelection = function() +{ + if(this.selection.count == 0) + return; + + //collapse open collections + for(var i=0; i<this.rowCount; i++) + if(this.selection.isSelected(i) && this.isContainer(i) && this.isContainerOpen(i)) + this.toggleOpenState(i); + this._refreshHashMap(); + + //create an array of collections + var rows = new Array(); + 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++) + if(!this._getItemAtRow(j).isLibrary()) + rows.push(j); + } + + //iterate and erase... + this._treebox.beginUpdateBatch(); + for (var i=0; i<rows.length; i++) + { + //erase collection from DB: + this._getItemAtRow(rows[i]-i).ref.erase(); + } + this._treebox.endUpdateBatch(); + + if(end.value < this.rowCount) + this.selection.select(end.value); + else + this.selection.select(this.rowCount-1); +} + +Scholar.CollectionTreeView.prototype._refreshHashMap = function() +{ + // Create hash map of collection and object ids to row indexes + + this._collectionRowMap = new Array(); + for(var i=0; i < this.rowCount; i++){ + if (this.isContainer(i)){ + this._collectionRowMap[this._getItemAtRow(i).ref.getID()] = i; + } + } + //Scholar.debug(Scholar.varDump(this.collectionRowMap)); + //Scholar.debug(Scholar.varDump(this.objectRowMap)); +} + +Scholar.CollectionTreeView.prototype.canDrop = function(row, orient) +{ + if(orient == this.DROP_ON && this._getItemAtRow(row).isCollection()) + return true; + else + return false; + +} + +Scholar.CollectionTreeView.prototype.drop = function(row, orient) +{ + //you can't really do anything here, look to overlay.js - ScholarCollectionsDragObserver +} + +// +// SCHOLAR ITEMGROUP +// +Scholar.ItemGroup = function(type, ref) +{ + this.type = type; + this.ref = ref; +} + +Scholar.ItemGroup.prototype.isLibrary = function() +{ + return this.type == 'library'; +} + +Scholar.ItemGroup.prototype.isCollection = function() +{ + return this.type == 'collection'; +} + +Scholar.ItemGroup.prototype.getName = function() +{ + if(this.isCollection()) + return this.ref.getName(); + else if(this.isLibrary()) + return Scholar.getString('pane.collections.library'); + else + return ""; +} + +Scholar.ItemGroup.prototype.getChildItems = function() +{ + if(this.isCollection()) + return Scholar.getItems(this.ref.getID()); + else if(this.isLibrary()) + return Scholar.getItems(); + else + return null; +} +\ No newline at end of file diff --git a/chrome/chromeFiles/content/scholar/folderTreeView.js b/chrome/chromeFiles/content/scholar/folderTreeView.js @@ -1,295 +0,0 @@ -Scholar.FolderTreeView = function() -{ - this._treebox = null; - this._dataItems = new Array(); - this.rowCount = 0; - this._showItem(new Scholar.ItemGroup('library',null),0,1); - this._unregisterID = Scholar.Notifier.registerColumnTree(this); -} - -/* - * Unregisters itself from Scholar.Notifier (called on window close) - */ -Scholar.FolderTreeView.prototype.unregister = function() -{ - Scholar.Notifier.unregisterColumnTree(this._unregisterID); -} - -/* - * Is called by Scholar.Notifier on any changes to the data layer - */ -Scholar.FolderTreeView.prototype.notify = function(action, type, ids) -{ - ids = Scholar.flattenArguments(ids); - var madeChanges = false; - - if(action == 'remove') - { - //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(this._collectionRowMap[ids[i]] != null) - rows.push(this._collectionRowMap[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]; - this._hideItem(row-i); - this._treebox.rowCountChanged(row-i,-1); - } - - madeChanges = true; - } - - } - else - { - for (var i=0, len=ids.length; i<len; i++) - { - - var row = this._collectionRowMap[ids[i]]; - if(action == 'modify' && row != null) //must check for null because it could legitimately be 0 - { - this._treebox.invalidateRow(row) - } - else if(action == 'add' && row == null) - { - var item = Scholar.Collections.get(ids[i]); - - this._showItem(new Scholar.ItemGroup('collection',item), 0, this.rowCount); - this._treebox.rowCountChanged(this.rowCount-1,1); - - madeChanges = true; - } - - } - } - - if(madeChanges) - this._refreshHashMap(); -} - -Scholar.FolderTreeView.prototype.setTree = function(treebox) -{ - if(this._treebox) - return; - this._treebox = treebox; - - var newRows = Scholar.getCollections(); - for(var i = 0; i < newRows.length; i++) - this._showItem(new Scholar.ItemGroup('collection',newRows[i]), 0, this._dataItems.length); //item ref, level, beforeRow - - this._refreshHashMap(); -} - -Scholar.FolderTreeView.prototype.getCellText = function(row, column) -{ - var obj = this._getItemAtRow(row); - - if(column.id == "name_column") - return obj.getName(); - else - return ""; -} - -Scholar.FolderTreeView.prototype.isContainer = function(row) -{ - return this._getItemAtRow(row).isCollection(); -} - -Scholar.FolderTreeView.prototype.isContainerOpen = function(row) -{ - return this._dataItems[row][1]; -} - -Scholar.FolderTreeView.prototype.isContainerEmpty = function(row) -{ - var itemGroup = this._getItemAtRow(row); - if(itemGroup.isCollection()) - return !itemGroup.ref.hasChildCollections(); - else - return true; -} - -Scholar.FolderTreeView.prototype.getLevel = function(row) { return this._dataItems[row][2]; } - -Scholar.FolderTreeView.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.FolderTreeView.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.FolderTreeView.prototype.toggleOpenState = function(row) -{ - var count = 0; //used to tell the tree how many rows were added/removed - var thisLevel = this.getLevel(row); - - this._treebox.beginUpdateBatch(); - 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 newRows = Scholar.getCollections(this._getItemAtRow(row).ref.getID()); //Get children - - for(var i = 0; i < newRows.length; i++) - { - count++; - this._showItem(new Scholar.ItemGroup('collection',newRows[i]), thisLevel+1, row+i+1); //insert new row - } - } - this._dataItems[row][1] = !this._dataItems[row][1]; //toggle container open value - - this._treebox.rowCountChanged(row+1, count); //tell treebox to repaint these - this._treebox.invalidateRow(row); - this._treebox.endUpdateBatch(); - this._refreshHashMap(); -} - -Scholar.FolderTreeView.prototype._showItem = function(item, level, beforeRow) { this._dataItems.splice(beforeRow, 0, [item, false, level]); this.rowCount++; } - -Scholar.FolderTreeView.prototype._hideItem = function(row) { this._dataItems.splice(row,1); this.rowCount--; } - -Scholar.FolderTreeView.prototype._getItemAtRow = function(row) { return this._dataItems[row][0]; } -Scholar.FolderTreeView.prototype.isSorted = function() { return false; } -Scholar.FolderTreeView.prototype.isSeparator = function(row) { return false; } -Scholar.FolderTreeView.prototype.isEditable = function(row, idx) { return false; } -Scholar.FolderTreeView.prototype.getRowProperties = function(row, prop) { } -Scholar.FolderTreeView.prototype.getColumnProperties = function(col, prop) { } -Scholar.FolderTreeView.prototype.getCellProperties = function(row, col, prop) { } -Scholar.FolderTreeView.prototype.getImageSrc = function(row, col) { } -Scholar.FolderTreeView.prototype.performAction = function(action) { } -Scholar.FolderTreeView.prototype.performActionOnCell = function(action, row, col) { } -Scholar.FolderTreeView.prototype.getProgressMode = function(row, col) { } -Scholar.FolderTreeView.prototype.cycleHeader = function(column) { } - -Scholar.FolderTreeView.prototype.deleteSelection = function() -{ - if(this.selection.count == 0) - return; - - //collapse open collections - for(var i=0; i<this.rowCount; i++) - if(this.selection.isSelected(i) && this.isContainer(i) && this.isContainerOpen(i)) - this.toggleOpenState(i); - this._refreshHashMap(); - - //create an array of collections - var rows = new Array(); - 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++) - if(!this._getItemAtRow(j).isLibrary()) - rows.push(j); - } - - //iterate and erase... - this._treebox.beginUpdateBatch(); - for (var i=0; i<rows.length; i++) - { - //erase collection from DB: - this._getItemAtRow(rows[i]-i).ref.erase(); - } - this._treebox.endUpdateBatch(); - - if(end.value < this.rowCount) - this.selection.select(end.value); - else - this.selection.select(this.rowCount-1); -} - -Scholar.FolderTreeView.prototype._refreshHashMap = function() -{ - // Create hash map of collection and object ids to row indexes - - this._collectionRowMap = new Array(); - for(var i=0; i < this.rowCount; i++){ - if (this.isContainer(i)){ - this._collectionRowMap[this._getItemAtRow(i).ref.getID()] = i; - } - } - //Scholar.debug(Scholar.varDump(this.collectionRowMap)); - //Scholar.debug(Scholar.varDump(this.objectRowMap)); -} - -Scholar.FolderTreeView.prototype.canDrop = function(row, orient) -{ - if(orient == this.DROP_ON && this._getItemAtRow(row).isCollection()) - return true; - else - return false; - -} - -Scholar.FolderTreeView.prototype.drop = function(row, orient) -{ - //you can't really do anything here, look to overlay.js - ScholarCollectionsDragObserver -} - -// -// SCHOLAR ITEMGROUP -// -Scholar.ItemGroup = function(type, ref) -{ - this.type = type; - this.ref = ref; -} - -Scholar.ItemGroup.prototype.isLibrary = function() -{ - return this.type == 'library'; -} - -Scholar.ItemGroup.prototype.isCollection = function() -{ - return this.type == 'collection'; -} - -Scholar.ItemGroup.prototype.getName = function() -{ - if(this.isCollection()) - return this.ref.getName(); - else if(this.isLibrary()) - return Scholar.getString('pane.collections.library'); - else - return ""; -} - -Scholar.ItemGroup.prototype.getChildItems = function() -{ - if(this.isCollection()) - return Scholar.getItems(this.ref.getID()); - else if(this.isLibrary()) - return Scholar.getItems(); - else - return null; -} -\ No newline at end of file diff --git a/chrome/chromeFiles/content/scholar/itemTreeView.js b/chrome/chromeFiles/content/scholar/itemTreeView.js @@ -178,15 +178,11 @@ Scholar.ItemTreeView.prototype.searchText = function(search) Scholar.ItemTreeView.prototype._refreshHashMap = function() { - // Create hash map of folder and object ids to row indexes + // Create hash map of item ids to row indexes this._itemRowMap = new Array(); for(var i=0; i < this.rowCount; i++) this._itemRowMap[this._getItemAtRow(i).getID()] = i; - - //Scholar.debug(Scholar.varDump(this.folderRowMap)); - //Scholar.debug(Scholar.varDump(this.objectRowMap)); - } Scholar.ItemTreeView.prototype.getCollectionID = function() diff --git a/chrome/chromeFiles/content/scholar/overlay.js b/chrome/chromeFiles/content/scholar/overlay.js @@ -3,7 +3,7 @@ */ var ScholarPane = new function() { - var foldersView; + var collectionsView; var itemsView; var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); @@ -13,7 +13,7 @@ var ScholarPane = new function() this.toggleDisplay = toggleDisplay; this.newItem = newItem; this.newCollection = newCollection; - this.folderSelected = folderSelected; + this.onCollectionSelected = onCollectionSelected; this.itemSelected = itemSelected; this.deleteItemSelection = deleteItemSelection; this.deleteCollectionSelection = deleteCollectionSelection; @@ -26,12 +26,12 @@ var ScholarPane = new function() */ function onLoad() { - //Initialize folders view - foldersView = new Scholar.FolderTreeView(); - document.getElementById('folders-tree').view = foldersView; + //Initialize collections view + collectionsView = new Scholar.CollectionTreeView(); + document.getElementById('collections-tree').view = collectionsView; //select Library - foldersView.selection.select(0); + collectionsView.selection.select(0); //Create the add menu with each item type var addMenu = document.getElementById('tb-add').firstChild; @@ -52,7 +52,7 @@ var ScholarPane = new function() */ function onUnload() { - foldersView.unregister(); + collectionsView.unregister(); if(itemsView) itemsView.unregister(); } @@ -84,14 +84,14 @@ var ScholarPane = new function() Scholar.Collections.add(Scholar.getString('pane.collections.untitled')); } - function folderSelected() + function onCollectionSelected() { if(itemsView) itemsView.unregister(); - if(foldersView.selection.count == 1 && foldersView.selection.currentIndex != -1) + if(collectionsView.selection.count == 1 && collectionsView.selection.currentIndex != -1) { - var collection = foldersView._getItemAtRow(foldersView.selection.currentIndex); + var collection = collectionsView._getItemAtRow(collectionsView.selection.currentIndex); itemsView = new Scholar.ItemTreeView(collection); document.getElementById('items-tree').view = itemsView; @@ -137,15 +137,15 @@ var ScholarPane = new function() function deleteCollectionSelection() { - if(foldersView.selection.count > 0 && confirm(Scholar.getString('pane.collections.delete'))) - foldersView.deleteSelection(); + if(collectionsView.selection.count > 0 && confirm(Scholar.getString('pane.collections.delete'))) + collectionsView.deleteSelection(); } function renameSelectedCollection() { - if(foldersView.selection.count > 0) + if(collectionsView.selection.count > 0) { - collection = foldersView._getItemAtRow(foldersView.selection.currentIndex); + collection = collectionsView._getItemAtRow(collectionsView.selection.currentIndex); var newName = prompt(Scholar.getString('pane.collections.rename'),collection.getName()); if(newName) diff --git a/chrome/chromeFiles/content/scholar/overlay.xul b/chrome/chromeFiles/content/scholar/overlay.xul @@ -11,7 +11,7 @@ <script src="overlay.js"/> <script src="itemTreeView.js"/> - <script src="folderTreeView.js"/> + <script src="collectionTreeView.js"/> <commandset id="mainCommandSet"> <command id="cmd_scholar_newItem" oncommand="ScholarPane.newItem(1);"/> @@ -46,8 +46,8 @@ <toolbarbutton label="&toolbar.newCollection.label;" command="cmd_scholar_newCollection"/> <toolbarbutton id="tb-rename" label="&toolbar.renameCollection.label;" oncommand="ScholarPane.renameSelectedCollection();" disabled="true"/> </toolbar> - <tree id="folders-tree" hidecolumnpicker="true" - onselect="ScholarPane.folderSelected();" seltype="single" + <tree id="collections-tree" hidecolumnpicker="true" + onselect="ScholarPane.onCollectionSelected();" seltype="single" ondragover="nsDragAndDrop.dragOver(event,ScholarCollectionsDragObserver)" ondragdrop="nsDragAndDrop.drop(event,ScholarCollectionsDragObserver)" onkeypress="if(event.keyCode == event.DOM_VK_BACK_SPACE || event.keyCode == event.DOM_VK_DELETE){ ScholarPane.deleteCollectionSelection(); return false; }" flex="1"> diff --git a/chrome/chromeFiles/skin/default/scholar/overlay.css b/chrome/chromeFiles/skin/default/scholar/overlay.css @@ -5,7 +5,7 @@ vbox #scholar-pane padding: 4px; } -tree #folders-tree +tree #collections-tree { min-width: 100px; max-width: 200px;