1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 22:07:59 +01:00

rename :bm, :bmadd, :bmdel to :bmarks, :bmark, :delbmarks respectively and use

the multiline output window for :bmarks and :history
This commit is contained in:
Doug Kearns
2007-08-15 13:24:51 +00:00
parent 0d6600962e
commit 1f0bc741ef
2 changed files with 159 additions and 88 deletions

View File

@@ -26,10 +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 *****/
/* // also includes methods for dealing with keywords and search engines
* also includes methods for dealing with
* keywords and search engines
*/
function Bookmarks() //{{{ function Bookmarks() //{{{
{ {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -71,9 +68,8 @@ function Bookmarks() //{{{
////////////////////// PUBLIC SECTION ////////////////////////////////////////// ////////////////////// PUBLIC SECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
/* // FIXME: add filtering here rather than having to calling
* @return a new Array() of our bookmarks // get_bookmark_completions()
*/
this.get = function() this.get = function()
{ {
if (!bookmarks) if (!bookmarks)
@@ -82,9 +78,7 @@ function Bookmarks() //{{{
return bookmarks; return bookmarks;
} }
/** // TODO: keyword support
* @TODO: keyword support
*/
this.add = function (title, uri, keyword) this.add = function (title, uri, keyword)
{ {
if (!bookmarks) if (!bookmarks)
@@ -101,10 +95,8 @@ function Bookmarks() //{{{
return true; return true;
} }
/* 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) this.remove = function(url)
{ {
var deleted = 0; var deleted = 0;
@@ -156,7 +148,7 @@ function Bookmarks() //{{{
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() this.getSearchEngines = function()
{ {
var search_engines = []; var search_engines = [];
@@ -248,21 +240,42 @@ function Bookmarks() //{{{
this.list = function(filter, fullmode) this.list = function(filter, fullmode)
{ {
if (fullmode) if (fullmode)
{
vimperator.open("chrome://browser/content/bookmarks/bookmarksPanel.xul", vimperator.NEW_TAB); vimperator.open("chrome://browser/content/bookmarks/bookmarksPanel.xul", vimperator.NEW_TAB);
}
else else
{ {
var items = vimperator.bookmarks.get(filter); var items = vimperator.completion.get_bookmark_completions(filter);
vimperator.previewwindow.show(items);
if (items.length == 0)
{
if (filter.length > 0)
vimperator.echoerr("E283: No bookmarks matching \"" + filter + "\"");
else
vimperator.echoerr("No bookmarks set");
return;
}
for (var i = 0; i < items.length; i++)
{
var list = "<table><tr align=\"left\" style=\"color: magenta\"><th>title</th><th>URL</th></tr>";
for (var i = 0; i < items.length; i++)
{
list += "<tr><td>" + items[i][1] + "</td><td>" + items[i][0] + "</td></tr>";
}
list += "</table>";
vimperator.commandline.echo(list, true);
}
} }
} }
/* // 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
*/
Bookmarks.parseBookmarkString = function(str) Bookmarks.parseBookmarkString = function(str)
{ {
var res = {}; var res = {};
@@ -389,9 +402,8 @@ function History() //{{{
////////////////////// PUBLIC SECTION ////////////////////////////////////////// ////////////////////// PUBLIC SECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
/* // FIXME: add filtering here rather than having to call
* @return a new Array() of our bookmarks // get_bookmark_completions()
*/
this.get = function() this.get = function()
{ {
if (!history) if (!history)
@@ -417,6 +429,7 @@ function History() //{{{
this.stepTo = function(steps) this.stepTo = function(steps)
{ {
var index = getWebNavigation().sessionHistory.index + steps; var index = getWebNavigation().sessionHistory.index + steps;
if (index >= 0 && index < getWebNavigation().sessionHistory.count) if (index >= 0 && index < getWebNavigation().sessionHistory.count)
{ {
getWebNavigation().gotoIndex(index); getWebNavigation().gotoIndex(index);
@@ -430,11 +443,13 @@ function History() //{{{
this.goToStart = function() this.goToStart = function()
{ {
var index = getWebNavigation().sessionHistory.index; var index = getWebNavigation().sessionHistory.index;
if (index == 0) if (index == 0)
{ {
vimperator.beep(); vimperator.beep();
return; return;
} }
getWebNavigation().gotoIndex(0); getWebNavigation().gotoIndex(0);
} }
@@ -442,22 +457,47 @@ function History() //{{{
{ {
var index = getWebNavigation().sessionHistory.index; var index = getWebNavigation().sessionHistory.index;
var max = getWebNavigation().sessionHistory.count - 1; var max = getWebNavigation().sessionHistory.count - 1;
if (index == max) if (index == max)
{ {
vimperator.beep(); vimperator.beep();
return; return;
} }
getWebNavigation().gotoIndex(max); getWebNavigation().gotoIndex(max);
} }
this.list = function(filter, fullmode) this.list = function(filter, fullmode)
{ {
if (fullmode) if (fullmode)
{
vimperator.open("chrome://browser/content/history/history-panel.xul", vimperator.NEW_TAB); vimperator.open("chrome://browser/content/history/history-panel.xul", vimperator.NEW_TAB);
}
else else
{ {
var items = vimperator.history.get(filter); var items = vimperator.completion.get_history_completions(filter);
vimperator.previewwindow.show(items);
if (items.length == 0)
{
if (filter.length > 0)
vimperator.echoerr("E283: No history matching \"" + filter + "\"");
else
vimperator.echoerr("No history set");
return;
}
for (var i = 0; i < items.length; i++)
{
var list = "<table><tr align=\"left\" style=\"color: magenta\"><th>title</th><th>URL</th></tr>";
for (var i = 0; i < items.length; i++)
{
list += "<tr><td>" + items[i][1] + "</td><td>" + items[i][0] + "</td></tr>";
}
list += "</table>";
vimperator.commandline.echo(list, true);
}
} }
} }
//}}} //}}}
@@ -473,6 +513,7 @@ function Marks() //{{{
var url_marks = {}; var url_marks = {};
var pending_jumps = []; var pending_jumps = [];
var appcontent = document.getElementById("appcontent"); var appcontent = document.getElementById("appcontent");
if (appcontent) if (appcontent)
appcontent.addEventListener("load", onPageLoad, true); appcontent.addEventListener("load", onPageLoad, true);
@@ -574,7 +615,7 @@ function Marks() //{{{
if (win.document.body.localName.toLowerCase() == "frameset") if (win.document.body.localName.toLowerCase() == "frameset")
{ {
vimperator.echo("marks support for frameset pages not implemented yet"); vimperator.echoerr("marks support for frameset pages not implemented yet");
return; return;
} }
@@ -699,7 +740,7 @@ function Marks() //{{{
} }
} }
var list = "<table><tr align=\"left\" style=\"color: magenta\"><th>mark</th><th>line</th><th>col</th><th>file</th></tr>"; var list = "<table><tr style=\"color: magenta\"><td>mark</td><td>line</td><td>col</td><td>file</td></tr>";
for (var i = 0; i < marks.length; i++) for (var i = 0; i < marks.length; i++)
{ {
list += "<tr>" list += "<tr>"
@@ -794,7 +835,7 @@ function QuickMarks() //{{{
} }
} }
var list = "<table><tr align=\"left\" style=\"color: magenta\"><th>QuickMark</th><th>URL</th></tr>"; var list = "<table><tr style=\"color: magenta\"><td>QuickMark</td><td>URL</td></tr>";
for (var i = 0; i < marks.length; i++) for (var i = 0; i < marks.length; i++)
{ {
list += "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;" + marks[i][0] + "</td><td>" + marks[i][1] + "</td></tr>"; list += "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;" + marks[i][0] + "</td><td>" + marks[i][1] + "</td></tr>";

View File

@@ -263,76 +263,69 @@ function Commands() //{{{
short_help: "Play a system beep" short_help: "Play a system beep"
} }
)); ));
addDefaultCommand(new Command(["bma[dd]"], addDefaultCommand(new Command(["bma[rk]"],
// takes: -t "foo" -T "tag1,tag2", myurl // takes: -t "foo" myurl
// converts that string to a useful url and title, and calls addBookmark // converts that string to a useful url and title, and calls addBookmark
// TODO: proper ex-style arg parsing
function(args) function(args)
{ {
var res = Bookmarks.parseBookmarkString(args); if (/-[Tk]/.test(args))
if (res)
{ {
if (res.url == null) vimperator.echoerr("-T {taglist} and -k {keyword} not implemented yet");
{ return;
res.url = vimperator.buffer.location;
// also guess title if the current url is :bmadded
if (res.title == null)
res.title = vimperator.buffer.title;
} }
if (res.title == null) // title could still be null var result = Bookmarks.parseBookmarkString(args);
res.title = res.url;
vimperator.bookmarks.add(res.title, res.url); if (result)
vimperator.echo("Bookmark `" + res.title + "' added with url `" + res.url + "'"); {
if (result.url == null)
{
result.url = vimperator.buffer.location;
// also guess title if the current url is :bmarked
if (result.title == null)
result.title = vimperator.buffer.title;
}
if (result.title == null) // title could still be null
result.title = result.url;
vimperator.bookmarks.add(result.title, result.url);
vimperator.echo("Bookmark `" + result.title + "' added with url `" + result.url + "'");
} }
else else
vimperator.echo("Usage: :bmadd [-t \"My Title\"] [-T tag1,tag2] <url>"); {
//vimperator.echo("Usage: :bmark [-t \"My Title\"] [-T tag1,tag2] <url>");
vimperator.echoerr("E474: Invalid argument");
}
}, },
{ {
usage: ["bma[dd] [-tTk] [url]"], usage: ["bma[rk] [-t {title}] [url]"],
short_help: "Add a bookmark", short_help: "Add a bookmark",
help: "If you don't add a custom title, either the title of the web page or the URL will be taken as the title.<br/>" + help: "If you don't add a custom title, either the title of the web page or the URL will be taken as the title.<br/>" +
"Tags WILL be some mechanism to classify bookmarks. Assume, you tag a url with the tags \"linux\" and \"computer\" you'll be able to search for bookmarks containing these tags.<br/>" + "You can omit the optional <code class=\"argument\">[url]</code> argument, so just do <code class=\"command\">:bmadd</code> to bookmark the currently loaded web page with a default title and without any tags.<br/>" +
"You can omit the optional [url] field, so just do <code class=\"command\">:bmadd</code> to bookmark the currently loaded web page with a default title and without any tags.<br/>" +
" -t \"custom title\"<br/>" + " -t \"custom title\"<br/>" +
"The following options will be interpreted in the future:<br/>" + "The following options will be interpreted in the future:<br/>" +
" -T comma,separated,tag,list<br/>" + " -T comma,separated,tag,list<br/>" +
" -k keyword <br/>" " -k keyword<br/>" +
"Tags WILL be some mechanism to classify bookmarks. Assume, you tag a url with the tags \"linux\" and \"computer\" you'll be able to search for bookmarks containing these tags."
} }
)); ));
addDefaultCommand(new Command(["bmd[el]"], addDefaultCommand(new Command(["bmarks"],
// TODO: proper ex-style arg parsing function(args, special)
function(args)
{ {
var res = Bookmarks.parseBookmarkString(args); if (/-T/.test(args))
if (res)
{ {
if (res.url == null) vimperator.echoerr("-T {taglist} not implemented yet");
res.url = vimperator.buffer.location; return;
var del = vimperator.bookmarks.remove(res.url);
vimperator.echo(del + " bookmark(s) with url `" + res.url + "' deleted");
} }
else
vimperator.echo("Usage: :bmdel <url>"); vimperator.bookmarks.list(args, special);
}, },
{ {
usage: ["bmd[el] [-T] {url}"], usage: ["bmarks [filter]", "bmarks!"],
short_help: "Delete a bookmark",
help: "Deletes <b>all</b> bookmarks which matches the url AND the specified tags. Use <code>&lt;Tab&gt;</code> key on a regular expression to complete the url which you want to delete.<br/>" +
"The following options WILL be interpreted in the future:<br/>" +
" -T comma,separated,tag,list <br/>",
completer: function(filter) { return vimperator.completion.get_bookmark_completions(filter); }
}
));
addDefaultCommand(new Command(["bookm[arks]", "bm"],
function(args, special) { vimperator.bookmarks.list(args, special); },
{
usage: ["bm[!] [-T] {regexp}"],
short_help: "Show bookmarks", short_help: "Show bookmarks",
help: "Open the preview window at the bottom of the screen for all bookmarks which match the regexp either in the title or URL.<br/>" + help: "Open the message window at the bottom of the screen with all bookmarks which match <code class\"argument\">[filter]</code> either in the title or URL.<br/>" +
"Close this window with <code class=\"command\">:pclose</code> or open entries with double click in the current tab or middle click in a new tab.<br/>" + "The special version <code class=\"command\">:bmarks!</code> will open the default Firefox bookmarks window.</br>" +
"The following options WILL be interpreted in the future:<br/>" + "The following options WILL be interpreted in the future:<br/>" +
" -T comma,separated,tag,list<br/>", " -T comma,separated,tag,list<br/>",
completer: function(filter) { return vimperator.completion.get_bookmark_completions(filter); } completer: function(filter) { return vimperator.completion.get_bookmark_completions(filter); }
@@ -377,6 +370,40 @@ function Commands() //{{{
help: "If the list is already shown, close the preview window." help: "If the list is already shown, close the preview window."
} }
)); ));
addDefaultCommand(new Command(["delbm[arks]"],
function(args, special)
{
if (special || /-T/.test(args))
{
vimperator.echoerr("[!] and -T {taglist} not implemented yet");
return;
}
var result = Bookmarks.parseBookmarkString(args);
if (result)
{
if (result.url == null)
result.url = vimperator.buffer.location;
var deleted_count = vimperator.bookmarks.remove(result.url);
vimperator.echo(deleted_count + " bookmark(s) with url `" + result.url + "' deleted");
}
else
{
vimperator.echoerr("E488: Trailing characters");
}
},
{
usage: ["delbm[arks] {url}"],
short_help: "Delete a bookmark",
help: "Deletes <b>all</b> bookmarks which match the <code class=\"argument\">{url}</code>. Use <code>&lt;Tab&gt;</code> key on a string to complete the url which you want to delete.<br/>" +
"The following options WILL be interpreted in the future:<br/>" +
" [!] a special version to delete ALL bookmarks <br/>" +
" -T comma,separated,tag,list <br/>",
completer: function(filter) { return vimperator.completion.get_bookmark_completions(filter); }
}
));
addDefaultCommand(new Command(["delm[arks]"], addDefaultCommand(new Command(["delm[arks]"],
function(args, special) function(args, special)
{ {
@@ -534,12 +561,15 @@ function Commands() //{{{
} }
)); ));
addDefaultCommand(new Command(["hist[ory]", "hs"], addDefaultCommand(new Command(["hist[ory]", "hs"],
function() { vimperator.history.list(); }, function(args, special)
{ {
usage: ["hist[ory] {filter}"], vimperator.history.list(args, special);
},
{
usage: ["hist[ory] [filter]", "history!"],
short_help: "Show recently visited URLs", short_help: "Show recently visited URLs",
help: "Open the preview window at the bottom of the screen for all history items which match the filter string either in the title or URL. " + help: "Open the message window at the bottom of the screen with all history items which match <code class\"argument\">[filter]</code> either in the title or URL.<br/>" +
"Close this window with <code class=\"command\">:pclose</code> or open entries with double click in the current tab or middle click in a new tab.", "The special version <code class=\"command\">:history!</code> will open the default Firefox history window.",
completer: function(filter) { return vimperator.completion.get_history_completions(filter); } completer: function(filter) { return vimperator.completion.get_history_completions(filter); }
} }
)); ));