1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 20: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.
}}} ***** 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() //{{{
{
////////////////////////////////////////////////////////////////////////////////
@@ -71,9 +68,8 @@ function Bookmarks() //{{{
////////////////////// PUBLIC SECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
/*
* @return a new Array() of our bookmarks
*/
// FIXME: add filtering here rather than having to calling
// get_bookmark_completions()
this.get = function()
{
if (!bookmarks)
@@ -82,9 +78,7 @@ function Bookmarks() //{{{
return bookmarks;
}
/**
* @TODO: keyword support
*/
// TODO: keyword support
this.add = function (title, uri, keyword)
{
if (!bookmarks)
@@ -101,10 +95,8 @@ function Bookmarks() //{{{
return true;
}
/* no idea what it does, it Just Works (TM)
*
* @returns number of deleted bookmarks
*/
// NOTE: no idea what it does, it Just Works (TM)
// returns number of deleted bookmarks
this.remove = function(url)
{
var deleted = 0;
@@ -156,7 +148,7 @@ function Bookmarks() //{{{
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()
{
var search_engines = [];
@@ -248,21 +240,42 @@ function Bookmarks() //{{{
this.list = function(filter, fullmode)
{
if (fullmode)
{
vimperator.open("chrome://browser/content/bookmarks/bookmarksPanel.xul", vimperator.NEW_TAB);
}
else
{
var items = vimperator.bookmarks.get(filter);
vimperator.previewwindow.show(items);
var items = vimperator.completion.get_bookmark_completions(filter);
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.tags is an array of tags
res.title is the title or "" if no one was given
res.url is the url as a string
returns null, if parsing failed
*/
// res = parseBookmarkString("-t tag1,tag2 -T title http://www.orf.at");
// res.tags is an array of tags
// res.title is the title or "" if no one was given
// res.url is the url as a string
// returns null, if parsing failed
Bookmarks.parseBookmarkString = function(str)
{
var res = {};
@@ -298,10 +311,10 @@ function Bookmarks() //{{{
if (res.title != null)
return null;
str = match_title[match_title.length-1]; // the last captured parenthesis is the rest of the string
str = match_title[match_title.length - 1]; // the last captured parenthesis is the rest of the string
var title = match_title[3];
if (title.charAt(0) == '"')
title = title.substring(1,title.length-1);
title = title.substring(1, title.length - 1);
res.title = title;
}
else // at last check for a URL
@@ -313,10 +326,10 @@ function Bookmarks() //{{{
if (res.url != null)
return null;
str = match_url[match_url.length-1]; // the last captured parenthesis is the rest of the string
str = match_url[match_url.length - 1]; // the last captured parenthesis is the rest of the string
url = match_url[1];
if (url.charAt(0) == '"')
url = url.substring(1,url.length-1);
url = url.substring(1, url.length - 1);
res.url = url;
}
else
@@ -389,9 +402,8 @@ function History() //{{{
////////////////////// PUBLIC SECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
/*
* @return a new Array() of our bookmarks
*/
// FIXME: add filtering here rather than having to call
// get_bookmark_completions()
this.get = function()
{
if (!history)
@@ -417,6 +429,7 @@ function History() //{{{
this.stepTo = function(steps)
{
var index = getWebNavigation().sessionHistory.index + steps;
if (index >= 0 && index < getWebNavigation().sessionHistory.count)
{
getWebNavigation().gotoIndex(index);
@@ -430,34 +443,61 @@ function History() //{{{
this.goToStart = function()
{
var index = getWebNavigation().sessionHistory.index;
if (index == 0)
{
vimperator.beep();
return;
}
getWebNavigation().gotoIndex(0);
}
this.goToEnd = function()
{
var index = getWebNavigation().sessionHistory.index;
var max = getWebNavigation().sessionHistory.count -1;
var max = getWebNavigation().sessionHistory.count - 1;
if (index == max)
{
vimperator.beep();
return;
}
getWebNavigation().gotoIndex(max);
}
this.list = function(filter, fullmode)
{
if (fullmode)
{
vimperator.open("chrome://browser/content/history/history-panel.xul", vimperator.NEW_TAB);
}
else
{
var items = vimperator.history.get(filter);
vimperator.previewwindow.show(items);
var items = vimperator.completion.get_history_completions(filter);
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 pending_jumps = [];
var appcontent = document.getElementById("appcontent");
if (appcontent)
appcontent.addEventListener("load", onPageLoad, true);
@@ -574,7 +615,7 @@ function Marks() //{{{
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;
}
@@ -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++)
{
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++)
{
list += "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;" + marks[i][0] + "</td><td>" + marks[i][1] + "</td></tr>";

View File

@@ -263,78 +263,71 @@ function Commands() //{{{
short_help: "Play a system beep"
}
));
addDefaultCommand(new Command(["bma[dd]"],
// takes: -t "foo" -T "tag1,tag2", myurl
addDefaultCommand(new Command(["bma[rk]"],
// takes: -t "foo" myurl
// converts that string to a useful url and title, and calls addBookmark
// TODO: proper ex-style arg parsing
function(args)
{
var res = Bookmarks.parseBookmarkString(args);
if (res)
if (/-[Tk]/.test(args))
{
if (res.url == null)
{
res.url = vimperator.buffer.location;
// also guess title if the current url is :bmadded
if (res.title == null)
res.title = vimperator.buffer.title;
vimperator.echoerr("-T {taglist} and -k {keyword} not implemented yet");
return;
}
if (res.title == null) // title could still be null
res.title = res.url;
var result = Bookmarks.parseBookmarkString(args);
vimperator.bookmarks.add(res.title, res.url);
vimperator.echo("Bookmark `" + res.title + "' added with url `" + res.url + "'");
if (result)
{
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
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",
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 [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/>" +
"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/>" +
" -t \"custom title\"<br/>" +
"The following options will be interpreted in the future:<br/>" +
" -T comma,separated,tag,list <br/>" +
" -k keyword <br/>"
" -T comma,separated,tag,list<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]"],
// TODO: proper ex-style arg parsing
function(args)
addDefaultCommand(new Command(["bmarks"],
function(args, special)
{
var res = Bookmarks.parseBookmarkString(args);
if (res)
if (/-T/.test(args))
{
if (res.url == null)
res.url = vimperator.buffer.location;
var del = vimperator.bookmarks.remove(res.url);
vimperator.echo(del + " bookmark(s) with url `" + res.url + "' deleted");
vimperator.echoerr("-T {taglist} not implemented yet");
return;
}
else
vimperator.echo("Usage: :bmdel <url>");
vimperator.bookmarks.list(args, special);
},
{
usage: ["bmd[el] [-T] {url}"],
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}"],
usage: ["bmarks [filter]", "bmarks!"],
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/>" +
"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/>" +
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/>" +
"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/>" +
" -T comma,separated,tag,list <br/>",
" -T comma,separated,tag,list<br/>",
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."
}
));
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]"],
function(args, special)
{
@@ -534,12 +561,15 @@ function Commands() //{{{
}
));
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",
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. " +
"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.",
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/>" +
"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); }
}
));