mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 20:17:58 +01:00
fully objectized History() and Bookmarks()
This commit is contained in:
@@ -1,84 +1,3 @@
|
|||||||
/*
|
|
||||||
* low-level BOOKMARK and HISTORY handling
|
|
||||||
*
|
|
||||||
* these commands try to be generic and don't use any GUI handling code
|
|
||||||
* for higher-level functions look into commands.js
|
|
||||||
*/
|
|
||||||
|
|
||||||
function getProperty( aInput, aArc, DS )
|
|
||||||
{
|
|
||||||
var node;
|
|
||||||
node = DS.GetTarget( aInput, aArc, true );
|
|
||||||
if( node instanceof Components.interfaces.nsIRDFResource ) {
|
|
||||||
return node.Value;
|
|
||||||
}
|
|
||||||
if( node instanceof Components.interfaces.nsIRDFLiteral ) {
|
|
||||||
return node.Value;
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
function addBookmark(title, uri)
|
|
||||||
{
|
|
||||||
folder = RDF.GetResource("NC:BookmarksRoot");
|
|
||||||
var rSource = BookmarksUtils.createBookmark(title, uri, null, title);
|
|
||||||
var selection = BookmarksUtils.getSelectionFromResource(rSource);
|
|
||||||
var target = BookmarksUtils.getTargetFromFolder(folder);
|
|
||||||
BookmarksUtils.insertAndCheckSelection("newbookmark", selection, target);
|
|
||||||
|
|
||||||
//also update bookmark cache
|
|
||||||
g_bookmarks.unshift([uri, title]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* no idea what it does, it Just Works (TM)
|
|
||||||
*
|
|
||||||
* returns number of deleted bookmarks
|
|
||||||
*/
|
|
||||||
function deleteBookmark(url)
|
|
||||||
{
|
|
||||||
var deleted = 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 || ! pNC_NS ) return null;
|
|
||||||
if ( !url) return null; // just in case
|
|
||||||
|
|
||||||
var curfolder = RDF.GetResource("NC:BookmarksRoot");
|
|
||||||
var urlArc = RDF.GetResource(pNC_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, pNC_NS+"Name");
|
|
||||||
uri = BookmarksUtils.getProperty(bmResource, pNC_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
|
|
||||||
if(deleted > 0)
|
|
||||||
bookmarks_loaded = false;
|
|
||||||
|
|
||||||
return deleted;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* call the function like this:
|
/* call the function like this:
|
||||||
var res = new Object();
|
var res = new Object();
|
||||||
parseBookmarkString("-t tag1,tag2 -T title http://www.orf.at", res);
|
parseBookmarkString("-t tag1,tag2 -T title http://www.orf.at", res);
|
||||||
@@ -147,20 +66,140 @@ function parseBookmarkString(str, res)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* also includes methods for dealing with
|
||||||
|
* keywords and search engines
|
||||||
|
*/
|
||||||
function Bookmarks()
|
function Bookmarks()
|
||||||
{
|
{
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
const search_service = Components.classes["@mozilla.org/browser/search-service;1"].
|
const search_service = Components.classes["@mozilla.org/browser/search-service;1"].
|
||||||
getService(Components.interfaces.nsIBrowserSearchService);
|
getService(Components.interfaces.nsIBrowserSearchService);
|
||||||
|
const rdf_service = Components.classes["@mozilla.org/rdf/rdf-service;1"].
|
||||||
|
getService( Components.interfaces.nsIRDFService );
|
||||||
|
|
||||||
|
var bookmarks = null;
|
||||||
|
var keywords = null;
|
||||||
|
|
||||||
|
if(get_pref("preload"))
|
||||||
|
setTimeout(function() { load(); } , 100);
|
||||||
|
|
||||||
|
function load()
|
||||||
|
{
|
||||||
|
// update our bookmark cache
|
||||||
|
var root = rdf_service.GetResource("NC:BookmarksRoot");
|
||||||
|
bookmarks = new Array(); // also clear our bookmark cache
|
||||||
|
keywords = new Array();
|
||||||
|
|
||||||
|
var bmarks = []; // here getAllChildren will store the bookmarks
|
||||||
|
BookmarksUtils.getAllChildren(root, bmarks);
|
||||||
|
for(var bm in bmarks)
|
||||||
|
{
|
||||||
|
if (bmarks[bm][0] && bmarks[bm][1])
|
||||||
|
bookmarks.push([bmarks[bm][1].Value, bmarks[bm][0].Value ]);
|
||||||
|
|
||||||
|
// keyword
|
||||||
|
if(bmarks[bm][1] && bmarks[bm][2])
|
||||||
|
keywords.push([bmarks[bm][2].Value, bmarks[bm][0].Value, bmarks[bm][1].Value]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/*
|
||||||
|
* @return a new Array() of our bookmarks
|
||||||
|
*/
|
||||||
|
this.get = function()
|
||||||
|
{
|
||||||
|
if (!bookmarks)
|
||||||
|
load();
|
||||||
|
|
||||||
|
return bookmarks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @TODO: keyword support
|
||||||
|
*/
|
||||||
|
this.add = function (title, uri, 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);
|
||||||
|
|
||||||
|
//also update bookmark cache
|
||||||
|
bookmarks.unshift([uri, title]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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 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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// also update bookmark cache, if we removed at least one bookmark
|
||||||
|
if(deleted > 0)
|
||||||
|
load();
|
||||||
|
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
/* also ensures that each search engine has a vimperator-friendly alias */
|
/* also ensures that each search engine has a vimperator-friendly alias */
|
||||||
this.getSearchEngines = function()
|
this.getSearchEngines = function()
|
||||||
{
|
{
|
||||||
var search_engines = [];
|
var search_engines = new Array();
|
||||||
var firefox_engines = search_service.getVisibleEngines({ });
|
var firefox_engines = search_service.getVisibleEngines({ });
|
||||||
for(var i in firefox_engines)
|
for(var i in firefox_engines)
|
||||||
{
|
{
|
||||||
@@ -175,35 +214,18 @@ function Bookmarks()
|
|||||||
return search_engines;
|
return search_engines;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: for now g_keywords is generated by get_bookmarks_completion, WILL HAVE TO CHANGE
|
|
||||||
// format of returned array:
|
// format of returned array:
|
||||||
// [keyword, helptext, url]
|
// [keyword, helptext, url]
|
||||||
this.getKeywords = function()
|
this.getKeywords = function()
|
||||||
{
|
{
|
||||||
return g_keywords;
|
if(!keywords)
|
||||||
|
load();
|
||||||
|
|
||||||
|
return keywords;
|
||||||
}
|
}
|
||||||
|
|
||||||
// xxx: probably remove these functions
|
|
||||||
// this.getDefaultEngine = function()
|
|
||||||
// {
|
|
||||||
// return search_service.currentEngine;
|
|
||||||
// }
|
|
||||||
// this.setDefaultEngine = function(alias)
|
|
||||||
// {
|
|
||||||
// var engine = search_service.getEngineByAlias(alias);
|
|
||||||
// if(engine)
|
|
||||||
// search_service.currentEngine = engine;
|
|
||||||
// else
|
|
||||||
// echoerr("Error: Search engine with alias '" + alias + "' does not exist");
|
|
||||||
// }
|
|
||||||
// this.getEngine = function(alias)
|
|
||||||
// {
|
|
||||||
// var engine = search_service.getEngineByAlias(alias);
|
|
||||||
// return engine;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if the engine name is null, it uses the default search engine
|
// if the engine name is null, it uses the default search engine
|
||||||
// returns a url for the search string
|
// @returns the url for the search string
|
||||||
this.getSearchURL = function(text, engine_name)
|
this.getSearchURL = function(text, engine_name)
|
||||||
{
|
{
|
||||||
var url = null;
|
var url = null;
|
||||||
@@ -221,27 +243,114 @@ function Bookmarks()
|
|||||||
}
|
}
|
||||||
else // check for keyword urls
|
else // check for keyword urls
|
||||||
{
|
{
|
||||||
for (var i in g_keywords)
|
if(!keywords)
|
||||||
|
load();
|
||||||
|
|
||||||
|
for (var i in keywords)
|
||||||
{
|
{
|
||||||
if(g_keywords[i][0] == engine_name)
|
if(keywords[i][0] == engine_name)
|
||||||
{
|
{
|
||||||
if (text == null)
|
if (text == null)
|
||||||
text = "";
|
text = "";
|
||||||
url = g_keywords[i][2].replace(/%s/g, encodeURIComponent(text));
|
url = keywords[i][2].replace(/%s/g, encodeURIComponent(text));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we came here, the engine_name is neither
|
// if we came here, the engine_name is neither a search engine or URL
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
logMessage("Bookmarks initialized.");
|
logMessage("Bookmarks initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
var bookmarks = new Bookmarks(); // FIXME, must it really be here? doesn't work in vimperator.js
|
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);
|
||||||
|
|
||||||
|
var history = null;
|
||||||
|
|
||||||
|
if(get_pref("preload"))
|
||||||
|
setTimeout(function() { load(); } , 100);
|
||||||
|
|
||||||
|
function load()
|
||||||
|
{
|
||||||
|
history = new Array();
|
||||||
|
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/*
|
||||||
|
* @return a new Array() of our bookmarks
|
||||||
|
*/
|
||||||
|
this.get = function()
|
||||||
|
{
|
||||||
|
if (!history)
|
||||||
|
load();
|
||||||
|
|
||||||
|
return history;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.add = function (uri, title)
|
||||||
|
{
|
||||||
|
if(!history)
|
||||||
|
load();
|
||||||
|
|
||||||
|
// XXX: check if fast enough
|
||||||
|
history = history.filter(function(elem) {
|
||||||
|
return elem[0] != uri;
|
||||||
|
});
|
||||||
|
// for(var i in history)
|
||||||
|
// {
|
||||||
|
// if(g_history[i][0] == url)
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// g_history.unshift([url, title]);
|
||||||
|
|
||||||
|
history.unshift([uri, title]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
logMessage("History initialized");
|
||||||
|
}
|
||||||
|
|
||||||
Vimperator.prototype.quickmarks = new function()
|
Vimperator.prototype.quickmarks = new function()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1346,7 +1346,7 @@ function stringToURLs(str)
|
|||||||
if (matches && matches[3] && matches[3].length >= 1)
|
if (matches && matches[3] && matches[3].length >= 1)
|
||||||
text = matches[3];
|
text = matches[3];
|
||||||
|
|
||||||
var search_url = bookmarks.getSearchURL(text, alias);
|
var search_url = vimperator.bookmarks.getSearchURL(text, alias);
|
||||||
if (search_url && search_url.length >= 1)
|
if (search_url && search_url.length >= 1)
|
||||||
{
|
{
|
||||||
urls[url] = search_url;
|
urls[url] = search_url;
|
||||||
@@ -1354,7 +1354,7 @@ function stringToURLs(str)
|
|||||||
}
|
}
|
||||||
else // the first word was not a search engine, search for the whole string in the default engine
|
else // the first word was not a search engine, search for the whole string in the default engine
|
||||||
{
|
{
|
||||||
search_url = bookmarks.getSearchURL(urls[url], null);
|
search_url = vimperator.bookmarks.getSearchURL(urls[url], null);
|
||||||
if (search_url && search_url.length >= 1)
|
if (search_url && search_url.length >= 1)
|
||||||
{
|
{
|
||||||
urls[url] = search_url;
|
urls[url] = search_url;
|
||||||
@@ -1515,11 +1515,11 @@ function bmadd(str)
|
|||||||
if(res.title == null) // title could still be null
|
if(res.title == null) // title could still be null
|
||||||
res.title = res.url;
|
res.title = res.url;
|
||||||
|
|
||||||
addBookmark(res.title, res.url);
|
vimperator.bookmarks.add(res.title, res.url);
|
||||||
echo("Bookmark `" + res.title + "' added with url `" + res.url + "'");
|
vimperator.echo("Bookmark `" + res.title + "' added with url `" + res.url + "'");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
echo("Usage: :bmadd [-t \"My Title\"] [-T tag1,tag2] <url>");
|
vimperator.echo("Usage: :bmadd [-t \"My Title\"] [-T tag1,tag2] <url>");
|
||||||
}
|
}
|
||||||
|
|
||||||
function bmdel(str)
|
function bmdel(str)
|
||||||
@@ -1530,11 +1530,11 @@ function bmdel(str)
|
|||||||
if(res.url == null)
|
if(res.url == null)
|
||||||
res.url = getCurrentLocation();
|
res.url = getCurrentLocation();
|
||||||
|
|
||||||
var del = deleteBookmark(res.url);
|
var del = vimperator.bookmarks.remove(res.url);
|
||||||
echo(del + " bookmark(s) with url `" + res.url + "' deleted");
|
vimperator.echo(del + " bookmark(s) with url `" + res.url + "' deleted");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
echo("Usage: :bmdel <url>");
|
vimperator.echo("Usage: :bmdel <url>");
|
||||||
}
|
}
|
||||||
|
|
||||||
function bmshow(filter, fullmode)
|
function bmshow(filter, fullmode)
|
||||||
@@ -1543,7 +1543,7 @@ function bmshow(filter, fullmode)
|
|||||||
openURLsInNewTab("chrome://browser/content/bookmarks/bookmarksPanel.xul", true);
|
openURLsInNewTab("chrome://browser/content/bookmarks/bookmarksPanel.xul", true);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var items = get_bookmark_completions(filter);
|
var items = vimperator.bookmarks.get(filter);
|
||||||
vimperator.previewwindow.show(items);
|
vimperator.previewwindow.show(items);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1553,7 +1553,7 @@ function hsshow(filter, fullmode)
|
|||||||
openURLsInNewTab("chrome://browser/content/history/history-panel.xul", true);
|
openURLsInNewTab("chrome://browser/content/history/history-panel.xul", true);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var items = get_history_completions(filter);
|
var items = vimperator.history.get(filter);
|
||||||
vimperator.previewwindow.show(items);
|
vimperator.previewwindow.show(items);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// array of all our bookmarks
|
// array of all our bookmarks
|
||||||
var g_bookmarks = [];
|
// var g_bookmarks = [];
|
||||||
var bookmarks_loaded = false;
|
// var bookmarks_loaded = false;
|
||||||
|
|
||||||
// array of all our history items
|
// array of all our history items
|
||||||
var g_history = [];
|
// var g_history = [];
|
||||||
var history_loaded = false;
|
// var history_loaded = false;
|
||||||
|
|
||||||
// array of our bookmark keywords
|
// array of our bookmark keywords
|
||||||
var g_keywords = [];
|
// var g_keywords = [];
|
||||||
|
|
||||||
// 2 dimensional: 1st element: what to complete
|
// 2 dimensional: 1st element: what to complete
|
||||||
// 2nd element: help description
|
// 2nd element: help description
|
||||||
@@ -211,9 +211,7 @@ function filter_url_array(urls, filter)/*{{{*/
|
|||||||
|
|
||||||
function get_search_completions(filter)/*{{{*/
|
function get_search_completions(filter)/*{{{*/
|
||||||
{
|
{
|
||||||
//var engines = bookmarks.getSearchEngines();//.concat(bookmarks.getKeywords());
|
var engines = vimperator.bookmarks.getSearchEngines().concat(vimperator.bookmarks.getKeywords());
|
||||||
//var engines = bokmarks.getKeywords();//.concat(bookmarks.getKeywords());
|
|
||||||
var engines = bookmarks.getSearchEngines().concat(bookmarks.getKeywords());
|
|
||||||
|
|
||||||
if (!filter) return engines.map(function($_) {
|
if (!filter) return engines.map(function($_) {
|
||||||
return [$_[0], $_[1]];
|
return [$_[0], $_[1]];
|
||||||
@@ -224,102 +222,17 @@ function get_search_completions(filter)/*{{{*/
|
|||||||
return build_longest_common_substring(mapped, filter);
|
return build_longest_common_substring(mapped, filter);
|
||||||
}/*}}}*/
|
}/*}}}*/
|
||||||
|
|
||||||
function get_history_completions(filter)/*{{{*/
|
function get_history_completions(filter)
|
||||||
{
|
{
|
||||||
var history = document.getElementById("hiddenHistoryTree");
|
var items = vimperator.history.get();
|
||||||
if (!history)
|
return filter_url_array(items, filter);
|
||||||
return [];
|
|
||||||
|
|
||||||
// build our history cache
|
|
||||||
if (history_loaded == false)
|
|
||||||
{
|
|
||||||
if (history.hidden)
|
|
||||||
{
|
|
||||||
history.hidden = false;
|
|
||||||
var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"].getService(Components.interfaces.nsIRDFDataSource);
|
|
||||||
history.database.AddDataSource(globalHistory);
|
|
||||||
g_history = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!history.ref)
|
function get_bookmark_completions(filter)
|
||||||
history.ref = "NC:HistoryRoot";
|
|
||||||
|
|
||||||
const NC_NS = "http://home.netscape.com/NC-rdf#";
|
|
||||||
if (!gRDF)
|
|
||||||
gRDF = Components.classes["@mozilla.org/rdf/rdf-service;1"]
|
|
||||||
.getService(Components.interfaces.nsIRDFService);
|
|
||||||
|
|
||||||
var nameResource = gRDF.GetResource(NC_NS + "Name");
|
|
||||||
var builder = history.builder.QueryInterface(Components.interfaces.nsIXULTreeBuilder);
|
|
||||||
|
|
||||||
var count = history.view.rowCount;
|
|
||||||
for (var i = count-1; i >= 0; i--)
|
|
||||||
{
|
{
|
||||||
var res = builder.getResourceAtIndex(i);
|
var bookmarks = vimperator.bookmarks.get();
|
||||||
var url = res.Value;
|
return filter_url_array(bookmarks, filter);
|
||||||
// var col = history.columns["Name"];
|
|
||||||
//var title = history.view.getCellText(i, col);
|
|
||||||
var title;
|
|
||||||
var titleRes = history.database.GetTarget(res, nameResource, true);
|
|
||||||
if (!titleRes)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var titleLiteral = titleRes.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
|
||||||
if(titleLiteral)
|
|
||||||
title = titleLiteral.Value;
|
|
||||||
else
|
|
||||||
title = "";
|
|
||||||
|
|
||||||
g_history.push([url, title]);
|
|
||||||
}
|
}
|
||||||
history_loaded = true;
|
|
||||||
}
|
|
||||||
return filter_url_array(g_history, filter);
|
|
||||||
}/*}}}*/
|
|
||||||
|
|
||||||
function get_bookmark_completions(filter)/*{{{*/
|
|
||||||
{
|
|
||||||
if (!bookmarks_loaded)
|
|
||||||
{
|
|
||||||
// update our bookmark cache
|
|
||||||
var RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService( Components.interfaces.nsIRDFService );
|
|
||||||
var root = RDF.GetResource( "NC:BookmarksRoot" );
|
|
||||||
var bmarks = []; // here getAllChildren will store the bookmarks
|
|
||||||
g_bookmarks = []; // also clear our bookmark cache
|
|
||||||
// FIXME: wrong location
|
|
||||||
g_keywords = [];
|
|
||||||
|
|
||||||
BookmarksUtils.getAllChildren(root, bmarks);
|
|
||||||
// alert(bookmarks[0].length);
|
|
||||||
for(var i = 0; i < bmarks.length; i++)
|
|
||||||
{
|
|
||||||
if (bmarks[i][0] && bmarks[i][1])
|
|
||||||
{
|
|
||||||
g_bookmarks.push([bmarks[i][1].Value, bmarks[i][0].Value ]);
|
|
||||||
}
|
|
||||||
// for(var j=0; j < bookmarks[i].length; j++)
|
|
||||||
// {
|
|
||||||
// keyword
|
|
||||||
if(bmarks[i][1] && bmarks[i][2])
|
|
||||||
g_keywords.push([bmarks[i][2].Value, bmarks[i][0].Value, bmarks[i][1].Value]);
|
|
||||||
//g_keywords.push([bookmarks[i][2].Value, bookmarks[i][0].Value + " (" + bookmarks[i][1].Value + ")"]);
|
|
||||||
//g_keywords.push([[bookmarks[i][2].Value, bookmarks[i][1].Value], bookmarks[i][0].Value]);
|
|
||||||
//alert("2: " + bookmarks[i][2].Value);
|
|
||||||
// if(bookmarks[i][3])
|
|
||||||
// alert("3: " + bookmarks[i][3].Value);
|
|
||||||
// if(bookmarks[i][4])
|
|
||||||
// alert("4: " + bookmarks[i][4].Value);
|
|
||||||
// if(bookmarks[i][5])
|
|
||||||
// alert("5: " + bookmarks[i][5].Value);
|
|
||||||
//alert("0: " + bookmarks[i][0].Value + " - 1: " + bookmarks[i][1].Value + "- 2:" + bookmarks[i][2].Value);// + "- 3:"+ bookmarks[i][3].Value + "- 4:" + bookmarks[i][4].Value);// + "- 5:" + bookmarks[i][5].Value);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
bookmarks_loaded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return filter_url_array(g_bookmarks, filter);
|
|
||||||
}/*}}}*/
|
|
||||||
|
|
||||||
function get_file_completions(filter)/*{{{*/
|
function get_file_completions(filter)/*{{{*/
|
||||||
{
|
{
|
||||||
@@ -509,8 +422,6 @@ function get_buffer_completions(filter)/*{{{*/
|
|||||||
return build_longest_common_substring(items, filter);
|
return build_longest_common_substring(items, filter);
|
||||||
}/*}}}*/
|
}/*}}}*/
|
||||||
|
|
||||||
|
|
||||||
// return [startindex, [[itemtext, itemhelp],...]]
|
|
||||||
function exTabCompletion(str)
|
function exTabCompletion(str)
|
||||||
{
|
{
|
||||||
var [count, cmd, special, args] = tokenize_ex(str);
|
var [count, cmd, special, args] = tokenize_ex(str);
|
||||||
|
|||||||
@@ -158,6 +158,10 @@ function CommandLine ()
|
|||||||
|
|
||||||
this.echo = function(str)
|
this.echo = function(str)
|
||||||
{
|
{
|
||||||
|
var focused = document.commandDispatcher.focusedElement;
|
||||||
|
if (focused && focused == command_widget.inputField)
|
||||||
|
return;
|
||||||
|
|
||||||
setNormalStyle();
|
setNormalStyle();
|
||||||
setPrompt("");
|
setPrompt("");
|
||||||
setCommand(str);
|
setCommand(str);
|
||||||
@@ -165,6 +169,10 @@ function CommandLine ()
|
|||||||
|
|
||||||
this.echoErr = function(str)
|
this.echoErr = function(str)
|
||||||
{
|
{
|
||||||
|
var focused = document.commandDispatcher.focusedElement;
|
||||||
|
if (focused && focused == command_widget.inputField)
|
||||||
|
return;
|
||||||
|
|
||||||
setErrorStyle();
|
setErrorStyle();
|
||||||
setPrompt("");
|
setPrompt("");
|
||||||
setCommand(str);
|
setCommand(str);
|
||||||
|
|||||||
@@ -167,20 +167,22 @@ window.addEventListener("load", init, false);
|
|||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// init/uninit //////////////////////////////////////////////////// {{{1
|
// init/uninit //////////////////////////////////////////////////// {{{1
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
//function moo() { return ["moo", "x"];};
|
||||||
|
// return [startindex, [[itemtext, itemhelp],...]]
|
||||||
|
|
||||||
function init()
|
function init()
|
||||||
{
|
{
|
||||||
// init the main object
|
// init the main object
|
||||||
vimperator = new Vimperator;
|
vimperator = new Vimperator;
|
||||||
|
|
||||||
// these inner classes are only created here, because outside the init()
|
// these inner classes are created here, because outside the init()
|
||||||
// function, the chrome:// is not ready
|
// function, the chrome:// is not ready
|
||||||
|
Vimperator.prototype.bookmarks = new Bookmarks;
|
||||||
|
Vimperator.prototype.history = new History;
|
||||||
Vimperator.prototype.qm = new QM;
|
Vimperator.prototype.qm = new QM;
|
||||||
// alert("ini3");
|
|
||||||
// Vimperator.prototype.commandline = new CommandLine;
|
// Vimperator.prototype.commandline = new CommandLine;
|
||||||
Vimperator.prototype.search = new Search;
|
Vimperator.prototype.search = new Search;
|
||||||
// alert("ini4");
|
|
||||||
Vimperator.prototype.previewwindow = new InformationList("vimperator-preview-window", { incremental_fill: false, max_items: 10 });
|
Vimperator.prototype.previewwindow = new InformationList("vimperator-preview-window", { incremental_fill: false, max_items: 10 });
|
||||||
// alert("ini5");
|
|
||||||
Vimperator.prototype.bufferwindow = new InformationList("vimperator-buffer-window", { incremental_fill: false, max_items: 10 });
|
Vimperator.prototype.bufferwindow = new InformationList("vimperator-buffer-window", { incremental_fill: false, max_items: 10 });
|
||||||
Vimperator.prototype.statusline = new StatusLine();
|
Vimperator.prototype.statusline = new StatusLine();
|
||||||
Vimperator.prototype.tabs = new Tabs();
|
Vimperator.prototype.tabs = new Tabs();
|
||||||
@@ -188,6 +190,7 @@ function init()
|
|||||||
// XXX: move elsewhere
|
// XXX: move elsewhere
|
||||||
vimperator.registerCallback("submit", vimperator.modes.EX, function(command) { /*vimperator.*/execute(command); } );
|
vimperator.registerCallback("submit", vimperator.modes.EX, function(command) { /*vimperator.*/execute(command); } );
|
||||||
vimperator.registerCallback("complete", vimperator.modes.EX, function(str) { return exTabCompletion(str); } );
|
vimperator.registerCallback("complete", vimperator.modes.EX, function(str) { return exTabCompletion(str); } );
|
||||||
|
//vimperator.registerCallback("complete", vimperator.modes.EX, function(str) { return moo();; } );
|
||||||
|
|
||||||
//status_line = document.getElementById("vim-statusbar");
|
//status_line = document.getElementById("vim-statusbar");
|
||||||
command_line = document.getElementById("vim-commandbar");
|
command_line = document.getElementById("vim-commandbar");
|
||||||
@@ -337,10 +340,6 @@ function init()
|
|||||||
gURLBar.blur();
|
gURLBar.blur();
|
||||||
vimperator.focusContent();
|
vimperator.focusContent();
|
||||||
|
|
||||||
// everything important is done, register a preload handler to speed up first time history cache
|
|
||||||
if(get_pref("preload"))
|
|
||||||
setTimeout(function() { get_url_completions(""); } , 100);
|
|
||||||
|
|
||||||
// firefox preferences which we need to be changed to work well with vimperator
|
// firefox preferences which we need to be changed to work well with vimperator
|
||||||
set_firefox_pref("browser.startup.page", 3); // start with saved session
|
set_firefox_pref("browser.startup.page", 3); // start with saved session
|
||||||
|
|
||||||
@@ -421,13 +420,8 @@ function addEventListeners()
|
|||||||
if (!event.persisted) // only if not bypassing cache
|
if (!event.persisted) // only if not bypassing cache
|
||||||
{
|
{
|
||||||
var url = getCurrentLocation();
|
var url = getCurrentLocation();
|
||||||
var title = document.title;
|
var title = getCurrentTitle(); // not perfect "- Vimperator" in the title
|
||||||
for(var i=0; i<g_history.length; i++)
|
vimperator.history.add(url, title);
|
||||||
{
|
|
||||||
if(g_history[i][0] == url)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
g_history.unshift([url, title]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
, null);
|
, null);
|
||||||
|
|||||||
Reference in New Issue
Block a user