2001-03-14 05:41:18 +03:00
|
|
|
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; -*-
|
1999-08-23 07:48:53 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03: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/
|
1999-08-23 07:48:53 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-08-23 07:48:53 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2001-03-14 05:41:18 +03:00
|
|
|
* Bradley Baetz <bbaetz@student.usyd.edu.au>
|
1999-08-23 07:48:53 +04:00
|
|
|
*/
|
|
|
|
|
1999-08-25 07:50:15 +04:00
|
|
|
/*
|
|
|
|
Script for the directory window
|
|
|
|
*/
|
|
|
|
|
2000-07-27 11:47:36 +04:00
|
|
|
|
|
|
|
|
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";
|
|
|
|
const WSTRING_CONTRACTID = "@mozilla.org/supports-wstring;1";
|
2000-08-28 08:24:49 +04:00
|
|
|
|
|
|
|
const NC_NS = "http://home.netscape.com/NC-rdf#";
|
|
|
|
const NC_NAME = NC_NS + "Name";
|
|
|
|
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;
|
|
|
|
const nsISupportsWString = Components.interfaces.nsISupportsWString;
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2000-07-27 11:47:36 +04:00
|
|
|
|
|
|
|
|
1999-08-25 07:50:15 +04:00
|
|
|
function debug(msg)
|
|
|
|
{
|
|
|
|
// Uncomment to print out debug info.
|
2001-03-14 05:41:18 +03:00
|
|
|
//dump(msg);
|
1999-08-25 07:50:15 +04:00
|
|
|
}
|
|
|
|
|
2000-07-27 11:47:36 +04:00
|
|
|
|
|
|
|
|
2000-12-13 04:28:08 +03:00
|
|
|
var loadingArc = null;
|
2000-08-28 08:24:49 +04:00
|
|
|
var loadingLevel = 0;
|
|
|
|
|
|
|
|
var RDF_observer = new Object;
|
|
|
|
|
|
|
|
RDF_observer =
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onChange : function(ds, src, prop, old_target, new_target)
|
|
|
|
{
|
|
|
|
},
|
|
|
|
onMove : function(ds, old_src, new_src, prop, target)
|
|
|
|
{
|
|
|
|
},
|
|
|
|
beginUpdateBatch : function(ds)
|
|
|
|
{
|
|
|
|
},
|
|
|
|
endUpdateBatch : function(ds)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function
|
|
|
|
SetBusyCursor(window, enable)
|
|
|
|
{
|
|
|
|
if(enable == true)
|
|
|
|
{
|
|
|
|
window.setCursor("wait");
|
|
|
|
debug("Directory: cursor=busy\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window.setCursor("auto");
|
|
|
|
debug("Directory: cursor=notbusy\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
var numFrames = window.frames.length;
|
|
|
|
for(var i = 0; i < numFrames; i++)
|
|
|
|
{
|
|
|
|
SetBusyCursor(window.frames[i], enable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// We need this hack because we've completely circumvented the onload() logic.
|
|
|
|
function Boot()
|
|
|
|
{
|
|
|
|
if (document.getElementById('tree')) {
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
setTimeout("Boot()", 500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout("Boot()", 0);
|
2000-07-27 11:47:36 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
1999-08-23 07:48:53 +04:00
|
|
|
function Init()
|
|
|
|
{
|
1999-08-25 07:50:15 +04:00
|
|
|
debug("directory.js: Init()\n");
|
1999-08-23 07:48:53 +04:00
|
|
|
|
2000-08-22 05:26:42 +04:00
|
|
|
var tree = document.getElementById('tree');
|
|
|
|
|
1999-08-23 07:48:53 +04:00
|
|
|
// Initialize the tree's base URL to whatever the HTTPIndex is rooted at
|
2000-04-27 05:17:10 +04:00
|
|
|
var baseURI = HTTPIndex.BaseURL;
|
|
|
|
|
2000-08-22 05:26:42 +04:00
|
|
|
if (baseURI && (baseURI.indexOf("ftp://") == 0))
|
2000-04-27 05:17:10 +04:00
|
|
|
{
|
2000-08-22 05:26:42 +04:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
// Lets also enable the loggin window.
|
|
|
|
|
|
|
|
var node = document.getElementById("main-splitter");
|
|
|
|
node.setAttribute("hidden", false);
|
|
|
|
|
|
|
|
node = document.getElementById("logbox");
|
|
|
|
node.setAttribute("hidden", false);
|
2001-03-14 05:41:18 +03:00
|
|
|
}
|
2001-04-15 01:10:14 +04:00
|
|
|
|
2001-03-14 05:41:18 +03:00
|
|
|
if (baseURI && (baseURI.indexOf("file://") != 0)) {
|
2000-08-22 05:26:42 +04:00
|
|
|
// Note: DON'T add the HTTPIndex datasource into the tree
|
2001-03-14 05:41:18 +03:00
|
|
|
// for file URLs, only do it for FTP/Gopher/etc URLs; the "rdf:files"
|
2000-08-22 05:26:42 +04:00
|
|
|
// datasources handles file URLs
|
2001-04-15 00:30:47 +04:00
|
|
|
tree.database.AddDataSource(HTTPIndex);
|
2000-04-27 05:17:10 +04:00
|
|
|
}
|
2000-07-15 03:21:48 +04:00
|
|
|
|
|
|
|
// Note: set encoding BEFORE setting "ref" (important!)
|
2000-09-14 03:57:52 +04:00
|
|
|
var RDF = Components.classes[RDFSERVICE_CONTRACTID].getService();
|
2000-08-28 08:24:49 +04:00
|
|
|
if (RDF) RDF = RDF.QueryInterface(nsIRDFService);
|
2000-07-15 03:21:48 +04:00
|
|
|
if (RDF)
|
|
|
|
{
|
2000-08-28 08:24:49 +04:00
|
|
|
loadingArc = RDF.GetResource(NC_LOADING, true);
|
|
|
|
|
2000-08-15 05:43:42 +04:00
|
|
|
var httpDS = HTTPIndex.DataSource;
|
2000-08-28 08:24:49 +04:00
|
|
|
if (httpDS) httpDS = httpDS.QueryInterface(nsIHTTPIndex);
|
2000-07-15 03:21:48 +04:00
|
|
|
if (httpDS)
|
|
|
|
{
|
|
|
|
httpDS.encoding = "ISO-8859-1";
|
2000-07-22 02:15:18 +04:00
|
|
|
|
|
|
|
// Use a default character set.
|
|
|
|
if (window._content.defaultCharacterset)
|
2000-07-27 11:47:36 +04:00
|
|
|
{
|
|
|
|
httpDS.encoding = window._content.defaultCharacterset;
|
|
|
|
}
|
2000-07-15 03:21:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-27 11:47:36 +04:00
|
|
|
// set window title
|
|
|
|
var theWindow = window._content.parentWindow;
|
|
|
|
if (theWindow)
|
|
|
|
{
|
|
|
|
theWindow.title = baseURI;
|
|
|
|
}
|
|
|
|
|
2000-08-28 08:24:49 +04:00
|
|
|
tree.database.AddObserver(RDF_observer);
|
|
|
|
debug("Directory: added observer\n");
|
|
|
|
|
2000-07-15 03:21:48 +04:00
|
|
|
// root the tree (do this last)
|
2000-04-27 05:17:10 +04:00
|
|
|
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");
|
|
|
|
if (tree)
|
|
|
|
{
|
2001-04-15 01:10:14 +04:00
|
|
|
tree.database.RemoveDatasource(HTTPIndex);
|
2000-08-28 08:24:49 +04:00
|
|
|
tree.database.RemoveObserver(RDF_observer);
|
|
|
|
debug("Directory: removed observer\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-27 11:47:36 +04:00
|
|
|
function OnClick(event, node)
|
1999-08-25 05:32:40 +04:00
|
|
|
{
|
2000-05-10 04:26:46 +04:00
|
|
|
if( event.type == "click" &&
|
2001-03-02 06:07:53 +03:00
|
|
|
( event.button != 0 || event.detail != 2 || node.nodeName != "treeitem") )
|
2000-07-27 11:47:36 +04:00
|
|
|
return(false);
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
if( event.type == "keypress" && event.keyCode != 13 )
|
2000-07-27 11:47:36 +04:00
|
|
|
return(false);
|
|
|
|
|
2000-05-10 04:26:46 +04:00
|
|
|
var tree = document.getElementById("tree");
|
2001-03-14 05:41:18 +03:00
|
|
|
if( tree.selectedItems.length == 1 ) {
|
2000-05-10 04:26:46 +04:00
|
|
|
var selectedItem = tree.selectedItems[0];
|
2001-03-14 05:41:18 +03:00
|
|
|
var url = selectedItem.getAttribute("URL");
|
|
|
|
|
|
|
|
window._content.location.href = url;
|
|
|
|
|
2000-07-27 11:47:36 +04:00
|
|
|
// set window title
|
|
|
|
var theWindow = window._content.parentWindow;
|
|
|
|
if (theWindow)
|
2001-03-14 05:41:18 +03:00
|
|
|
theWindow.title = url;
|
|
|
|
}
|
1999-08-25 07:50:15 +04:00
|
|
|
}
|
|
|
|
|
2001-03-14 05:41:18 +03:00
|
|
|
function OnMouseOver(event, node)
|
|
|
|
{
|
|
|
|
if (node.nodeName != "treeitem")
|
|
|
|
return false;
|
|
|
|
var url = node.getAttribute("URL");
|
|
|
|
window._content.status = url;
|
|
|
|
return true;
|
|
|
|
}
|
1999-08-25 07:50:15 +04:00
|
|
|
|
2001-03-14 05:41:18 +03:00
|
|
|
function OnMouseOut(event, node)
|
|
|
|
{
|
|
|
|
window._content.status = "";
|
|
|
|
return true;
|
|
|
|
}
|
1999-08-25 05:32:40 +04:00
|
|
|
|
1999-08-30 13:34:46 +04:00
|
|
|
function doSort(sortColName)
|
|
|
|
{
|
|
|
|
var node = document.getElementById(sortColName);
|
|
|
|
if (!node) return(false);
|
|
|
|
|
|
|
|
// determine column resource to sort on
|
|
|
|
var sortResource = node.getAttribute('resource');
|
|
|
|
|
|
|
|
// switch between ascending & descending sort (no natural order support)
|
|
|
|
var sortDirection="ascending";
|
|
|
|
var isSortActive = node.getAttribute('sortActive');
|
|
|
|
if (isSortActive == "true")
|
|
|
|
{
|
|
|
|
var currentDirection = node.getAttribute('sortDirection');
|
|
|
|
if (currentDirection == "ascending")
|
|
|
|
{
|
|
|
|
sortDirection = "descending";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-17 09:07:26 +04:00
|
|
|
try
|
|
|
|
{
|
2000-09-14 03:57:52 +04:00
|
|
|
var isupports = Components.classes[XULSORTSERVICE_CONTRACTID].getService();
|
2000-04-17 09:07:26 +04:00
|
|
|
if (!isupports) return(false);
|
2000-08-28 08:24:49 +04:00
|
|
|
var xulSortService = isupports.QueryInterface(nsIXULSortService);
|
2000-04-17 09:07:26 +04:00
|
|
|
if (!xulSortService) return(false);
|
|
|
|
xulSortService.Sort(node, sortResource, sortDirection);
|
|
|
|
}
|
|
|
|
catch(ex)
|
|
|
|
{
|
|
|
|
}
|
1999-08-30 13:34:46 +04:00
|
|
|
return(false);
|
|
|
|
}
|
2000-07-28 04:22:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function BeginDragTree ( event )
|
|
|
|
{
|
|
|
|
var tree = document.getElementById("tree");
|
|
|
|
if ( event.target == tree )
|
|
|
|
return(true); // continue propagating the event
|
|
|
|
|
2000-08-01 12:24:07 +04:00
|
|
|
// only <treeitem>s can be dragged out
|
|
|
|
if ( event.target.parentNode.parentNode.tagName != "treeitem")
|
|
|
|
return(false);
|
|
|
|
|
2000-07-28 04:22:07 +04:00
|
|
|
var database = tree.database;
|
|
|
|
if (!database) return(false);
|
|
|
|
|
|
|
|
var RDF =
|
2000-09-14 03:57:52 +04:00
|
|
|
Components.classes[RDFSERVICE_CONTRACTID].getService(nsIRDFService);
|
2000-07-28 04:22:07 +04:00
|
|
|
if (!RDF) return(false);
|
|
|
|
|
|
|
|
var dragStarted = false;
|
|
|
|
|
2001-04-15 00:30:47 +04:00
|
|
|
var transferable =
|
2000-09-14 03:57:52 +04:00
|
|
|
Components.classes[TRANSFERABLE_CONTRACTID].createInstance(nsITransferable);
|
2001-04-15 00:30:47 +04:00
|
|
|
if ( !transferable ) return(false);
|
2000-07-28 04:22:07 +04:00
|
|
|
|
|
|
|
var genData =
|
2000-09-14 03:57:52 +04:00
|
|
|
Components.classes[WSTRING_CONTRACTID].createInstance(nsISupportsWString);
|
2000-07-28 04:22:07 +04:00
|
|
|
if (!genData) return(false);
|
|
|
|
|
|
|
|
var genDataURL =
|
2000-09-14 03:57:52 +04:00
|
|
|
Components.classes[WSTRING_CONTRACTID].createInstance(nsISupportsWString);
|
2000-07-28 04:22:07 +04:00
|
|
|
if (!genDataURL) return(false);
|
|
|
|
|
2001-04-15 00:30:47 +04:00
|
|
|
transferable.addDataFlavor("text/unicode");
|
|
|
|
transferable.addDataFlavor("moz/rdfitem");
|
2000-07-28 04:22:07 +04:00
|
|
|
|
|
|
|
// ref/id (url) is on the <treeitem> which is two levels above the <treecell> which is
|
|
|
|
// the target of the event.
|
|
|
|
var id = event.target.parentNode.parentNode.getAttribute("ref");
|
|
|
|
if (!id || id=="")
|
|
|
|
{
|
|
|
|
id = event.target.parentNode.parentNode.getAttribute("id");
|
|
|
|
}
|
|
|
|
|
|
|
|
var parentID = event.target.parentNode.parentNode.parentNode.parentNode.getAttribute("ref");
|
|
|
|
if (!parentID || parentID == "")
|
|
|
|
{
|
|
|
|
parentID = event.target.parentNode.parentNode.parentNode.parentNode.getAttribute("id");
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we can get node's name, append (space) name to url
|
|
|
|
var src = RDF.GetResource(id, true);
|
2000-08-28 08:24:49 +04:00
|
|
|
var prop = RDF.GetResource(NC_NAME, true);
|
2000-07-28 04:22:07 +04:00
|
|
|
var target = database.GetTarget(src, prop, true);
|
2000-08-28 08:24:49 +04:00
|
|
|
if (target) target = target.QueryInterface(nsIRDFLiteral);
|
2000-07-28 04:22:07 +04:00
|
|
|
if (target) target = target.Value;
|
|
|
|
if (target && (target != ""))
|
|
|
|
{
|
|
|
|
id = id + " " + target;
|
|
|
|
}
|
|
|
|
|
|
|
|
var trueID = id;
|
|
|
|
if (parentID != null)
|
|
|
|
{
|
|
|
|
trueID += "\n" + parentID;
|
|
|
|
}
|
|
|
|
genData.data = trueID;
|
|
|
|
genDataURL.data = id;
|
|
|
|
|
2001-04-15 00:30:47 +04:00
|
|
|
transferable.setTransferData ( "moz/rdfitem", genData, genData.data.length * 2); // double byte data
|
|
|
|
transferable.setTransferData ( "text/unicode", genDataURL, genDataURL.data.length * 2); // double byte data
|
2000-07-28 04:22:07 +04:00
|
|
|
|
|
|
|
var transArray =
|
2000-09-14 03:57:52 +04:00
|
|
|
Components.classes[ARRAY_CONTRACTID].createInstance(nsISupportsArray);
|
2000-07-28 04:22:07 +04:00
|
|
|
if ( !transArray ) return(false);
|
|
|
|
|
|
|
|
// put it into the transferable as an |nsISupports|
|
2001-04-15 00:30:47 +04:00
|
|
|
var genTrans = transferable.QueryInterface(Components.interfaces.nsISupports);
|
2000-07-28 04:22:07 +04:00
|
|
|
transArray.AppendElement(genTrans);
|
|
|
|
|
|
|
|
var dragService =
|
2000-09-14 03:57:52 +04:00
|
|
|
Components.classes[DRAGSERVICE_CONTRACTID].getService(nsIDragService);
|
2000-07-28 04:22:07 +04:00
|
|
|
if ( !dragService ) return(false);
|
|
|
|
|
|
|
|
dragService.invokeDragSession ( event.target, transArray, null, nsIDragService.DRAGDROP_ACTION_COPY +
|
|
|
|
nsIDragService.DRAGDROP_ACTION_MOVE );
|
|
|
|
dragStarted = true;
|
|
|
|
|
|
|
|
return(!dragStarted);
|
|
|
|
}
|
2001-04-15 01:10:14 +04:00
|
|
|
|
|
|
|
function scrollDown()
|
|
|
|
{
|
|
|
|
window.frames[0].scrollTo(0, window.frames[0].document.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|