2006-07-27 18:50:16 +04:00
|
|
|
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
2006-07-27 18:50:24 +04:00
|
|
|
* Contributor(s):
|
|
|
|
* Alec Flett <alecf@netscape.com>
|
2006-07-27 18:50:16 +04:00
|
|
|
*/
|
1999-08-05 09:11:42 +04:00
|
|
|
|
2006-07-27 18:50:16 +04:00
|
|
|
// The history window uses JavaScript in bookmarks.js too.
|
1999-08-05 09:11:42 +04:00
|
|
|
|
2006-07-27 18:52:30 +04:00
|
|
|
function debug(msg)
|
|
|
|
{
|
|
|
|
// Uncomment for noise
|
|
|
|
//dump(msg+"\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
var gHistoryTree;
|
|
|
|
var gLastHostname;
|
|
|
|
var gLastDomain;
|
|
|
|
var gGlobalHistory;
|
|
|
|
|
|
|
|
var gDeleteByHostname;
|
|
|
|
var gDeleteByDomain;
|
|
|
|
var gHistoryBundle;
|
|
|
|
|
2006-07-27 18:50:16 +04:00
|
|
|
function HistoryInit() {
|
2006-07-27 18:50:24 +04:00
|
|
|
|
2006-07-27 18:52:30 +04:00
|
|
|
gHistoryTree = document.getElementById("historyTree");
|
|
|
|
gDeleteByHostname = document.getElementById("cmd_deleteByHostname");
|
|
|
|
gDeleteByDomain = document.getElementById("cmd_deleteByDomain");
|
|
|
|
gHistoryBundle = document.getElementById("historyBundle");
|
|
|
|
|
|
|
|
var treeController = new nsTreeController(gHistoryTree);
|
|
|
|
var historyController = new nsHistoryController;
|
|
|
|
gHistoryTree.controllers.appendController(historyController);
|
|
|
|
|
|
|
|
gGlobalHistory = Components.classes["@mozilla.org/browser/global-history;1"].getService(Components.interfaces.nsIGlobalHistory);
|
|
|
|
|
2006-07-27 18:50:16 +04:00
|
|
|
var children = document.getElementById('treechildren-bookmarks');
|
2006-07-27 18:50:24 +04:00
|
|
|
if (children.firstChild)
|
2006-07-27 18:52:30 +04:00
|
|
|
gHistoryTree.selectItem(children.firstChild);
|
|
|
|
gHistoryTree.focus();
|
2006-07-27 18:52:25 +04:00
|
|
|
|
|
|
|
// do a sort
|
|
|
|
RefreshSort();
|
1999-08-05 09:11:42 +04:00
|
|
|
}
|
1999-08-20 02:02:40 +04:00
|
|
|
|
2006-07-27 18:52:30 +04:00
|
|
|
function updateHistoryCommands()
|
|
|
|
{
|
|
|
|
goUpdateCommand("cmd_deleteByHostname");
|
|
|
|
goUpdateCommand("cmd_deleteByDomain");
|
|
|
|
}
|
|
|
|
|
|
|
|
function historyOnSelect(event)
|
|
|
|
{
|
|
|
|
// every time selection changes, save the last hostname
|
|
|
|
gLastHostname = "";
|
|
|
|
gLastDomain = "";
|
2006-07-27 18:52:31 +04:00
|
|
|
var match;
|
2006-07-27 18:52:30 +04:00
|
|
|
var selection = gHistoryTree.selectedItems;
|
|
|
|
if (selection && selection.length > 0) {
|
|
|
|
var url = selection[0].id;
|
|
|
|
// matches scheme://(hostname)...
|
2006-07-27 18:52:31 +04:00
|
|
|
match = url.match(/.*:\/\/([^\/:]*)/);
|
2006-07-27 18:52:30 +04:00
|
|
|
|
|
|
|
if (match && match.length>1)
|
|
|
|
gLastHostname = match[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gLastHostname) {
|
|
|
|
// matches the last foo.bar in foo.bar or baz.foo.bar
|
2006-07-27 18:52:31 +04:00
|
|
|
match = gLastHostname.match(/([^.]+\.[^.]+$)/);
|
2006-07-27 18:52:30 +04:00
|
|
|
if (match)
|
|
|
|
gLastDomain = match[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
document.commandDispatcher.updateCommands("select");
|
|
|
|
}
|
|
|
|
|
|
|
|
function nsHistoryController()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHistoryController.prototype =
|
|
|
|
{
|
|
|
|
supportsCommand: function(command)
|
|
|
|
{
|
|
|
|
switch(command) {
|
|
|
|
case "cmd_deleteByHostname":
|
|
|
|
case "cmd_deleteByDomain":
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
isCommandEnabled: function(command)
|
|
|
|
{
|
|
|
|
var enabled = false;
|
|
|
|
var stringId;
|
|
|
|
var text;
|
|
|
|
switch(command) {
|
|
|
|
case "cmd_deleteByHostname":
|
|
|
|
if (gLastHostname) {
|
|
|
|
stringId = "deleteHost";
|
|
|
|
enabled = true;
|
|
|
|
} else {
|
|
|
|
stringId = "deleteHostNoSelection";
|
|
|
|
}
|
|
|
|
text =
|
|
|
|
gHistoryBundle.stringBundle.formatStringFromName(stringId,
|
|
|
|
[ gLastHostname ], 1);
|
|
|
|
gDeleteByHostname.setAttribute("value", text);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case "cmd_deleteByDomain":
|
|
|
|
if (gLastDomain) {
|
|
|
|
stringId = "deleteDomain";
|
|
|
|
enabled = true;
|
|
|
|
} else {
|
|
|
|
stringId = "deleteDomainNoSelection";
|
|
|
|
}
|
|
|
|
text = gHistoryBundle.stringBundle.formatStringFromName(stringId,
|
|
|
|
[ gLastDomain ], 1);
|
|
|
|
gDeleteByDomain.setAttribute("value", text);
|
|
|
|
}
|
|
|
|
return enabled;
|
|
|
|
},
|
|
|
|
|
|
|
|
doCommand: function(command)
|
|
|
|
{
|
|
|
|
switch(command) {
|
|
|
|
case "cmd_deleteByHostname":
|
|
|
|
gGlobalHistory.RemovePagesFromHost(gLastHostname, false)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case "cmd_deleteByDomain":
|
|
|
|
gGlobalHistory.RemovePagesFromHost(gLastDomain, true)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-07-27 18:50:17 +04:00
|
|
|
var historyDNDObserver = {
|
|
|
|
onDragStart: function (aEvent)
|
|
|
|
{
|
|
|
|
var title = aEvent.target.getAttribute("value");
|
|
|
|
var uri = aEvent.target.parentNode.parentNode.id;
|
2006-07-27 18:50:26 +04:00
|
|
|
if (aEvent.target.localName != "treecell") // make sure we have something to drag
|
2006-07-27 18:50:18 +04:00
|
|
|
return null;
|
|
|
|
|
2006-07-27 18:50:17 +04:00
|
|
|
var htmlString = "<A HREF='" + uri + "'>" + title + "</A>";
|
|
|
|
var flavourList = { };
|
|
|
|
flavourList["text/unicode"] = { width: 2, data: uri };
|
|
|
|
flavourList["text/html"] = { width: 2, data: htmlString };
|
2006-07-27 18:50:22 +04:00
|
|
|
flavourList["text/x-moz-url"] = { width: 2, data: uri + "\n" + title };
|
2006-07-27 18:50:17 +04:00
|
|
|
return flavourList;
|
2006-07-27 18:50:23 +04:00
|
|
|
}
|
2006-07-27 18:50:17 +04:00
|
|
|
|
2006-07-27 18:50:22 +04:00
|
|
|
};
|
2006-07-27 18:50:25 +04:00
|
|
|
|
|
|
|
function OpenURL(event, node, root)
|
|
|
|
{
|
2006-07-27 18:53:23 +04:00
|
|
|
if ((event.button != 0) || (event.detail != 2)
|
2006-07-27 18:50:25 +04:00
|
|
|
|| (node.nodeName != "treeitem"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (node.getAttribute("container") == "true")
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var url = node.id;
|
2006-07-27 18:53:24 +04:00
|
|
|
if (event.metaKey)
|
|
|
|
// if metaKey is down, open in a new browser window
|
|
|
|
window.openDialog( getBrowserURL(), "_blank", "chrome,all,dialog=no", id );
|
|
|
|
else
|
|
|
|
openTopWin(url);
|
2006-07-27 18:50:26 +04:00
|
|
|
return true;
|
2006-07-27 18:50:25 +04:00
|
|
|
}
|