2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-08-23 07:48:53 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
|
|
|
*
|
|
|
|
* 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.
|
1999-08-23 07:48:53 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
2001-03-14 05:41:18 +03:00
|
|
|
* Bradley Baetz <bbaetz@student.usyd.edu.au>
|
2002-03-29 05:46:01 +03:00
|
|
|
* Joe Hewitt <hewitt@netscape.com>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-08-23 07:48:53 +04:00
|
|
|
|
1999-08-25 07:50:15 +04:00
|
|
|
/*
|
|
|
|
Script for the directory window
|
|
|
|
*/
|
|
|
|
|
2000-09-14 03:57:52 +04:00
|
|
|
const RDFSERVICE_CONTRACTID = "@mozilla.org/rdf/rdf-service;1";
|
|
|
|
const DRAGSERVICE_CONTRACTID = "@mozilla.org/widget/dragservice;1";
|
|
|
|
const TRANSFERABLE_CONTRACTID = "@mozilla.org/widget/transferable;1";
|
2001-02-22 06:01:34 +03:00
|
|
|
const XULSORTSERVICE_CONTRACTID = "@mozilla.org/xul/xul-sort-service;1";
|
2000-09-14 03:57:52 +04:00
|
|
|
const ARRAY_CONTRACTID = "@mozilla.org/supports-array;1";
|
2002-08-06 04:53:19 +04:00
|
|
|
const WSTRING_CONTRACTID = "@mozilla.org/supports-string;1";
|
2000-08-28 08:24:49 +04:00
|
|
|
|
|
|
|
const NC_NS = "http://home.netscape.com/NC-rdf#";
|
|
|
|
const NC_NAME = NC_NS + "Name";
|
2001-11-04 06:05:15 +03:00
|
|
|
const NC_URL = NC_NS + "URL";
|
2000-08-28 08:24:49 +04:00
|
|
|
const NC_LOADING = NC_NS + "loading";
|
|
|
|
|
|
|
|
const nsIHTTPIndex = Components.interfaces.nsIHTTPIndex;
|
|
|
|
const nsIDragService = Components.interfaces.nsIDragService;
|
|
|
|
const nsITransferable = Components.interfaces.nsITransferable;
|
|
|
|
const nsIXULSortService = Components.interfaces.nsIXULSortService;
|
|
|
|
const nsIRDFService = Components.interfaces.nsIRDFService;
|
|
|
|
const nsIRDFLiteral = Components.interfaces.nsIRDFLiteral;
|
|
|
|
const nsISupportsArray = Components.interfaces.nsISupportsArray;
|
2002-08-06 04:53:19 +04:00
|
|
|
const nsISupportsString = Components.interfaces.nsISupportsString;
|
2000-08-28 08:24:49 +04:00
|
|
|
|
1999-08-23 07:48:53 +04:00
|
|
|
// By the time this runs, The 'HTTPIndex' variable will have been
|
|
|
|
// magically set on the global object by the native code.
|
|
|
|
|
1999-08-25 07:50:15 +04:00
|
|
|
function debug(msg)
|
|
|
|
{
|
2002-03-29 05:46:01 +03:00
|
|
|
// Uncomment to print out debug info.
|
|
|
|
//dump(msg);
|
1999-08-25 07:50:15 +04:00
|
|
|
}
|
|
|
|
|
2000-12-13 04:28:08 +03:00
|
|
|
var loadingArc = null;
|
2000-08-28 08:24:49 +04:00
|
|
|
var loadingLevel = 0;
|
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
var RDF_observer =
|
2000-08-28 08:24:49 +04:00
|
|
|
{
|
2002-03-29 05:46:01 +03:00
|
|
|
onAssert: function(ds, src, prop, target)
|
|
|
|
{
|
|
|
|
if (prop == loadingArc) {
|
|
|
|
if (loadingLevel++ == 0)
|
|
|
|
SetBusyCursor(window, true);
|
|
|
|
debug("Directory: assert: loading level is " + loadingLevel + " for " + src.Value + "\n");
|
2000-08-28 08:24:49 +04:00
|
|
|
}
|
2002-03-29 05:46:01 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onUnassert: function(ds, src, prop, target)
|
|
|
|
{
|
|
|
|
if (prop == loadingArc) {
|
|
|
|
if (loadingLevel > 0)
|
|
|
|
if (--loadingLevel == 0)
|
|
|
|
SetBusyCursor(window, false);
|
|
|
|
debug("Directory: unassert: loading level is " + loadingLevel + " for " + src.Value + "\n");
|
|
|
|
}
|
|
|
|
},
|
2000-08-28 08:24:49 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
onChange: function(ds, src, prop, old_target, new_target) { },
|
|
|
|
onMove: function(ds, old_src, new_src, prop, target) { },
|
2003-05-23 16:03:40 +04:00
|
|
|
onBeginUpdateBatch: function(ds) { },
|
|
|
|
onEndUpdateBatch: function(ds) { }
|
2002-03-29 05:46:01 +03:00
|
|
|
};
|
2000-08-28 08:24:49 +04:00
|
|
|
|
|
|
|
function
|
|
|
|
SetBusyCursor(window, enable)
|
|
|
|
{
|
2002-03-29 05:46:01 +03:00
|
|
|
// Defensive check: setCursor() is only available for
|
|
|
|
// chrome windows. Since one of our frame might be a
|
|
|
|
// non-chrome window, make sure the window we treat has
|
|
|
|
// a setCursor method.
|
|
|
|
if("setCursor" in window) {
|
|
|
|
if(enable == true) {
|
|
|
|
window.setCursor("wait");
|
|
|
|
debug("Directory: cursor=busy\n");
|
|
|
|
} else {
|
|
|
|
window.setCursor("auto");
|
|
|
|
debug("Directory: cursor=notbusy\n");
|
2000-08-28 08:24:49 +04:00
|
|
|
}
|
2002-03-29 05:46:01 +03:00
|
|
|
}
|
2000-08-28 08:24:49 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
var numFrames = window.frames.length;
|
|
|
|
for (var i = 0; i < numFrames; i++)
|
|
|
|
SetBusyCursor(window.frames[i], enable);
|
2000-08-28 08:24:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// We need this hack because we've completely circumvented the onload() logic.
|
|
|
|
function Boot()
|
|
|
|
{
|
2002-03-29 05:46:01 +03:00
|
|
|
if (document.getElementById('tree'))
|
|
|
|
Init();
|
|
|
|
else
|
|
|
|
setTimeout("Boot()", 500);
|
2000-08-28 08:24:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout("Boot()", 0);
|
2000-07-27 11:47:36 +04:00
|
|
|
|
1999-08-23 07:48:53 +04:00
|
|
|
function Init()
|
|
|
|
{
|
2002-03-29 05:46:01 +03:00
|
|
|
debug("directory.js: Init()\n");
|
1999-08-23 07:48:53 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
var tree = document.getElementById('tree');
|
2000-08-22 05:26:42 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
// Initialize the tree's base URL to whatever the HTTPIndex is rooted at
|
|
|
|
var baseURI = HTTPIndex.BaseURL;
|
2000-04-27 05:17:10 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
if (baseURI && (baseURI.indexOf("ftp://") == 0)) {
|
|
|
|
// fix bug # 37102: if its a FTP directory
|
|
|
|
// ensure it ends with a trailing slash
|
|
|
|
if (baseURI.substr(baseURI.length - 1) != "/") {
|
|
|
|
debug("append traiing slash to FTP directory URL\n");
|
|
|
|
baseURI += "/";
|
|
|
|
}
|
2001-04-15 01:10:14 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
// Lets also enable the loggin window.
|
2001-04-15 01:10:14 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
var node = document.getElementById("main-splitter");
|
|
|
|
node.setAttribute("hidden", false);
|
2001-04-15 01:10:14 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
node = document.getElementById("logbox");
|
|
|
|
node.setAttribute("hidden", false);
|
|
|
|
}
|
2001-04-15 01:10:14 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
if (baseURI && (baseURI.indexOf("file://") != 0)) {
|
|
|
|
// Note: DON'T add the HTTPIndex datasource into the tree
|
|
|
|
// for file URLs, only do it for FTP/Gopher/etc URLs; the "rdf:files"
|
|
|
|
// datasources handles file URLs
|
|
|
|
tree.database.AddDataSource(HTTPIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: set encoding BEFORE setting "ref" (important!)
|
|
|
|
var RDF = Components.classes[RDFSERVICE_CONTRACTID].getService();
|
|
|
|
if (RDF) RDF = RDF.QueryInterface(nsIRDFService);
|
|
|
|
if (RDF) {
|
|
|
|
loadingArc = RDF.GetResource(NC_LOADING, true);
|
2000-07-15 03:21:48 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
var httpDS = HTTPIndex.DataSource;
|
|
|
|
if (httpDS) httpDS = httpDS.QueryInterface(nsIHTTPIndex);
|
|
|
|
if (httpDS) {
|
|
|
|
httpDS.encoding = "ISO-8859-1";
|
|
|
|
|
|
|
|
// Use a default character set.
|
|
|
|
if (window._content.defaultCharacterset)
|
|
|
|
httpDS.encoding = window._content.defaultCharacterset;
|
2000-07-15 03:21:48 +04:00
|
|
|
}
|
2002-03-29 05:46:01 +03:00
|
|
|
}
|
2000-07-15 03:21:48 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
// set window title
|
|
|
|
document.title = baseURI;
|
2000-07-27 11:47:36 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
tree.database.AddObserver(RDF_observer);
|
|
|
|
debug("Directory: added observer\n");
|
2000-08-28 08:24:49 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
// root the tree (do this last)
|
|
|
|
tree.setAttribute("ref", baseURI);
|
1999-08-23 07:48:53 +04:00
|
|
|
}
|
|
|
|
|
2000-08-28 08:24:49 +04:00
|
|
|
function DoUnload()
|
|
|
|
{
|
|
|
|
var tree = document.getElementById("tree");
|
2002-03-29 05:46:01 +03:00
|
|
|
if (tree) {
|
2001-04-22 23:11:54 +04:00
|
|
|
tree.database.RemoveDataSource(HTTPIndex);
|
2000-08-28 08:24:49 +04:00
|
|
|
tree.database.RemoveObserver(RDF_observer);
|
2002-03-29 05:46:01 +03:00
|
|
|
debug("Directory: removed observer\n");
|
2000-08-28 08:24:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
function OnClick(event)
|
1999-08-25 05:32:40 +04:00
|
|
|
{
|
2002-03-29 05:46:01 +03:00
|
|
|
if (event.target.localName != "treechildren")
|
|
|
|
return false;
|
|
|
|
if( event.type == "click" && (event.button != 0 || event.detail != 2))
|
|
|
|
return false;
|
|
|
|
if( event.type == "keypress" && event.keyCode != 13)
|
|
|
|
return false;
|
2000-07-27 11:47:36 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
var tree = document.getElementById("tree");
|
|
|
|
if (tree.currentIndex >= 0) {
|
|
|
|
var item = tree.contentView.getItemAtIndex(tree.currentIndex);
|
|
|
|
window._content.location.href = item.getAttributeNS(NC_NS, "url");
|
|
|
|
}
|
2001-03-14 05:41:18 +03:00
|
|
|
}
|
1999-08-25 05:32:40 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
function doSort(aTarget)
|
1999-08-30 13:34:46 +04:00
|
|
|
{
|
2002-03-29 05:46:01 +03:00
|
|
|
if (aTarget.localName != "treecol")
|
|
|
|
return;
|
|
|
|
|
1999-08-30 13:34:46 +04:00
|
|
|
// determine column resource to sort on
|
2002-03-29 05:46:01 +03:00
|
|
|
var sortResource = aTarget.getAttribute('resource');
|
1999-08-30 13:34:46 +04:00
|
|
|
|
|
|
|
// switch between ascending & descending sort (no natural order support)
|
2002-03-29 05:46:01 +03:00
|
|
|
var sortDirection = aTarget.getAttribute("sortDirection") == "ascending" ? "descending" : "ascending";
|
1999-08-30 13:34:46 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
try {
|
|
|
|
var sortService = Components.classes[XULSORTSERVICE_CONTRACTID].getService(nsIXULSortService);
|
2002-10-22 23:49:29 +04:00
|
|
|
sortService.sort(aTarget, sortResource, sortDirection);
|
2002-03-29 05:46:01 +03:00
|
|
|
} catch(ex) { }
|
1999-08-30 13:34:46 +04:00
|
|
|
}
|
2000-07-28 04:22:07 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
function BeginDragTree (event)
|
2000-07-28 04:22:07 +04:00
|
|
|
{
|
2002-03-29 05:46:01 +03:00
|
|
|
if (event.target.localName != "treechildren")
|
|
|
|
return true;
|
|
|
|
|
2000-07-28 04:22:07 +04:00
|
|
|
var dragStarted = false;
|
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
try {
|
|
|
|
// determine which treeitem was dragged
|
|
|
|
var tree = document.getElementById("tree");
|
|
|
|
var row = {}, colId = {}, child = {};
|
|
|
|
tree.treeBoxObject.getCellAt(event.clientX, event.clientY, row, colId, child);
|
|
|
|
var item = tree.contentView.getItemAtIndex(row.value);
|
|
|
|
|
|
|
|
// get information from treeitem for drag
|
|
|
|
var url = item.getAttributeNS(NC_NS, "url");
|
|
|
|
var desc = item.getAttributeNS(NC_NS, "desc");
|
|
|
|
|
|
|
|
var RDF = Components.classes[RDFSERVICE_CONTRACTID].getService(nsIRDFService);
|
|
|
|
var transferable =
|
|
|
|
Components.classes[TRANSFERABLE_CONTRACTID].createInstance(nsITransferable);
|
|
|
|
var genDataURL =
|
2002-08-06 04:53:19 +04:00
|
|
|
Components.classes[WSTRING_CONTRACTID].createInstance(nsISupportsString);
|
2002-03-29 05:46:01 +03:00
|
|
|
var genDataHTML =
|
2002-08-06 04:53:19 +04:00
|
|
|
Components.classes[WSTRING_CONTRACTID].createInstance(nsISupportsString);
|
2002-03-29 05:46:01 +03:00
|
|
|
var genData =
|
2002-08-06 04:53:19 +04:00
|
|
|
Components.classes[WSTRING_CONTRACTID].createInstance(nsISupportsString);
|
2002-03-29 05:46:01 +03:00
|
|
|
var genDataURL =
|
2002-08-06 04:53:19 +04:00
|
|
|
Components.classes[WSTRING_CONTRACTID].createInstance(nsISupportsString);
|
2002-03-29 05:46:01 +03:00
|
|
|
|
|
|
|
transferable.addDataFlavor("text/x-moz-url");
|
|
|
|
transferable.addDataFlavor("text/html");
|
|
|
|
transferable.addDataFlavor("text/unicode");
|
|
|
|
|
|
|
|
genDataURL.data = url + "\n" + desc;
|
|
|
|
genDataHTML.data = "<a href=\"" + url + "\">" + desc + "</a>";
|
|
|
|
genData.data = url;
|
|
|
|
|
|
|
|
transferable.setTransferData("text/x-moz-url", genDataURL, genDataURL.data.length * 2);
|
|
|
|
transferable.setTransferData("text/html", genDataHTML, genDataHTML.data.length * 2);
|
|
|
|
transferable.setTransferData("text/unicode", genData, genData.data.length * 2);
|
|
|
|
|
|
|
|
var transArray =
|
|
|
|
Components.classes[ARRAY_CONTRACTID].createInstance(nsISupportsArray);
|
|
|
|
|
|
|
|
// put it into the transferable as an |nsISupports|
|
|
|
|
var genTrans = transferable.QueryInterface(Components.interfaces.nsISupports);
|
|
|
|
transArray.AppendElement(genTrans);
|
|
|
|
|
|
|
|
var dragService =
|
|
|
|
Components.classes[DRAGSERVICE_CONTRACTID].getService(nsIDragService);
|
|
|
|
|
|
|
|
dragService.invokeDragSession(event.target, transArray, null, nsIDragService.DRAGDROP_ACTION_COPY +
|
|
|
|
nsIDragService.DRAGDROP_ACTION_MOVE);
|
2001-11-04 06:05:15 +03:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
dragStarted = true;
|
|
|
|
} catch (ex) { }
|
2000-07-28 04:22:07 +04:00
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
return !dragStarted;
|
2000-07-28 04:22:07 +04:00
|
|
|
}
|
2001-04-15 01:10:14 +04:00
|
|
|
|
|
|
|
function scrollDown()
|
|
|
|
{
|
2002-03-29 05:46:01 +03:00
|
|
|
window.frames[0].scrollTo(0, window.frames[0].document.height);
|
2001-04-15 01:10:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function OnFTPControlLog( server, msg )
|
|
|
|
{
|
|
|
|
var logdoc = frames[0].document;
|
|
|
|
var logdocDiv = logdoc.getElementById("logboxDiv");
|
|
|
|
var div = document.createElementNS("http://www.w3.org/1999/xhtml",
|
|
|
|
"html:div");
|
|
|
|
|
|
|
|
if (server)
|
|
|
|
div.setAttribute("class", "server");
|
|
|
|
else
|
|
|
|
div.setAttribute("class", "client");
|
|
|
|
|
|
|
|
div.appendChild (document.createTextNode(msg));
|
|
|
|
|
|
|
|
logdocDiv.appendChild(div);
|
|
|
|
|
|
|
|
scrollDown();
|
|
|
|
}
|
|
|
|
|