PK
授7ub/ b/ content/webDavTreeItem.jsUT oZG1GUx /* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is WebDavBrowser.
*
* The Initial Developer of the Original Code is
* Rafa Malinowski, Pozna Supercomputing And Networing Center
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
const nsIWebDavResource = Components.interfaces.nsIWebDavResource;
/**
* Item on the tree. Represend nsIWebDavResource
*/
WebDavTreeItem.prototype = {
_webDavTreeView: null,
_webDavResource: null,
_items: null,
_parent: null,
_level: -1,
_index: -1,
_opened: 0,
_removing: false,
_sortBy: "name",
_sortIncreasing: true,
// nsIWebDavResourceObserver
onStatusChanged: function(resource) {
if (resource.loaded == nsIWebDavResource.WEBDAV_LOADED_CREATING_FAILED) {
// remove it becouse it doesn't exists, and it wont
this._webDavTreeView.removeItems(this._index, this.subItemsCount + 1);
if (this._parent)
this._parent.subItemRemoved(this);
return;
}
this._webDavTreeView.itemUpdated(this.index);
},
onLoaded: function(resource) {
},
onRemoved: function(resource) {
// remove it becouse it doesn't exists now
this._webDavTreeView.removeItems(this._index, this.subItemsCount + 1);
this._items = new Array();
if (this._parent)
this._parent.subItemRemoved(this);
},
onSubResourceAdded: function(resource, subResource) {
if (!this._opened)
return;
var wevDavTreeItem = new WebDavTreeItem(this._webDavTreeView, this, subResource);
var i = 0;
for (; i < this._items.length; i++)
if (this._compareItems(this, this._items[i], wevDavTreeItem) == 1)
break;
this._items.splice(i, 0, wevDavTreeItem);
this._webDavTreeView.addItem(this.level + 1, this.index + i + 1, wevDavTreeItem);
},
onSubResourcesLoaded: function(resource) {
this._webDavTreeView.itemUpdated(this.index);
},
onCreated: function(resource) {
this._webDavTreeView.itemUpdated(this.index);
},
onDebugMessage: function(message) {
alert(message);
},
onError: function(resource, action, errorCode) {
var error;
var reason;
switch (action) {
case nsIWebDavResource.WEBDAV_ACTION_LOAD:
error = "Unable to load resource " + resource.path;
break;
case nsIWebDavResource.WEBDAV_ACTION_CREATE:
error = "Unable to create resource in " + resource.path;
break;
case nsIWebDavResource.WEBDAV_ACTION_DELETE:
error = "Unable to delete resource " + resource.path;
break;
case nsIWebDavResource.WEBDAV_ACTION_READ:
default:
return;
}
switch (errorCode) {
case nsIWebDavResource.WEBDAV_ERROR_NO_ERROR:
return;
case nsIWebDavResource.WEBDAV_ERROR_UNKNOW:
reason = "\nReason: unknow";
break;
case nsIWebDavResource.WEBDAV_ERROR_SERVER_UNAVAILABLE:
reason = "\nReason: server unavailable";
break;
case nsIWebDavResource.WEBDAV_ERROR_INVALID_RESPONSE:
reason = "\nReason: invalid response from server";
break;
case nsIWebDavResource.WEBDAV_ERROR_BAD_REQUEST:
reason = "\nReason: bad request to server";
break;
case nsIWebDavResource.WEBDAV_ERROR_INSUFFICENT_STORAGE:
reason = "\nReason: insufficent storage on server";
break;
case nsIWebDavResource.WEBDAV_ERROR_RESOURCE_ALREADY_EXISTS:
reason = "\nReason: resource already exists";
break;
case nsIWebDavResource.WEBDAV_ERROR_PARENT_COLLECTION_NOT_FOUND:
reason = "\nReason: one of parent collections is missing";
break;
case nsIWebDavResource.WEBDAV_ERROR_NOT_FOUND:
reason = "\nReason: resource not found";
break;
case nsIWebDavResource.WEBDAV_ERROR_FORBIDDEN:
reason = "\nReason: access forbidden";
break;
default:
reason = "\nReason: unknow";
break;
}
alert(error + reason);
},
// WebDavTreeItem
get level() { return this._level; },
get isCollection() { return this._webDavResource.isCollection; },
get isCollectionEmpty() { return this._webDavResource.subResourcesCount == 0; },
get webDavResource() { return this._webDavResource; },
get opened() { return this._opened; },
get parent() { return this._parent; },
get removing() { return this._removing; },
set removing(removing) {
if (removing && this._removing)
return;
this._removing = removing;
// if this resoruce is removing, any of the sub-resources doesn't need to be removed separately
for (var i in this._items)
this._items[i].removing = false;
},
get items() { return this._items; },
/**
* Returns path relative to parent (or full path, if parent is null)
*/
get displayName() {
if (this.parent)
return this._webDavResource.path.substr(this.parent.webDavResource.path.length);
else
return this._webDavResource.path;
},
/**
* Returns size in kB, MB, GB or TB
*/
get size() {
var size = this._webDavResource.size;
if (size == -1)
return "";
suffix = "B";
if (size > 1024) {
size /= 1024;
suffix = "kB";
}
if (size > 1024) {
size /= 1024;
suffix = "MB";
}
if (size > 1024) {
size /= 1024;
suffix = "GB";
}
if (size > 1024) {
size /= 1024;
suffix = "TB";
}
return size.toFixed(2) + " " + suffix;
},
/**
* Returns creation date of resource in iso 8601 format.
*/
get creationDate() { return this._webDavResource.creationDate; },
/**
* Returns modification date of resource in iso 8601 format.
*/
get modificationDate() { return this._webDavResource.modificationDate; },
/**
* Returns mime type of resource.
*/
get mimeType() { return this._webDavResource.mimeType; },
/**
* Returns status text of resource. Splited into 2 parts: loaded and deleting.
*/
get status() {
var loaded = "";
switch (this._webDavResource.loaded) {
case nsIWebDavResource.WEBDAV_LOADED_NOT_LOADED:
loaded = "Not loaded";
break;
case nsIWebDavResource.WEBDAV_LOADED_LOADING:
loaded = "Loading";
break;
case nsIWebDavResource.WEBDAV_LOADED_LOADED:
loaded = "";
break;
case nsIWebDavResource.WEBDAV_LOADED_NOT_AVAILABLE:
loaded = "Not available";
break;
case nsIWebDavResource.WEBDAV_LOADED_CREATING:
loaded = "Creating";
break;
default:
loaded = "";
}
var deleting = "";
switch (this._webDavResource.deleting) {
case nsIWebDavResource.WEBDAV_DELETING_NOT_DELETING:
deleting = "";
break;
case nsIWebDavResource.WEBDAV_DELETING_DELETING:
deleting = "Deleting";
break;
case nsIWebDavResource.WEBDAV_DELETING_DELETED:
deleting = "Deleted";
break;
default:
deleting = "";
}
if (loaded != "" && deleting != "")
return loaded + ", " + deleting;
else
if (loaded != "")
return loaded;
else
return deleting;
},
set index(index) { this._index = index; },
get index() { return this._index; },
get lastItem() {
if (this._items.length > 0)
return this._items[this._items.length - 1];
else
return null;
},
/**
* Returns count of sub items with count of sub items of sub items and so on.
*/
get subItemsCount() {
var result = 0;
for (var i in this._items) {
result++;
result += this._items[i].subItemsCount;
}
return result;
},
/**
* If it is added to tree view, and sub items too.
*/
addedToTreeView: function(treeView, level, index) {
this._level = level;
for (var i in this._items) {
index++;
treeView.addItem(level + 1, index, this._items[i]);
}
},
toggleOpenState: function() {
if (this._opened)
this.close();
else
this.open();
},
subItemRemoved: function(item) {
var index = this._items.indexOf(item);
if (index != -1)
this._items.splice(index, 1);
},
/**
* Opens a resource.
* If it is a non-collection, then redirect to this resoruce so it can be downloaded.
* If it is a collection then just get sub-resources and add TreeViewItems to tree.
*/
open: function() {
if (this._opened)
return;
if (!this._webDavResource.isCollection) {
document.location = "webdav://" + this._webDavResource.host + "/" + this._webDavResource.path;
return;
}
var subResources = this._webDavResource.getSubResources();
var enumerator = subResources.enumerate();
this._items = new Array();
while (enumerator.hasMoreElements()) {
var element = enumerator.getNext();
element.QueryInterface(nsIWebDavResource);
if (element)
this._items[this._items.length] = new WebDavTreeItem(this._webDavTreeView, this, element);
}
this._sortItems();
this._webDavTreeView.addItems(this._level + 1, this._index + 1, this._items);
this._opened = 1;
},
close: function() {
// close removes sub-TreeViewItems, but not subResources
this._webDavTreeView.removeItems(this._index + 1, this.subItemsCount);
this._opened = 0;
this._items = new Array();
},
setSorting: function(sortBy, sortIncreasing) {
if ((this._sortBy == sortBy) && (this._sortIncreasing == sortIncreasing))
return;
this._sortBy = sortBy;
this._sortIncreasing = sortIncreasing;
this._sortItems();
},
_sortItems: function() {
var item = this;
this._items.sort(function(a, b) {
return item._compareItems(item, a, b);
});
},
_compareItems: function(item, a, b) {
// collections go first
if (!a.isCollection && b.isCollection)
return 1;
if (a.isCollection && !b.isCollection)
return -1;
var mul = 1;
if (!item._sortIncreasing)
mul = -1;
switch (item._sortBy) {
case "name":
return mul * ((a.displayName > b.displayName) ? 1 : -1);
case "type":
if (a.mimeType == b.mimeType)
return (a.displayName > b.displayName) ? 1 : -1;
return mul * ((a.mimeType > b.mimeType) ? 1 : -1);
case "size":
if (a.webDavResource.size == b.webDavResource.size)
return (a.displayName > b.displayName) ? 1 : -1;
return mul * ((a.webDavResource.size > b.webDavResource.size) ? 1 : -1);
case "creation-date":
var acreationDate = Date.parse(a.creationDate);
var bcreationDate = Date.parse(b.creationDate);
if (acreationDate == acreationDate)
return (a.displayName > b.displayName) ? 1 : -1;
return mul * ((acreationDate > bcreationDate) ? 1 : -1);
case "modification-date":
var amodificationDate = Date.parse(a.modificationDate);
var bmodificationDate = Date.parse(b.modificationDate);
if (amodificationDate == bmodificationDate)
return (a.displayName > b.displayName) ? 1 : -1;
return mul * ((amodificationDate > bmodificationDate) ? 1 : -1);
}
}
};
function WebDavTreeItem(webDavTreeView, parent, webDavResource) {
this._webDavTreeView = webDavTreeView;
this._parent = parent;
this._webDavResource = webDavResource;
this._items = new Array();
webDavResource.observer = this;
}
PK
i7b_`r r content/webDavBrowser.xulUT 3G0GUx
PK
㎈7©? content/webDavBrowser.jsUT jZG0GUx /* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is WebDavBrowser.
*
* The Initial Developer of the Original Code is
* Rafa Malinowski, Pozna Supercomputing And Networing Center
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// for file sending
const nsILocalFile = Components.interfaces.nsILocalFile;
const nsIFilePicker = Components.interfaces.nsIFilePicker;
var webDavBrowser;
function WebDavBrowser() {
}
/**
* Class for displaying tree-view of WebDav resources.
*/
WebDavBrowser.prototype = {
_webDavTreeView: null,
_popupItem: null, // item clicked with RMB
init: function() {
this._webDavTreeView = new WebDavTreeView(document);
document.getElementById("webdav-browser-tree").view = this._webDavTreeView;
var rootResource = Components.classes["@mozilla.org/network/webdav-resource;1"]
.createInstance(Components.interfaces.nsIWebDavResource);
// get resource requested in URL bar
rootResource.observer = this;
rootResource.init(null, window.location.host, window.location.pathname, true);
},
// rootResource.observer
onDebugMessage: function(message) {
alert(message);
},
onStatusChanged: function(resource) {
},
onLoaded: function(resource) {
// we got resource requested in URL bar, make TreeItem and add it to Tree
var webDavTreeItem = new WebDavTreeItem(this._webDavTreeView, null, resource);
this._webDavTreeView.addRootItem(webDavTreeItem);
},
onRemoved: function(resource) {
},
onSubResourceAdded: function(resource, subResource) {
},
onSubResourcesLoaded: function(resource) {
},
onCreated: function(resource) {
},
onError: function(resource, action, errorCode) {
var error;
var reason;
switch (action) {
case nsIWebDavResource.WEBDAV_ACTION_LOAD:
error = "Unable to load resource " + resource.path;
break;
case nsIWebDavResource.WEBDAV_ACTION_CREATE:
error = "Unable to create resource in " + resource.path;
break;
case nsIWebDavResource.WEBDAV_ACTION_DELETE:
error = "Unable to delete resource " + resource.path;
break;
case nsIWebDavResource.WEBDAV_ACTION_READ:
default:
return;
}
switch (errorCode) {
case nsIWebDavResource.WEBDAV_ERROR_NO_ERROR:
return;
case nsIWebDavResource.WEBDAV_ERROR_UNKNOW:
reason = "\nReason: unknow";
break;
case nsIWebDavResource.WEBDAV_ERROR_SERVER_UNAVAILABLE:
reason = "\nReason: server unavailable";
break;
case nsIWebDavResource.WEBDAV_ERROR_INVALID_RESPONSE:
reason = "\nReason: invalid response from server";
break;
case nsIWebDavResource.WEBDAV_ERROR_BAD_REQUEST: // also hen MKCOL on non-collection resource<
reason = "\nReason: bad request to server";
break;
case nsIWebDavResource.WEBDAV_ERROR_INSUFFICENT_STORAGE:
reason = "\nReason: insufficent storage on server";
break;
case nsIWebDavResource.WEBDAV_ERROR_RESOURCE_ALREADY_EXISTS:
reason = "\nReason: resource already exists";
break;
case nsIWebDavResource.WEBDAV_ERROR_PARENT_COLLECTION_NOT_FOUND:
reason = "\nReason: one of parent collections is missing";
break;
case nsIWebDavResource.WEBDAV_ERROR_NOT_FOUND:
reason = "\nReason: resource not found";
break;
case nsIWebDavResource.WEBDAV_ERROR_FORBIDDEN:
reason = "\nReason: access forbidden";
break;
default:
reason = "\nReason: unknow";
break;
}
alert(error + reason);
},
// and handling
onDblClick: function(event) {
this._webDavTreeView.onTreeDblClick(event.clientX, event.clientY);
},
onPopupShowing: function(event) {
var popup = document.getElementById("tree-popup-menu");
var row = this._webDavTreeView.tree.getRowAt(event.clientX, event.clientY);
if (row == -1)
return false;
this._popupItem = this._webDavTreeView._items[row];
if (this._popupItem.isCollection) {
document.getElementById("tree-popup-menu-new-collection").setAttribute("disabled", false);
document.getElementById("tree-popup-menu-add-file").setAttribute("disabled", false);
} else {
document.getElementById("tree-popup-menu-new-collection").setAttribute("disabled", true);
document.getElementById("tree-popup-menu-add-file").setAttribute("disabled", true);
}
return true;
},
onOpenClicked: function(event) {
if (this._popupItem)
this._popupItem.open();
},
onCreateNewCollectionClicked: function(event) {
if (!this._popupItem) // ignore when clicked on free space
return;
var subCollection = prompt("New collection name:");
if (subCollection) {
if (!this._popupItem.webDavResource.isNameValid(subCollection)) {
alert("Invalid collection name");
return;
}
this._popupItem.open();
var subResource = this._popupItem.webDavResource.createSubResource(subCollection, true);
if (subResource != null)
subResource.createCollection(false);
else
alert("Unable to create collection " + subCollection);
}
},
onAddFileClicked: function(event) {
if (!this._popupItem) // ignore when clicked on free space
return;
try {
// open file window and get some files
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
fp.init(window, "", nsIFilePicker.modeOpenMultiple);
fp.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterText |
nsIFilePicker.filterAll | nsIFilePicker.filterImages | nsIFilePicker.filterXML);
if (fp.show() == nsIFilePicker.returnOK) {
var files = fp.files;
while (files.hasMoreElements()) {
var file = files.getNext().QueryInterface(nsILocalFile);
if (!this._popupItem.webDavResource.isNameValid(file.leafName)) {
alert("Server does not support file name: " + file.leafName);
continue;
}
var subResource = this._popupItem.webDavResource.createSubResource(file.leafName, false);
if (subResource != null)
subResource.createResourceFromFile(file, false);
else
alert("Unable to add file " + file.path);
}
}
}
catch(ex) {
alert(ex);
}
},
onDeleteClicked: function(event) {
var selection = webDavBrowser._webDavTreeView.selection;
var rangeCount = selection.getRangeCount();
var min = {};
var max = {};
// a trick to avoid removing subResources and then resources
// only minimal set of resources will be removed
for (var i = rangeCount - 1; i >= 0; i--) {
selection.getRangeAt(i, min, max);
for (var j = max.value; j >= min.value; j--)
webDavBrowser._webDavTreeView._items[j].removing = true;
}
for (var i = rangeCount - 1; i >= 0; i--) {
selection.getRangeAt(i, min, max);
for (var j = max.value; j >= min.value; j--) {
if (webDavBrowser._webDavTreeView._items[j].removing)
webDavBrowser._webDavTreeView._items[j].webDavResource.remove(false);
}
}
}
};
function WebDavBrowserStartup() {
webDavBrowser = new WebDavBrowser();
webDavBrowser.init();
}
PK
i7+Lt,. . content/webDavTreeView.jsUT 3G1GUx /* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is WebDavBrowser.
*
* The Initial Developer of the Original Code is
* Rafa Malinowski, Pozna Supercomputing And Networing Center
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
const nsITreeView = Components.interfaces.nsITreeView;
/**
* nsITreeView implementation for WebDavBrowsers.
* Uses webDavTreeItem for displaing nsIWebDavResources.
*/
WebDavTreeView.prototype = {
_xul: null, // xul element of treeview
_items: null,
_selection: null,
_tree: null,
_sortColumn: "name", // current sort column
_sortIncreasing: true,
get rowCount() { return this._items.length; },
get selection() { return this._selection; },
set selection(selection) { this._selection = selection; },
get tree() { return this._tree; },
/**
* Add one item at level and index
*/
addItem: function (level, index, item) {
item.setSorting(this._sortColumn, this._sortIncreasing);
this._items.splice(index, 0, item);
this._updateIndexes(index);
this.tree.rowCountChanged(index, 1);
item.addedToTreeView(this, level, index);
},
/**
* Add many items at level and first at index
*/
addItems: function(level, index, items) {
var insertionIndex = index;
for (var i = 0; i < items.length; i++) {
items[i].setSorting(this._sortColumn, this._sortIncreasing);
this._items.splice(insertionIndex, 0, items[i]);
items[i].addedToTreeView(this, level, insertionIndex);
insertionIndex++;
}
this._updateIndexes(index);
this._tree.rowCountChanged(index, items.length);
},
/**
* Remove item and all of its subitems.
*/
removeItem: function (item) {
var count = item.subItemsCount + 1;
this._items.splice(item.index, count);
this._updateIndexes(item.index - 1);
this._tree.rowCountChanged(item.index, -count);
},
/**
* Remove count items from index. Dont care about subitems.
* Them shoul be included in 'count' variable. If not - it is a bug.
*/
removeItems: function (index, count) {
this._items.splice(index, count);
this._updateIndexes(index);
this._tree.rowCountChanged(index, -count);
},
/**
* Adds item at top of the tree.
*/
addRootItem: function (item) {
this.addItem(0, 0, item);
},
itemUpdated: function(row) {
this._tree.invalidateRow(row);
},
/**
* Allows only drops on collection and before/after non-collections.
*/
canDrop: function (row, orientation) {
if (row == -1)
return false;
if ((row == 0) && (orientation == nsITreeView.DROP_BEFORE))
return false;
return (this._items[row].isCollection || (orientation != nsITreeView.DROP_ON));
},
cycleCell: function (row, col) {
},
/**
* Sort items by given columnt.
*/
cycleHeader: function (col) {
if (col.id == "tree-view-column-status")
return;
if ("tree-view-column-" + this._sortColumn == col.id) {
this._sortIncreasing = !this._sortIncreasing;
if (this._sortIncreasing)
this._getXulColumn(this._sortColumn).setAttribute("sortDirection", "ascending");
else
this._getXulColumn(this._sortColumn).setAttribute("sortDirection", "descending");
} else {
this._sortIncreasing = true;
this._getXulColumn(this._sortColumn).removeAttribute("sortActive");
this._getXulColumn(this._sortColumn).removeAttribute("sortDirection");
this._sortColumn = col.id.substr(17);
this._getXulColumn(this._sortColumn).setAttribute("sortActive", true);
this._getXulColumn(this._sortColumn).setAttribute("sortDirection", "ascending");
}
for (var i in this._items)
this._items[i].setSorting(this._sortColumn, this._sortIncreasing);
var rootItem = this._items[0];
this._tree.rowCountChanged(0, -this._items.length);
this._items = new Array();
this._fillTree(rootItem);
this._updateIndexes();
this._tree.rowCountChanged(0, this._items.length);
this._tree.invalidate();
},
/**
* Adds an item and its subitems (and its subiems and so on) to the end of tree.
*/
_fillTree: function(item) {
this._items[this._items.length] = item;
var items = item.items;
for (var i in items)
this._fillTree(items[i]);
},
/**
* Get drops of a file on tree view.
*/
drop: function (row, orientation) {
if (row == -1)
return false;
var dragService = Components.classes["@mozilla.org/widget/dragservice;1"]
.getService(Components.interfaces.nsIDragService);
var dragSession = dragService.getCurrentSession();
// on windows it is a file
var dataFlavor = "application/x-moz-file";
if (!dragSession.isDataFlavorSupported(dataFlavor)) {
// on linux it is a file-name
dataFlavor = "text/unicode";
if (!dragSession.isDataFlavorSupported(dataFlavor))
return;
}
// select collection to add this item to
// either current (dropped on) or parent collection
var addToCollection = null;
if (orientation == nsITreeView.DROP_ON) // drop on collection = select current
if (this._items[row].isCollection)
addToCollection = this._items[row];
else
return;
else
if (row == 0) // drop on root = select root
addToCollection = this._items[row];
else // drop after collection = select current
if ((orientation == nsITreeView.DROP_AFTER) && (this._items[row].isCollection))
addToCollection = this._items[row];
else // select parent
addToCollection = this._items[row].parent;
if (!addToCollection)
return;
var transferObject = Components.classes["@mozilla.org/widget/transferable;1"]
.createInstance();
transferObject = transferObject.QueryInterface(Components.interfaces.nsITransferable);
transferObject.addDataFlavor(dataFlavor);
var numItems = dragSession.numDropItems;
for (var i = 0; i < numItems; i++) {
dragSession.getData(transferObject, i);
var dataObj = new Object();
var dropSizeObj = new Object();
transferObject.getTransferData(dataFlavor, dataObj, dropSizeObj);
var droppedFile = null;
if (dataFlavor == "text/unicode") { // on unix create file from file name
var filePath = "";
if ("nsISupportsWString" in Components.interfaces)
filePath = new String(dataObj.value.QueryInterface(Components.interfaces.nsISupportsWString));
else if ("nsISupportsString" in Components.interfaces)
filePath = new String(dataObj.value.QueryInterface(Components.interfaces.nsISupportsString));
else
continue;
if (filePath.substr(0, 7) == "file://")
filePath = filePath.substr(7);
else
continue;
droppedFile = Components.classes["@mozilla.org/file/local;1"]
.createInstance();
droppedFile = droppedFile.QueryInterface(Components.interfaces.nsILocalFile);
droppedFile.initWithPath(filePath);
} else
droppedFile = dataObj.value.QueryInterface(Components.interfaces.nsILocalFile);
if (!droppedFile.isFile())
return;
if (!addToCollection.webDavResource.isNameValid(droppedFile.leafName)) {
alert("Server does not support file name: " + droppedFile.leafName);
continue;
}
var webDavResource = addToCollection.webDavResource.createSubResource(droppedFile.leafName, false);
if (webDavResource != null) // async create file
webDavResource.createResourceFromFile(droppedFile, false);
else // oops, file name invalid
alert("Unable to add file: " + filePath);
}
// display the item by opening collection it was added to
addToCollection.open();
},
getCellProperties: function (row, col, properties) {
},
getCellText: function (row, col) {
if (col == this._getColumn("name")) {
return this._items[row].displayName;
} else if (col == this._getColumn("size")) {
return this._items[row].size;
} else if (col == this._getColumn("type")) {
return this._items[row].mimeType;
} else if (col == this._getColumn("creation-date")) {
return this._items[row].creationDate;
} else if (col == this._getColumn("modification-date")) {
return this._items[row].modificationDate;
} else if (col == this._getColumn("status")) {
return this._items[row].status;
} else
return "";
},
getCellValue: function (row, col) {
return "";
},
getColumnProperties: function (col, properties) {
},
getImageSrc: function (row, col) {
if (col != this._getColumn("name"))
return;
// TODO: images stolen from gopher directory, needs new one
if (this._items[row].isCollection)
return "chrome://webdavbrowser/content/img/collection.png";
else
return "chrome://webdavbrowser/content/img/file.png";
},
getLevel: function (row) {
return this._items[row].level;
},
getParentIndex: function (row) {
var parent = this._items[row].parent;
if (parent)
return parent.index;
else
return -1;
},
getProgressMode: function (row, col) {
},
getRowProperties: function (index, properties) {
},
hasNextSibling: function (row, afterIndex) {
var parent = this._items[row].parent;
if (parent)
return afterIndex < parent.lastItem.index;
else
return false;
},
isContainer: function (row) {
return this._items[row].isCollection;
},
isContainerEmpty: function (row) {
return this._items[row].isCollectionEmpty;
},
isContainerOpen: function (row) {
return this._items[row].opened;
},
isEditable: function (row, col) {
return false;
},
isSeparator: function (index) {
return false;
},
isSorted: function () {
return true;
},
performAction: function () {
},
performActionOnCell: function () {
},
performActionOnRow: function (action, row) {
},
selectonChanged: function () {
},
setCellText: function () {
},
setCellValue: function () {
},
setTree: function (tree) {
this._tree = tree;
},
toggleOpenState: function (row) {
this._items[row].toggleOpenState();
},
/**
* Gives every TreeItem and index so it can be easily identified.
*/
_updateIndexes: function (start) {
for (var i = start; i < this._items.length; i++)
this._items[i].index = i;
this._tree.invalidate();
},
onTreeDblClick: function(x, y) {
var row = this._tree.getRowAt(x, y);
if (row != -1)
if (!this._items[row].isCollection)
this._items[row].open();
},
_getColumn: function(name) {
return this._xul.columns.getNamedColumn("tree-view-column-" + name);
},
_getXulColumn: function(name) {
return document.getElementById("tree-view-column-" + name);
}
};
function WebDavTreeView(document) {
this._xul = document.getElementById("webdav-browser-tree");
this._items = new Array();
return this;
}
PK
OV7X content/img/collection.pngUT G}GUx PNG
IHDR ;x87 PLTE Bv tRNS @f bKGD H pHYs tIME
%- DIDATc`
G0CQDQAQPPV`Pv618 5`))9
_7׃ IENDB`PK
IV7lR/ content/img/file.pngUT
GGUx PNG
IHDR ;x87 PLTE B tRNS @f bKGD H pHYs tIME
'0L 3IDATc`6666b fG8Cp42\ %(C&rq a ݀* . IENDB`PK
-S7 locale/en-US/webdavbrowser.dtdUT UG1GUx PK
2S7ëB_ _ % locale/en-US/webdavbrowser.propertiesUT `G1GUx prefMessage=Int Pref Value: %d
extensions.webdavbrowser.description=WebDav Browser for Firefox
PK
5S7 skin/overlay.cssUT eG1GUx PK
授7ub/ b/
content/webDavTreeItem.jsUT oZGUx PK
i7b_`r r
/ content/webDavBrowser.xulUT 3GUx PK
㎈7©?
lA content/webDavBrowser.jsUT jZGUx PK
i7+Lt,. .
b content/webDavTreeView.jsUT 3GUx PK
OV7X
m content/img/collection.pngUT GUx PK
IV7lR/
content/img/file.pngUT
GUx PK
-S7
locale/en-US/webdavbrowser.dtdUT UGUx PK
2S7ëB_ _ %
locale/en-US/webdavbrowser.propertiesUT `GUx PK
5S7
skin/overlay.cssUT eGUx PK