1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-24 03:42:27 +01: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
* Robert Heckel
* Stefan Krauth
* Giuseppe Guida
I want to say a big <b>THANK YOU</b> for all people which supported this project in this way.
</pre>

View File

@@ -32,11 +32,14 @@ function Bookmarks() //{{{
////////////////////////////////////////////////////////////////////////////////
////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
const history_service = Components.classes["@mozilla.org/browser/nav-history-service;1"]
.getService(Components.interfaces.nsINavHistoryService);
const bookmarks_service = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
.getService(Components.interfaces.nsINavBookmarksService);
const search_service = Components.classes["@mozilla.org/browser/search-service;1"].
getService(Components.interfaces.nsIBrowserSearchService);
const rdf_service = Components.classes["@mozilla.org/rdf/rdf-service;1"].
getService( Components.interfaces.nsIRDFService );
const io_service = Components.classes['@mozilla.org/network/io-service;1']
.getService(Components.interfaces.nsIIOService);
var bookmarks = null;
var keywords = null;
@@ -47,23 +50,48 @@ function Bookmarks() //{{{
function load()
{
// update our bookmark cache
var root = rdf_service.GetResource("NC:BookmarksRoot");
bookmarks = []; // also clear our bookmark cache
keywords = [];
var root = bookmarks_service.bookmarksRoot;
var bmarks = []; // here getAllChildren will store the bookmarks
BookmarksUtils.getAllChildren(root, bmarks);
for (var bm in bmarks)
var folders = [root];
var query = history_service.getNewQuery();
var options = history_service.getNewQueryOptions();
// query.searchTerms = "test";
while (folders.length > 0)
{
if (bmarks[bm][0] && bmarks[bm][1])
bookmarks.push([bmarks[bm][1].Value, bmarks[bm][0].Value ]);
//comment out the next line for now; the bug hasn't been fixed; final version should include the next line
//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
if (bmarks[bm][1] && bmarks[bm][2])
keywords.push([bmarks[bm][2].Value, bmarks[bm][0].Value, bmarks[bm][1].Value]);
folders.shift();
// iterate over the immediate children of this folder
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;
}
/////////////////////////////////////////////////////////////////////////////}}}
////////////////////// PUBLIC SECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
@@ -78,74 +106,42 @@ function Bookmarks() //{{{
return bookmarks;
}
// TODO: keyword support
this.add = function (title, uri, keyword)
this.add = function (title, url, keyword)
{
if (!bookmarks)
load();
folder = rdf_service.GetResource("NC:BookmarksRoot");
var rSource = BookmarksUtils.createBookmark(title, uri, keyword, title);
var selection = BookmarksUtils.getSelectionFromResource(rSource);
var target = BookmarksUtils.getTargetFromFolder(folder);
BookmarksUtils.insertAndCheckSelection("newbookmark", selection, target);
var uri = io_service.newURI(url, null, null);
var id = bookmarks_service.insertBookmark(bookmarks_service.bookmarksRoot, uri, -1, title);
if (id && keyword)
{
bookmarks_service.setKeywordForBookmark(id, keyword);
keywords.unshift([keyword, title, url]);
}
//also update bookmark cache
bookmarks.unshift([uri, title]);
bookmarks.unshift([url, title]);
return true;
}
// NOTE: no idea what it does, it Just Works (TM)
// returns number of deleted bookmarks
this.remove = function(url)
{
var deleted = 0;
if (!url)
return 0;
// gNC_NS for trunk, NC_NS for 1.X
//try { var pNC_NS; pNC_NS = gNC_NS;} catch (err) { pNC_NS = NC_NS;}
if (!BMSVC || !BMDS || !RDF || !gNC_NS) // defined from firefox
return 0;
var uri = io_service.newURI(url, null, null);
var count = {};
var bmarks = bookmarks_service.getBookmarkIdsForURI(uri, count);
var curfolder = RDF.GetResource("NC:BookmarksRoot");
var urlArc = RDF.GetResource(gNC_NS + "URL");
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++;
}
}
}
}
}
for (var i = 0; i < bmarks.length; i++)
bookmarks_service.removeItem(bmarks[i]);
// also update bookmark cache, if we removed at least one bookmark
if (deleted > 0)
if (count.value > 0)
load();
return deleted;
return count.value;
}
// 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"].
getService( Components.interfaces.nsIRDFService );
const global_history_service = Components.classes["@mozilla.org/browser/global-history;2"].
getService(Components.interfaces.nsIRDFDataSource);
// const global_history_service = Components.classes["@mozilla.org/browser/global-history;2"].
// getService(Components.interfaces.nsIRDFDataSource);
var history = null;
@@ -365,40 +361,40 @@ function History() //{{{
{
history = [];
var historytree = document.getElementById("hiddenHistoryTree");
if (!historytree)
return;
if (historytree.hidden)
{
historytree.hidden = false;
historytree.database.AddDataSource(global_history_service);
}
if (!historytree.ref)
historytree.ref = "NC:HistoryRoot";
var nameResource = rdf_service.GetResource(gNC_NS + "Name");
var builder = historytree.builder.QueryInterface(Components.interfaces.nsIXULTreeBuilder);
var count = historytree.view.rowCount;
for (var i = count - 1; i >= 0; i--)
{
var res = builder.getResourceAtIndex(i);
var url = res.Value;
var title;
var titleRes = historytree.database.GetTarget(res, nameResource, true);
if (!titleRes)
continue;
var titleLiteral = titleRes.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (titleLiteral)
title = titleLiteral.Value;
else
title = "";
history.push([url, title]);
}
// var historytree = document.getElementById("hiddenHistoryTree");
// if (!historytree)
// return;
//
// if (historytree.hidden)
// {
// historytree.hidden = false;
// historytree.database.AddDataSource(global_history_service);
// }
//
// if (!historytree.ref)
// historytree.ref = "NC:HistoryRoot";
//
// var nameResource = rdf_service.GetResource(gNC_NS + "Name");
// var builder = historytree.builder.QueryInterface(Components.interfaces.nsIXULTreeBuilder);
//
// var count = historytree.view.rowCount;
// for (var i = count - 1; i >= 0; i--)
// {
// var res = builder.getResourceAtIndex(i);
// var url = res.Value;
// var title;
// var titleRes = historytree.database.GetTarget(res, nameResource, true);
// if (!titleRes)
// continue;
//
// var titleLiteral = titleRes.QueryInterface(Components.interfaces.nsIRDFLiteral);
// if (titleLiteral)
// title = titleLiteral.Value;
// else
// title = "";
//
// history.push([url, title]);
// }
}
/////////////////////////////////////////////////////////////////////////////}}}
@@ -415,6 +411,8 @@ function 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)
{
if (!history)
@@ -429,6 +427,7 @@ function History() //{{{
};
// TODO: better names?
// and move to vimperator.buffer.?
this.stepTo = function(steps)
{
var index = getWebNavigation().sessionHistory.index + steps;

View File

@@ -141,7 +141,9 @@ fieldset.paypal {
#vimperator-bufferwindow, #vimperator-completion, #vimperator-previewwindow {
-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 */

View File

@@ -72,6 +72,15 @@ function Events() //{{{
vimperator.setMode(); // trick to reshow the mode in the command line
}, 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)
{
//alert("titlechanged");
@@ -209,6 +218,11 @@ function Events() //{{{
window.dump("TODO: remove all eventlisteners");
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
@@ -356,12 +370,15 @@ function Events() //{{{
// if (event.target.id == "main-window")
// 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
// also fixes key navigation in menus, etc.
if (key == "<Tab>" || key == "<Return>" || key == "<Space>" || key == "<Up>" || key == "<Down>")
return false;
// XXX: for now only, later: input mappings if form element focused
if (isFormElemFocused())
{

View File

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

View File

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