mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 21:17:59 +01:00
use the singleton construction idiom for all top level modules and convert all
identifiers to camel case
This commit is contained in:
2
NEWS
2
NEWS
@@ -53,7 +53,7 @@
|
||||
* added a visual bell and replaced 'beep' with 'visualbell'
|
||||
* added vimperator logo (can be seen in the addons manager)
|
||||
* added 'hlsearch','incsearch', 'ignorecase' and 'smartcase' options
|
||||
* many small bug fixes and enhancments
|
||||
* many small bug fixes and enhancements
|
||||
|
||||
2007-09-03:
|
||||
* version 0.5.1
|
||||
|
||||
@@ -33,21 +33,21 @@ vimperator.Bookmarks = function () //{{{
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
const search_service = Components.classes["@mozilla.org/browser/search-service;1"].
|
||||
const searchService = 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 rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"].
|
||||
getService(Components.interfaces.nsIRDFService);
|
||||
|
||||
var bookmarks = null;
|
||||
var keywords = null;
|
||||
|
||||
if (vimperator.options["preload"])
|
||||
setTimeout(function () { load(); } , 100);
|
||||
setTimeout(function () { load(); }, 100);
|
||||
|
||||
function load()
|
||||
{
|
||||
// update our bookmark cache
|
||||
var root = rdf_service.GetResource("NC:BookmarksRoot");
|
||||
var root = rdfService.GetResource("NC:BookmarksRoot");
|
||||
bookmarks = []; // also clear our bookmark cache
|
||||
keywords = [];
|
||||
|
||||
@@ -56,15 +56,15 @@ vimperator.Bookmarks = function () //{{{
|
||||
|
||||
// getAllChildren(root) ignores the BTF
|
||||
// NOTE: there's probably a better way to do this...
|
||||
var btf_bmarks = [];
|
||||
BookmarksUtils.getAllChildren(BMSVC.getBookmarksToolbarFolder(), btf_bmarks);
|
||||
var btfBmarks = [];
|
||||
BookmarksUtils.getAllChildren(BMSVC.getBookmarksToolbarFolder(), btfBmarks);
|
||||
|
||||
bmarks = bmarks.concat(btf_bmarks);
|
||||
bmarks = bmarks.concat(btfBmarks);
|
||||
|
||||
for (var i = 0; i < bmarks.length; i++)
|
||||
{
|
||||
if (bmarks[i][0] && bmarks[i][1])
|
||||
bookmarks.push([bmarks[i][1].Value, bmarks[i][0].Value ]);
|
||||
bookmarks.push([bmarks[i][1].Value, bmarks[i][0].Value]);
|
||||
|
||||
// keyword
|
||||
if (bmarks[i][1] && bmarks[i][2])
|
||||
@@ -76,23 +76,25 @@ vimperator.Bookmarks = function () //{{{
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
return {
|
||||
|
||||
// FIXME: add filtering here rather than having to calling
|
||||
// get_bookmark_completions()
|
||||
this.get = function ()
|
||||
// v.completion.bookmark()
|
||||
get: function ()
|
||||
{
|
||||
if (!bookmarks)
|
||||
load();
|
||||
|
||||
return bookmarks;
|
||||
}
|
||||
},
|
||||
|
||||
// TODO: keyword support
|
||||
this.add = function (title, uri, keyword)
|
||||
add: function (title, uri, keyword)
|
||||
{
|
||||
if (!bookmarks)
|
||||
load();
|
||||
|
||||
folder = rdf_service.GetResource("NC:BookmarksRoot");
|
||||
folder = rdfService.GetResource("NC:BookmarksRoot");
|
||||
var rSource = BookmarksUtils.createBookmark(title, uri, keyword, title);
|
||||
var selection = BookmarksUtils.getSelectionFromResource(rSource);
|
||||
var target = BookmarksUtils.getTargetFromFolder(folder);
|
||||
@@ -101,11 +103,11 @@ vimperator.Bookmarks = function () //{{{
|
||||
//also update bookmark cache
|
||||
bookmarks.unshift([uri, title]);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
// NOTE: no idea what it does, it Just Works (TM)
|
||||
// returns number of deleted bookmarks
|
||||
this.remove = function (url)
|
||||
remove: function (url)
|
||||
{
|
||||
var deleted = 0;
|
||||
if (!url)
|
||||
@@ -131,9 +133,9 @@ vimperator.Bookmarks = function () //{{{
|
||||
{
|
||||
ptype = BookmarksUtils.resolveType(BMSVC.getParent(bmResource));
|
||||
// alert(type);
|
||||
// if ( type == "Folder") // store the current folder
|
||||
// if (type == "Folder") // store the current folder
|
||||
// curfolder = bmResource;
|
||||
if ( (type == "Bookmark" || type == "IEFavorite") && ptype != "Livemark")
|
||||
if ((type == "Bookmark" || type == "IEFavorite") && ptype != "Livemark")
|
||||
{
|
||||
title = BookmarksUtils.getProperty(bmResource, gNC_NS + "Name");
|
||||
uri = BookmarksUtils.getProperty(bmResource, gNC_NS + "URL");
|
||||
@@ -154,73 +156,74 @@ vimperator.Bookmarks = function () //{{{
|
||||
load();
|
||||
|
||||
return deleted;
|
||||
}
|
||||
},
|
||||
|
||||
// also ensures that each search engine has a Vimperator-friendly alias
|
||||
this.getSearchEngines = function ()
|
||||
getSearchEngines: function ()
|
||||
{
|
||||
var search_engines = [];
|
||||
var firefox_engines = search_service.getVisibleEngines({ });
|
||||
for (var i in firefox_engines)
|
||||
var searchEngines = [];
|
||||
var firefoxEngines = searchService.getVisibleEngines({ });
|
||||
for (var i in firefoxEngines)
|
||||
{
|
||||
var alias = firefox_engines[i].alias;
|
||||
var alias = firefoxEngines[i].alias;
|
||||
if (!alias || !alias.match(/^[a-z0-9_-]+$/))
|
||||
alias = firefox_engines[i].name.replace(/^\W*([a-zA-Z_-]+).*/, "$1").toLowerCase();
|
||||
alias = firefoxEngines[i].name.replace(/^\W*([a-zA-Z_-]+).*/, "$1").toLowerCase();
|
||||
if (!alias)
|
||||
alias = "search"; // for search engines which we can't find a suitable alias
|
||||
|
||||
// make sure we can use search engines which would have the same alias (add numbers at the end)
|
||||
var newalias = alias;
|
||||
var newAlias = alias;
|
||||
for (var j = 1; j <= 10; j++) // <=10 is intentional
|
||||
{
|
||||
if (!search_engines.some(function (item) { return (item[0] == newalias); }))
|
||||
if (!searchEngines.some(function (item) { return (item[0] == newAlias); }))
|
||||
break;
|
||||
|
||||
newalias = alias + j;
|
||||
newAlias = alias + j;
|
||||
}
|
||||
// only write when it changed, writes are really slow
|
||||
if (firefox_engines[i].alias != newalias)
|
||||
firefox_engines[i].alias = newalias;
|
||||
if (firefoxEngines[i].alias != newAlias)
|
||||
firefoxEngines[i].alias = newAlias;
|
||||
|
||||
search_engines.push([firefox_engines[i].alias, firefox_engines[i].description]);
|
||||
searchEngines.push([firefoxEngines[i].alias, firefoxEngines[i].description]);
|
||||
}
|
||||
|
||||
return search_engines;
|
||||
}
|
||||
return searchEngines;
|
||||
},
|
||||
|
||||
// TODO: add filtering
|
||||
// format of returned array:
|
||||
// [keyword, helptext, url]
|
||||
this.getKeywords = function ()
|
||||
getKeywords: function ()
|
||||
{
|
||||
if (!keywords)
|
||||
load();
|
||||
|
||||
return keywords;
|
||||
}
|
||||
},
|
||||
|
||||
// if @param engine_name is null, it uses the default search engine
|
||||
// if @param engineName is null, it uses the default search engine
|
||||
// @returns the url for the search string
|
||||
// if the search also requires a postdata, [url, postdata] is returned
|
||||
this.getSearchURL = function (text, engine_name)
|
||||
// if the search also requires a postData, [url, postData] is returned
|
||||
getSearchURL: function (text, engineName)
|
||||
{
|
||||
var url = null;
|
||||
var postdata = null;
|
||||
if (!engine_name)
|
||||
engine_name = vimperator.options["defsearch"];
|
||||
var postData = null;
|
||||
if (!engineName)
|
||||
engineName = vimperator.options["defsearch"];
|
||||
|
||||
// we need to make sure our custom alias have been set, even if the user
|
||||
// did not :open <tab> once before
|
||||
this.getSearchEngines();
|
||||
|
||||
// first checks the search engines for a match
|
||||
var engine = search_service.getEngineByAlias(engine_name);
|
||||
var engine = searchService.getEngineByAlias(engineName);
|
||||
if (engine)
|
||||
{
|
||||
if (text)
|
||||
{
|
||||
var submission = engine.getSubmission(text, null);
|
||||
url = submission.uri.spec;
|
||||
postdata = submission.postData;
|
||||
postData = submission.postData;
|
||||
}
|
||||
else
|
||||
url = engine.searchForm;
|
||||
@@ -232,7 +235,7 @@ vimperator.Bookmarks = function () //{{{
|
||||
|
||||
for (var i in keywords)
|
||||
{
|
||||
if (keywords[i][0] == engine_name)
|
||||
if (keywords[i][0] == engineName)
|
||||
{
|
||||
if (text == null)
|
||||
text = "";
|
||||
@@ -242,14 +245,14 @@ vimperator.Bookmarks = function () //{{{
|
||||
}
|
||||
}
|
||||
|
||||
// if we came here, the engine_name is neither a search engine or URL
|
||||
if (postdata)
|
||||
return [url, postdata];
|
||||
// if we came here, the engineName is neither a search engine or URL
|
||||
if (postData)
|
||||
return [url, postData];
|
||||
else
|
||||
return url; // can be null
|
||||
}
|
||||
},
|
||||
|
||||
this.list = function (filter, fullmode)
|
||||
list: function (filter, fullmode)
|
||||
{
|
||||
if (fullmode)
|
||||
{
|
||||
@@ -257,7 +260,7 @@ vimperator.Bookmarks = function () //{{{
|
||||
}
|
||||
else
|
||||
{
|
||||
var items = vimperator.completion.get_bookmark_completions(filter);
|
||||
var items = vimperator.completion.bookmark(filter);
|
||||
|
||||
if (items.length == 0)
|
||||
{
|
||||
@@ -283,65 +286,65 @@ vimperator.Bookmarks = function () //{{{
|
||||
|
||||
vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// res = parseBookmarkString("-t tag1,tag2 -T title http://www.orf.at");
|
||||
// res.tags is an array of tags
|
||||
// res.title is the title or "" if no one was given
|
||||
// res.url is the url as a string
|
||||
// returns null, if parsing failed
|
||||
this.parseBookmarkString = function (str)
|
||||
parseBookmarkString: function (str)
|
||||
{
|
||||
var res = {};
|
||||
res.tags = [];
|
||||
res.title = null;
|
||||
res.url = null;
|
||||
|
||||
var re_title = /^\s*((-t|--title)\s+(\w+|\".*\"))(.*)/;
|
||||
var re_tags = /^\s*((-T|--tags)\s+((\w+)(,\w+)*))(.*)/;
|
||||
var re_url = /^\s*(\".+\"|\S+)(.*)/;
|
||||
var reTitle = /^\s*((-t|--title)\s+(\w+|\".*\"))(.*)/;
|
||||
var reTags = /^\s*((-T|--tags)\s+((\w+)(,\w+)*))(.*)/;
|
||||
var reUrl = /^\s*(\".+\"|\S+)(.*)/;
|
||||
|
||||
var match_tags = null;
|
||||
var match_title = null;
|
||||
var match_url = null;
|
||||
var matchTags = null;
|
||||
var matchTitle = null;
|
||||
var matchUrl = null;
|
||||
|
||||
while (!str.match(/^\s*$/))
|
||||
{
|
||||
// first check for --tags
|
||||
match_tags = str.match(re_tags);
|
||||
if (match_tags != null)
|
||||
matchTags = str.match(reTags);
|
||||
if (matchTags != null)
|
||||
{
|
||||
str = match_tags[match_tags.length - 1]; // the last captured parenthesis is the rest of the string
|
||||
tags = match_tags[3].split(",");
|
||||
str = matchTags[matchTags.length - 1]; // the last captured parenthesis is the rest of the string
|
||||
tags = matchTags[3].split(",");
|
||||
res.tags = res.tags.concat(tags);
|
||||
}
|
||||
else // then for --titles
|
||||
{
|
||||
|
||||
match_title = str.match(re_title);
|
||||
if (match_title != null)
|
||||
matchTitle = str.match(reTitle);
|
||||
if (matchTitle != null)
|
||||
{
|
||||
// only one title allowed
|
||||
if (res.title != null)
|
||||
return null;
|
||||
|
||||
str = match_title[match_title.length - 1]; // the last captured parenthesis is the rest of the string
|
||||
var title = match_title[3];
|
||||
str = matchTitle[matchTitle.length - 1]; // the last captured parenthesis is the rest of the string
|
||||
var title = matchTitle[3];
|
||||
if (title.charAt(0) == '"')
|
||||
title = title.substring(1, title.length - 1);
|
||||
res.title = title;
|
||||
}
|
||||
else // at last check for a URL
|
||||
{
|
||||
match_url = str.match(re_url);
|
||||
if (match_url != null)
|
||||
matchUrl = str.match(reUrl);
|
||||
if (matchUrl != null)
|
||||
{
|
||||
// only one url allowed
|
||||
if (res.url != null)
|
||||
return null;
|
||||
|
||||
str = match_url[match_url.length - 1]; // the last captured parenthesis is the rest of the string
|
||||
url = match_url[1];
|
||||
str = matchUrl[matchUrl.length - 1]; // the last captured parenthesis is the rest of the string
|
||||
url = matchUrl[1];
|
||||
if (url.charAt(0) == '"')
|
||||
url = url.substring(1, url.length - 1);
|
||||
res.url = url;
|
||||
@@ -353,8 +356,10 @@ vimperator.Bookmarks = function () //{{{
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
};
|
||||
//}}}
|
||||
} //}}}
|
||||
}; //}}}
|
||||
|
||||
vimperator.History = function () //{{{
|
||||
{
|
||||
@@ -362,15 +367,15 @@ vimperator.History = function () //{{{
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
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"].
|
||||
const rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"].
|
||||
getService(Components.interfaces.nsIRDFService);
|
||||
const globalHistoryService = Components.classes["@mozilla.org/browser/global-history;2"].
|
||||
getService(Components.interfaces.nsIRDFDataSource);
|
||||
|
||||
var history = null;
|
||||
|
||||
if (vimperator.options["preload"])
|
||||
setTimeout(function () { load(); } , 100);
|
||||
setTimeout(function () { load(); }, 100);
|
||||
|
||||
function load()
|
||||
{
|
||||
@@ -383,13 +388,13 @@ vimperator.History = function () //{{{
|
||||
if (historytree.hidden)
|
||||
{
|
||||
historytree.hidden = false;
|
||||
historytree.database.AddDataSource(global_history_service);
|
||||
historytree.database.AddDataSource(globalHistoryService);
|
||||
}
|
||||
|
||||
if (!historytree.ref)
|
||||
historytree.ref = "NC:HistoryRoot";
|
||||
|
||||
var nameResource = rdf_service.GetResource(gNC_NS + "Name");
|
||||
var nameResource = rdfService.GetResource(gNC_NS + "Name");
|
||||
var builder = historytree.builder.QueryInterface(Components.interfaces.nsIXULTreeBuilder);
|
||||
|
||||
var count = historytree.view.rowCount;
|
||||
@@ -416,17 +421,19 @@ vimperator.History = function () //{{{
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
return {
|
||||
|
||||
// FIXME: add filtering here rather than having to call
|
||||
// get_bookmark_completions()
|
||||
this.get = function ()
|
||||
// v.completion.history()
|
||||
get: function ()
|
||||
{
|
||||
if (!history)
|
||||
load();
|
||||
|
||||
return history;
|
||||
}
|
||||
},
|
||||
|
||||
this.add = function (url, title)
|
||||
add: function (url, title)
|
||||
{
|
||||
if (!history)
|
||||
load();
|
||||
@@ -437,11 +444,11 @@ vimperator.History = function () //{{{
|
||||
|
||||
history.unshift([url, title]);
|
||||
return true;
|
||||
};
|
||||
},
|
||||
|
||||
// TODO: better names?
|
||||
// and move to vimperator.buffer.?
|
||||
this.stepTo = function (steps)
|
||||
stepTo: function (steps)
|
||||
{
|
||||
var index = getWebNavigation().sessionHistory.index + steps;
|
||||
|
||||
@@ -453,9 +460,9 @@ vimperator.History = function () //{{{
|
||||
{
|
||||
vimperator.beep();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
this.goToStart = function ()
|
||||
goToStart: function ()
|
||||
{
|
||||
var index = getWebNavigation().sessionHistory.index;
|
||||
|
||||
@@ -466,9 +473,9 @@ vimperator.History = function () //{{{
|
||||
}
|
||||
|
||||
getWebNavigation().gotoIndex(0);
|
||||
}
|
||||
},
|
||||
|
||||
this.goToEnd = function ()
|
||||
goToEnd: function ()
|
||||
{
|
||||
var index = getWebNavigation().sessionHistory.index;
|
||||
var max = getWebNavigation().sessionHistory.count - 1;
|
||||
@@ -480,9 +487,9 @@ vimperator.History = function () //{{{
|
||||
}
|
||||
|
||||
getWebNavigation().gotoIndex(max);
|
||||
}
|
||||
},
|
||||
|
||||
this.list = function (filter, fullmode)
|
||||
list: function (filter, fullmode)
|
||||
{
|
||||
if (fullmode)
|
||||
{
|
||||
@@ -490,7 +497,7 @@ vimperator.History = function () //{{{
|
||||
}
|
||||
else
|
||||
{
|
||||
var items = vimperator.completion.get_history_completions(filter);
|
||||
var items = vimperator.completion.history(filter);
|
||||
|
||||
if (items.length == 0)
|
||||
{
|
||||
@@ -516,8 +523,10 @@ vimperator.History = function () //{{{
|
||||
vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
//}}}
|
||||
} //}}}
|
||||
}; //}}}
|
||||
|
||||
vimperator.Marks = function () //{{{
|
||||
{
|
||||
@@ -525,24 +534,24 @@ vimperator.Marks = function () //{{{
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
var local_marks = {};
|
||||
var url_marks = {};
|
||||
var pending_jumps = [];
|
||||
var appcontent = document.getElementById("appcontent");
|
||||
var localMarks = {};
|
||||
var urlMarks = {};
|
||||
var pendingJumps = [];
|
||||
var appContent = document.getElementById("appcontent");
|
||||
|
||||
if (appcontent)
|
||||
appcontent.addEventListener("load", onPageLoad, true);
|
||||
if (appContent)
|
||||
appContent.addEventListener("load", onPageLoad, true);
|
||||
|
||||
function onPageLoad(event)
|
||||
{
|
||||
var win = event.originalTarget.defaultView;
|
||||
for (var i = 0, length = pending_jumps.length; i < length; i++)
|
||||
for (var i = 0, length = pendingJumps.length; i < length; i++)
|
||||
{
|
||||
var mark = pending_jumps[i];
|
||||
var mark = pendingJumps[i];
|
||||
if (win.location.href == mark.location)
|
||||
{
|
||||
win.scrollTo(mark.position.x * win.scrollMaxX, mark.position.y * win.scrollMaxY);
|
||||
pending_jumps.splice(i, 1);
|
||||
pendingJumps.splice(i, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -550,17 +559,17 @@ vimperator.Marks = function () //{{{
|
||||
|
||||
function removeLocalMark(mark)
|
||||
{
|
||||
if (mark in local_marks)
|
||||
if (mark in localMarks)
|
||||
{
|
||||
var win = window.content;
|
||||
for (var i = 0; i < local_marks[mark].length; i++)
|
||||
for (var i = 0; i < localMarks[mark].length; i++)
|
||||
{
|
||||
if (local_marks[mark][i].location == win.location.href)
|
||||
if (localMarks[mark][i].location == win.location.href)
|
||||
{
|
||||
vimperator.log("Deleting local mark: " + mark + " | " + local_marks[mark][i].location + " | (" + local_marks[mark][i].position.x + ", " + local_marks[mark][i].position.y + ") | tab: " + vimperator.tabs.index(local_marks[mark][i].tab), 5);
|
||||
local_marks[mark].splice(i, 1);
|
||||
if (local_marks[mark].length == 0)
|
||||
delete local_marks[mark];
|
||||
vimperator.log("Deleting local mark: " + mark + " | " + localMarks[mark][i].location + " | (" + localMarks[mark][i].position.x + ", " + localMarks[mark][i].position.y + ") | tab: " + vimperator.tabs.index(localMarks[mark][i].tab), 5);
|
||||
localMarks[mark].splice(i, 1);
|
||||
if (localMarks[mark].length == 0)
|
||||
delete localMarks[mark];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -569,10 +578,10 @@ vimperator.Marks = function () //{{{
|
||||
|
||||
function removeURLMark(mark)
|
||||
{
|
||||
if (mark in url_marks)
|
||||
if (mark in urlMarks)
|
||||
{
|
||||
vimperator.log("Deleting URL mark: " + mark + " | " + url_marks[mark].location + " | (" + url_marks[mark].position.x + ", " + url_marks[mark].position.y + ") | tab: " + vimperator.tabs.index(url_marks[mark].tab), 5);
|
||||
delete url_marks[mark];
|
||||
vimperator.log("Deleting URL mark: " + mark + " | " + urlMarks[mark].location + " | (" + urlMarks[mark].position.x + ", " + urlMarks[mark].position.y + ") | tab: " + vimperator.tabs.index(urlMarks[mark].tab), 5);
|
||||
delete urlMarks[mark];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -591,12 +600,12 @@ vimperator.Marks = function () //{{{
|
||||
// local marks
|
||||
var lmarks = [];
|
||||
|
||||
for (var mark in local_marks)
|
||||
for (var mark in localMarks)
|
||||
{
|
||||
for (var i = 0; i < local_marks[mark].length; i++)
|
||||
for (var i = 0; i < localMarks[mark].length; i++)
|
||||
{
|
||||
if (local_marks[mark][i].location == window.content.location.href)
|
||||
lmarks.push([mark, local_marks[mark][i]]);
|
||||
if (localMarks[mark][i].location == window.content.location.href)
|
||||
lmarks.push([mark, localMarks[mark][i]]);
|
||||
}
|
||||
}
|
||||
lmarks.sort();
|
||||
@@ -604,8 +613,8 @@ vimperator.Marks = function () //{{{
|
||||
// URL marks
|
||||
var umarks = [];
|
||||
|
||||
for (var mark in url_marks)
|
||||
umarks.push([mark, url_marks[mark]]);
|
||||
for (var mark in urlMarks)
|
||||
umarks.push([mark, urlMarks[mark]]);
|
||||
// FIXME: why does umarks.sort() cause a "Component is not available =
|
||||
// NS_ERROR_NOT_AVAILABLE" exception when used here?
|
||||
umarks.sort(function (a, b) {
|
||||
@@ -624,8 +633,10 @@ vimperator.Marks = function () //{{{
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
return {
|
||||
|
||||
// TODO: add support for frameset pages
|
||||
this.add = function (mark)
|
||||
add: function (mark)
|
||||
{
|
||||
var win = window.content;
|
||||
|
||||
@@ -642,55 +653,55 @@ vimperator.Marks = function () //{{{
|
||||
if (isURLMark(mark))
|
||||
{
|
||||
vimperator.log("Adding URL mark: " + mark + " | " + win.location.href + " | (" + position.x + ", " + position.y + ") | tab: " + vimperator.tabs.index(vimperator.tabs.getTab()), 5);
|
||||
url_marks[mark] = { location: win.location.href, position: position, tab: vimperator.tabs.getTab() };
|
||||
urlMarks[mark] = { location: win.location.href, position: position, tab: vimperator.tabs.getTab() };
|
||||
}
|
||||
else if (isLocalMark(mark))
|
||||
{
|
||||
// remove any previous mark of the same name for this location
|
||||
removeLocalMark(mark);
|
||||
if (!local_marks[mark])
|
||||
local_marks[mark] = [];
|
||||
if (!localMarks[mark])
|
||||
localMarks[mark] = [];
|
||||
vimperator.log("Adding local mark: " + mark + " | " + win.location.href + " | (" + position.x + ", " + position.y + ")", 5);
|
||||
local_marks[mark].push({ location: win.location.href, position: position });
|
||||
}
|
||||
localMarks[mark].push({ location: win.location.href, position: position });
|
||||
}
|
||||
},
|
||||
|
||||
this.remove = function (filter, special)
|
||||
remove: function (filter, special)
|
||||
{
|
||||
if (special)
|
||||
{
|
||||
// :delmarks! only deletes a-z marks
|
||||
for (var mark in local_marks)
|
||||
for (var mark in localMarks)
|
||||
removeLocalMark(mark);
|
||||
}
|
||||
else
|
||||
{
|
||||
var pattern = new RegExp("[" + filter.replace(/\s+/g, "") + "]");
|
||||
for (var mark in url_marks)
|
||||
for (var mark in urlMarks)
|
||||
{
|
||||
if (pattern.test(mark))
|
||||
removeURLMark(mark);
|
||||
}
|
||||
for (var mark in local_marks)
|
||||
for (var mark in localMarks)
|
||||
{
|
||||
if (pattern.test(mark))
|
||||
removeLocalMark(mark);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
this.jumpTo = function (mark)
|
||||
jumpTo: function (mark)
|
||||
{
|
||||
var ok = false;
|
||||
|
||||
if (isURLMark(mark))
|
||||
{
|
||||
var slice = url_marks[mark];
|
||||
var slice = urlMarks[mark];
|
||||
if (slice && slice.tab && slice.tab.linkedBrowser)
|
||||
{
|
||||
if (!slice.tab.parentNode)
|
||||
{
|
||||
pending_jumps.push(slice);
|
||||
pendingJumps.push(slice);
|
||||
// NOTE: this obviously won't work on generated pages using
|
||||
// non-unique URLs, like Vimperator's help :(
|
||||
vimperator.open(slice.location, vimperator.NEW_TAB);
|
||||
@@ -703,7 +714,7 @@ vimperator.Marks = function () //{{{
|
||||
var win = slice.tab.linkedBrowser.contentWindow;
|
||||
if (win.location.href != slice.location)
|
||||
{
|
||||
pending_jumps.push(slice);
|
||||
pendingJumps.push(slice);
|
||||
win.location.href = slice.location;
|
||||
return;
|
||||
}
|
||||
@@ -716,7 +727,7 @@ vimperator.Marks = function () //{{{
|
||||
else if (isLocalMark(mark))
|
||||
{
|
||||
var win = window.content;
|
||||
var slice = local_marks[mark] || [];
|
||||
var slice = localMarks[mark] || [];
|
||||
|
||||
for (var i = 0; i < slice.length; i++)
|
||||
{
|
||||
@@ -731,9 +742,9 @@ vimperator.Marks = function () //{{{
|
||||
|
||||
if (!ok)
|
||||
vimperator.echoerr("E20: Mark not set"); // FIXME: move up?
|
||||
}
|
||||
},
|
||||
|
||||
this.list = function (filter)
|
||||
list: function (filter)
|
||||
{
|
||||
var marks = getSortedMarks();
|
||||
|
||||
@@ -771,8 +782,10 @@ vimperator.Marks = function () //{{{
|
||||
|
||||
vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE);
|
||||
}
|
||||
|
||||
};
|
||||
//}}}
|
||||
} //}}}
|
||||
}; //}}}
|
||||
|
||||
vimperator.QuickMarks = function () //{{{
|
||||
{
|
||||
@@ -781,24 +794,26 @@ vimperator.QuickMarks = function () //{{{
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
var qmarks = {};
|
||||
var saved_marks = vimperator.options.getPref("quickmarks", "").split("\n");
|
||||
var savedMarks = vimperator.options.getPref("quickmarks", "").split("\n");
|
||||
|
||||
// load the saved quickmarks -- TODO: change to sqlite
|
||||
for (var i = 0; i < saved_marks.length - 1; i += 2)
|
||||
for (var i = 0; i < savedMarks.length - 1; i += 2)
|
||||
{
|
||||
qmarks[saved_marks[i]] = saved_marks[i + 1];
|
||||
qmarks[savedMarks[i]] = savedMarks[i + 1];
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
this.add = function (qmark, location)
|
||||
return {
|
||||
|
||||
add: function (qmark, location)
|
||||
{
|
||||
qmarks[qmark] = location;
|
||||
}
|
||||
},
|
||||
|
||||
this.remove = function (filter)
|
||||
remove: function (filter)
|
||||
{
|
||||
var pattern = new RegExp("[" + filter.replace(/\s+/g, "") + "]");
|
||||
|
||||
@@ -807,14 +822,14 @@ vimperator.QuickMarks = function () //{{{
|
||||
if (pattern.test(qmark))
|
||||
delete qmarks[qmark];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
this.removeAll = function ()
|
||||
removeAll: function ()
|
||||
{
|
||||
qmarks = {};
|
||||
}
|
||||
},
|
||||
|
||||
this.jumpTo = function (qmark, where)
|
||||
jumpTo: function (qmark, where)
|
||||
{
|
||||
var url = qmarks[qmark];
|
||||
|
||||
@@ -822,9 +837,9 @@ vimperator.QuickMarks = function () //{{{
|
||||
vimperator.open(url, where);
|
||||
else
|
||||
vimperator.echoerr("E20: QuickMark not set");
|
||||
}
|
||||
},
|
||||
|
||||
this.list = function (filter)
|
||||
list: function (filter)
|
||||
{
|
||||
var marks = [];
|
||||
|
||||
@@ -862,22 +877,24 @@ vimperator.QuickMarks = function () //{{{
|
||||
list += "</table>";
|
||||
|
||||
vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE);
|
||||
}
|
||||
},
|
||||
|
||||
this.destroy = function ()
|
||||
destroy: function ()
|
||||
{
|
||||
// save the quickmarks
|
||||
var saved_qmarks = "";
|
||||
var savedQuickMarks = "";
|
||||
|
||||
for (var i in qmarks)
|
||||
{
|
||||
saved_qmarks += i + "\n";
|
||||
saved_qmarks += qmarks[i] + "\n";
|
||||
savedQuickMarks += i + "\n";
|
||||
savedQuickMarks += qmarks[i] + "\n";
|
||||
}
|
||||
|
||||
vimperator.options.setPref("quickmarks", saved_qmarks);
|
||||
vimperator.options.setPref("quickmarks", savedQuickMarks);
|
||||
}
|
||||
|
||||
};
|
||||
//}}}
|
||||
} //}}}
|
||||
}; //}}}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
@@ -31,24 +31,25 @@ vimperator.Buffer = function () //{{{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
// used for the "B" mapping to remember the last :buffer[!] command
|
||||
var lastBufferSwitchArgs = "";
|
||||
var lastBufferSwitchSpecial = true;
|
||||
|
||||
var zoom_manager = ZoomManager.prototype.getInstance();
|
||||
var zoomManager = ZoomManager.prototype.getInstance();
|
||||
const ZOOM_INTERVAL = 25;
|
||||
|
||||
// initialize the zoom levels
|
||||
zoom_manager.zoomFactors = [zoom_manager.MIN];
|
||||
for (var i = ZOOM_INTERVAL; i <= zoom_manager.MAX; i += ZOOM_INTERVAL)
|
||||
zoom_manager.zoomFactors.push(i);
|
||||
zoomManager.zoomFactors = [zoomManager.MIN];
|
||||
for (var i = ZOOM_INTERVAL; i <= zoomManager.MAX; i += ZOOM_INTERVAL)
|
||||
zoomManager.zoomFactors.push(i);
|
||||
|
||||
function setZoom(value)
|
||||
{
|
||||
try
|
||||
{
|
||||
zoom_manager.textZoom = value;
|
||||
vimperator.echo("Text zoom: " + zoom_manager.textZoom + "%");
|
||||
zoomManager.textZoom = value;
|
||||
vimperator.echo("Text zoom: " + zoomManager.textZoom + "%");
|
||||
// TODO: shouldn't this just recalculate hint coords, rather than
|
||||
// unsuccessfully attempt to reshow hints? i.e. isn't it just relying
|
||||
// on the recalculation side effect? -- djk
|
||||
@@ -57,7 +58,7 @@ vimperator.Buffer = function () //{{{
|
||||
}
|
||||
catch (e) // Components.results.NS_ERROR_INVALID_ARG
|
||||
{
|
||||
vimperator.echoerr("Zoom value out of range (" + zoom_manager.MIN + "-" + zoom_manager.MAX + ")");
|
||||
vimperator.echoerr("Zoom value out of range (" + zoomManager.MIN + "-" + zoomManager.MAX + ")");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,11 +67,11 @@ vimperator.Buffer = function () //{{{
|
||||
// get this added to ZoomManager
|
||||
function bumpZoomLevel(steps)
|
||||
{
|
||||
var adjusted_zoom = zoom_manager.snap(zoom_manager.textZoom);
|
||||
var current = zoom_manager.indexOf(adjusted_zoom);
|
||||
var adjustedZoom = zoomManager.snap(zoomManager.textZoom);
|
||||
var current = zoomManager.indexOf(adjustedZoom);
|
||||
var next = current + steps;
|
||||
|
||||
var start = 0, end = zoom_manager.zoomFactors.length - 1;
|
||||
var start = 0, end = zoomManager.zoomFactors.length - 1;
|
||||
|
||||
if ((current == start && steps < 0) || (current == end && steps > 0))
|
||||
{
|
||||
@@ -83,7 +84,7 @@ vimperator.Buffer = function () //{{{
|
||||
else if (next > end)
|
||||
next = end;
|
||||
|
||||
setZoom(zoom_manager.zoomFactors[next]);
|
||||
setZoom(zoomManager.zoomFactors[next]);
|
||||
}
|
||||
|
||||
function checkScrollYBounds(win, direction)
|
||||
@@ -116,35 +117,37 @@ vimperator.Buffer = function () //{{{
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
this.__defineGetter__("URL", function ()
|
||||
return {
|
||||
|
||||
get URL()
|
||||
{
|
||||
// TODO: .URL is not defined for XUL documents
|
||||
//return window.content.document.URL;
|
||||
return window.content.document.location.href;
|
||||
});
|
||||
},
|
||||
|
||||
this.__defineGetter__("pageHeight", function ()
|
||||
get pageHeight()
|
||||
{
|
||||
return window.content.innerHeight;
|
||||
});
|
||||
},
|
||||
|
||||
this.__defineGetter__("textZoom", function ()
|
||||
get textZoom()
|
||||
{
|
||||
return zoom_manager.textZoom;
|
||||
});
|
||||
return zoomManager.textZoom;
|
||||
},
|
||||
|
||||
this.__defineSetter__("textZoom", function (value)
|
||||
get textZoom(value)
|
||||
{
|
||||
setZoom(value);
|
||||
});
|
||||
},
|
||||
|
||||
this.__defineGetter__("title", function ()
|
||||
get title()
|
||||
{
|
||||
return window.content.document.title;
|
||||
});
|
||||
},
|
||||
|
||||
// returns an XPathResult object
|
||||
this.evaluateXPath = function (expression, doc, elem, ordered)
|
||||
evaluateXPath: function (expression, doc, elem, ordered)
|
||||
{
|
||||
if (!doc)
|
||||
doc = window.content.document;
|
||||
@@ -152,8 +155,10 @@ vimperator.Buffer = function () //{{{
|
||||
elem = doc;
|
||||
|
||||
var result = doc.evaluate(expression, elem,
|
||||
function lookupNamespaceURI(prefix) {
|
||||
switch (prefix) {
|
||||
function lookupNamespaceURI(prefix)
|
||||
{
|
||||
switch (prefix)
|
||||
{
|
||||
case "xhtml":
|
||||
return "http://www.w3.org/1999/xhtml";
|
||||
default:
|
||||
@@ -165,9 +170,9 @@ vimperator.Buffer = function () //{{{
|
||||
);
|
||||
|
||||
return result;
|
||||
};
|
||||
},
|
||||
|
||||
this.list = function (fullmode)
|
||||
list: function (fullmode)
|
||||
{
|
||||
if (fullmode)
|
||||
{
|
||||
@@ -178,7 +183,7 @@ vimperator.Buffer = function () //{{{
|
||||
}
|
||||
else
|
||||
{
|
||||
var items = vimperator.completion.get_buffer_completions("");
|
||||
var items = vimperator.completion.buffer("");
|
||||
vimperator.bufferwindow.show(items);
|
||||
vimperator.bufferwindow.selectItem(getBrowser().mTabContainer.selectedIndex);
|
||||
}
|
||||
@@ -186,7 +191,7 @@ vimperator.Buffer = function () //{{{
|
||||
else
|
||||
{
|
||||
// TODO: move this to vimperator.buffers.get()
|
||||
var items = vimperator.completion.get_buffer_completions("");
|
||||
var items = vimperator.completion.buffer("");
|
||||
var number, indicator, title, url;
|
||||
|
||||
var list = ":" + vimperator.util.escapeHTML(vimperator.commandline.getCommand()) + "<br/>" + "<table>";
|
||||
@@ -212,14 +217,14 @@ vimperator.Buffer = function () //{{{
|
||||
|
||||
vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE);
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
this.scrollBottom = function ()
|
||||
scrollBottom: function ()
|
||||
{
|
||||
scrollToPercentiles(-1, 100);
|
||||
};
|
||||
},
|
||||
|
||||
this.scrollColumns = function (cols)
|
||||
scrollColumns: function (cols)
|
||||
{
|
||||
var win = window.document.commandDispatcher.focusedWindow;
|
||||
const COL_WIDTH = 20;
|
||||
@@ -228,44 +233,44 @@ vimperator.Buffer = function () //{{{
|
||||
vimperator.beep();
|
||||
|
||||
win.scrollBy(COL_WIDTH * cols, 0);
|
||||
};
|
||||
},
|
||||
|
||||
this.scrollEnd = function ()
|
||||
scrollEnd: function ()
|
||||
{
|
||||
scrollToPercentiles(100, -1);
|
||||
};
|
||||
},
|
||||
|
||||
this.scrollLines = function (lines)
|
||||
scrollLines: function (lines)
|
||||
{
|
||||
var win = window.document.commandDispatcher.focusedWindow;
|
||||
checkScrollYBounds(win, lines);
|
||||
win.scrollByLines(lines);
|
||||
};
|
||||
},
|
||||
|
||||
this.scrollPages = function (pages)
|
||||
scrollPages: function (pages)
|
||||
{
|
||||
var win = window.document.commandDispatcher.focusedWindow;
|
||||
checkScrollYBounds(win, pages);
|
||||
win.scrollByPages(pages);
|
||||
};
|
||||
},
|
||||
|
||||
this.scrollToPercentile = function (percentage)
|
||||
scrollToPercentile: function (percentage)
|
||||
{
|
||||
scrollToPercentiles(-1, percentage);
|
||||
};
|
||||
},
|
||||
|
||||
this.scrollStart = function ()
|
||||
scrollStart: function ()
|
||||
{
|
||||
scrollToPercentiles(0, -1);
|
||||
};
|
||||
},
|
||||
|
||||
this.scrollTop = function ()
|
||||
scrollTop: function ()
|
||||
{
|
||||
scrollToPercentiles(-1, 0);
|
||||
};
|
||||
},
|
||||
|
||||
// TODO: allow callback for filtering out unwanted frames? User defined?
|
||||
this.shiftFrameFocus = function (count, forward)
|
||||
shiftFrameFocus: function (count, forward)
|
||||
{
|
||||
if (!window.content.document instanceof HTMLDocument)
|
||||
return;
|
||||
@@ -278,7 +283,7 @@ vimperator.Buffer = function () //{{{
|
||||
if (frame.document.body.localName.toLowerCase() == "body")
|
||||
frames.push(frame);
|
||||
for (var i = 0; i < frame.frames.length; i++)
|
||||
arguments.callee(frame.frames[i])
|
||||
arguments.callee(frame.frames[i]);
|
||||
})(window.content);
|
||||
|
||||
if (frames.length == 0) // currently top is always included
|
||||
@@ -361,23 +366,23 @@ vimperator.Buffer = function () //{{{
|
||||
|
||||
// remove the frame indicator
|
||||
setTimeout(function () { doc.body.removeChild(indicator); }, 500);
|
||||
};
|
||||
},
|
||||
|
||||
// updates the buffer preview in place only if list is visible
|
||||
this.updateBufferList = function ()
|
||||
updateBufferList: function ()
|
||||
{
|
||||
if (!vimperator.bufferwindow.visible())
|
||||
return false;
|
||||
|
||||
var items = vimperator.completion.get_buffer_completions("");
|
||||
var items = vimperator.completion.buffer("");
|
||||
vimperator.bufferwindow.show(items);
|
||||
vimperator.bufferwindow.selectItem(getBrowser().mTabContainer.selectedIndex);
|
||||
};
|
||||
},
|
||||
|
||||
// XXX: should this be in v.buffers. or v.tabs.?
|
||||
// "buffer" is a string which matches the URL or title of a buffer, if it
|
||||
// is null, the last used string is used again
|
||||
this.switchTo = function (buffer, allowNonUnique, count, reverse)
|
||||
switchTo: function (buffer, allowNonUnique, count, reverse)
|
||||
{
|
||||
if (buffer != null)
|
||||
{
|
||||
@@ -402,7 +407,7 @@ vimperator.Buffer = function () //{{{
|
||||
return vimperator.tabs.select(parseInt(match[1], 10) - 1, false); // make it zero-based
|
||||
|
||||
var matches = [];
|
||||
var lower_buffer = buffer.toLowerCase();
|
||||
var lowerBuffer = buffer.toLowerCase();
|
||||
var first = vimperator.tabs.index() + (reverse ? 0 : 1);
|
||||
for (var i = 0; i < getBrowser().browsers.length; i++)
|
||||
{
|
||||
@@ -412,7 +417,7 @@ vimperator.Buffer = function () //{{{
|
||||
if (url == buffer)
|
||||
return vimperator.tabs.select(index, false);
|
||||
|
||||
if (url.indexOf(buffer) >= 0 || title.indexOf(lower_buffer) >= 0)
|
||||
if (url.indexOf(buffer) >= 0 || title.indexOf(lowerBuffer) >= 0)
|
||||
matches.push(index);
|
||||
}
|
||||
if (matches.length == 0)
|
||||
@@ -432,19 +437,19 @@ vimperator.Buffer = function () //{{{
|
||||
|
||||
vimperator.tabs.select(matches[index], false);
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
this.zoomIn = function (steps)
|
||||
zoomIn: function (steps)
|
||||
{
|
||||
bumpZoomLevel(steps);
|
||||
};
|
||||
},
|
||||
|
||||
this.zoomOut = function (steps)
|
||||
zoomOut: function (steps)
|
||||
{
|
||||
bumpZoomLevel(-steps);
|
||||
};
|
||||
},
|
||||
|
||||
this.pageInfo = function (verbose)
|
||||
pageInfo: function (verbose)
|
||||
{
|
||||
const feedTypes = {
|
||||
"application/rss+xml": "RSS",
|
||||
@@ -646,7 +651,7 @@ vimperator.Buffer = function () //{{{
|
||||
|
||||
// sort: ignore-case
|
||||
tmpSort.sort(function (a,b){return a.toLowerCase() > b.toLowerCase() ? 1 : -1;});
|
||||
for (var i=0; i < tmpSort.length; i++)
|
||||
for (var i = 0; i < tmpSort.length; i++)
|
||||
pageMeta.push([tmpDict[tmpSort[i]][0], vimperator.util.highlightURL(tmpDict[tmpSort[i]][1], false)]);
|
||||
}
|
||||
|
||||
@@ -689,8 +694,10 @@ vimperator.Buffer = function () //{{{
|
||||
}
|
||||
}
|
||||
vimperator.echo(pageInfoText, vimperator.commandline.FORCE_MULTILINE);
|
||||
}
|
||||
|
||||
};
|
||||
//}}}
|
||||
} //}}}
|
||||
}; //}}}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -26,14 +26,18 @@ the provisions above, a recipient may use your version of this file under
|
||||
the terms of any one of the MPL, the GPL or the LGPL.
|
||||
}}} ***** END LICENSE BLOCK *****/
|
||||
|
||||
vimperator.Completion = function () // {{{
|
||||
vimperator.Completion = function () //{{{
|
||||
{
|
||||
// The completion substrings, used for showing the longest common match
|
||||
var g_substrings = [];
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
// the completion substrings, used for showing the longest common match
|
||||
var substrings = [];
|
||||
|
||||
// function uses smartcase
|
||||
// list = [ [['com1', 'com2'], 'text'], [['com3', 'com4'], 'text'] ]
|
||||
function build_longest_common_substring(list, filter) //{{{
|
||||
function buildLongestCommonSubstring(list, filter)
|
||||
{
|
||||
var filtered = [];
|
||||
var ignorecase = false;
|
||||
@@ -51,19 +55,19 @@ vimperator.Completion = function () // {{{
|
||||
if (item.indexOf(filter) == -1)
|
||||
continue;
|
||||
|
||||
if (g_substrings.length == 0)
|
||||
if (substrings.length == 0)
|
||||
{
|
||||
var last_index = item.lastIndexOf(filter);
|
||||
var lastIndex = item.lastIndexOf(filter);
|
||||
var length = item.length;
|
||||
for (var k = item.indexOf(filter); k != -1 && k <= last_index; k = item.indexOf(filter, k + 1))
|
||||
for (var k = item.indexOf(filter); k != -1 && k <= lastIndex; k = item.indexOf(filter, k + 1))
|
||||
{
|
||||
for (var l = k + filter.length; l <= length; l++)
|
||||
g_substrings.push(list[i][0][j].substring(k, l));
|
||||
substrings.push(list[i][0][j].substring(k, l));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_substrings = g_substrings.filter(function ($_) {
|
||||
substrings = substrings.filter(function ($_) {
|
||||
return list[i][0][j].indexOf($_) >= 0;
|
||||
});
|
||||
}
|
||||
@@ -72,10 +76,10 @@ vimperator.Completion = function () // {{{
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
} //}}}
|
||||
}
|
||||
|
||||
/* this function is case sensitive and should be documented about input and output ;) */
|
||||
function build_longest_starting_substring(list, filter) //{{{
|
||||
// this function is case sensitive and should be documented about input and output ;)
|
||||
function buildLongestStartingSubstring(list, filter)
|
||||
{
|
||||
var filtered = [];
|
||||
for (var i = 0; i < list.length; i++)
|
||||
@@ -85,15 +89,15 @@ vimperator.Completion = function () // {{{
|
||||
if (list[i][0][j].indexOf(filter) != 0)
|
||||
continue;
|
||||
|
||||
if (g_substrings.length == 0)
|
||||
if (substrings.length == 0)
|
||||
{
|
||||
var length = list[i][0][j].length;
|
||||
for (var k = filter.length; k <= length; k++)
|
||||
g_substrings.push(list[i][0][j].substring(0, k));
|
||||
substrings.push(list[i][0][j].substring(0, k));
|
||||
}
|
||||
else
|
||||
{
|
||||
g_substrings = g_substrings.filter(function ($_) {
|
||||
substrings = substrings.filter(function ($_) {
|
||||
return list[i][0][j].indexOf($_) == 0;
|
||||
});
|
||||
}
|
||||
@@ -102,18 +106,18 @@ vimperator.Completion = function () // {{{
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
} //}}}
|
||||
}
|
||||
|
||||
/* discard all entries in the 'urls' array, which don't match 'filter */
|
||||
function filter_url_array(urls, filter) //{{{
|
||||
function filterUrlArray(urls, filter)
|
||||
{
|
||||
var filtered = [];
|
||||
// completions which don't match the url but just the description
|
||||
// list them add the end of the array
|
||||
var additional_completions = [];
|
||||
var additionalCompletions = [];
|
||||
|
||||
if (!filter) return urls.map(function ($_) {
|
||||
return [$_[0], $_[1]]
|
||||
return [$_[0], $_[1]];
|
||||
});
|
||||
|
||||
var ignorecase = false;
|
||||
@@ -122,7 +126,7 @@ vimperator.Completion = function () // {{{
|
||||
|
||||
/*
|
||||
* Longest Common Subsequence
|
||||
* This shouldn't use build_longest_common_substring
|
||||
* This shouldn't use buildLongestCommonSubstring
|
||||
* for performance reasons, so as not to cycle through the urls twice
|
||||
*/
|
||||
for (var i = 0; i < urls.length; i++)
|
||||
@@ -138,49 +142,54 @@ vimperator.Completion = function () // {{{
|
||||
if (url.indexOf(filter) == -1)
|
||||
{
|
||||
if (title.indexOf(filter) != -1)
|
||||
additional_completions.push([ urls[i][0], urls[i][1] ]);
|
||||
additionalCompletions.push([ urls[i][0], urls[i][1] ]);
|
||||
continue;
|
||||
}
|
||||
if (g_substrings.length == 0) // Build the substrings
|
||||
if (substrings.length == 0) // Build the substrings
|
||||
{
|
||||
var last_index = url.lastIndexOf(filter);
|
||||
var url_length = url.length;
|
||||
for (var k = url.indexOf(filter); k != -1 && k <= last_index; k = url.indexOf(filter, k + 1))
|
||||
var lastIndex = url.lastIndexOf(filter);
|
||||
var urlLength = url.length;
|
||||
for (var k = url.indexOf(filter); k != -1 && k <= lastIndex; k = url.indexOf(filter, k + 1))
|
||||
{
|
||||
for (var l = k + filter.length; l <= url_length; l++)
|
||||
g_substrings.push(url.substring(k, l));
|
||||
for (var l = k + filter.length; l <= urlLength; l++)
|
||||
substrings.push(url.substring(k, l));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_substrings = g_substrings.filter(function ($_) {
|
||||
substrings = substrings.filter(function ($_) {
|
||||
return url.indexOf($_) >= 0;
|
||||
});
|
||||
}
|
||||
filtered.push([urls[i][0], urls[i][1]]);
|
||||
}
|
||||
|
||||
return filtered.concat(additional_completions);
|
||||
} //}}}
|
||||
return filtered.concat(additionalCompletions);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
return {
|
||||
|
||||
/*
|
||||
* returns the longest common substring
|
||||
* used for the 'longest' setting for wildmode
|
||||
*/
|
||||
get_longest_substring: function () //{{{
|
||||
getLongestSubstring: function ()
|
||||
{
|
||||
if (g_substrings.length == 0)
|
||||
if (substrings.length == 0)
|
||||
return "";
|
||||
|
||||
var longest = g_substrings[0];
|
||||
for (var i = 1; i < g_substrings.length; i++)
|
||||
var longest = substrings[0];
|
||||
for (var i = 1; i < substrings.length; i++)
|
||||
{
|
||||
if (g_substrings[i].length > longest.length)
|
||||
longest = g_substrings[i];
|
||||
if (substrings[i].length > longest.length)
|
||||
longest = substrings[i];
|
||||
}
|
||||
return longest;
|
||||
}, //}}}
|
||||
},
|
||||
|
||||
/*
|
||||
* filter a list of urls
|
||||
@@ -189,29 +198,29 @@ vimperator.Completion = function () // {{{
|
||||
* depending on the 'complete' option
|
||||
* if the 'complete' argument is passed like "h", it temporarily overrides the complete option
|
||||
*/
|
||||
get_url_completions: function (filter, complete) //{{{
|
||||
url: function (filter, complete)
|
||||
{
|
||||
var completions = [];
|
||||
g_substrings = [];
|
||||
substrings = [];
|
||||
|
||||
var cpt = complete || vimperator.options["complete"];
|
||||
// join all completion arrays together
|
||||
for (var i = 0; i < cpt.length; i++)
|
||||
{
|
||||
if (cpt[i] == "s")
|
||||
completions = completions.concat(this.get_search_completions(filter));
|
||||
completions = completions.concat(this.search(filter));
|
||||
else if (cpt[i] == "b")
|
||||
completions = completions.concat(this.get_bookmark_completions(filter));
|
||||
completions = completions.concat(this.bookmark(filter));
|
||||
else if (cpt[i] == "h")
|
||||
completions = completions.concat(this.get_history_completions(filter));
|
||||
completions = completions.concat(this.history(filter));
|
||||
else if (cpt[i] == "f")
|
||||
completions = completions.concat(this.get_file_completions(filter, true));
|
||||
completions = completions.concat(this.file(filter, true));
|
||||
}
|
||||
|
||||
return completions;
|
||||
}, //}}}
|
||||
},
|
||||
|
||||
get_search_completions: function (filter) //{{{
|
||||
search: function (filter)
|
||||
{
|
||||
var engines = vimperator.bookmarks.getSearchEngines().concat(vimperator.bookmarks.getKeywords());
|
||||
|
||||
@@ -221,28 +230,28 @@ vimperator.Completion = function () // {{{
|
||||
var mapped = engines.map(function (engine) {
|
||||
return [[engine[0]], engine[1]];
|
||||
});
|
||||
return build_longest_common_substring(mapped, filter);
|
||||
}, //}}}
|
||||
return buildLongestCommonSubstring(mapped, filter);
|
||||
},
|
||||
|
||||
get_history_completions: function (filter) //{{{
|
||||
history: function (filter)
|
||||
{
|
||||
var items = vimperator.history.get();
|
||||
return filter_url_array(items, filter);
|
||||
}, //}}}
|
||||
return filterUrlArray(items, filter);
|
||||
},
|
||||
|
||||
get_bookmark_completions: function (filter) //{{{
|
||||
bookmark: function (filter)
|
||||
{
|
||||
var bookmarks = vimperator.bookmarks.get();
|
||||
return filter_url_array(bookmarks, filter);
|
||||
}, //}}}
|
||||
return filterUrlArray(bookmarks, filter);
|
||||
},
|
||||
|
||||
// TODO: support file:// and \ or / path separators on both platforms
|
||||
get_file_completions: function (filter)
|
||||
file: function (filter)
|
||||
{
|
||||
// this is now also used as part of the url completion, so the
|
||||
// substrings shouldn't be cleared for that case
|
||||
if (!arguments[1])
|
||||
g_substrings = [];
|
||||
substrings = [];
|
||||
|
||||
var matches = filter.match(/^(.*[\/\\])(.*?)$/);
|
||||
var dir;
|
||||
@@ -266,56 +275,56 @@ vimperator.Completion = function () // {{{
|
||||
}
|
||||
|
||||
|
||||
return build_longest_starting_substring(mapped, filter);
|
||||
return buildLongestStartingSubstring(mapped, filter);
|
||||
},
|
||||
|
||||
get_help_completions: function (filter) //{{{
|
||||
help: function (filter)
|
||||
{
|
||||
var help_array = [[["introduction"], "Introductory text"],
|
||||
var helpArray = [[["introduction"], "Introductory text"],
|
||||
[["initialization"], "Initialization and startup"],
|
||||
[["mappings"], "Normal mode commands"],
|
||||
[["commands"], "Ex commands"],
|
||||
[["options"], "Configuration options"]]; // TODO: hardcoded until we have proper 'pages'
|
||||
g_substrings = [];
|
||||
substrings = [];
|
||||
for (var command in vimperator.commands)
|
||||
help_array.push([command.long_names.map(function ($_) { return ":" + $_; }), command.short_help]);
|
||||
options = this.get_options_completions(filter, true);
|
||||
help_array = help_array.concat(options.map(function ($_) {
|
||||
helpArray.push([command.longNames.map(function ($_) { return ":" + $_; }), command.shortHelp]);
|
||||
options = this.option(filter, true);
|
||||
helpArray = helpArray.concat(options.map(function ($_) {
|
||||
return [
|
||||
$_[0].map(function ($_) { return "'" + $_ + "'"; }),
|
||||
$_[1]
|
||||
];
|
||||
}));
|
||||
for (var map in vimperator.mappings)
|
||||
help_array.push([map.names, map.short_help]);
|
||||
helpArray.push([map.names, map.shortHelp]);
|
||||
|
||||
if (!filter) return help_array.map(function ($_) {
|
||||
if (!filter) return helpArray.map(function ($_) {
|
||||
return [$_[0][0], $_[1]]; // unfiltered, use the first command
|
||||
});
|
||||
|
||||
return build_longest_common_substring(help_array, filter);
|
||||
}, //}}}
|
||||
return buildLongestCommonSubstring(helpArray, filter);
|
||||
},
|
||||
|
||||
get_command_completions: function (filter) //{{{
|
||||
command: function (filter)
|
||||
{
|
||||
g_substrings = [];
|
||||
substrings = [];
|
||||
var completions = [];
|
||||
if (!filter)
|
||||
{
|
||||
for (var command in vimperator.commands)
|
||||
completions.push([command.name, command.short_help]);
|
||||
completions.push([command.name, command.shortHelp]);
|
||||
return completions;
|
||||
}
|
||||
|
||||
for (var command in vimperator.commands)
|
||||
completions.push([command.long_names, command.short_help]);
|
||||
return build_longest_starting_substring(completions, filter);
|
||||
}, //}}}
|
||||
completions.push([command.longNames, command.shortHelp]);
|
||||
return buildLongestStartingSubstring(completions, filter);
|
||||
},
|
||||
|
||||
get_options_completions: function (filter, unfiltered) //{{{
|
||||
option: function (filter, unfiltered)
|
||||
{
|
||||
g_substrings = [];
|
||||
var options_completions = [];
|
||||
substrings = [];
|
||||
var optionsCompletions = [];
|
||||
var prefix = filter.match(/^no|inv/) || "";
|
||||
|
||||
if (prefix)
|
||||
@@ -328,7 +337,7 @@ vimperator.Completion = function () // {{{
|
||||
{
|
||||
if (prefix && option.type != "boolean")
|
||||
continue;
|
||||
options.push([option.names, option.short_help]);
|
||||
options.push([option.names, option.shortHelp]);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
@@ -340,7 +349,7 @@ vimperator.Completion = function () // {{{
|
||||
{
|
||||
if (prefix && option.type != "boolean")
|
||||
continue;
|
||||
options.push([prefix + option.name, option.short_help]);
|
||||
options.push([prefix + option.name, option.shortHelp]);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
@@ -352,15 +361,15 @@ vimperator.Completion = function () // {{{
|
||||
{
|
||||
if (option.hasName(filter))
|
||||
{
|
||||
options_completions.push([filter + "=" + option.value, ""]);
|
||||
return options_completions;
|
||||
optionsCompletions.push([filter + "=" + option.value, ""]);
|
||||
return optionsCompletions;
|
||||
}
|
||||
}
|
||||
return options_completions;
|
||||
return optionsCompletions;
|
||||
}
|
||||
|
||||
// can't use b_l_s_s, since this has special requirements (the prefix)
|
||||
var filter_length = filter.length;
|
||||
var filterLength = filter.length;
|
||||
for (var option in vimperator.options)
|
||||
{
|
||||
if (prefix && option.type != "boolean")
|
||||
@@ -371,29 +380,29 @@ vimperator.Completion = function () // {{{
|
||||
if (option.names[j].indexOf(filter) != 0)
|
||||
continue;
|
||||
|
||||
if (g_substrings.length == 0)
|
||||
if (substrings.length == 0)
|
||||
{
|
||||
var length = option.names[j].length;
|
||||
for (var k = filter_length; k <= length; k++)
|
||||
g_substrings.push(prefix + option.names[j].substring(0, k));
|
||||
for (var k = filterLength; k <= length; k++)
|
||||
substrings.push(prefix + option.names[j].substring(0, k));
|
||||
}
|
||||
else
|
||||
{
|
||||
g_substrings = g_substrings.filter(function ($_) {
|
||||
substrings = substrings.filter(function ($_) {
|
||||
return option.names[j].indexOf($_) == 0;
|
||||
});
|
||||
}
|
||||
options_completions.push([prefix + option.names[j], option.short_help]);
|
||||
optionsCompletions.push([prefix + option.names[j], option.shortHelp]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return options_completions;
|
||||
}, //}}}
|
||||
return optionsCompletions;
|
||||
},
|
||||
|
||||
get_buffer_completions: function (filter) //{{{
|
||||
buffer: function (filter)
|
||||
{
|
||||
g_substrings = [];
|
||||
substrings = [];
|
||||
var items = [];
|
||||
var num = getBrowser().browsers.length;
|
||||
var title, url;
|
||||
@@ -424,13 +433,13 @@ vimperator.Completion = function () // {{{
|
||||
if (!filter) return items.map(function ($_) {
|
||||
return [$_[0][0], $_[1]];
|
||||
});
|
||||
return build_longest_common_substring(items, filter);
|
||||
}, //}}}
|
||||
return buildLongestCommonSubstring(items, filter);
|
||||
},
|
||||
|
||||
get_sidebar_completions: function (filter) //{{{
|
||||
sidebar: function (filter)
|
||||
{
|
||||
g_substrings = [];
|
||||
var menu = document.getElementById("viewSidebarMenu")
|
||||
substrings = [];
|
||||
var menu = document.getElementById("viewSidebarMenu");
|
||||
var nodes = [];
|
||||
|
||||
for (var i = 0; i < menu.childNodes.length; i++)
|
||||
@@ -443,12 +452,12 @@ vimperator.Completion = function () // {{{
|
||||
return [[node[0]], node[1]];
|
||||
});
|
||||
|
||||
return build_longest_common_substring(mapped, filter);
|
||||
}, //}}}
|
||||
return buildLongestCommonSubstring(mapped, filter);
|
||||
},
|
||||
|
||||
javascript: function (str) // {{{
|
||||
{
|
||||
g_substrings = [];
|
||||
substrings = [];
|
||||
var matches = str.match(/^(.*?)(\s*\.\s*)?(\w*)$/);
|
||||
var object = "window";
|
||||
var filter = matches[3] || "";
|
||||
@@ -514,18 +523,18 @@ vimperator.Completion = function () // {{{
|
||||
completions = [];
|
||||
}
|
||||
|
||||
return build_longest_starting_substring(completions, filter);
|
||||
return buildLongestStartingSubstring(completions, filter);
|
||||
}, // }}}
|
||||
|
||||
// helper function which checks if the given arguments pass "filter"
|
||||
// items must be an array of strings
|
||||
// if case_sensitive == true, be sure to pass filter already in lowercased version
|
||||
match: function (filter, items, case_sensitive)
|
||||
// if caseSensitive == true, be sure to pass filter already in lowercased version
|
||||
match: function (filter, items, caseSensitive)
|
||||
{
|
||||
if (typeof(filter) != "string" || !items)
|
||||
if (typeof filter != "string" || !items)
|
||||
return false;
|
||||
|
||||
if (case_sensitive)
|
||||
if (caseSensitive)
|
||||
{
|
||||
for (var i = 0; i < items.length; i++)
|
||||
{
|
||||
@@ -544,7 +553,7 @@ vimperator.Completion = function () // {{{
|
||||
return false;
|
||||
},
|
||||
|
||||
exTabCompletion: function (str) //{{{
|
||||
exTabCompletion: function (str)
|
||||
{
|
||||
var [count, cmd, special, args] = vimperator.commands.parseCommand(str);
|
||||
var completions = [];
|
||||
@@ -555,7 +564,7 @@ vimperator.Completion = function () // {{{
|
||||
var matches = str.match(/^(:*\d*)\w*$/);
|
||||
if (matches)
|
||||
{
|
||||
completions = this.get_command_completions(cmd);
|
||||
completions = this.command(cmd);
|
||||
start = matches[1].length;
|
||||
}
|
||||
else // dynamically get completions as specified with the command's completer function
|
||||
@@ -587,9 +596,10 @@ vimperator.Completion = function () // {{{
|
||||
}
|
||||
}
|
||||
return [start, completions];
|
||||
} //}}}
|
||||
|
||||
}
|
||||
} // }}}
|
||||
|
||||
};
|
||||
//}}}
|
||||
}; //}}}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
@@ -74,7 +74,7 @@ vimperator.Events = function () //{{{
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// track if a popup is open or the menubar is active
|
||||
var active_menubar = false;
|
||||
var activeMenubar = false;
|
||||
function enterPopupMode(event)
|
||||
{
|
||||
if (event.originalTarget.localName == "tooltip" || event.originalTarget.id == "vimperator-visualbell")
|
||||
@@ -85,17 +85,17 @@ vimperator.Events = function () //{{{
|
||||
function exitPopupMode()
|
||||
{
|
||||
// gContextMenu is set to NULL by firefox, when a context menu is closed
|
||||
if (!gContextMenu && !active_menubar)
|
||||
if (!gContextMenu && !activeMenubar)
|
||||
vimperator.removeMode(null, vimperator.modes.MENU);
|
||||
}
|
||||
function enterMenuMode()
|
||||
{
|
||||
active_menubar = true;
|
||||
vimperator.addMode(null, vimperator.modes.MENU)
|
||||
activeMenubar = true;
|
||||
vimperator.addMode(null, vimperator.modes.MENU);
|
||||
}
|
||||
function exitMenuMode()
|
||||
{
|
||||
active_menubar = false;
|
||||
activeMenubar = false;
|
||||
vimperator.removeMode(null, vimperator.modes.MENU);
|
||||
}
|
||||
window.addEventListener("popupshown", enterPopupMode, true);
|
||||
@@ -182,7 +182,7 @@ vimperator.Events = function () //{{{
|
||||
var tagname = elt.localName.toLowerCase();
|
||||
var type = elt.type.toLowerCase();
|
||||
|
||||
if ( (tagname == "input" && (type != "image")) ||
|
||||
if ((tagname == "input" && (type != "image")) ||
|
||||
tagname == "textarea" ||
|
||||
// tagName == "SELECT" ||
|
||||
// tagName == "BUTTON" ||
|
||||
@@ -234,7 +234,9 @@ vimperator.Events = function () //{{{
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
this.destroy = function ()
|
||||
var eventManager = {
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
// removeEventListeners() to avoid mem leaks
|
||||
window.dump("TODO: remove all eventlisteners\n");
|
||||
@@ -248,7 +250,7 @@ vimperator.Events = function () //{{{
|
||||
|
||||
window.removeEventListener("keypress", this.onKeyPress, true);
|
||||
window.removeEventListener("keydown", this.onKeyDown, true);
|
||||
}
|
||||
},
|
||||
|
||||
// This method pushes keys into the event queue from vimperator
|
||||
// it is similar to vim's feedkeys() method, but cannot cope with
|
||||
@@ -256,7 +258,7 @@ vimperator.Events = function () //{{{
|
||||
//
|
||||
// @param keys: a string like "2<C-f>" to pass
|
||||
// if you want < to be taken literally, prepend it with a \\
|
||||
this.feedkeys = function (keys, noremap)
|
||||
feedkeys: function (keys, noremap)
|
||||
{
|
||||
var doc = window.document;
|
||||
var view = window.document.defaultView;
|
||||
@@ -314,13 +316,13 @@ vimperator.Events = function () //{{{
|
||||
evt.noremap = noremap;
|
||||
elem.dispatchEvent(evt);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// this function converts the given event to
|
||||
// a keycode which can be used in mappings
|
||||
// e.g. pressing ctrl+n would result in the string "<C-n>"
|
||||
// null if unknown key
|
||||
this.toString = function (event) //{{{
|
||||
toString: function (event)
|
||||
{
|
||||
if (!event)
|
||||
return;
|
||||
@@ -394,19 +396,20 @@ vimperator.Events = function () //{{{
|
||||
// a key like F1 is always enclosed in < and >
|
||||
return "<" + modifier + key + ">";
|
||||
|
||||
} //}}}
|
||||
},
|
||||
|
||||
this.isAcceptKey = function (key)
|
||||
isAcceptKey: function (key)
|
||||
{
|
||||
return (key == "<Return>" || key == "<C-j>" || key == "<C-m>");
|
||||
}
|
||||
this.isCancelKey = function (key)
|
||||
},
|
||||
|
||||
isCancelKey: function (key)
|
||||
{
|
||||
return (key == "<Esc>" || key == "<C-[>" || key == "<C-c>");
|
||||
}
|
||||
},
|
||||
|
||||
// global escape handler, is called in ALL modes
|
||||
this.onEscape = function ()
|
||||
onEscape: function ()
|
||||
{
|
||||
if (!vimperator.hasMode(vimperator.modes.ESCAPE_ONE_KEY))
|
||||
{
|
||||
@@ -422,11 +425,11 @@ vimperator.Events = function () //{{{
|
||||
vimperator.statusline.updateUrl();
|
||||
vimperator.focusContent();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// this keypress handler gets always called first, even if e.g.
|
||||
// the commandline has focus
|
||||
this.onKeyPress = function (event)
|
||||
onKeyPress: function (event)
|
||||
{
|
||||
var key = vimperator.events.toString(event);
|
||||
if (!key)
|
||||
@@ -438,6 +441,7 @@ vimperator.Events = function () //{{{
|
||||
if (win && win.document.designMode == "on")
|
||||
return true;
|
||||
|
||||
// menus have their own command handlers
|
||||
if (vimperator.hasMode(vimperator.modes.MENU))
|
||||
return true;
|
||||
|
||||
@@ -537,10 +541,10 @@ vimperator.Events = function () //{{{
|
||||
var map = vimperator.mappings.get(vimperator.modes.HINTS, key);
|
||||
if (map)
|
||||
{
|
||||
if (map.always_active || vimperator.hints.currentState() == 1)
|
||||
if (map.alwaysActive || vimperator.hints.currentState() == 1)
|
||||
{
|
||||
map.execute(null, vimperator.input.count);
|
||||
if (map.cancel_mode) // stop processing this event
|
||||
if (map.cancelMode) // stop processing this event
|
||||
{
|
||||
vimperator.hints.disableHahMode();
|
||||
vimperator.input.buffer = "";
|
||||
@@ -602,13 +606,13 @@ vimperator.Events = function () //{{{
|
||||
return true;
|
||||
}
|
||||
|
||||
var count_str = vimperator.input.buffer.match(/^[0-9]*/)[0];
|
||||
var candidate_command = (vimperator.input.buffer + key).replace(count_str, "");
|
||||
var countStr = vimperator.input.buffer.match(/^[0-9]*/)[0];
|
||||
var candidateCommand = (vimperator.input.buffer + key).replace(countStr, "");
|
||||
var map;
|
||||
if (event.noremap)
|
||||
map = vimperator.mappings.getDefaultMap(vimperator.modes.NORMAL, candidate_command);
|
||||
map = vimperator.mappings.getDefaultMap(vimperator.modes.NORMAL, candidateCommand);
|
||||
else
|
||||
map = vimperator.mappings.get(vimperator.modes.NORMAL, candidate_command);
|
||||
map = vimperator.mappings.get(vimperator.modes.NORMAL, candidateCommand);
|
||||
|
||||
// counts must be at the start of a complete mapping (10j -> go 10 lines down)
|
||||
if ((vimperator.input.buffer + key).match(/^[1-9][0-9]*$/))
|
||||
@@ -630,7 +634,7 @@ vimperator.Events = function () //{{{
|
||||
}
|
||||
else if (map)
|
||||
{
|
||||
vimperator.input.count = parseInt(count_str, 10);
|
||||
vimperator.input.count = parseInt(countStr, 10);
|
||||
if (isNaN(vimperator.input.count))
|
||||
vimperator.input.count = -1;
|
||||
if (map.flags & vimperator.Mappings.flags.ARGUMENT)
|
||||
@@ -642,7 +646,7 @@ vimperator.Events = function () //{{{
|
||||
{
|
||||
if (key != "<Esc>" && key != "<C-[>")
|
||||
{
|
||||
vimperator.input.pendingMotionMap.execute(candidate_command, vimperator.input.count, null);
|
||||
vimperator.input.pendingMotionMap.execute(candidateCommand, vimperator.input.count, null);
|
||||
}
|
||||
vimperator.input.pendingMotionMap = null;
|
||||
vimperator.input.buffer = "";
|
||||
@@ -659,7 +663,7 @@ vimperator.Events = function () //{{{
|
||||
map.execute(null, vimperator.input.count);
|
||||
}
|
||||
}
|
||||
else if (vimperator.mappings.getCandidates(vimperator.modes.NORMAL, candidate_command).length > 0)
|
||||
else if (vimperator.mappings.getCandidates(vimperator.modes.NORMAL, candidateCommand).length > 0)
|
||||
{
|
||||
vimperator.input.buffer += key;
|
||||
}
|
||||
@@ -683,26 +687,22 @@ vimperator.Events = function () //{{{
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
var motion_map = (vimperator.input.pendingMotionMap && vimperator.input.pendingMotionMap.names[0]) || "";
|
||||
vimperator.statusline.updateInputBuffer(motion_map + vimperator.input.buffer);
|
||||
var motionMap = (vimperator.input.pendingMotionMap && vimperator.input.pendingMotionMap.names[0]) || "";
|
||||
vimperator.statusline.updateInputBuffer(motionMap + vimperator.input.buffer);
|
||||
return false;
|
||||
}
|
||||
window.addEventListener("keypress", this.onKeyPress, true);
|
||||
},
|
||||
|
||||
// this is need for sites like msn.com which focus the input field on keydown
|
||||
this.onKeyUpOrDown = function (event)
|
||||
onKeyUpOrDown: function (event)
|
||||
{
|
||||
if (vimperator.hasMode(vimperator.modes.ESCAPE_ONE_KEY) || vimperator.hasMode(vimperator.modes.ESCAPE_ALL_KEYS) || isFormElemFocused())
|
||||
return true;
|
||||
|
||||
event.stopPropagation();
|
||||
return false;
|
||||
}
|
||||
window.addEventListener("keydown", this.onKeyUpOrDown, true);
|
||||
window.addEventListener("keyup", this.onKeyUpOrDown, true);
|
||||
},
|
||||
|
||||
this.progressListener =
|
||||
{
|
||||
progressListener: {
|
||||
QueryInterface: function (aIID)
|
||||
{
|
||||
if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
|
||||
@@ -788,17 +788,25 @@ vimperator.Events = function () //{{{
|
||||
setJSDefaultStatus: function (status) { ; },
|
||||
setDefaultStatus: function (status) { ; },
|
||||
onLinkIconAvailable: function () { ; }
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
window.XULBrowserWindow = this.progressListener;
|
||||
window.XULBrowserWindow = eventManager.progressListener;
|
||||
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIWebNavigation)
|
||||
.QueryInterface(Components.interfaces.nsIDocShellTreeItem).treeOwner
|
||||
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIXULWindow)
|
||||
.XULBrowserWindow = window.XULBrowserWindow;
|
||||
getBrowser().addProgressListener(this.progressListener, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
|
||||
getBrowser().addProgressListener(eventManager.progressListener, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
|
||||
|
||||
window.addEventListener("keypress", eventManager.onKeyPress, true);
|
||||
window.addEventListener("keydown", eventManager.onKeyUpOrDown, true);
|
||||
window.addEventListener("keyup", eventManager.onKeyUpOrDown, true);
|
||||
|
||||
return eventManager;
|
||||
//}}}
|
||||
} //}}}
|
||||
}; //}}}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
137
content/find.js
137
content/find.js
@@ -39,27 +39,32 @@ the terms of any one of the MPL, the GPL or the LGPL.
|
||||
// make sure you only create this object when the "vimperator" object is ready
|
||||
vimperator.Search = function () //{{{
|
||||
{
|
||||
var self = this; // needed for callbacks since "this" is the "vimperator" object in a callback
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
// FIXME:
|
||||
//var self = this; // needed for callbacks since "this" is the "vimperator" object in a callback
|
||||
var found = false; // true if the last search was successful
|
||||
var backwards = false; // currently searching backwards
|
||||
var search_string = ""; // current search string (without modifiers)
|
||||
var search_pattern = ""; // current search string (includes modifiers)
|
||||
var last_search_pattern = ""; // the last searched pattern (includes modifiers)
|
||||
var last_search_string = ""; // the last searched string (without modifiers)
|
||||
var last_search_backwards = false; // like "backwards", but for the last search, so if you cancel a search with <esc> this is not set
|
||||
var case_sensitive = false; // search string is case sensitive
|
||||
var links_only = false; // search is limited to link text only
|
||||
var searchString = ""; // current search string (without modifiers)
|
||||
var searchPattern = ""; // current search string (includes modifiers)
|
||||
var lastSearchPattern = ""; // the last searched pattern (includes modifiers)
|
||||
var lastSearchString = ""; // the last searched string (without modifiers)
|
||||
var lastSearchBackwards = false; // like "backwards", but for the last search, so if you cancel a search with <esc> this is not set
|
||||
var caseSensitive = false; // search string is case sensitive
|
||||
var linksOnly = false; // search is limited to link text only
|
||||
|
||||
// Event handlers for search - closure is needed
|
||||
vimperator.registerCallback("change", vimperator.modes.SEARCH_FORWARD, function (command) { self.searchKeyPressed(command); });
|
||||
vimperator.registerCallback("submit", vimperator.modes.SEARCH_FORWARD, function (command) { self.searchSubmitted(command); });
|
||||
vimperator.registerCallback("cancel", vimperator.modes.SEARCH_FORWARD, function () { self.searchCanceled(); });
|
||||
vimperator.registerCallback("change", vimperator.modes.SEARCH_FORWARD, function (command) { vimperator.search.searchKeyPressed(command); });
|
||||
vimperator.registerCallback("submit", vimperator.modes.SEARCH_FORWARD, function (command) { vimperator.search.searchSubmitted(command); });
|
||||
vimperator.registerCallback("cancel", vimperator.modes.SEARCH_FORWARD, function () { vimperator.search.searchCanceled(); });
|
||||
// TODO: allow advanced modes in register/triggerCallback
|
||||
vimperator.registerCallback("change", vimperator.modes.SEARCH_BACKWARD, function (command) { self.searchKeyPressed(command); });
|
||||
vimperator.registerCallback("submit", vimperator.modes.SEARCH_BACKWARD, function (command) { self.searchSubmitted(command); });
|
||||
vimperator.registerCallback("cancel", vimperator.modes.SEARCH_BACKWARD, function () { self.searchCanceled(); });
|
||||
vimperator.registerCallback("change", vimperator.modes.SEARCH_BACKWARD, function (command) { vimperator.search.searchKeyPressed(command); });
|
||||
vimperator.registerCallback("submit", vimperator.modes.SEARCH_BACKWARD, function (command) { vimperator.search.searchSubmitted(command); });
|
||||
vimperator.registerCallback("cancel", vimperator.modes.SEARCH_BACKWARD, function () { vimperator.search.searchCanceled(); });
|
||||
|
||||
// set search_string, search_pattern, case_sensitive, links_only
|
||||
// set searchString, searchPattern, caseSensitive, linksOnly
|
||||
function processUserPattern(pattern)
|
||||
{
|
||||
// strip off pattern terminator and offset
|
||||
@@ -68,32 +73,32 @@ vimperator.Search = function () //{{{
|
||||
else
|
||||
pattern = pattern.replace(/\/.*/, "");
|
||||
|
||||
search_pattern = pattern;
|
||||
searchPattern = pattern;
|
||||
|
||||
// links only search - \l wins if both modifiers specified
|
||||
if (/\\l/.test(pattern))
|
||||
links_only = false;
|
||||
linksOnly = false;
|
||||
else if (/\L/.test(pattern))
|
||||
links_only = true;
|
||||
linksOnly = true;
|
||||
else if (vimperator.options["linksearch"])
|
||||
links_only = true;
|
||||
linksOnly = true;
|
||||
else
|
||||
links_only = false;
|
||||
linksOnly = false;
|
||||
|
||||
// strip links-only modifiers
|
||||
pattern = pattern.replace(/(\\)?\\[lL]/g, function ($0, $1) { return $1 ? $0 : ""; });
|
||||
|
||||
// case sensitivity - \c wins if both modifiers specified
|
||||
if (/\c/.test(pattern))
|
||||
case_sensitive = false;
|
||||
caseSensitive = false;
|
||||
else if (/\C/.test(pattern))
|
||||
case_sensitive = true;
|
||||
caseSensitive = true;
|
||||
else if (vimperator.options["ignorecase"] && vimperator.options["smartcase"] && /[A-Z]/.test(pattern))
|
||||
case_sensitive = true;
|
||||
caseSensitive = true;
|
||||
else if (vimperator.options["ignorecase"])
|
||||
case_sensitive = false;
|
||||
caseSensitive = false;
|
||||
else
|
||||
case_sensitive = true;
|
||||
caseSensitive = true;
|
||||
|
||||
// strip case-sensitive modifiers
|
||||
pattern = pattern.replace(/(\\)?\\[cC]/g, function ($0, $1) { return $1 ? $0 : ""; });
|
||||
@@ -101,12 +106,18 @@ vimperator.Search = function () //{{{
|
||||
// remove any modifer escape \
|
||||
pattern = pattern.replace(/\\(\\[cClL])/g, "$1");
|
||||
|
||||
search_string = pattern;
|
||||
searchString = pattern;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
return {
|
||||
|
||||
// Called when the search dialog is asked for
|
||||
// If you omit "mode", it will default to forward searching
|
||||
this.openSearchDialog = function (mode)
|
||||
openSearchDialog: function (mode)
|
||||
{
|
||||
if (mode == vimperator.modes.SEARCH_BACKWARD)
|
||||
{
|
||||
@@ -120,35 +131,35 @@ vimperator.Search = function () //{{{
|
||||
}
|
||||
|
||||
// TODO: focus the top of the currently visible screen
|
||||
}
|
||||
},
|
||||
|
||||
// Finds text in a page
|
||||
// TODO: backwards seems impossible i fear :(
|
||||
this.find = function (str, backwards)
|
||||
find: function (str, backwards)
|
||||
{
|
||||
var fastFind = getBrowser().fastFind;
|
||||
|
||||
processUserPattern(str);
|
||||
|
||||
fastFind.caseSensitive = case_sensitive;
|
||||
found = fastFind.find(search_string, links_only) != Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND;
|
||||
fastFind.caseSensitive = caseSensitive;
|
||||
found = fastFind.find(searchString, linksOnly) != Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND;
|
||||
|
||||
if (!found)
|
||||
setTimeout(function () { vimperator.echoerr("E486: Pattern not found: " + search_pattern); }, 0);
|
||||
setTimeout(function () { vimperator.echoerr("E486: Pattern not found: " + searchPattern); }, 0);
|
||||
|
||||
return found;
|
||||
}
|
||||
},
|
||||
|
||||
// Called when the current search needs to be repeated
|
||||
this.findAgain = function (reverse)
|
||||
findAgain: function (reverse)
|
||||
{
|
||||
// this hack is needed to make n/N work with the correct string, if
|
||||
// we typed /foo<esc> after the original search. Since searchString is
|
||||
// readonly we have to call find() again to update it.
|
||||
if (getBrowser().fastFind.searchString != last_search_string)
|
||||
this.find(last_search_string, false);
|
||||
if (getBrowser().fastFind.searchString != lastSearchString)
|
||||
this.find(lastSearchString, false);
|
||||
|
||||
var up = reverse ? !last_search_backwards : last_search_backwards;
|
||||
var up = reverse ? !lastSearchBackwards : lastSearchBackwards;
|
||||
var result;
|
||||
|
||||
if (up)
|
||||
@@ -158,7 +169,7 @@ vimperator.Search = function () //{{{
|
||||
|
||||
if (result == Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND)
|
||||
{
|
||||
vimperator.echoerr("E486: Pattern not found: " + last_search_pattern);
|
||||
vimperator.echoerr("E486: Pattern not found: " + lastSearchPattern);
|
||||
}
|
||||
else if (result == Components.interfaces.nsITypeAheadFind.FIND_WRAPPED)
|
||||
{
|
||||
@@ -173,72 +184,72 @@ vimperator.Search = function () //{{{
|
||||
}
|
||||
else
|
||||
{
|
||||
vimperator.echo((up ? "?" : "/") + last_search_pattern);
|
||||
vimperator.echo((up ? "?" : "/") + lastSearchPattern);
|
||||
|
||||
if (vimperator.options["hlsearch"])
|
||||
this.highlight(last_search_string);
|
||||
}
|
||||
this.highlight(lastSearchString);
|
||||
}
|
||||
},
|
||||
|
||||
// Called when the user types a key in the search dialog. Triggers a find attempt if 'incsearch' is set
|
||||
this.searchKeyPressed = function (command)
|
||||
searchKeyPressed: function (command)
|
||||
{
|
||||
if (vimperator.options["incsearch"])
|
||||
this.find(command, backwards);
|
||||
}
|
||||
},
|
||||
|
||||
// Called when the enter key is pressed to trigger a search
|
||||
// use forced_direction if you call this function directly
|
||||
this.searchSubmitted = function (command, forced_backward)
|
||||
// use forcedBackward if you call this function directly
|
||||
searchSubmitted: function (command, forcedBackward)
|
||||
{
|
||||
if (typeof forced_backward === "boolean")
|
||||
backwards = forced_backward;
|
||||
if (typeof forcedBackward === "boolean")
|
||||
backwards = forcedBackward;
|
||||
|
||||
// use the last pattern if none specified
|
||||
if (!command)
|
||||
command = last_search_pattern;
|
||||
command = lastSearchPattern;
|
||||
|
||||
this.clear();
|
||||
this.find(command, backwards);
|
||||
|
||||
last_search_backwards = backwards;
|
||||
last_search_pattern = command.replace(backwards ? /\?.*/ : /\/.*/, ""); // XXX
|
||||
last_search_string = search_string;
|
||||
lastSearchBackwards = backwards;
|
||||
lastSearchPattern = command.replace(backwards ? /\?.*/ : /\/.*/, ""); // XXX
|
||||
lastSearchString = searchString;
|
||||
|
||||
// TODO: move to find() when reverse incremental searching is kludged in
|
||||
// need to find again for reverse searching
|
||||
if (backwards)
|
||||
setTimeout(function () { self.findAgain(false); }, 0);
|
||||
setTimeout(function () { vimperator.search.findAgain(false); }, 0);
|
||||
|
||||
if (vimperator.options["hlsearch"])
|
||||
this.highlight(search_string);
|
||||
this.highlight(searchString);
|
||||
|
||||
vimperator.setMode(vimperator.modes.NORMAL);
|
||||
vimperator.focusContent();
|
||||
}
|
||||
},
|
||||
|
||||
// Called when the search is cancelled - for example if someone presses
|
||||
// escape while typing a search
|
||||
this.searchCanceled = function ()
|
||||
searchCanceled: function ()
|
||||
{
|
||||
//removeMode(MODE_SEARCH);
|
||||
vimperator.setMode(vimperator.modes.NORMAL);
|
||||
vimperator.focusContent();
|
||||
}
|
||||
},
|
||||
|
||||
this.highlight = function (text)
|
||||
highlight: function (text)
|
||||
{
|
||||
// already highlighted?
|
||||
if (window.content.document.getElementById("__firefox-findbar-search-id"))
|
||||
return;
|
||||
|
||||
if (!text)
|
||||
text = last_search_string;
|
||||
text = lastSearchString;
|
||||
|
||||
// NOTE: gFindBar.setCaseSensitivity() in FF2 does NOT set the
|
||||
// accessibility.typeaheadfind.casesensitive pref as needed by
|
||||
// highlightDoc()
|
||||
gFindBar.mTypeAheadCaseSensitive = case_sensitive ? 1 : 0;
|
||||
gFindBar.mTypeAheadCaseSensitive = caseSensitive ? 1 : 0;
|
||||
gFindBar.highlightDoc("white", "black", text);
|
||||
|
||||
// TODO: seems fast enough for now...just
|
||||
@@ -256,9 +267,9 @@ vimperator.Search = function () //{{{
|
||||
getBrowser().fastFind.findNext();
|
||||
|
||||
// TODO: remove highlighting from non-link matches (HTML - A/AREA with href attribute; XML - Xlink [@type="simple"])
|
||||
}
|
||||
},
|
||||
|
||||
this.clear = function ()
|
||||
clear: function ()
|
||||
{
|
||||
gFindBar.highlightDoc();
|
||||
// need to manually collapse the selection if the document is not
|
||||
@@ -266,6 +277,8 @@ vimperator.Search = function () //{{{
|
||||
getBrowser().fastFind.collapseSelection();
|
||||
}
|
||||
|
||||
} //}}}
|
||||
};
|
||||
//}}}
|
||||
}; //}}}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
@@ -52,7 +52,7 @@ vimperator.help = function (section, easter) //{{{
|
||||
{
|
||||
// the usage information for the command
|
||||
ret += '<tr class="description"><td class="usage" valign="top">';
|
||||
for (var j=0; j < command.usage.length; j++)
|
||||
for (var j = 0; j < command.usage.length; j++)
|
||||
{
|
||||
var usage = command.usage[j];
|
||||
|
||||
@@ -72,10 +72,10 @@ vimperator.help = function (section, easter) //{{{
|
||||
ret += '</td><td valign="top">';
|
||||
|
||||
// the actual help text with the first line in bold
|
||||
if (command.short_help)
|
||||
if (command.shortHelp)
|
||||
{
|
||||
ret += '<span class="shorthelp">';
|
||||
ret += command.short_help; // the help description
|
||||
ret += command.shortHelp; // the help description
|
||||
ret += "</span><br/>";
|
||||
if (func) // for options we print default values here, e.g.
|
||||
{
|
||||
@@ -93,11 +93,11 @@ vimperator.help = function (section, easter) //{{{
|
||||
// the tags which are printed on the top right
|
||||
ret += '</td><td class="taglist" valign="top">';
|
||||
var names = command.names;
|
||||
for (var j=0; j < names.length; j++)
|
||||
for (var j = 0; j < names.length; j++)
|
||||
{
|
||||
var cmd_name = names[j];
|
||||
cmd_name = vimperator.util.escapeHTML(cmd_name);
|
||||
ret += '<code class="tag">' + beg + cmd_name + end + '</code><br/>';
|
||||
var cmdName = names[j];
|
||||
cmdName = vimperator.util.escapeHTML(cmdName);
|
||||
ret += '<code class="tag">' + beg + cmdName + end + '</code><br/>';
|
||||
}
|
||||
ret += '</td></tr>';
|
||||
|
||||
@@ -114,17 +114,17 @@ vimperator.help = function (section, easter) //{{{
|
||||
ret = command.type + ' (default: ';
|
||||
if (command.type == "boolean")
|
||||
{
|
||||
if (command.default_value == true)
|
||||
if (command.defaultValue == true)
|
||||
ret += "on";
|
||||
else
|
||||
ret += "off";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (typeof command.default_value == "string" && command.default_value.length == 0)
|
||||
if (typeof command.defaultValue == "string" && command.defaultValue.length == 0)
|
||||
ret += "''";
|
||||
else
|
||||
ret += command.default_value;
|
||||
ret += command.defaultValue;
|
||||
}
|
||||
|
||||
ret += ")<br/>";
|
||||
@@ -286,6 +286,6 @@ vimperator.help = function (section, easter) //{{{
|
||||
window.content.scrollTo(0, pos[1]);
|
||||
}
|
||||
}, 0);
|
||||
} //}}}
|
||||
}; //}}}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
551
content/hints.js
551
content/hints.js
@@ -24,11 +24,11 @@
|
||||
|
||||
vimperator.Hints = function () //{{{
|
||||
{
|
||||
const HINT_PREFIX = "hah_hint_"; // prefix for the hint id
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
this.hintedElements = function () { return hintedElems; };
|
||||
this.currentState = function () { return state;};
|
||||
this.setCurrentState = function (s) { state = s;};
|
||||
const HINT_PREFIX = "hah_hint_"; // prefix for the hint id
|
||||
|
||||
var isHahModeEnabled = false; // is typing mode on
|
||||
var hintedElems = [];
|
||||
@@ -68,27 +68,6 @@ vimperator.Hints = function () //{{{
|
||||
win.coordLoaderId = window.setTimeout("vimperator.hints.loadCoord(" + win.winId + ", 0);", 1);
|
||||
}
|
||||
|
||||
this.loadCoord = function (winId, i)
|
||||
{
|
||||
win = wins[winId];
|
||||
|
||||
// win.res is not ready when loading has not finished yet
|
||||
if (!win.res)
|
||||
return;
|
||||
|
||||
var elem = win.res.snapshotItem(i);
|
||||
|
||||
if (elem)
|
||||
genElemCoords(elem);
|
||||
|
||||
i++;
|
||||
|
||||
if (i < win.res.snapshotLength && !isHahModeEnabled)
|
||||
window.setTimeout("vimperator.hints.loadCoord(" + winId + ", "+ i +");", 1);
|
||||
else
|
||||
win.coordLoaderId = null;
|
||||
};
|
||||
|
||||
function genElemCoords(elem)
|
||||
{
|
||||
// NOTE: experiment for making the function faster, report problems
|
||||
@@ -101,7 +80,7 @@ vimperator.Hints = function () //{{{
|
||||
//}
|
||||
//return;
|
||||
|
||||
if (typeof(elem.validCoord) != "undefined")
|
||||
if (typeof elem.validCoord != "undefined")
|
||||
{
|
||||
if (elem.validCoord == elem.ownerDocument.validCoords)
|
||||
return;
|
||||
@@ -157,7 +136,7 @@ vimperator.Hints = function () //{{{
|
||||
if (!hintContainer)
|
||||
return false;
|
||||
}
|
||||
hintContainer.valid_hint_count = 0; // none of these hints should be visible initially
|
||||
hintContainer.validHintCount = 0; // none of these hints should be visible initially
|
||||
|
||||
var hints = hintContainer.childNodes;
|
||||
var maxhints = vimperator.options["maxhints"];
|
||||
@@ -197,7 +176,7 @@ vimperator.Hints = function () //{{{
|
||||
hintElem.style.left = elem.absoLeft + "px";
|
||||
hintElem.refElem = elem;
|
||||
|
||||
hintContainer.valid_hint_count++; // one more visible hint in this frame
|
||||
hintContainer.validHintCount++; // one more visible hint in this frame
|
||||
linkCount++; // and one more total hint
|
||||
}
|
||||
|
||||
@@ -235,7 +214,7 @@ vimperator.Hints = function () //{{{
|
||||
var hints = hintContainer.childNodes;
|
||||
var i, j;
|
||||
|
||||
for (i = 0; i < hintContainer.valid_hint_count; i++)
|
||||
for (i = 0; i < hintContainer.validHintCount; i++)
|
||||
{
|
||||
hintText = formatHint(offset+i);
|
||||
hintElem = hints[i];
|
||||
@@ -244,7 +223,7 @@ vimperator.Hints = function () //{{{
|
||||
hintElem.innerHTML = hintText;
|
||||
hintElem.id = HINT_PREFIX + hintText;
|
||||
}
|
||||
offset += hintContainer.valid_hint_count;
|
||||
offset += hintContainer.validHintCount;
|
||||
|
||||
// recursively show hints
|
||||
for (j = 0; j < win.frames.length; j++)
|
||||
@@ -260,7 +239,7 @@ vimperator.Hints = function () //{{{
|
||||
win = window.content;
|
||||
|
||||
var doc = win.document;
|
||||
var res = vimperator.buffer.evaluateXPath("//HINTS/SPAN", doc)
|
||||
var res = vimperator.buffer.evaluateXPath("//HINTS/SPAN", doc);
|
||||
var elem, i;
|
||||
|
||||
for (i = 0; i < res.snapshotLength; i++)
|
||||
@@ -387,201 +366,52 @@ vimperator.Hints = function () //{{{
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// basic functionality
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Enables the HaH-mode by showing the hints and prepare to input the
|
||||
* hint numbers
|
||||
*
|
||||
* @author Pekka Sillanpaa
|
||||
* @param event that caused the mode to change
|
||||
* @return -1 if already enabled
|
||||
*/
|
||||
//function enableHahMode(event, mode)
|
||||
this.enableHahMode = function (mode)
|
||||
function genHintContainer(doc)
|
||||
{
|
||||
if (doc.getElementsByTagName("HINTS").length > 0)
|
||||
return;
|
||||
|
||||
hints = doc.createElement("HINTS");
|
||||
hints.id = "hah_hints";
|
||||
hints.validHintCount = 0; // initially 0 elements are usable as hints
|
||||
|
||||
if (doc.body)
|
||||
doc.body.appendChild(hints);
|
||||
}
|
||||
|
||||
function initDoc(event)
|
||||
{
|
||||
// vimperator.echoerr("Content loaded");
|
||||
|
||||
doc = event.originalTarget;
|
||||
genHintContainer(doc);
|
||||
isHahModeEnabled = false;
|
||||
hintedElems = [];
|
||||
|
||||
if (!doc.validCoords)
|
||||
doc.validCoords = true;
|
||||
else
|
||||
doc.validCoords = false;
|
||||
|
||||
// XXX: prepend a ! ?
|
||||
if (doc.coordsInvalidated)
|
||||
doc.coordsInvalidated = true;
|
||||
else
|
||||
doc.coordsInvalidated = false;
|
||||
|
||||
startCoordLoader(doc);
|
||||
|
||||
if (vimperator.hasMode(vimperator.modes.ALWAYS_HINT))
|
||||
{
|
||||
vimperator.setMode(vimperator.modes.HINTS, mode);
|
||||
state = 0;
|
||||
linkCount = 0;
|
||||
linkNumString = "";
|
||||
isHahModeEnabled = true;
|
||||
|
||||
setTimeout(function () {
|
||||
createHints();
|
||||
showHints(null, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the HaH-mode by hiding the hints and disabling the input mode
|
||||
*
|
||||
* @author Pekka Sillanpaa
|
||||
* @param event that caused the mode to change
|
||||
* @param action = true if something is to be clicked
|
||||
* false if cancel
|
||||
* @return -1 if already disabled
|
||||
*/
|
||||
//function disableHahMode(event)
|
||||
this.disableHahMode = function (win)
|
||||
{
|
||||
if (!isHahModeEnabled)
|
||||
return;
|
||||
|
||||
vimperator.setMode(vimperator.modes.NORMAL);
|
||||
isHahModeEnabled = false;
|
||||
linkNumString = "";
|
||||
hintedElems = [];
|
||||
|
||||
removeHints(win);
|
||||
return 0;
|
||||
};
|
||||
|
||||
this.resetHintedElements = function ()
|
||||
{
|
||||
linkNumString = "";
|
||||
state = 0;
|
||||
|
||||
while (hintedElems.length > 0)
|
||||
{
|
||||
var elem = hintedElems.pop();
|
||||
if (!elem)
|
||||
return 0;
|
||||
// reset style attribute
|
||||
setHintStyle(elem, vimperator.options["hintstyle"]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.reshowHints = function ()
|
||||
{
|
||||
onResize(null);
|
||||
|
||||
if (isHahModeEnabled)
|
||||
{
|
||||
removeHints();
|
||||
createHints();
|
||||
showHints(null, 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// TODO: move these functions somewhere more general
|
||||
|
||||
// this function 'click' an element, which also works
|
||||
// for javascript links
|
||||
this.openHints = function (new_tab, new_window)
|
||||
{
|
||||
var x = 0, y = 0;
|
||||
|
||||
while (hintedElems.length > 0)
|
||||
{
|
||||
var elem = hintedElems.pop();
|
||||
if (!elem)
|
||||
return 0;
|
||||
|
||||
setHintStyle(elem, vimperator.options["hintstyle"]);
|
||||
elem = elem.refElem;
|
||||
var elemTagName = elem.localName.toLowerCase();
|
||||
elem.focus();
|
||||
|
||||
if (elemTagName == "frame" || elemTagName == "iframe")
|
||||
return 0;
|
||||
|
||||
// for imagemap
|
||||
if (elemTagName == "area")
|
||||
{
|
||||
var coords = elem.getAttribute("coords").split(",");
|
||||
x = Number(coords[0]);
|
||||
y = Number(coords[1]);
|
||||
}
|
||||
var doc = window.content.document;
|
||||
var view = window.document.defaultView;
|
||||
|
||||
var evt = doc.createEvent("MouseEvents");
|
||||
evt.initMouseEvent("mousedown", true, true, view, 1, x + 1, y + 1, 0, 0, /*ctrl*/ new_tab, /*event.altKey*/0, /*event.shiftKey*/ new_window, /*event.metaKey*/ new_tab, 0, null);
|
||||
elem.dispatchEvent(evt);
|
||||
|
||||
var evt = doc.createEvent("MouseEvents");
|
||||
evt.initMouseEvent("click", true, true, view, 1, x + 1, y + 1, 0, 0, /*ctrl*/ new_tab, /*event.altKey*/0, /*event.shiftKey*/ new_window, /*event.metaKey*/ new_tab, 0, null);
|
||||
elem.dispatchEvent(evt);
|
||||
|
||||
// for 'pure' open calls without a new tab or window it doesn't
|
||||
// make sense to open more hints in the current tab, open new tabs
|
||||
// for it
|
||||
if (!new_tab && !new_window)
|
||||
new_tab = true;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
this.yankUrlHints = function ()
|
||||
{
|
||||
var loc = "";
|
||||
var elems = this.hintedElements();
|
||||
var tmp = "";
|
||||
for (var i = 0; i < elems.length; i++)
|
||||
{
|
||||
tmp = elems[i].refElem.href;
|
||||
if (typeof(tmp) != "undefined" && tmp.length > 0)
|
||||
{
|
||||
if (i > 0)
|
||||
loc += "\n";
|
||||
loc += tmp;
|
||||
}
|
||||
}
|
||||
|
||||
// disable the hints before we can echo() an information
|
||||
this.disableHahMode(null, true);
|
||||
|
||||
vimperator.copyToClipboard(loc);
|
||||
vimperator.echo("Yanked " + loc);
|
||||
};
|
||||
|
||||
this.yankTextHints = function ()
|
||||
{
|
||||
var loc = "";
|
||||
var elems = this.hintedElements();
|
||||
var tmp = "";
|
||||
for (var i = 0; i < elems.length; i++)
|
||||
{
|
||||
tmp = elems[i].refElem.textContent;
|
||||
if (typeof(tmp) != "undefined" && tmp.length > 0)
|
||||
{
|
||||
if (i > 0)
|
||||
loc += "\n";
|
||||
loc += tmp;
|
||||
}
|
||||
}
|
||||
|
||||
// disable the hints before we can echo() an information
|
||||
this.disableHahMode(null, true);
|
||||
|
||||
vimperator.copyToClipboard(loc);
|
||||
vimperator.echo("Yanked " + loc);
|
||||
};
|
||||
|
||||
this.saveHints = function (skip_prompt)
|
||||
{
|
||||
var elems = this.hintedElements();
|
||||
|
||||
for (var i = 0; i < elems.length; i++)
|
||||
{
|
||||
var doc = elems[i].ownerDocument;
|
||||
var url = makeURLAbsolute(elems[i].refElem.baseURI, elems[i].refElem.href);
|
||||
var text = elems[i].refElem.textContent;
|
||||
|
||||
try
|
||||
{
|
||||
urlSecurityCheck(url, doc.location.href);
|
||||
saveURL(url, text, null, true, skip_prompt, makeURI(url, doc.characterSet));
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
vimperator.echoerr(e);
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -615,6 +445,235 @@ vimperator.Hints = function () //{{{
|
||||
elem.dispatchEvent(evt);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
var hintManager = {
|
||||
|
||||
get hintedElements() { return hintedElems; },
|
||||
get currentState() { return state; },
|
||||
get setCurrentState(s) { state = s; },
|
||||
|
||||
loadCoord: function (winId, i)
|
||||
{
|
||||
win = wins[winId];
|
||||
|
||||
// win.res is not ready when loading has not finished yet
|
||||
if (!win.res)
|
||||
return;
|
||||
|
||||
var elem = win.res.snapshotItem(i);
|
||||
|
||||
if (elem)
|
||||
genElemCoords(elem);
|
||||
|
||||
i++;
|
||||
|
||||
if (i < win.res.snapshotLength && !isHahModeEnabled)
|
||||
window.setTimeout("vimperator.hints.loadCoord(" + winId + ", "+ i +");", 1);
|
||||
else
|
||||
win.coordLoaderId = null;
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// basic functionality
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Enables the HaH-mode by showing the hints and prepare to input the
|
||||
* hint numbers
|
||||
*
|
||||
* @author Pekka Sillanpaa
|
||||
* @param event that caused the mode to change
|
||||
* @return -1 if already enabled
|
||||
*/
|
||||
//function enableHahMode(event, mode)
|
||||
enableHahMode: function (mode)
|
||||
{
|
||||
vimperator.setMode(vimperator.modes.HINTS, mode);
|
||||
state = 0;
|
||||
linkCount = 0;
|
||||
linkNumString = "";
|
||||
isHahModeEnabled = true;
|
||||
|
||||
createHints();
|
||||
showHints(null, 0);
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Disables the HaH-mode by hiding the hints and disabling the input mode
|
||||
*
|
||||
* @author Pekka Sillanpaa
|
||||
* @param event that caused the mode to change
|
||||
* @param action = true if something is to be clicked
|
||||
* false if cancel
|
||||
* @return -1 if already disabled
|
||||
*/
|
||||
//function disableHahMode(event)
|
||||
disableHahMode: function (win)
|
||||
{
|
||||
if (!isHahModeEnabled)
|
||||
return;
|
||||
|
||||
vimperator.setMode(vimperator.modes.NORMAL);
|
||||
isHahModeEnabled = false;
|
||||
linkNumString = "";
|
||||
hintedElems = [];
|
||||
|
||||
removeHints(win);
|
||||
return 0;
|
||||
},
|
||||
|
||||
resetHintedElements: function ()
|
||||
{
|
||||
linkNumString = "";
|
||||
state = 0;
|
||||
|
||||
while (hintedElems.length > 0)
|
||||
{
|
||||
var elem = hintedElems.pop();
|
||||
if (!elem)
|
||||
return 0;
|
||||
// reset style attribute
|
||||
setHintStyle(elem, vimperator.options["hintstyle"]);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
reshowHints: function ()
|
||||
{
|
||||
onResize(null);
|
||||
|
||||
if (isHahModeEnabled)
|
||||
{
|
||||
removeHints();
|
||||
createHints();
|
||||
showHints(null, 0);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// TODO: move these functions somewhere more general
|
||||
|
||||
// this function 'click' an element, which also works
|
||||
// for javascript links
|
||||
openHints: function (newTab, newWindow)
|
||||
{
|
||||
var x = 0, y = 0;
|
||||
|
||||
while (hintedElems.length > 0)
|
||||
{
|
||||
var elem = hintedElems.pop();
|
||||
if (!elem)
|
||||
return 0;
|
||||
|
||||
setHintStyle(elem, vimperator.options["hintstyle"]);
|
||||
elem = elem.refElem;
|
||||
var elemTagName = elem.localName.toLowerCase();
|
||||
elem.focus();
|
||||
|
||||
if (elemTagName == "frame" || elemTagName == "iframe")
|
||||
return 0;
|
||||
|
||||
// for imagemap
|
||||
if (elemTagName == "area")
|
||||
{
|
||||
var coords = elem.getAttribute("coords").split(",");
|
||||
x = Number(coords[0]);
|
||||
y = Number(coords[1]);
|
||||
}
|
||||
var doc = window.content.document;
|
||||
var view = window.document.defaultView;
|
||||
|
||||
var evt = doc.createEvent("MouseEvents");
|
||||
evt.initMouseEvent("mousedown", true, true, view, 1, x + 1, y + 1, 0, 0, /*ctrl*/ newTab, /*event.altKey*/0, /*event.shiftKey*/ newWindow, /*event.metaKey*/ newTab, 0, null);
|
||||
elem.dispatchEvent(evt);
|
||||
|
||||
var evt = doc.createEvent("MouseEvents");
|
||||
evt.initMouseEvent("click", true, true, view, 1, x + 1, y + 1, 0, 0, /*ctrl*/ newTab, /*event.altKey*/0, /*event.shiftKey*/ newWindow, /*event.metaKey*/ newTab, 0, null);
|
||||
elem.dispatchEvent(evt);
|
||||
|
||||
// for 'pure' open calls without a new tab or window it doesn't
|
||||
// make sense to open more hints in the current tab, open new tabs
|
||||
// for it
|
||||
if (!newTab && !newWindow)
|
||||
newTab = true;
|
||||
}
|
||||
|
||||
return 0;
|
||||
},
|
||||
|
||||
yankUrlHints: function ()
|
||||
{
|
||||
var loc = "";
|
||||
var elems = this.hintedElements();
|
||||
var tmp = "";
|
||||
for (var i = 0; i < elems.length; i++)
|
||||
{
|
||||
tmp = elems[i].refElem.href;
|
||||
if (typeof tmp != "undefined" && tmp.length > 0)
|
||||
{
|
||||
if (i > 0)
|
||||
loc += "\n";
|
||||
loc += tmp;
|
||||
}
|
||||
}
|
||||
|
||||
// disable the hints before we can echo() an information
|
||||
this.disableHahMode(null, true);
|
||||
|
||||
vimperator.copyToClipboard(loc);
|
||||
vimperator.echo("Yanked " + loc);
|
||||
},
|
||||
|
||||
yankTextHints: function ()
|
||||
{
|
||||
var loc = "";
|
||||
var elems = this.hintedElements();
|
||||
var tmp = "";
|
||||
for (var i = 0; i < elems.length; i++)
|
||||
{
|
||||
tmp = elems[i].refElem.textContent;
|
||||
if (typeof tmp != "undefined" && tmp.length > 0)
|
||||
{
|
||||
if (i > 0)
|
||||
loc += "\n";
|
||||
loc += tmp;
|
||||
}
|
||||
}
|
||||
|
||||
// disable the hints before we can echo() an information
|
||||
this.disableHahMode(null, true);
|
||||
|
||||
vimperator.copyToClipboard(loc);
|
||||
vimperator.echo("Yanked " + loc);
|
||||
},
|
||||
|
||||
saveHints: function (skipPrompt)
|
||||
{
|
||||
var elems = this.hintedElements();
|
||||
|
||||
for (var i = 0; i < elems.length; i++)
|
||||
{
|
||||
var doc = elems[i].ownerDocument;
|
||||
var url = makeURLAbsolute(elems[i].refElem.baseURI, elems[i].refElem.href);
|
||||
var text = elems[i].refElem.textContent;
|
||||
|
||||
try
|
||||
{
|
||||
urlSecurityCheck(url, doc.location.href);
|
||||
saveURL(url, text, null, true, skipPrompt, makeURI(url, doc.characterSet));
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
vimperator.echoerr(e);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// event handlers
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -622,7 +681,7 @@ vimperator.Hints = function () //{{{
|
||||
// returns nr. of fully parsed links when a new hint has been found,
|
||||
// otherwise 0 if current state is part of a hint, or -1 if an error occured
|
||||
// (like we have typed keys which never can become a hint
|
||||
this.processEvent = function (event)
|
||||
processEvent: function (event)
|
||||
{
|
||||
if (!isHahModeEnabled)
|
||||
return -1;
|
||||
@@ -664,58 +723,14 @@ vimperator.Hints = function () //{{{
|
||||
return -1;
|
||||
}
|
||||
|
||||
function genHintContainer(doc)
|
||||
{
|
||||
if (doc.getElementsByTagName("HINTS").length > 0)
|
||||
return;
|
||||
|
||||
hints = doc.createElement("HINTS");
|
||||
hints.id = "hah_hints";
|
||||
hints.valid_hint_count = 0; // initially 0 elements are usable as hints
|
||||
|
||||
if (doc.body)
|
||||
doc.body.appendChild(hints);
|
||||
}
|
||||
|
||||
function initDoc(event)
|
||||
{
|
||||
// vimperator.echoerr("Content loaded");
|
||||
|
||||
doc = event.originalTarget;
|
||||
genHintContainer(doc);
|
||||
isHahModeEnabled = false;
|
||||
hintedElems = [];
|
||||
|
||||
if (!doc.validCoords)
|
||||
doc.validCoords = true;
|
||||
else
|
||||
doc.validCoords = false;
|
||||
|
||||
// XXX: prepend a ! ?
|
||||
if (doc.coordsInvalidated)
|
||||
doc.coordsInvalidated = true;
|
||||
else
|
||||
doc.coordsInvalidated = false;
|
||||
|
||||
startCoordLoader(doc);
|
||||
|
||||
if (vimperator.hasMode(vimperator.modes.ALWAYS_HINT))
|
||||
{
|
||||
state = 0;
|
||||
linkCount = 0;
|
||||
linkNumString = "";
|
||||
isHahModeEnabled = true;
|
||||
|
||||
setTimeout( function () {
|
||||
createHints();
|
||||
showHints(null, 0);
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
window.document.addEventListener("DOMContentLoaded", initDoc, null);
|
||||
// FIXME: add resize support
|
||||
//window.addEventListener("resize", onResize, null);
|
||||
} //}}}
|
||||
|
||||
return hintManager;
|
||||
//}}}
|
||||
}; //}}}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
@@ -27,9 +27,9 @@ the provisions above, a recipient may use your version of this file under
|
||||
the terms of any one of the MPL, the GPL or the LGPL.
|
||||
}}} ***** END LICENSE BLOCK *****/
|
||||
|
||||
vimperator.IO = function ()
|
||||
vimperator.IO = function () //{{{
|
||||
{
|
||||
var environment_service = Components.classes["@mozilla.org/process/environment;1"]
|
||||
var environmentService = Components.classes["@mozilla.org/process/environment;1"]
|
||||
.getService(Components.interfaces.nsIEnvironment);
|
||||
|
||||
return {
|
||||
@@ -54,30 +54,30 @@ vimperator.IO = function ()
|
||||
// expand "~" to VIMPERATOR_HOME or HOME (USERPROFILE or HOMEDRIVE\HOMEPATH on Windows if HOME is not set)
|
||||
if (/^~/.test(path))
|
||||
{
|
||||
var home = environment_service.get("VIMPERATOR_HOME");
|
||||
var home = environmentService.get("VIMPERATOR_HOME");
|
||||
|
||||
if (!home)
|
||||
home = environment_service.get("HOME");
|
||||
home = environmentService.get("HOME");
|
||||
|
||||
if (WINDOWS && !home)
|
||||
home = environment_service.get("USERPROFILE") ||
|
||||
environment_service.get("HOMEDRIVE") + environment_service.get("HOMEPATH");
|
||||
home = environmentService.get("USERPROFILE") ||
|
||||
environmentService.get("HOMEDRIVE") + environmentService.get("HOMEPATH");
|
||||
|
||||
path = path.replace("~", home);
|
||||
}
|
||||
|
||||
// expand any $ENV vars
|
||||
var env_vars = path.match(/\$\w+\b/g); // this is naive but so is Vim and we like to be compatible
|
||||
var envVars = path.match(/\$\w+\b/g); // this is naive but so is Vim and we like to be compatible
|
||||
|
||||
if (env_vars)
|
||||
if (envVars)
|
||||
{
|
||||
var expansion;
|
||||
|
||||
for (var i = 0; i < env_vars.length; i++)
|
||||
for (var i = 0; i < envVars.length; i++)
|
||||
{
|
||||
expansion = environment_service.get(env_vars[i].replace("$", ""));
|
||||
expansion = environmentService.get(envVars[i].replace("$", ""));
|
||||
if (expansion)
|
||||
path = path.replace(env_vars[i], expansion);
|
||||
path = path.replace(envVars[i], expansion);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,30 +86,30 @@ vimperator.IO = function ()
|
||||
|
||||
getPluginDir: function ()
|
||||
{
|
||||
var plugin_dir;
|
||||
var pluginDir;
|
||||
|
||||
if (navigator.platform == "Win32")
|
||||
plugin_dir = "~/vimperator/plugin";
|
||||
pluginDir = "~/vimperator/plugin";
|
||||
else
|
||||
plugin_dir = "~/.vimperator/plugin";
|
||||
pluginDir = "~/.vimperator/plugin";
|
||||
|
||||
plugin_dir = this.getFile(this.expandPath(plugin_dir));
|
||||
pluginDir = this.getFile(this.expandPath(pluginDir));
|
||||
|
||||
return plugin_dir.exists() && plugin_dir.isDirectory() ? plugin_dir : null;
|
||||
return pluginDir.exists() && pluginDir.isDirectory() ? pluginDir : null;
|
||||
},
|
||||
|
||||
getRCFile: function ()
|
||||
{
|
||||
var rc_file1 = this.getFile(this.expandPath("~/.vimperatorrc"));
|
||||
var rc_file2 = this.getFile(this.expandPath("~/_vimperatorrc"));
|
||||
var rcFile1 = this.getFile(this.expandPath("~/.vimperatorrc"));
|
||||
var rcFile2 = this.getFile(this.expandPath("~/_vimperatorrc"));
|
||||
|
||||
if (navigator.platform == "Win32")
|
||||
[rc_file1, rc_file2] = [rc_file2, rc_file1]
|
||||
[rcFile1, rcFile2] = [rcFile2, rcFile1]
|
||||
|
||||
if (rc_file1.exists() && rc_file1.isFile())
|
||||
return rc_file1;
|
||||
else if (rc_file2.exists() && rc_file2.isFile())
|
||||
return rc_file2;
|
||||
if (rcFile1.exists() && rcFile1.isFile())
|
||||
return rcFile1;
|
||||
else if (rcFile2.exists() && rcFile2.isFile())
|
||||
return rcFile2;
|
||||
else
|
||||
return null;
|
||||
},
|
||||
@@ -133,12 +133,12 @@ vimperator.IO = function ()
|
||||
createInstance(Components.interfaces.nsILocalFile);
|
||||
if (navigator.platform == "Win32")
|
||||
{
|
||||
var dir = environment_service.get("TMP") || environment_service.get("TEMP") || "C:\\";
|
||||
var dir = environmentService.get("TMP") || environmentService.get("TEMP") || "C:\\";
|
||||
file.initWithPath(dir + "\\vimperator.tmp");
|
||||
}
|
||||
else
|
||||
{
|
||||
var dir = environment_service.get("TMP") || environment_service.get("TEMP") || "/tmp/";
|
||||
var dir = environmentService.get("TMP") || environmentService.get("TEMP") || "/tmp/";
|
||||
file.initWithPath(dir + "/vimperator.tmp");
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ vimperator.IO = function ()
|
||||
ocstream.close();
|
||||
ofstream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}; //}}}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -26,7 +26,7 @@ the provisions above, a recipient may use your version of this file under
|
||||
the terms of any one of the MPL, the GPL or the LGPL.
|
||||
}}} ***** END LICENSE BLOCK *****/
|
||||
|
||||
vimperator.Option = function (names, type, extra_info) //{{{
|
||||
vimperator.Option = function (names, type, extraInfo) //{{{
|
||||
{
|
||||
if (!names || !type)
|
||||
return null;
|
||||
@@ -38,29 +38,29 @@ vimperator.Option = function (names, type, extra_info) //{{{
|
||||
this.usage = this.names;
|
||||
this.type = type;
|
||||
|
||||
if (extra_info)
|
||||
if (extraInfo)
|
||||
{
|
||||
if (extra_info.usage)
|
||||
this.usage = extra_info.usage;
|
||||
if (extraInfo.usage)
|
||||
this.usage = extraInfo.usage;
|
||||
|
||||
this.help = extra_info.help || null;
|
||||
this.short_help = extra_info.short_help || null;
|
||||
this.help = extraInfo.help || null;
|
||||
this.shortHelp = extraInfo.shortHelp || null;
|
||||
|
||||
// "", 0 are valid default values
|
||||
if (extra_info.default_value !== undefined)
|
||||
this.default_value = extra_info.default_value;
|
||||
if (extraInfo.defaultValue !== undefined)
|
||||
this.defaultValue = extraInfo.defaultValue;
|
||||
else
|
||||
this.default_value = null;
|
||||
this.defaultValue = null;
|
||||
|
||||
value = this.default_value;
|
||||
value = this.defaultValue;
|
||||
|
||||
if (extra_info.setter)
|
||||
this.setter = extra_info.setter;
|
||||
if (extra_info.getter)
|
||||
this.getter = extra_info.getter;
|
||||
if (extraInfo.setter)
|
||||
this.setter = extraInfo.setter;
|
||||
if (extraInfo.getter)
|
||||
this.getter = extraInfo.getter;
|
||||
|
||||
this.completer = extra_info.completer || null;
|
||||
this.validator = extra_info.validator || null;
|
||||
this.completer = extraInfo.completer || null;
|
||||
this.validator = extraInfo.validator || null;
|
||||
}
|
||||
|
||||
// add noOPTION variant of boolean OPTION to this.names
|
||||
@@ -85,9 +85,9 @@ vimperator.Option = function (names, type, extra_info) //{{{
|
||||
}
|
||||
);
|
||||
this.__defineSetter__("value",
|
||||
function (new_value)
|
||||
function (newValue)
|
||||
{
|
||||
value = new_value;
|
||||
value = newValue;
|
||||
if (this.setter)
|
||||
this.setter.call(this, value);
|
||||
}
|
||||
@@ -104,7 +104,7 @@ vimperator.Option = function (names, type, extra_info) //{{{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
this.isValidValue = function (value)
|
||||
{
|
||||
@@ -112,26 +112,27 @@ vimperator.Option = function (names, type, extra_info) //{{{
|
||||
return this.validator(value);
|
||||
else
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
this.reset = function ()
|
||||
{
|
||||
this.value = this.default_value;
|
||||
}
|
||||
} //}}}
|
||||
this.value = this.defaultValue;
|
||||
};
|
||||
}; //}}}
|
||||
|
||||
vimperator.Options = function () //{{{
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
var firefox_prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
|
||||
var firefoxPrefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
var vimperator_prefs = firefox_prefs.getBranch("extensions.vimperator.");
|
||||
var vimperatorPrefs = firefoxPrefs.getBranch("extensions.vimperator.");
|
||||
var options = [];
|
||||
|
||||
// save if we already changed a GUI related option, used for setInitialGUI
|
||||
var guioptions_done = false, showtabline_done = false, laststatus_done = false;
|
||||
var guioptionsDone = false, showtablineDone = false, laststatusDone = false;
|
||||
|
||||
function optionsIterator()
|
||||
{
|
||||
@@ -141,14 +142,14 @@ vimperator.Options = function () //{{{
|
||||
throw StopIteration;
|
||||
}
|
||||
|
||||
function storePreference(name, value, vimperator_branch)
|
||||
function storePreference(name, value, vimperatorBranch)
|
||||
{
|
||||
var branch;
|
||||
|
||||
if (vimperator_branch)
|
||||
branch = vimperator_prefs;
|
||||
if (vimperatorBranch)
|
||||
branch = vimperatorPrefs;
|
||||
else
|
||||
branch = firefox_prefs;
|
||||
branch = firefoxPrefs;
|
||||
|
||||
switch (typeof value)
|
||||
{
|
||||
@@ -166,23 +167,23 @@ vimperator.Options = function () //{{{
|
||||
}
|
||||
}
|
||||
|
||||
function loadPreference(name, forced_default, vimperator_branch)
|
||||
function loadPreference(name, forcedDefault, vimperatorBranch)
|
||||
{
|
||||
var default_value = null;
|
||||
if (forced_default != null) // this argument sets defaults for non-user settable options (like comp_history)
|
||||
default_value = forced_default;
|
||||
var defaultValue = null;
|
||||
if (forcedDefault != null) // this argument sets defaults for non-user settable options (like comp_history)
|
||||
defaultValue = forcedDefault;
|
||||
|
||||
if (vimperator_branch)
|
||||
if (vimperatorBranch)
|
||||
{
|
||||
branch = vimperator_prefs;
|
||||
branch = vimperatorPrefs;
|
||||
|
||||
if (!forced_default) // this argument sets defaults for non-user settable options (like comp_history)
|
||||
if (!forcedDefault) // this argument sets defaults for non-user settable options (like comp_history)
|
||||
{
|
||||
for (var i = 0; i < options.length; i++)
|
||||
{
|
||||
if (options[i].name == name) // only first name is searched
|
||||
{
|
||||
default_value = options[i].default_value;
|
||||
defaultValue = options[i].defaultValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -190,12 +191,12 @@ vimperator.Options = function () //{{{
|
||||
}
|
||||
else
|
||||
{
|
||||
branch = firefox_prefs;
|
||||
branch = firefoxPrefs;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
switch (typeof default_value)
|
||||
switch (typeof defaultValue)
|
||||
{
|
||||
case "string":
|
||||
return branch.getCharPref(name);
|
||||
@@ -204,12 +205,12 @@ vimperator.Options = function () //{{{
|
||||
case "boolean":
|
||||
return branch.getBoolPref(name);
|
||||
default:
|
||||
return default_value;
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
return default_value;
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +226,7 @@ vimperator.Options = function () //{{{
|
||||
document.getElementById("PersonalToolbar").collapsed = value.indexOf("b") > -1 ? false : true;
|
||||
document.getElementById("PersonalToolbar").hidden = value.indexOf("b") > -1 ? false : true;
|
||||
|
||||
guioptions_done = true;
|
||||
guioptionsDone = true;
|
||||
}
|
||||
|
||||
function setLastStatus(value)
|
||||
@@ -245,7 +246,7 @@ vimperator.Options = function () //{{{
|
||||
document.getElementById("status-bar").hidden = false;
|
||||
}
|
||||
|
||||
laststatus_done = true;
|
||||
laststatusDone = true;
|
||||
}
|
||||
|
||||
function setShowTabline(value)
|
||||
@@ -269,7 +270,7 @@ vimperator.Options = function () //{{{
|
||||
tabs.collapsed = false;
|
||||
}
|
||||
|
||||
showtabline_done = true;
|
||||
showtablineDone = true;
|
||||
}
|
||||
|
||||
function setTitleString(value)
|
||||
@@ -296,9 +297,9 @@ vimperator.Options = function () //{{{
|
||||
//
|
||||
|
||||
// work around firefox popup blocker
|
||||
var popup_allowed_events = loadPreference("dom.popup_allowed_events", "change click dblclick mouseup reset submit");
|
||||
if (!popup_allowed_events.match("keypress"))
|
||||
storePreference("dom.popup_allowed_events", popup_allowed_events + " keypress");
|
||||
var popupAllowedEvents = loadPreference("dom.popup_allowed_events", "change click dblclick mouseup reset submit");
|
||||
if (!popupAllowedEvents.match("keypress"))
|
||||
storePreference("dom.popup_allowed_events", popupAllowedEvents + " keypress");
|
||||
|
||||
// TODO: shouldn't we be resetting these in destroy() as well?
|
||||
// we have our own typeahead find implementation
|
||||
@@ -312,12 +313,14 @@ vimperator.Options = function () //{{{
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
this.__iterator__ = function ()
|
||||
var optionManager = {
|
||||
|
||||
__iterator__: function ()
|
||||
{
|
||||
return optionsIterator();
|
||||
}
|
||||
},
|
||||
|
||||
this.get = function (name)
|
||||
get: function (name)
|
||||
{
|
||||
for (var i = 0; i < options.length; i++)
|
||||
{
|
||||
@@ -325,24 +328,24 @@ vimperator.Options = function () //{{{
|
||||
return options[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
this.add = function (option)
|
||||
add: function (option)
|
||||
{
|
||||
this.__defineGetter__(option.name, function () { return option.value; });
|
||||
this.__defineSetter__(option.name, function (value) { option.value = value; });
|
||||
options.push(option);
|
||||
}
|
||||
},
|
||||
|
||||
this.destroy = function ()
|
||||
destroy: function ()
|
||||
{
|
||||
// reset some modified firefox prefs
|
||||
if (loadPreference("dom.popup_allowed_events", "change click dblclick mouseup reset submit")
|
||||
== popup_allowed_events + " keypress")
|
||||
storePreference("dom.popup_allowed_events", popup_allowed_events);
|
||||
}
|
||||
== popupAllowedEvents + " keypress")
|
||||
storePreference("dom.popup_allowed_events", popupAllowedEvents);
|
||||
},
|
||||
|
||||
this.list = function (only_non_default)
|
||||
list: function (onlyNondefault)
|
||||
{
|
||||
// TODO: columns like Vim?
|
||||
var list = ":" + vimperator.util.escapeHTML(vimperator.commandline.getCommand()) + "<br/>" +
|
||||
@@ -353,9 +356,9 @@ vimperator.Options = function () //{{{
|
||||
{
|
||||
name = options[i].name;
|
||||
value = options[i].value;
|
||||
def = options[i].default_value;
|
||||
def = options[i].defaultValue;
|
||||
|
||||
if (only_non_default && value == def)
|
||||
if (onlyNondefault && value == def)
|
||||
continue;
|
||||
|
||||
if (options[i].type == "boolean")
|
||||
@@ -382,40 +385,42 @@ vimperator.Options = function () //{{{
|
||||
list += "</table>";
|
||||
|
||||
vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE);
|
||||
}
|
||||
},
|
||||
|
||||
// this hack is only needed, because we need to do asynchronous loading of the .vimperatorrc
|
||||
this.setInitialGUI = function ()
|
||||
setInitialGUI: function ()
|
||||
{
|
||||
if (!guioptions_done)
|
||||
if (!guioptionsDone)
|
||||
this.get("guioptions").reset();
|
||||
if (!laststatus_done)
|
||||
if (!laststatusDone)
|
||||
this.get("laststatus").reset();
|
||||
if (!showtabline_done)
|
||||
if (!showtablineDone)
|
||||
this.get("showtabline").reset();
|
||||
}
|
||||
},
|
||||
|
||||
// TODO: separate Preferences from Options? Would these utility functions
|
||||
// be better placed in the 'core' vimperator namespace somewhere?
|
||||
this.setPref = function (name, value)
|
||||
setPref: function (name, value)
|
||||
{
|
||||
return storePreference(name, value, true);
|
||||
}
|
||||
},
|
||||
|
||||
this.getPref = function (name, forced_default)
|
||||
getPref: function (name, forcedDefault)
|
||||
{
|
||||
return loadPreference(name, forced_default, true);
|
||||
}
|
||||
return loadPreference(name, forcedDefault, true);
|
||||
},
|
||||
|
||||
this.setFirefoxPref = function (name, value)
|
||||
setFirefoxPref: function (name, value)
|
||||
{
|
||||
return storePreference(name, value);
|
||||
},
|
||||
|
||||
getFirefoxPref: function (name, forcedDefault)
|
||||
{
|
||||
return loadPreference(name, forcedDefault);
|
||||
}
|
||||
|
||||
this.getFirefoxPref = function (name, forced_default)
|
||||
{
|
||||
return loadPreference(name, forced_default);
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// DEFAULT OPTIONS /////////////////////////////////////////
|
||||
@@ -424,11 +429,11 @@ vimperator.Options = function () //{{{
|
||||
const DEFAULT_HINTTAGS = "//*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @class='s'] | " +
|
||||
"//input[not(@type='hidden')] | //a | //area | //iframe | //textarea | //button | //select | " +
|
||||
"//xhtml:*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @class='s'] | " +
|
||||
"//xhtml:input[not(@type='hidden')] | //xhtml:a | //xhtml:area | //xhtml:iframe | //xhtml:textarea | //xhtml:button | //xhtml:select"
|
||||
"//xhtml:input[not(@type='hidden')] | //xhtml:a | //xhtml:area | //xhtml:iframe | //xhtml:textarea | //xhtml:button | //xhtml:select";
|
||||
|
||||
this.add(new vimperator.Option(["activate", "act"], "stringlist",
|
||||
optionManager.add(new vimperator.Option(["activate", "act"], "stringlist",
|
||||
{
|
||||
short_help: "Define when tabs are automatically activated",
|
||||
shortHelp: "Define when tabs are automatically activated",
|
||||
help: "Available items:<br/>" +
|
||||
"<ul>" +
|
||||
"<li><b>homepage</b>: <code class=\"mapping\">gH</code> mapping</li>" +
|
||||
@@ -436,16 +441,16 @@ vimperator.Options = function () //{{{
|
||||
"<li><b>tabopen</b>: <code class=\"command\">:tabopen[!]</code> command</li>" +
|
||||
"<li><b>paste</b>: <code class=\"mapping\">P</code> and <code class=\"mapping\">gP</code> mappings</li>" +
|
||||
"</ul>",
|
||||
default_value: "homepage,quickmark,tabopen,paste",
|
||||
defaultValue: "homepage,quickmark,tabopen,paste",
|
||||
validator: function (value)
|
||||
{
|
||||
return value.split(",").every(function (item) { return /^(homepage|quickmark|tabopen|paste|)$/.test(item); });
|
||||
}
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["complete", "cpt"], "charlist",
|
||||
optionManager.add(new vimperator.Option(["complete", "cpt"], "charlist",
|
||||
{
|
||||
short_help: "Items which are completed at the :[tab]open prompt",
|
||||
shortHelp: "Items which are completed at the :[tab]open prompt",
|
||||
help: "Available items:<br/>" +
|
||||
"<ul>" +
|
||||
"<li><b>s</b>: Search engines and keyword URLs</li>" +
|
||||
@@ -455,43 +460,42 @@ vimperator.Options = function () //{{{
|
||||
"</ul>" +
|
||||
"The order is important, so <code class=\"command\">:set complete=bs</code> would list bookmarks first, and then any available quick searches.<br/>" +
|
||||
"Add <code class=\"option\">'sort'</code> to the <code class=\"option\">'wildoptions'</code> option if you want all entries sorted.",
|
||||
default_value: "sfbh",
|
||||
defaultValue: "sfbh",
|
||||
validator: function (value) { return !/[^sfbh]/.test(value); }
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["defsearch", "ds"], "string",
|
||||
optionManager.add(new vimperator.Option(["defsearch", "ds"], "string",
|
||||
{
|
||||
short_help: "Set the default search engine",
|
||||
shortHelp: "Set the default search engine",
|
||||
help: "The default search engine is used in the <code class=\"command\">:[tab]open [arg]</code> command " +
|
||||
"if [arg] neither looks like a URL or like a specified search engine/keyword.",
|
||||
completer: function () { return [["foo", "bar"], ["shit", "blub"]]; },
|
||||
default_value: "google"
|
||||
defaultValue: "google"
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["extendedhinttags", "eht"], "string",
|
||||
optionManager.add(new vimperator.Option(["extendedhinttags", "eht"], "string",
|
||||
{
|
||||
short_help: "XPath string of hintable elements activated by ';'",
|
||||
default_value: DEFAULT_HINTTAGS
|
||||
shortHelp: "XPath string of hintable elements activated by ';'",
|
||||
defaultValue: DEFAULT_HINTTAGS
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["focusedhintstyle", "fhs"], "string",
|
||||
optionManager.add(new vimperator.Option(["focusedhintstyle", "fhs"], "string",
|
||||
{
|
||||
short_help: "CSS specification of focused hints",
|
||||
default_value: "z-index:5000; font-family:monospace; font-size:12px; color:ButtonText; background-color:ButtonShadow; " +
|
||||
shortHelp: "CSS specification of focused hints",
|
||||
defaultValue: "z-index:5000; font-family:monospace; font-size:12px; color:ButtonText; background-color:ButtonShadow; " +
|
||||
"border-color:ButtonShadow; border-width:1px; border-style:solid; padding:0px 1px 0px 1px; position:absolute;"
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["fullscreen", "fs"], "boolean",
|
||||
optionManager.add(new vimperator.Option(["fullscreen", "fs"], "boolean",
|
||||
{
|
||||
short_help: "Show the current window fullscreen",
|
||||
shortHelp: "Show the current window fullscreen",
|
||||
setter: function (value) { window.fullScreen = value; },
|
||||
getter: function () { return window.fullScreen; },
|
||||
default_value: false
|
||||
defaultValue: false
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["guioptions", "go"], "charlist",
|
||||
optionManager.add(new vimperator.Option(["guioptions", "go"], "charlist",
|
||||
{
|
||||
short_help: "Show or hide the menu, toolbar and scrollbars",
|
||||
shortHelp: "Show or hide the menu, toolbar and scrollbars",
|
||||
help: "Supported characters:<br/>" +
|
||||
"<ul>" +
|
||||
"<li><b>m</b>: menubar</li>" +
|
||||
@@ -499,58 +503,58 @@ vimperator.Options = function () //{{{
|
||||
"<li><b>b</b>: bookmark bar</li>" +
|
||||
"</ul>",
|
||||
setter: function (value) { setGuiOptions(value); },
|
||||
default_value: "",
|
||||
defaultValue: "",
|
||||
validator: function (value) { return !/[^mTb]/.test(value); }
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["hintchars", "hc"], "charlist",
|
||||
optionManager.add(new vimperator.Option(["hintchars", "hc"], "charlist",
|
||||
{
|
||||
short_help: "String of single characters which can be used to follow hints",
|
||||
default_value: "hjklasdfgyuiopqwertnmzxcvb"
|
||||
shortHelp: "String of single characters which can be used to follow hints",
|
||||
defaultValue: "hjklasdfgyuiopqwertnmzxcvb"
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["hintstyle", "hs"], "string",
|
||||
optionManager.add(new vimperator.Option(["hintstyle", "hs"], "string",
|
||||
{
|
||||
short_help: "CSS specification of unfocused hints",
|
||||
default_value: "z-index:5000; font-family:monospace; font-size:12px; color:white; background-color:red; " +
|
||||
shortHelp: "CSS specification of unfocused hints",
|
||||
defaultValue: "z-index:5000; font-family:monospace; font-size:12px; color:white; background-color:red; " +
|
||||
"border-color:ButtonShadow; border-width:0px; border-style:solid; padding:0px 1px 0px 1px; position:absolute;"
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["hinttags", "ht"], "string",
|
||||
optionManager.add(new vimperator.Option(["hinttags", "ht"], "string",
|
||||
{
|
||||
short_help: "XPath string of hintable elements activated by <code class=\"mapping\">'f'</code> and <code class=\"mapping\">'F'</code>",
|
||||
default_value: DEFAULT_HINTTAGS
|
||||
shortHelp: "XPath string of hintable elements activated by <code class=\"mapping\">'f'</code> and <code class=\"mapping\">'F'</code>",
|
||||
defaultValue: DEFAULT_HINTTAGS
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["hlsearch", "hls"], "boolean",
|
||||
optionManager.add(new vimperator.Option(["hlsearch", "hls"], "boolean",
|
||||
{
|
||||
short_help: "Highlight previous search pattern matches",
|
||||
shortHelp: "Highlight previous search pattern matches",
|
||||
setter: function (value) { if (value) vimperator.search.highlight(); else vimperator.search.clear(); },
|
||||
default_value: false
|
||||
defaultValue: false
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["hlsearchstyle", "hlss"], "string",
|
||||
optionManager.add(new vimperator.Option(["hlsearchstyle", "hlss"], "string",
|
||||
{
|
||||
short_help: "CSS specification of highlighted search items",
|
||||
default_value: "color: black; background-color: yellow; padding: 0; display: inline;"
|
||||
shortHelp: "CSS specification of highlighted search items",
|
||||
defaultValue: "color: black; background-color: yellow; padding: 0; display: inline;"
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["ignorecase", "ic"], "boolean",
|
||||
optionManager.add(new vimperator.Option(["ignorecase", "ic"], "boolean",
|
||||
{
|
||||
short_help: "Ignore case in search patterns",
|
||||
default_value: true
|
||||
shortHelp: "Ignore case in search patterns",
|
||||
defaultValue: true
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["incsearch", "is"], "boolean",
|
||||
optionManager.add(new vimperator.Option(["incsearch", "is"], "boolean",
|
||||
{
|
||||
short_help: "Show where the search pattern matches as it is typed",
|
||||
shortHelp: "Show where the search pattern matches as it is typed",
|
||||
help: "NOTE: Incremental searching currently only works in the forward direction.",
|
||||
default_value: true
|
||||
defaultValue: true
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["laststatus", "ls"], "number",
|
||||
optionManager.add(new vimperator.Option(["laststatus", "ls"], "number",
|
||||
{
|
||||
short_help: "Show the status line",
|
||||
shortHelp: "Show the status line",
|
||||
help: "Determines when the last window will have a status line. " +
|
||||
"Possible values:<br/>" +
|
||||
"<ul>" +
|
||||
@@ -559,35 +563,35 @@ vimperator.Options = function () //{{{
|
||||
"<li><b>2</b>: always</li>" +
|
||||
"</ul>" +
|
||||
"NOTE: laststatus=1 not implemented yet.",
|
||||
default_value: 2,
|
||||
defaultValue: 2,
|
||||
setter: function (value) { setLastStatus(value); },
|
||||
validator: function (value) { return (value >= 0 && value <= 2); }
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["linksearch", "lks"], "boolean",
|
||||
optionManager.add(new vimperator.Option(["linksearch", "lks"], "boolean",
|
||||
{
|
||||
short_help: "Limit the search to hyperlink text",
|
||||
shortHelp: "Limit the search to hyperlink text",
|
||||
help: "This includes (X)HTML elements with an \"href\" atrribute and XLink \"simple\" links.",
|
||||
default_value: false
|
||||
defaultValue: false
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["more"], "boolean",
|
||||
optionManager.add(new vimperator.Option(["more"], "boolean",
|
||||
{
|
||||
short_help: "Pause the message list window when more than one screen of listings is displayed",
|
||||
default_value: true
|
||||
shortHelp: "Pause the message list window when more than one screen of listings is displayed",
|
||||
defaultValue: true
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["maxhints", "mh"], "number",
|
||||
optionManager.add(new vimperator.Option(["maxhints", "mh"], "number",
|
||||
{
|
||||
short_help: "Maximum number of simultaneously shown hints",
|
||||
shortHelp: "Maximum number of simultaneously shown hints",
|
||||
help: "If you want to speed up display of hints, choose a smaller value",
|
||||
default_value: 250,
|
||||
defaultValue: 250,
|
||||
validator: function (value) { if (value >= 1 && value <= 1000) return true; else return false; }
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["pageinfo", "pa"], "charlist",
|
||||
optionManager.add(new vimperator.Option(["pageinfo", "pa"], "charlist",
|
||||
{
|
||||
short_help: "Desired info on :pa[geinfo]",
|
||||
shortHelp: "Desired info on :pa[geinfo]",
|
||||
help: "Available items:<br/>" +
|
||||
"<ul>" +
|
||||
"<li><b>g</b>: general info</li>" +
|
||||
@@ -595,13 +599,13 @@ vimperator.Options = function () //{{{
|
||||
"<li><b>m</b>: meta tags</li>" +
|
||||
"</ul>" +
|
||||
"The order matters",
|
||||
default_value: "gfm",
|
||||
validator: function (value) { return !(/[^gfm]/.test(value) || value.length > 3 || value.length < 1) }
|
||||
defaultValue: "gfm",
|
||||
validator: function (value) { return !(/[^gfm]/.test(value) || value.length > 3 || value.length < 1); }
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["popups", "pps"], "number",
|
||||
optionManager.add(new vimperator.Option(["popups", "pps"], "number",
|
||||
{
|
||||
short_help: "Where to show requested popup windows",
|
||||
shortHelp: "Where to show requested popup windows",
|
||||
help: "Define where to show requested popup windows. Does not apply to windows which are opened by middle clicking a link, they always open in a new tab. " +
|
||||
"Possible values:<br/>" +
|
||||
"<ul>" +
|
||||
@@ -611,48 +615,48 @@ vimperator.Options = function () //{{{
|
||||
"<li><b>3</b>: Always open in a new window</li>" +
|
||||
"</ul>" +
|
||||
"NOTE: This option does not change the popup blocker of Firefox in any way.",
|
||||
default_value: 1,
|
||||
defaultValue: 1,
|
||||
setter: function (value) { setPopups(value); },
|
||||
validator: function (value) { return (value >= 0 && value <= 3); }
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["preload"], "boolean",
|
||||
optionManager.add(new vimperator.Option(["preload"], "boolean",
|
||||
{
|
||||
short_help: "Speed up first time history/bookmark completion",
|
||||
shortHelp: "Speed up first time history/bookmark completion",
|
||||
help: "History access can be quite slow for a large history. Vimperator maintains a cache to speed it up significantly on subsequent access.<br/>" +
|
||||
"In order to also speed up first time access, it is cached at startup, if this option is set (recommended).",
|
||||
default_value: true
|
||||
defaultValue: true
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["previewheight", "pvh"], "number",
|
||||
optionManager.add(new vimperator.Option(["previewheight", "pvh"], "number",
|
||||
{
|
||||
short_help: "Default height for preview window",
|
||||
shortHelp: "Default height for preview window",
|
||||
help: "Value must be between 1 and 50. If the value is too high, completions may cover the command-line. " +
|
||||
"Close the preview window with <code class=\"command\">:pclose</code>.<br/>" +
|
||||
"NOTE: Option currently disabled",
|
||||
default_value: 10,
|
||||
defaultValue: 10,
|
||||
validator: function (value) { return (value >= 1 && value <= 50); }
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["scroll", "scr"], "number",
|
||||
optionManager.add(new vimperator.Option(["scroll", "scr"], "number",
|
||||
{
|
||||
short_help: "Number of lines to scroll with <code class=\"mapping\">C-u</code> and <code class=\"mapping\">C-d</code> commands",
|
||||
shortHelp: "Number of lines to scroll with <code class=\"mapping\">C-u</code> and <code class=\"mapping\">C-d</code> commands",
|
||||
help: "The number of lines scrolled defaults to half the window size. " +
|
||||
"When a <code class=\"argument\">{count}</code> is specified to the <code class=\"mapping\"><C-u></code> or <code class=\"mapping\"><C-d></code> commands this is used to set the value of <code class=\"option\">'scroll'</code> and also used for the current command. " +
|
||||
"The value can be reset to half the window height with <code class=\"command\">:set scroll=0</code>.",
|
||||
default_value: 0,
|
||||
defaultValue: 0,
|
||||
validator: function (value) { return value >= 0; }
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["showmode", "smd"], "boolean",
|
||||
optionManager.add(new vimperator.Option(["showmode", "smd"], "boolean",
|
||||
{
|
||||
short_help: "Show the current mode in the command line",
|
||||
default_value: true
|
||||
shortHelp: "Show the current mode in the command line",
|
||||
defaultValue: true
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["showstatuslinks", "ssli"], "number",
|
||||
optionManager.add(new vimperator.Option(["showstatuslinks", "ssli"], "number",
|
||||
{
|
||||
short_help: "Show the destination of the link under the cursor in the status bar",
|
||||
shortHelp: "Show the destination of the link under the cursor in the status bar",
|
||||
help: "Also links which are focused by keyboard commands like <code class=\"mapping\"><Tab></code> are shown. " +
|
||||
"Possible values:<br/>" +
|
||||
"<ul>" +
|
||||
@@ -660,13 +664,13 @@ vimperator.Options = function () //{{{
|
||||
"<li><b>1</b>: Show the link in the status line</li>" +
|
||||
"<li><b>2</b>: Show the link in the command line</li>" +
|
||||
"</ul>",
|
||||
default_value: 1,
|
||||
defaultValue: 1,
|
||||
validator: function (value) { return (value >= 0 && value <= 2); }
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["showtabline", "stal"], "number",
|
||||
optionManager.add(new vimperator.Option(["showtabline", "stal"], "number",
|
||||
{
|
||||
short_help: "Control when to show the tab bar of opened web pages",
|
||||
shortHelp: "Control when to show the tab bar of opened web pages",
|
||||
help: "Possible values:<br/>" +
|
||||
"<ul>" +
|
||||
"<li><b>0</b>: Never show tab bar</li>" +
|
||||
@@ -674,63 +678,63 @@ vimperator.Options = function () //{{{
|
||||
"<li><b>2</b>: Always show tab bar</li>" +
|
||||
"</ul>",
|
||||
setter: function (value) { setShowTabline(value); },
|
||||
default_value: 2,
|
||||
defaultValue: 2,
|
||||
validator: function (value) { return (value >= 0 && value <= 2); }
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["smartcase", "scs"], "boolean",
|
||||
optionManager.add(new vimperator.Option(["smartcase", "scs"], "boolean",
|
||||
{
|
||||
short_help: "Override the 'ignorecase' option if the pattern contains uppercase characters",
|
||||
shortHelp: "Override the 'ignorecase' option if the pattern contains uppercase characters",
|
||||
help: "This is only used if the <code class=\"option\">'ignorecase'</code> option is set.",
|
||||
default_value: true
|
||||
defaultValue: true
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["titlestring"], "string",
|
||||
optionManager.add(new vimperator.Option(["titlestring"], "string",
|
||||
{
|
||||
short_help: "Change the title of the browser window",
|
||||
shortHelp: "Change the title of the browser window",
|
||||
help: "Vimperator changes the browser title from \"Title of web page - Mozilla Firefox\" to " +
|
||||
"\"Title of web page - Vimperator\".<br/>If you don't like that, you can restore it with: " +
|
||||
"<code class=\"command\">:set titlestring=Mozilla Firefox</code>.",
|
||||
setter: function (value) { setTitleString(value); },
|
||||
default_value: "Vimperator"
|
||||
defaultValue: "Vimperator"
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["usermode", "um"], "boolean",
|
||||
optionManager.add(new vimperator.Option(["usermode", "um"], "boolean",
|
||||
{
|
||||
short_help: "Show current website with a minimal style sheet to make it easily accessible",
|
||||
shortHelp: "Show current website with a minimal style sheet to make it easily accessible",
|
||||
help: "Note that this is a local option for now, later it may be split into a global and <code class=\"command\">:setlocal</code> part",
|
||||
setter: function (value) { getMarkupDocumentViewer().authorStyleDisabled = value; },
|
||||
getter: function () { return getMarkupDocumentViewer().authorStyleDisabled; },
|
||||
default_value: false
|
||||
defaultValue: false
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["verbose", "vbs"], "number",
|
||||
optionManager.add(new vimperator.Option(["verbose", "vbs"], "number",
|
||||
{
|
||||
short_help: "Define which type of messages are logged",
|
||||
shortHelp: "Define which type of messages are logged",
|
||||
help: "When bigger than zero, Vimperator will give messages about what it is doing. They are printed to the error console which can be shown with <code class=\"command\">:javascript!</code>.<br/>" +
|
||||
"The highest value is 9, being the most verbose mode.",
|
||||
default_value: 0,
|
||||
defaultValue: 0,
|
||||
validator: function (value) { return (value >= 0 && value <= 9); }
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["visualbell", "vb"], "boolean",
|
||||
optionManager.add(new vimperator.Option(["visualbell", "vb"], "boolean",
|
||||
{
|
||||
short_help: "Use visual bell instead of beeping on errors",
|
||||
shortHelp: "Use visual bell instead of beeping on errors",
|
||||
setter: function (value) { vimperator.options.setFirefoxPref("accessibility.typeaheadfind.enablesound", !value); },
|
||||
default_value: false
|
||||
defaultValue: false
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["visualbellstyle", "t_vb"], "string",
|
||||
optionManager.add(new vimperator.Option(["visualbellstyle", "t_vb"], "string",
|
||||
{
|
||||
short_help: "CSS specification of the visual bell",
|
||||
shortHelp: "CSS specification of the visual bell",
|
||||
help: "To hide the visual bell use a value of \"display: none;\" or unset it with <code class=\"command\">:set t_vb=</code>",
|
||||
setter: function (value) { if (!value) value = "display: none;"; },
|
||||
default_value: "background-color: black; color: black;"
|
||||
defaultValue: "background-color: black; color: black;"
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["wildmode", "wim"], "stringlist",
|
||||
optionManager.add(new vimperator.Option(["wildmode", "wim"], "stringlist",
|
||||
{
|
||||
short_help: "Define how command line completion works",
|
||||
shortHelp: "Define how command line completion works",
|
||||
help: "It is a comma-separated list of parts, where each part specifies " +
|
||||
"what to do for each consecutive use of the completion key. The first part " +
|
||||
"specifies the behavior for the first use of the completion key, the second part " +
|
||||
@@ -745,22 +749,22 @@ vimperator.Options = function () //{{{
|
||||
"<tr><td><b>'list:longest'</b></td><td>When more than one match, list all matches and complete till the longest common string.</td></tr>" +
|
||||
"</table>" +
|
||||
"When there is only a single match, it is fully completed regardless of the case.",
|
||||
default_value: "list:full",
|
||||
defaultValue: "list:full",
|
||||
validator: function (value)
|
||||
{
|
||||
return value.split(",").every(function (item) { return /^(full|longest|list|list:full|list:longest|)$/.test(item); });
|
||||
}
|
||||
}
|
||||
));
|
||||
this.add(new vimperator.Option(["wildoptions", "wop"], "stringlist",
|
||||
optionManager.add(new vimperator.Option(["wildoptions", "wop"], "stringlist",
|
||||
{
|
||||
short_help: "Change how command line completion is done",
|
||||
shortHelp: "Change how command line completion is done",
|
||||
help: "A list of words that change how command line completion is done.<br/>" +
|
||||
"Currently only one word is allowed:<br/>" +
|
||||
"<table>" +
|
||||
"<tr><td><b>sort</b></td><td>Always sorts completion list, overriding the <code class=\"option\">'complete'</code> option.</td></tr>" +
|
||||
"</table>",
|
||||
default_value: "",
|
||||
defaultValue: "",
|
||||
validator: function (value) { return /^(sort|)$/.test(value); }
|
||||
}
|
||||
));
|
||||
@@ -771,10 +775,12 @@ vimperator.Options = function () //{{{
|
||||
setShowTabline(0);
|
||||
setGuiOptions("");
|
||||
setLastStatus(0);
|
||||
guioptions_done = showtabline_done = laststatus_done = false;
|
||||
guioptionsDone = showtablineDone = laststatusDone = false;
|
||||
|
||||
setTitleString(this.titlestring);
|
||||
setPopups(this.popups);
|
||||
} //}}}
|
||||
setTitleString(optionManager.titlestring);
|
||||
setPopups(optionManager.popups);
|
||||
|
||||
return optionManager;
|
||||
}; //}}}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
112
content/tabs.js
112
content/tabs.js
@@ -38,13 +38,12 @@ vimperator.Tabs = function () //{{{
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
/** @param spec can either be:
|
||||
* - an absolute integer
|
||||
* - "" for the current tab
|
||||
* - "+1" for the next tab
|
||||
* - "-3" for the tab, which is 3 positions left of the current
|
||||
* - "$" for the last tab
|
||||
*/
|
||||
// @param spec can either be:
|
||||
// - an absolute integer
|
||||
// - "" for the current tab
|
||||
// - "+1" for the next tab
|
||||
// - "-3" for the tab, which is 3 positions left of the current
|
||||
// - "$" for the last tab
|
||||
function indexFromSpec(spec, wrap)
|
||||
{
|
||||
var position = getBrowser().tabContainer.selectedIndex;
|
||||
@@ -58,7 +57,7 @@ vimperator.Tabs = function () //{{{
|
||||
position = spec;
|
||||
else if (spec === "$")
|
||||
return last;
|
||||
else if (!spec.match(/^([+-]?\d+|)$/))
|
||||
else if (!/^([+-]?\d+|)$/.test(spec))
|
||||
{
|
||||
// TODO: move error reporting to ex-command?
|
||||
vimperator.echoerr("E488: Trailing characters");
|
||||
@@ -66,7 +65,7 @@ vimperator.Tabs = function () //{{{
|
||||
}
|
||||
else
|
||||
{
|
||||
if (spec.match(/^([+-]\d+)$/)) // relative position +/-N
|
||||
if (/^([+-]\d+)$/.test(spec)) // relative position +/-N
|
||||
position += parseInt(spec, 10);
|
||||
else // absolute position
|
||||
position = parseInt(spec, 10);
|
||||
@@ -80,14 +79,20 @@ vimperator.Tabs = function () //{{{
|
||||
return position;
|
||||
}
|
||||
|
||||
var alternates = [null, null];
|
||||
var alternates = [getBrowser().mCurrentTab, null];
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
return {
|
||||
|
||||
get alternate() { return alternates[1]; },
|
||||
|
||||
get count() { return getBrowser().mTabs.length; },
|
||||
|
||||
// @returns the index of the currently selected tab starting with 0
|
||||
this.index = function (tab)
|
||||
index: function (tab)
|
||||
{
|
||||
if (tab)
|
||||
{
|
||||
@@ -101,16 +106,11 @@ vimperator.Tabs = function () //{{{
|
||||
}
|
||||
|
||||
return getBrowser().tabContainer.selectedIndex;
|
||||
}
|
||||
|
||||
this.count = function ()
|
||||
{
|
||||
return getBrowser().mTabs.length;
|
||||
}
|
||||
},
|
||||
|
||||
// TODO: implement filter
|
||||
// @returns an array of tabs which match filter
|
||||
this.get = function (filter)
|
||||
get: function (filter)
|
||||
{
|
||||
var buffers = [];
|
||||
var browsers = getBrowser().browsers;
|
||||
@@ -122,34 +122,32 @@ vimperator.Tabs = function () //{{{
|
||||
buffers.push([number, title, uri]);
|
||||
}
|
||||
return buffers;
|
||||
}
|
||||
},
|
||||
|
||||
this.getTab = function (index)
|
||||
getTab: function (index)
|
||||
{
|
||||
if (index)
|
||||
return getBrowser().mTabs[index];
|
||||
|
||||
return getBrowser().tabContainer.selectedItem;
|
||||
}
|
||||
},
|
||||
|
||||
/* spec == "" moves the tab to the last position as per Vim
|
||||
* wrap causes the movement to wrap around the start and end of the tab list
|
||||
* NOTE: position is a 0 based index
|
||||
* FIXME: tabmove! N should probably produce an error
|
||||
*/
|
||||
this.move = function (tab, spec, wrap)
|
||||
// spec == "" moves the tab to the last position as per Vim
|
||||
// wrap causes the movement to wrap around the start and end of the tab list
|
||||
// NOTE: position is a 0 based index
|
||||
// FIXME: tabmove! N should probably produce an error
|
||||
move: function (tab, spec, wrap)
|
||||
{
|
||||
if (spec === "")
|
||||
spec = "$"; // if not specified, move to the last tab -> XXX: move to ex handling?
|
||||
|
||||
var index = indexFromSpec(spec, wrap);
|
||||
getBrowser().moveTabTo(tab, index);
|
||||
}
|
||||
},
|
||||
|
||||
/* quit_on_last_tab = 1: quit without saving session
|
||||
* quit_on_last_tab = 2: quit and save session
|
||||
*/
|
||||
this.remove = function (tab, count, focus_left_tab, quit_on_last_tab)
|
||||
// quitOnLastTab = 1: quit without saving session
|
||||
// quitOnLastTab = 2: quit and save session
|
||||
remove: function (tab, count, focusLeftTab, quitOnLastTab)
|
||||
{
|
||||
function removeOrBlankTab (tab)
|
||||
{
|
||||
@@ -171,44 +169,44 @@ vimperator.Tabs = function () //{{{
|
||||
if (count < 1)
|
||||
count = 1;
|
||||
|
||||
if (quit_on_last_tab >= 1 && getBrowser().mTabs.length <= count)
|
||||
if (quitOnLastTab >= 1 && getBrowser().mTabs.length <= count)
|
||||
{
|
||||
if (vimperator.windows.length > 1)
|
||||
window.close();
|
||||
else
|
||||
vimperator.quit(quit_on_last_tab == 2);
|
||||
vimperator.quit(quitOnLastTab == 2);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var index = this.index(tab);
|
||||
if (focus_left_tab)
|
||||
if (focusLeftTab)
|
||||
{
|
||||
var last_removed_tab = 0;
|
||||
var lastRemovedTab = 0;
|
||||
for (var i = index; i > index - count && i >= 0; i--)
|
||||
{
|
||||
removeOrBlankTab(this.getTab(i));
|
||||
last_removed_tab = i > 0 ? i : 1;
|
||||
lastRemovedTab = i > 0 ? i : 1;
|
||||
}
|
||||
getBrowser().mTabContainer.selectedIndex = last_removed_tab - 1;
|
||||
getBrowser().mTabContainer.selectedIndex = lastRemovedTab - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
var i = index + count - 1;
|
||||
if (i >= this.count())
|
||||
i = this.count() - 1;
|
||||
if (i >= this.count)
|
||||
i = this.count - 1;
|
||||
|
||||
for (; i >= index; i--)
|
||||
removeOrBlankTab(this.getTab(i));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
this.keepOnly = function (tab)
|
||||
keepOnly: function (tab)
|
||||
{
|
||||
getBrowser().removeAllTabsBut(tab);
|
||||
}
|
||||
},
|
||||
|
||||
this.select = function (spec, wrap)
|
||||
select: function (spec, wrap)
|
||||
{
|
||||
var index = indexFromSpec(spec, wrap);
|
||||
if (index === false)
|
||||
@@ -217,24 +215,20 @@ vimperator.Tabs = function () //{{{
|
||||
return false;
|
||||
}
|
||||
getBrowser().mTabContainer.selectedIndex = index;
|
||||
}
|
||||
},
|
||||
|
||||
// TODO: when restarting a session FF selects the first tab and then the
|
||||
// tab that was selected when the session was created. As a result the
|
||||
// alternate after a restart is often incorrectly tab 1 when there
|
||||
// shouldn't be one yet.
|
||||
this.updateSelectionHistory = function ()
|
||||
updateSelectionHistory: function ()
|
||||
{
|
||||
alternates = [this.getTab(), alternates[0]];
|
||||
this.alternate = alternates[1];
|
||||
}
|
||||
},
|
||||
|
||||
// TODO: move to v.buffers
|
||||
this.alternate = this.getTab();
|
||||
|
||||
this.reload = function (tab, bypass_cache)
|
||||
reload: function (tab, bypassCache)
|
||||
{
|
||||
if (bypass_cache)
|
||||
if (bypassCache)
|
||||
{
|
||||
const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
|
||||
const flags = nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY | nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
|
||||
@@ -244,17 +238,17 @@ vimperator.Tabs = function () //{{{
|
||||
{
|
||||
getBrowser().reloadTab(tab);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
this.reloadAll = function (bypass_cache)
|
||||
reloadAll: function (bypassCache)
|
||||
{
|
||||
if (bypass_cache)
|
||||
if (bypassCache)
|
||||
{
|
||||
for (var i = 0; i < getBrowser().mTabs.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.reload(getBrowser().mTabs[i], bypass_cache)
|
||||
this.reload(getBrowser().mTabs[i], bypassCache);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
@@ -268,7 +262,9 @@ vimperator.Tabs = function () //{{{
|
||||
getBrowser().reloadAllTabs();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
//}}}
|
||||
} //}}}
|
||||
}; //}}}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
636
content/ui.js
636
content/ui.js
File diff suppressed because it is too large
Load Diff
@@ -26,7 +26,8 @@ the provisions above, a recipient may use your version of this file under
|
||||
the terms of any one of the MPL, the GPL or the LGPL.
|
||||
}}} ***** END LICENSE BLOCK *****/
|
||||
|
||||
vimperator.util = {
|
||||
vimperator.util = { //{{{
|
||||
|
||||
escapeHTML: function (str)
|
||||
{
|
||||
// XXX: the following code is _much_ slower than a simple .replace()
|
||||
@@ -39,11 +40,11 @@ vimperator.util = {
|
||||
},
|
||||
|
||||
// TODO: use :highlight color groups
|
||||
// if "process_strings" is true, any passed strings will be surrounded by " and
|
||||
// if "processStrings" is true, any passed strings will be surrounded by " and
|
||||
// any line breaks are displayed as \n
|
||||
colorize: function (arg, process_strings)
|
||||
colorize: function (arg, processStrings)
|
||||
{
|
||||
var type = typeof(arg);
|
||||
var type = typeof arg;
|
||||
|
||||
// some objects like window.JSON or getBrowsers()._browsers need the try/catch
|
||||
try
|
||||
@@ -54,7 +55,7 @@ vimperator.util = {
|
||||
}
|
||||
else if (type == "string")
|
||||
{
|
||||
if (process_strings)
|
||||
if (processStrings)
|
||||
arg = '"' + vimperator.util.escapeHTML(arg.replace(/\n/, "\\n")) + '"';
|
||||
|
||||
return "<span style=\"color: green;\">" + arg + "</span>";
|
||||
@@ -97,7 +98,7 @@ vimperator.util = {
|
||||
|
||||
begin: for (var url = 0; url < urls.length; url++)
|
||||
{
|
||||
var new_url = vimperator.buffer.URL;
|
||||
var newURL = vimperator.buffer.URL;
|
||||
var matches;
|
||||
|
||||
// strip each 'URL' - makes things simpler later on
|
||||
@@ -108,13 +109,13 @@ vimperator.util = {
|
||||
if (matches = urls[url].match(/^(?:\.$|\.\/(\S*))/))
|
||||
{
|
||||
var tail = matches[1] || "";
|
||||
urls[url] = new_url.replace(/(.+\/)[^\/]*/, "$1" + tail); // NOTE: escape / in character sets so as not to break Vim syntax highlighting
|
||||
urls[url] = newURL.replace(/(.+\/)[^\/]*/, "$1" + tail); // NOTE: escape / in character sets so as not to break Vim syntax highlighting
|
||||
continue;
|
||||
}
|
||||
else if (matches = urls[url].match(/^(?:\.\.$|\.\.\/(\S*))/))
|
||||
{
|
||||
var tail = matches[1] || "";
|
||||
urls[url] = new_url.replace(/(.+\/)[^\/]*/, "$1../" + tail);
|
||||
urls[url] = newURL.replace(/(.+\/)[^\/]*/, "$1../" + tail);
|
||||
continue;
|
||||
}
|
||||
else if (matches = urls[url].match(/^(?:\.\.\.$|\.\.\.\/(\S*))/))
|
||||
@@ -142,18 +143,18 @@ vimperator.util = {
|
||||
// like the comments below ;-)
|
||||
|
||||
// check if the first word is a search engine
|
||||
var search_url = vimperator.bookmarks.getSearchURL(text, alias);
|
||||
if (search_url/* && search_url.length >= 1*/)
|
||||
var searchURL = vimperator.bookmarks.getSearchURL(text, alias);
|
||||
if (searchURL/* && searchURL.length >= 1*/)
|
||||
{
|
||||
urls[url] = search_url;
|
||||
urls[url] = searchURL;
|
||||
continue;
|
||||
}
|
||||
else // the first word was not a search engine, search for the whole string in the default engine
|
||||
{
|
||||
search_url = vimperator.bookmarks.getSearchURL(urls[url], null);
|
||||
if (search_url/* && search_url.length >= 1*/)
|
||||
searchURL = vimperator.bookmarks.getSearchURL(urls[url], null);
|
||||
if (searchURL/* && searchURL.length >= 1*/)
|
||||
{
|
||||
urls[url] = search_url;
|
||||
urls[url] = searchURL;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -206,6 +207,7 @@ vimperator.util = {
|
||||
|
||||
return strNum[0] + " " + unitVal[unitIndex];
|
||||
}
|
||||
};
|
||||
|
||||
}; //}}}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
@@ -52,32 +52,32 @@ const vimperator = (function () //{{{
|
||||
EXTENDED_HINT: 1 << 18,
|
||||
ALWAYS_HINT: 1 << 19,
|
||||
MENU: 1 << 20 // a popupmenu is active
|
||||
}
|
||||
};
|
||||
|
||||
var mode_messages = {};
|
||||
mode_messages[modes.NORMAL] = "";
|
||||
mode_messages[modes.INSERT] = "INSERT";
|
||||
mode_messages[modes.VISUAL] = "VISUAL";
|
||||
mode_messages[modes.HINTS] = "HINTS";
|
||||
mode_messages[modes.ESCAPE_ONE_KEY] = "escape one key";
|
||||
mode_messages[modes.ESCAPE_ALL_KEYS] = "escape all keys";
|
||||
mode_messages[modes.ESCAPE_ONE_KEY | modes.ESCAPE_ALL_KEYS] = "pass one key";
|
||||
mode_messages[modes.QUICK_HINT] = "quick";
|
||||
mode_messages[modes.EXTENDED_HINT] = "extended";
|
||||
mode_messages[modes.ALWAYS_HINT] = "always";
|
||||
//mode_messages[modes.MENU] = "menu"; // not a user visible mode
|
||||
var modeMessages = {};
|
||||
modeMessages[modes.NORMAL] = "";
|
||||
modeMessages[modes.INSERT] = "INSERT";
|
||||
modeMessages[modes.VISUAL] = "VISUAL";
|
||||
modeMessages[modes.HINTS] = "HINTS";
|
||||
modeMessages[modes.ESCAPE_ONE_KEY] = "escape one key";
|
||||
modeMessages[modes.ESCAPE_ALL_KEYS] = "escape all keys";
|
||||
modeMessages[modes.ESCAPE_ONE_KEY | modes.ESCAPE_ALL_KEYS] = "pass one key";
|
||||
modeMessages[modes.QUICK_HINT] = "quick";
|
||||
modeMessages[modes.EXTENDED_HINT] = "extended";
|
||||
modeMessages[modes.ALWAYS_HINT] = "always";
|
||||
//modeMessages[modes.MENU] = "menu"; // not a user visible mode
|
||||
|
||||
var mode = modes.NORMAL;
|
||||
var extended_mode = modes.NONE;
|
||||
var extendedMode = modes.NONE;
|
||||
|
||||
var callbacks = [];
|
||||
|
||||
// our services
|
||||
var sound_service = Components.classes["@mozilla.org/sound;1"]
|
||||
var soundService = Components.classes["@mozilla.org/sound;1"]
|
||||
.getService(Components.interfaces.nsISound);
|
||||
var console_service = Components.classes["@mozilla.org/consoleservice;1"]
|
||||
var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
|
||||
.getService(Components.interfaces.nsIConsoleService);
|
||||
var environment_service = Components.classes["@mozilla.org/process/environment;1"]
|
||||
var environmentService = Components.classes["@mozilla.org/process/environment;1"]
|
||||
.getService(Components.interfaces.nsIEnvironment);
|
||||
|
||||
function showMode()
|
||||
@@ -85,23 +85,23 @@ const vimperator = (function () //{{{
|
||||
if (!vimperator.options["showmode"])
|
||||
return;
|
||||
|
||||
var str_mode = mode_messages[mode];
|
||||
var str_extended = mode_messages[extended_mode];
|
||||
if (!str_mode && !str_extended)
|
||||
var strMode = modeMessages[mode];
|
||||
var strExtended = modeMessages[extendedMode];
|
||||
if (!strMode && !strExtended)
|
||||
{
|
||||
vimperator.echo("");
|
||||
return;
|
||||
}
|
||||
|
||||
if (str_mode && str_extended)
|
||||
str_extended = " (" + str_extended + ")";
|
||||
if (strMode && strExtended)
|
||||
strExtended = " (" + strExtended + ")";
|
||||
else
|
||||
{
|
||||
str_extended = "(" + str_extended + ")";
|
||||
str_mode = "";
|
||||
strExtended = "(" + strExtended + ")";
|
||||
strMode = "";
|
||||
}
|
||||
|
||||
vimperator.echo("-- " + str_mode + str_extended + " --");
|
||||
vimperator.echo("-- " + strMode + strExtended + " --");
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
@@ -154,7 +154,7 @@ const vimperator = (function () //{{{
|
||||
|
||||
getMode: function ()
|
||||
{
|
||||
return [mode, extended_mode];
|
||||
return [mode, extendedMode];
|
||||
},
|
||||
|
||||
// set current mode
|
||||
@@ -165,10 +165,10 @@ const vimperator = (function () //{{{
|
||||
if (main)
|
||||
{
|
||||
mode = main;
|
||||
extended_mode = vimperator.modes.NONE;
|
||||
extendedMode = vimperator.modes.NONE;
|
||||
}
|
||||
if (typeof extended === "number")
|
||||
extended_mode = extended;
|
||||
extendedMode = extended;
|
||||
|
||||
if (!silent)
|
||||
showMode();
|
||||
@@ -178,7 +178,7 @@ const vimperator = (function () //{{{
|
||||
// extended mode
|
||||
hasMode: function (whichmode)
|
||||
{
|
||||
return ((mode & whichmode) || (extended_mode & whichmode) > 0) ? true : false;
|
||||
return ((mode & whichmode) || (extendedMode & whichmode) > 0) ? true : false;
|
||||
},
|
||||
|
||||
addMode: function (main, extended)
|
||||
@@ -186,7 +186,7 @@ const vimperator = (function () //{{{
|
||||
if (main)
|
||||
mode |= main;
|
||||
if (extended)
|
||||
extended_mode |= extended;
|
||||
extendedMode |= extended;
|
||||
|
||||
showMode();
|
||||
},
|
||||
@@ -197,7 +197,7 @@ const vimperator = (function () //{{{
|
||||
if (main)
|
||||
mode = (mode | main) ^ main;
|
||||
if (extended)
|
||||
extended_mode = (extended_mode | extended) ^ extended;
|
||||
extendedMode = (extendedMode | extended) ^ extended;
|
||||
|
||||
showMode();
|
||||
},
|
||||
@@ -217,13 +217,13 @@ const vimperator = (function () //{{{
|
||||
vbell.style.left = box.x + "px";
|
||||
vbell.style.top = box.y + "px";
|
||||
|
||||
vbell.hidden = false
|
||||
vbell.hidden = false;
|
||||
|
||||
setTimeout(function () { vbell.hidden = true; }, 50); // may as well be 0 ;-)
|
||||
}
|
||||
else
|
||||
{
|
||||
sound_service.beep();
|
||||
soundService.beep();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -409,7 +409,7 @@ const vimperator = (function () //{{{
|
||||
if (typeof msg == "object")
|
||||
msg = this.objectToString(msg, false);
|
||||
|
||||
console_service.logStringMessage("vimperator: " + msg);
|
||||
consoleService.logStringMessage("vimperator: " + msg);
|
||||
},
|
||||
|
||||
// open one or more URLs
|
||||
@@ -482,9 +482,9 @@ const vimperator = (function () //{{{
|
||||
},
|
||||
|
||||
// quit vimperator, no matter how many tabs/windows are open
|
||||
quit: function (save_session)
|
||||
quit: function (saveSession)
|
||||
{
|
||||
if (save_session)
|
||||
if (saveSession)
|
||||
vimperator.options.setFirefoxPref("browser.startup.page", 3); // start with saved session
|
||||
else
|
||||
vimperator.options.setFirefoxPref("browser.startup.page", 1); // start with default homepage session
|
||||
@@ -532,7 +532,7 @@ const vimperator = (function () //{{{
|
||||
if (!args)
|
||||
args = [];
|
||||
|
||||
if (typeof(blocking) != "boolean")
|
||||
if (typeof blocking != "boolean")
|
||||
blocking = false;
|
||||
|
||||
try
|
||||
@@ -541,7 +541,7 @@ const vimperator = (function () //{{{
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
var dirs = environment_service.get("PATH").split(WINDOWS ? ";" : ":");
|
||||
var dirs = environmentService.get("PATH").split(WINDOWS ? ";" : ":");
|
||||
for (var i = 0; i < dirs.length; i++)
|
||||
{
|
||||
var path = dirs[i] + (WINDOWS ? "\\" : "/") + program;
|
||||
@@ -604,8 +604,8 @@ const vimperator = (function () //{{{
|
||||
filein.remove(false);
|
||||
|
||||
// if there is only one \n at the end, chop it off
|
||||
if (output && output.indexOf("\n") == output.length-1)
|
||||
output = output.substr(0, output.length-1);
|
||||
if (output && output.indexOf("\n") == output.length - 1)
|
||||
output = output.substr(0, output.length - 1);
|
||||
|
||||
return output;
|
||||
},
|
||||
@@ -628,16 +628,16 @@ const vimperator = (function () //{{{
|
||||
else
|
||||
{
|
||||
var heredoc = "";
|
||||
var heredoc_end = null; // the string which ends the heredoc
|
||||
var heredocEnd = null; // the string which ends the heredoc
|
||||
str.split("\n").forEach(function (line)
|
||||
{
|
||||
if (heredoc_end) // we already are in a heredoc
|
||||
if (heredocEnd) // we already are in a heredoc
|
||||
{
|
||||
if (heredoc_end.test(line))
|
||||
if (heredocEnd.test(line))
|
||||
{
|
||||
eval(heredoc);
|
||||
heredoc = "";
|
||||
heredoc_end = null;
|
||||
heredocEnd = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -654,7 +654,7 @@ const vimperator = (function () //{{{
|
||||
var matches = args.match(/(.*)<<\s*([^\s]+)$/);
|
||||
if (matches)
|
||||
{
|
||||
heredoc_end = new RegExp("^" + matches[2] + "$", "m");
|
||||
heredocEnd = new RegExp("^" + matches[2] + "$", "m");
|
||||
if (matches[1])
|
||||
heredoc = matches[1] + "\n";
|
||||
}
|
||||
@@ -688,51 +688,51 @@ const vimperator = (function () //{{{
|
||||
|
||||
// these objects are created here only after the chrome is ready
|
||||
vimperator.log("Loading module options...", 3);
|
||||
vimperator.options = new vimperator.Options();
|
||||
vimperator.options = vimperator.Options();
|
||||
vimperator.log("Loading module events...", 3);
|
||||
vimperator.events = new vimperator.Events();
|
||||
vimperator.events = vimperator.Events();
|
||||
vimperator.log("Loading module commands...", 3);
|
||||
vimperator.commands = new vimperator.Commands();
|
||||
vimperator.commands = vimperator.Commands();
|
||||
vimperator.log("Loading module bookmarks...", 3);
|
||||
vimperator.bookmarks = new vimperator.Bookmarks();
|
||||
vimperator.bookmarks = vimperator.Bookmarks();
|
||||
vimperator.log("Loading module history...", 3);
|
||||
vimperator.history = new vimperator.History();
|
||||
vimperator.history = vimperator.History();
|
||||
vimperator.log("Loading module commandline...", 3);
|
||||
vimperator.commandline = new vimperator.CommandLine();
|
||||
vimperator.commandline = vimperator.CommandLine();
|
||||
vimperator.log("Loading module search...", 3);
|
||||
vimperator.search = new vimperator.Search();
|
||||
vimperator.search = vimperator.Search();
|
||||
vimperator.log("Loading module preview window...", 3);
|
||||
vimperator.previewwindow = new vimperator.InformationList("vimperator-previewwindow", { incremental_fill: false, max_items: 10 });
|
||||
vimperator.previewwindow = vimperator.InformationList("vimperator-previewwindow", { incrementalFill: false, maxItems: 10 });
|
||||
vimperator.log("Loading module buffer window...", 3);
|
||||
vimperator.bufferwindow = new vimperator.InformationList("vimperator-bufferwindow", { incremental_fill: false, max_items: 10 });
|
||||
vimperator.bufferwindow = vimperator.InformationList("vimperator-bufferwindow", { incrementalFill: false, maxItems: 10 });
|
||||
vimperator.log("Loading module mappings...", 3);
|
||||
vimperator.mappings = new vimperator.Mappings();
|
||||
vimperator.mappings = vimperator.Mappings();
|
||||
vimperator.log("Loading module statusline...", 3);
|
||||
vimperator.statusline = new vimperator.StatusLine();
|
||||
vimperator.statusline = vimperator.StatusLine();
|
||||
vimperator.log("Loading module buffer...", 3);
|
||||
vimperator.buffer = new vimperator.Buffer();
|
||||
vimperator.buffer = vimperator.Buffer();
|
||||
vimperator.log("Loading module tabs...", 3);
|
||||
vimperator.tabs = new vimperator.Tabs();
|
||||
vimperator.tabs = vimperator.Tabs();
|
||||
vimperator.log("Loading module marks...", 3);
|
||||
vimperator.marks = new vimperator.Marks();
|
||||
vimperator.marks = vimperator.Marks();
|
||||
vimperator.log("Loading module quickmarks...", 3);
|
||||
vimperator.quickmarks = new vimperator.QuickMarks();
|
||||
vimperator.quickmarks = vimperator.QuickMarks();
|
||||
vimperator.log("Loading module hints...", 3);
|
||||
vimperator.hints = new vimperator.Hints();
|
||||
vimperator.hints = vimperator.Hints();
|
||||
vimperator.log("Loading module io...", 3);
|
||||
vimperator.io = new vimperator.IO();
|
||||
vimperator.io = vimperator.IO();
|
||||
vimperator.log("Loading module completion...", 3);
|
||||
vimperator.completion = new vimperator.Completion();
|
||||
vimperator.completion = vimperator.Completion();
|
||||
vimperator.log("All modules loaded", 3);
|
||||
|
||||
vimperator.echo = function (str) { vimperator.commandline.echo(str); }
|
||||
vimperator.echoerr = function (str) { vimperator.commandline.echo(str, vimperator.commandline.HL_ERRORMSG); }
|
||||
vimperator.echo = function (str, flags) { vimperator.commandline.echo(str, vimperator.commandline.HL_NORMAL, flags); };
|
||||
vimperator.echoerr = function (str, flags) { vimperator.commandline.echo(str, vimperator.commandline.HL_ERRORMSG, flags); };
|
||||
|
||||
vimperator.globalVariables = {};
|
||||
|
||||
// TODO: move elsewhere
|
||||
vimperator.registerCallback("submit", vimperator.modes.EX, function (command) { vimperator.execute(command); } );
|
||||
vimperator.registerCallback("complete", vimperator.modes.EX, function (str) { return vimperator.completion.exTabCompletion(str); } );
|
||||
vimperator.registerCallback("submit", vimperator.modes.EX, function (command) { vimperator.execute(command); });
|
||||
vimperator.registerCallback("complete", vimperator.modes.EX, function (str) { return vimperator.completion.exTabCompletion(str); });
|
||||
|
||||
// first time intro message
|
||||
if (vimperator.options.getPref("firsttime", true))
|
||||
@@ -749,20 +749,20 @@ const vimperator = (function () //{{{
|
||||
// make sourcing asynchronous, otherwise commands that open new tabs won't work
|
||||
setTimeout(function () {
|
||||
|
||||
var rc_file = vimperator.io.getRCFile();
|
||||
var rcFile = vimperator.io.getRCFile();
|
||||
|
||||
if (rc_file)
|
||||
vimperator.source(rc_file.path, true);
|
||||
if (rcFile)
|
||||
vimperator.source(rcFile.path, true);
|
||||
else
|
||||
vimperator.log("No user RC file found", 3);
|
||||
|
||||
// also source plugins in ~/.vimperator/plugin/
|
||||
try
|
||||
{
|
||||
var plugin_dir = vimperator.io.getPluginDir();
|
||||
if (plugin_dir)
|
||||
var pluginDir = vimperator.io.getPluginDir();
|
||||
if (pluginDir)
|
||||
{
|
||||
var files = vimperator.io.readDirectory(plugin_dir.path);
|
||||
var files = vimperator.io.readDirectory(pluginDir.path);
|
||||
vimperator.log("Sourcing plugin directory...", 3);
|
||||
files.forEach(function (file) {
|
||||
if (!file.isDirectory() && /\.js$/.test(file.path))
|
||||
@@ -809,21 +809,22 @@ const vimperator = (function () //{{{
|
||||
var mainThread = threadManager.mainThread;
|
||||
|
||||
var then = new Date().getTime(), now = then;
|
||||
for (; now - then < ms; now = new Date().getTime()) {
|
||||
for (; now - then < ms; now = new Date().getTime())
|
||||
mainThread.processNextEvent(true);
|
||||
}
|
||||
},
|
||||
|
||||
get windows()
|
||||
{
|
||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
|
||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||
.getService(Components.interfaces.nsIWindowMediator);
|
||||
var wa = [];
|
||||
var enumerator = wm.getEnumerator("navigator:browser");
|
||||
while (enumerator.hasMoreElements())
|
||||
wa.push(enumerator.getNext());
|
||||
return wa;
|
||||
}
|
||||
} //}}}
|
||||
|
||||
}; //}}}
|
||||
})(); //}}}
|
||||
|
||||
// called when the chrome is fully loaded and before the main window is shown
|
||||
|
||||
Reference in New Issue
Block a user