/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * * 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 the Initial Developer are Copyright (C) 1998 * 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 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 ***** */ /* This is the old bookmarks code, included here for the sake of the bookmarks sidebar panel, which will be fixed to use my new code in .9. In the mean time, this file provides a life line to various functionality. */ var NC_NS = "http://home.netscape.com/NC-rdf#"; var RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; function Init() { var tree = document.getElementById("bookmarksTree"); tree.controllers.appendController(BookmarksController); var children = document.getElementById('treechildren-bookmarks'); tree.selectItem(children.firstChild); tree.focus(); RefreshSort(); } var BookmarksController = { supportsCommand: function(command) { switch(command) { case "cmd_undo": case "cmd_redo": return false; case "cmd_cut": case "cmd_copy": case "cmd_paste": case "cmd_delete": case "cmd_selectAll": return true; default: return false; } }, isCommandEnabled: function(command) { switch(command) { case "cmd_undo": case "cmd_redo": return false; case "cmd_cut": case "cmd_copy": case "cmd_paste": case "cmd_delete": case "cmd_selectAll": return true; default: return false; } }, doCommand: function(command) { switch(command) { case "cmd_undo": case "cmd_redo": break; case "cmd_cut": doCut(); break; case "cmd_copy": doCopy(); break; case "cmd_paste": doPaste(); break; case "cmd_delete": doDelete(); break; case "cmd_selectAll": doSelectAll(); break; } }, onEvent: function(event) { // On blur events set the menu item texts back to the normal values /*if (event == 'blur' ) { goSetMenuValue('cmd_undo', 'valueDefault'); goSetMenuValue('cmd_redo', 'valueDefault'); }*/ } }; function CommandUpdate_Bookmarks() { //goUpdateCommand('button_delete'); // get selection info from dir pane /* var oneAddressBookSelected = false; if ( dirTree && dirTree.selectedItems && (dirTree.selectedItems.length == 1) ) oneAddressBookSelected = true; // get selection info from results pane var selectedCards = GetSelectedAddresses(); var oneOrMoreCardsSelected = false; if ( selectedCards ) oneOrMoreCardsSelected = true; */ // set commands to enabled / disabled //goSetCommandEnabled('cmd_PrintCard', oneAddressBookSelected); goSetCommandEnabled('bm_cmd_find', true/*oneAddressBookSelected*/); } function copySelectionToClipboard() { var treeNode = document.getElementById("bookmarksTree"); if (!treeNode) return false; var select_list = treeNode.selectedItems; if (!select_list) return false; if (select_list.length < 1) return false; var rdf_uri = "@mozilla.org/rdf/rdf-service;1" var RDF = Components.classes[rdf_uri].getService(); RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService); if (!RDF) return false; var Bookmarks = RDF.GetDataSource("rdf:bookmarks"); if (!Bookmarks) return false; var nameRes = RDF.GetResource(NC_NS + "Name"); if (!nameRes) return false; // Build a url that encodes all the select nodes // as well as their parent nodes var url = ""; var text = ""; var html = ""; for (var nodeIndex = 0; nodeIndex < select_list.length; nodeIndex++) { var node = select_list[nodeIndex]; if (!node) continue; var ID = getAbsoluteID("bookmarksTree", node); if (!ID) continue; var IDRes = RDF.GetResource(ID); if (!IDRes) continue; var nameNode = Bookmarks.GetTarget(IDRes, nameRes, true); var theName = ""; if (nameNode) nameNode = nameNode.QueryInterface(Components.interfaces.nsIRDFLiteral); if (nameNode) theName = nameNode.Value; url += "ID:{" + ID + "};"; url += "NAME:{" + theName + "};"; if (node.getAttribute("container") == "true") { var type = node.getAttribute("type"); if (type == NC_NS + "BookmarkSeparator") { // Note: can't encode separators in text, just html html += "
"; } else { text += ID + "\r"; html += ""; if (theName != "") { html += theName; } html += "
";
}
}
}
if (url == "") return false;
// get some useful components
var trans_uri = "@mozilla.org/widget/transferable;1";
var trans = Components.classes[trans_uri].createInstance();
if (trans) trans = trans.QueryInterface(Components.interfaces.nsITransferable);
if (!trans) return false;
var clip_uri = "@mozilla.org/widget/clipboard;1";
var clip = Components.classes[clip_uri].getService();
if (clip) clip = clip.QueryInterface(Components.interfaces.nsIClipboard);
if (!clip) return false;
clip.emptyClipboard(Components.interfaces.nsIClipboard.kGlobalClipboard);
// save bookmark's ID
trans.addDataFlavor("moz/bookmarkclipboarditem");
var data_uri = "@mozilla.org/supports-wstring;1";
var data = Components.classes[data_uri].createInstance();
if (data) {
data = data.QueryInterface(Components.interfaces.nsISupportsWString);
}
if (!data) return false;
data.data = url;
// double byte data
trans.setTransferData("moz/bookmarkclipboarditem", data, url.length*2);
if (text != "")
{
trans.addDataFlavor("text/unicode");
var textData_uri = "@mozilla.org/supports-wstring;1";
var textData = Components.classes[textData_uri].createInstance();
if (textData) textData = textData.QueryInterface(Components.interfaces.nsISupportsWString);
if (!textData) return false;
textData.data = text;
// double byte data
trans.setTransferData("text/unicode", textData, text.length*2);
}
if (html != "")
{
trans.addDataFlavor("text/html");
var wstring_uri = "@mozilla.org/supports-wstring;1";
var htmlData = Components.classes[wstring_uri].createInstance();
if (htmlData) {
var wstring_interface = Components.interfaces.nsISupportsWString;
htmlData = htmlData.QueryInterface(wstring_interface);
}
if (!htmlData) return false;
htmlData.data = html;
// double byte data
trans.setTransferData("text/html", htmlData, html.length*2);
}
clip.setData(trans, null,
Components.interfaces.nsIClipboard.kGlobalClipboard);
return true;
}
function doCut()
{
if (copySelectionToClipboard() == true) {
doDelete(false);
}
return true;
}
function doCopy()
{
copySelectionToClipboard();
return true;
}
function doPaste()
{
var treeNode = document.getElementById("bookmarksTree");
if (!treeNode) return false;
var select_list = treeNode.selectedItems;
if (!select_list) return false;
if (select_list.length != 1) return false;
var pasteNodeID = select_list[0].getAttribute("id");
var isContainerFlag = (select_list[0].getAttribute("container") == "true");
var clip_uri = "@mozilla.org/widget/clipboard;1";
var clip = Components.classes[clip_uri].getService();
if (clip) clip = clip.QueryInterface(Components.interfaces.nsIClipboard);
if (!clip) return false;
var trans_uri = "@mozilla.org/widget/transferable;1";
var trans = Components.classes[trans_uri].createInstance();
if (trans) {
trans = trans.QueryInterface(Components.interfaces.nsITransferable);
}
if (!trans) return false;
trans.addDataFlavor("moz/bookmarkclipboarditem");
clip.getData(trans, Components.interfaces.nsIClipboard.kGlobalClipboard);
var data = new Object();
var dataLen = new Object();
trans.getTransferData("moz/bookmarkclipboarditem", data, dataLen);
if (data) {
var data_interface = Components.interfaces.nsISupportsWString
data = data.value.QueryInterface(data_interface);
}
var url = null;
// double byte data
if (data) url = data.data.substring(0, dataLen.value / 2);
if (!url) return false;
var strings = url.split(";");
if (!strings) return false;
var rdf_uri = "@mozilla.org/rdf/rdf-service;1";
var RDF = Components.classes[rdf_uri].getService();
RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
if (!RDF) return false;
var rdfc_uri = "@mozilla.org/rdf/container;1";
var RDFC = Components.classes[rdfc_uri].getService();
RDFC = RDFC.QueryInterface(Components.interfaces.nsIRDFContainer);
if (!RDFC) return false;
var Bookmarks = RDF.GetDataSource("rdf:bookmarks");
if (!Bookmarks) return false;
var nameRes = RDF.GetResource(NC_NS + "Name");
if (!nameRes) return false;
pasteNodeRes = RDF.GetResource(pasteNodeID);
if (!pasteNodeRes) return false;
var pasteContainerRes = null;
var pasteNodeIndex = -1;
if (isContainerFlag == true)
{
pasteContainerRes = pasteNodeRes;
}
else
{
var parID = select_list[0].parentNode.parentNode.getAttribute("ref");
if (!parID) {
parID = select_list[0].parentNode.parentNode.getAttribute("id");
}
if (!parID) return false;
pasteContainerRes = RDF.GetResource(parID);
if (!pasteContainerRes) return false;
}
RDFC.Init(Bookmarks, pasteContainerRes);
if (isContainerFlag == false)
{
pasteNodeIndex = RDFC.IndexOf(pasteNodeRes);
if (pasteNodeIndex < 0) return false; // how did that happen?
}
var typeRes = RDF.GetResource(RDF_NS + "type");
if (!typeRes) return false;
var bmTypeRes = RDF.GetResource(NC_NS + "Bookmark");
if (!bmTypeRes) return false;
var dirty = false;
for (var x=0; x