1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-04-03 20:13:34 +02:00

ATTENTION: FIRST FIREFOX 3 alpha7+ ONLY RELEASE!

Ported bookmarks/keywords to Places
Disabled global history for now, will come soon.
This commit is contained in:
Martin Stubenschrott
2007-08-24 04:57:10 +00:00
parent 857cbb0337
commit a0f82aa9a1
6 changed files with 122 additions and 102 deletions

View File

@@ -8,6 +8,7 @@
* Miron Tewfik * Miron Tewfik
* Robert Heckel * Robert Heckel
* Stefan Krauth * Stefan Krauth
* Giuseppe Guida
I want to say a big <b>THANK YOU</b> for all people which supported this project in this way. I want to say a big <b>THANK YOU</b> for all people which supported this project in this way.
</pre> </pre>

View File

@@ -32,11 +32,14 @@ function Bookmarks() //{{{
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
////////////////////// PRIVATE SECTION ///////////////////////////////////////// ////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
const history_service = Components.classes["@mozilla.org/browser/nav-history-service;1"]
const search_service = Components.classes["@mozilla.org/browser/search-service;1"]. .getService(Components.interfaces.nsINavHistoryService);
getService(Components.interfaces.nsIBrowserSearchService); const bookmarks_service = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
const rdf_service = Components.classes["@mozilla.org/rdf/rdf-service;1"]. .getService(Components.interfaces.nsINavBookmarksService);
getService( Components.interfaces.nsIRDFService ); const search_service = Components.classes["@mozilla.org/browser/search-service;1"].
getService(Components.interfaces.nsIBrowserSearchService);
const io_service = Components.classes['@mozilla.org/network/io-service;1']
.getService(Components.interfaces.nsIIOService);
var bookmarks = null; var bookmarks = null;
var keywords = null; var keywords = null;
@@ -47,21 +50,46 @@ function Bookmarks() //{{{
function load() function load()
{ {
// update our bookmark cache // update our bookmark cache
var root = rdf_service.GetResource("NC:BookmarksRoot");
bookmarks = []; // also clear our bookmark cache bookmarks = []; // also clear our bookmark cache
keywords = []; keywords = [];
var root = bookmarks_service.bookmarksRoot;
var bmarks = []; // here getAllChildren will store the bookmarks var folders = [root];
BookmarksUtils.getAllChildren(root, bmarks); var query = history_service.getNewQuery();
for (var bm in bmarks) var options = history_service.getNewQueryOptions();
// query.searchTerms = "test";
while (folders.length > 0)
{ {
if (bmarks[bm][0] && bmarks[bm][1]) //comment out the next line for now; the bug hasn't been fixed; final version should include the next line
bookmarks.push([bmarks[bm][1].Value, bmarks[bm][0].Value ]); //options.setGroupingMode(options.GROUP_BY_FOLDER);
query.setFolders(folders, 1);
var result = history_service.executeQuery(query, options);
result.sortingMode = options.SORT_BY_DATE_DESCENDING;
//result.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING;
var rootNode = result.root;
rootNode.containerOpen = true;
// keyword folders.shift();
if (bmarks[bm][1] && bmarks[bm][2]) // iterate over the immediate children of this folder
keywords.push([bmarks[bm][2].Value, bmarks[bm][0].Value, bmarks[bm][1].Value]); for (var i = 0; i < rootNode.childCount; i ++)
{
var node = rootNode.getChild(i);
//dump("Child " + node.itemId + ": " + node.title + " - " + node.type + "\n");
if (node.type == node.RESULT_TYPE_FOLDER) // folder
folders.push(node.itemId);
else if (node.type == node.RESULT_TYPE_URI) // bookmark
{
bookmarks.push([node.uri, node.title]);
var kw = bookmarks_service.getKeywordForBookmark(node.itemId);
if (kw)
keywords.push([kw, node.title, node.uri]);
}
}
// close a container after using it!
rootNode.containerOpen = false;
} }
return;
} }
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
@@ -78,74 +106,42 @@ function Bookmarks() //{{{
return bookmarks; return bookmarks;
} }
// TODO: keyword support this.add = function (title, url, keyword)
this.add = function (title, uri, keyword)
{ {
if (!bookmarks) if (!bookmarks)
load(); load();
folder = rdf_service.GetResource("NC:BookmarksRoot"); var uri = io_service.newURI(url, null, null);
var rSource = BookmarksUtils.createBookmark(title, uri, keyword, title); var id = bookmarks_service.insertBookmark(bookmarks_service.bookmarksRoot, uri, -1, title);
var selection = BookmarksUtils.getSelectionFromResource(rSource); if (id && keyword)
var target = BookmarksUtils.getTargetFromFolder(folder); {
BookmarksUtils.insertAndCheckSelection("newbookmark", selection, target); bookmarks_service.setKeywordForBookmark(id, keyword);
keywords.unshift([keyword, title, url]);
}
//also update bookmark cache //also update bookmark cache
bookmarks.unshift([uri, title]); bookmarks.unshift([url, title]);
return true; return true;
} }
// NOTE: no idea what it does, it Just Works (TM)
// returns number of deleted bookmarks // returns number of deleted bookmarks
this.remove = function(url) this.remove = function(url)
{ {
var deleted = 0;
if (!url) if (!url)
return 0; return 0;
// gNC_NS for trunk, NC_NS for 1.X var uri = io_service.newURI(url, null, null);
//try { var pNC_NS; pNC_NS = gNC_NS;} catch (err) { pNC_NS = NC_NS;} var count = {};
if (!BMSVC || !BMDS || !RDF || !gNC_NS) // defined from firefox var bmarks = bookmarks_service.getBookmarkIdsForURI(uri, count);
return 0;
var curfolder = RDF.GetResource("NC:BookmarksRoot"); for (var i = 0; i < bmarks.length; i++)
var urlArc = RDF.GetResource(gNC_NS + "URL"); bookmarks_service.removeItem(bmarks[i]);
var urlLiteral = RDF.GetLiteral(url);
if (BMDS.hasArcIn(urlLiteral, urlArc))
{
var bmResources, bmResource, title, uri, type, ptype;
bmResources = BMSVC.GetSources(urlArc, urlLiteral, true);
while (bmResources.hasMoreElements())
{
bmResource = bmResources.getNext();
type = BookmarksUtils.resolveType(bmResource);
if (type != "ImmutableBookmark")
{
ptype = BookmarksUtils.resolveType(BMSVC.getParent(bmResource));
// alert(type);
// if ( type == "Folder") // store the current folder
// curfolder = bmResource;
if ( (type == "Bookmark" || type == "IEFavorite") && ptype != "Livemark")
{
title = BookmarksUtils.getProperty(bmResource, gNC_NS + "Name");
uri = BookmarksUtils.getProperty(bmResource, gNC_NS + "URL");
if (uri == url)
{
RDFC.Init(BMDS, BMSVC.getParent(bmResource));
RDFC.RemoveElement(bmResource, true);
deleted++;
}
}
}
}
}
// also update bookmark cache, if we removed at least one bookmark // also update bookmark cache, if we removed at least one bookmark
if (deleted > 0) if (count.value > 0)
load(); load();
return deleted; return count.value;
} }
// also ensures that each search engine has a Vimperator-friendly alias // also ensures that each search engine has a Vimperator-friendly alias
@@ -353,8 +349,8 @@ function History() //{{{
const rdf_service = Components.classes["@mozilla.org/rdf/rdf-service;1"]. const rdf_service = Components.classes["@mozilla.org/rdf/rdf-service;1"].
getService( Components.interfaces.nsIRDFService ); getService( Components.interfaces.nsIRDFService );
const global_history_service = Components.classes["@mozilla.org/browser/global-history;2"]. // const global_history_service = Components.classes["@mozilla.org/browser/global-history;2"].
getService(Components.interfaces.nsIRDFDataSource); // getService(Components.interfaces.nsIRDFDataSource);
var history = null; var history = null;
@@ -365,40 +361,40 @@ function History() //{{{
{ {
history = []; history = [];
var historytree = document.getElementById("hiddenHistoryTree"); // var historytree = document.getElementById("hiddenHistoryTree");
if (!historytree) // if (!historytree)
return; // return;
//
if (historytree.hidden) // if (historytree.hidden)
{ // {
historytree.hidden = false; // historytree.hidden = false;
historytree.database.AddDataSource(global_history_service); // historytree.database.AddDataSource(global_history_service);
} // }
//
if (!historytree.ref) // if (!historytree.ref)
historytree.ref = "NC:HistoryRoot"; // historytree.ref = "NC:HistoryRoot";
//
var nameResource = rdf_service.GetResource(gNC_NS + "Name"); // var nameResource = rdf_service.GetResource(gNC_NS + "Name");
var builder = historytree.builder.QueryInterface(Components.interfaces.nsIXULTreeBuilder); // var builder = historytree.builder.QueryInterface(Components.interfaces.nsIXULTreeBuilder);
//
var count = historytree.view.rowCount; // var count = historytree.view.rowCount;
for (var i = count - 1; i >= 0; i--) // for (var i = count - 1; i >= 0; i--)
{ // {
var res = builder.getResourceAtIndex(i); // var res = builder.getResourceAtIndex(i);
var url = res.Value; // var url = res.Value;
var title; // var title;
var titleRes = historytree.database.GetTarget(res, nameResource, true); // var titleRes = historytree.database.GetTarget(res, nameResource, true);
if (!titleRes) // if (!titleRes)
continue; // continue;
//
var titleLiteral = titleRes.QueryInterface(Components.interfaces.nsIRDFLiteral); // var titleLiteral = titleRes.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (titleLiteral) // if (titleLiteral)
title = titleLiteral.Value; // title = titleLiteral.Value;
else // else
title = ""; // title = "";
//
history.push([url, title]); // history.push([url, title]);
} // }
} }
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
@@ -415,6 +411,8 @@ function History() //{{{
return history; return history;
} }
// the history is automatically added to the Places global history
// so just update our cached history here
this.add = function (url, title) this.add = function (url, title)
{ {
if (!history) if (!history)
@@ -429,6 +427,7 @@ function History() //{{{
}; };
// TODO: better names? // TODO: better names?
// and move to vimperator.buffer.?
this.stepTo = function(steps) this.stepTo = function(steps)
{ {
var index = getWebNavigation().sessionHistory.index + steps; var index = getWebNavigation().sessionHistory.index + steps;

View File

@@ -141,7 +141,9 @@ fieldset.paypal {
#vimperator-bufferwindow, #vimperator-completion, #vimperator-previewwindow { #vimperator-bufferwindow, #vimperator-completion, #vimperator-previewwindow {
-moz-user-focus: ignore; -moz-user-focus: ignore;
overflow: -moz-scrollbars-none; overflow: -moz-scrollbars-none !important; /* does not seem to work fully */
border-width: 0px !important;
-moz-appearance: none !important; /* prevent an ugly 3D border */
} }
/* the selected item in listboxes is hardly readable without this */ /* the selected item in listboxes is hardly readable without this */

View File

@@ -72,6 +72,15 @@ function Events() //{{{
vimperator.setMode(); // trick to reshow the mode in the command line vimperator.setMode(); // trick to reshow the mode in the command line
}, null); }, null);
// Code for keeping track if a popup is currently active
// XXX: does currently not handle submenus
this.openPopupCount = 0;
this.menuBarActive = 100;
window.addEventListener("popupshown", function() { vimperator.log(++vimperator.events.openPopupCount); vimperator.addMode(null, vimperator.modes.MENU); }, true);
window.addEventListener("popuphidden", function() { vimperator.log(--vimperator.events.openPopupCount); vimperator.removeMode(null, vimperator.modes.MENU); }, true);
window.addEventListener("DOMMenuBarActive", function() { vimperator.log(++vimperator.events.menuBarActive);vimperator.addMode(null, vimperator.modes.MENU); }, true);
window.addEventListener("DOMMenuBarInactive", function() { vimperator.log(--vimperator.events.menuBarActive); vimperator.removeMode(null, vimperator.modes.MENU); }, true);
window.document.addEventListener("DOMTitleChanged", function(event) window.document.addEventListener("DOMTitleChanged", function(event)
{ {
//alert("titlechanged"); //alert("titlechanged");
@@ -209,6 +218,11 @@ function Events() //{{{
window.dump("TODO: remove all eventlisteners"); window.dump("TODO: remove all eventlisteners");
getBrowser().removeProgressListener(this.progressListener); getBrowser().removeProgressListener(this.progressListener);
window.removeEventListener("popupshowing");
window.removeEventListener("popuphidden");
window.removeEventListener("DOMMenuBarActive");
window.removeEventListener("DOMMenuBarInactive");
} }
// This method pushes keys into the event queue from vimperator // This method pushes keys into the event queue from vimperator
@@ -356,12 +370,15 @@ function Events() //{{{
// if (event.target.id == "main-window") // if (event.target.id == "main-window")
// alert("focusContent();"); // alert("focusContent();");
if (vimperator.hasMode(vimperator.modes.MENU))
return false;
// XXX: ugly hack for now pass certain keys to firefox as they are without beeping // XXX: ugly hack for now pass certain keys to firefox as they are without beeping
// also fixes key navigation in menus, etc. // also fixes key navigation in menus, etc.
if (key == "<Tab>" || key == "<Return>" || key == "<Space>" || key == "<Up>" || key == "<Down>") if (key == "<Tab>" || key == "<Return>" || key == "<Space>" || key == "<Up>" || key == "<Down>")
return false; return false;
// XXX: for now only, later: input mappings if form element focused // XXX: for now only, later: input mappings if form element focused
if (isFormElemFocused()) if (isFormElemFocused())
{ {

View File

@@ -49,7 +49,8 @@ const vimperator = (function() //{{{
ESCAPE_ALL_KEYS: 1 << 15, ESCAPE_ALL_KEYS: 1 << 15,
QUICK_HINT: 1 << 16, QUICK_HINT: 1 << 16,
EXTENDED_HINT: 1 << 17, EXTENDED_HINT: 1 << 17,
ALWAYS_HINT: 1 << 18 ALWAYS_HINT: 1 << 18,
MENU: 1 << 19 // a popupmenu is active
} }
var mode_messages = {}; var mode_messages = {};

View File

@@ -19,8 +19,8 @@
<em:targetApplication> <em:targetApplication>
<Description> <Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id> <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>2.0</em:minVersion> <em:minVersion>3.0a7</em:minVersion>
<em:maxVersion>2.0.0.*</em:maxVersion> <em:maxVersion>3.0.0.*</em:maxVersion>
</Description> </Description>
</em:targetApplication> </em:targetApplication>
</Description> </Description>