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