diff --git a/chrome/content/vimperator/bookmarks.js b/chrome/content/vimperator/bookmarks.js index 6c8db3b7..f540f553 100644 --- a/chrome/content/vimperator/bookmarks.js +++ b/chrome/content/vimperator/bookmarks.js @@ -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 = ""; + for (var i = 0; i < items.length; i++) + { + list += ""; + } + list += "
titleURL
" + items[i][1] + "" + items[i][0] + "
"; + + 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 = ""; + for (var i = 0; i < items.length; i++) + { + list += ""; + } + list += "
titleURL
" + items[i][1] + "" + items[i][0] + "
"; + + 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 = ""; + var list = "
marklinecolfile
"; for (var i = 0; i < marks.length; i++) { list += "" @@ -794,7 +835,7 @@ function QuickMarks() //{{{ } } - var list = "
marklinecolfile
"; + var list = "
QuickMarkURL
"; for (var i = 0; i < marks.length; i++) { list += ""; diff --git a/chrome/content/vimperator/commands.js b/chrome/content/vimperator/commands.js index 3747f5aa..b30eea97 100644 --- a/chrome/content/vimperator/commands.js +++ b/chrome/content/vimperator/commands.js @@ -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) + vimperator.echoerr("-T {taglist} and -k {keyword} not implemented yet"); + return; + } + + var result = Bookmarks.parseBookmarkString(args); + + if (result) + { + if (result.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; + result.url = vimperator.buffer.location; + // also guess title if the current url is :bmarked + if (result.title == null) + result.title = vimperator.buffer.title; } - if (res.title == null) // title could still be null - res.title = res.url; + if (result.title == null) // title could still be null + result.title = result.url; - vimperator.bookmarks.add(res.title, res.url); - vimperator.echo("Bookmark `" + res.title + "' added with url `" + res.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] "); + { + //vimperator.echo("Usage: :bmark [-t \"My Title\"] [-T tag1,tag2] "); + 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.
" + - "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.
" + - "You can omit the optional [url] field, so just do :bmadd to bookmark the currently loaded web page with a default title and without any tags.
" + + "You can omit the optional [url] argument, so just do :bmadd to bookmark the currently loaded web page with a default title and without any tags.
" + " -t \"custom title\"
" + "The following options will be interpreted in the future:
" + - " -T comma,separated,tag,list
" + - " -k keyword
" + " -T comma,separated,tag,list
" + + " -k keyword
" + + "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 "); + + vimperator.bookmarks.list(args, special); }, { - usage: ["bmd[el] [-T] {url}"], - short_help: "Delete a bookmark", - help: "Deletes all bookmarks which matches the url AND the specified tags. Use <Tab> key on a regular expression to complete the url which you want to delete.
" + - "The following options WILL be interpreted in the future:
" + - " -T comma,separated,tag,list
", - 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.
" + - "Close this window with :pclose 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 bookmarks which match [filter] either in the title or URL.
" + + "The special version :bmarks! will open the default Firefox bookmarks window.
" + "The following options WILL be interpreted in the future:
" + - " -T comma,separated,tag,list
", + " -T comma,separated,tag,list
", 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 all bookmarks which match the {url}. Use <Tab> key on a string to complete the url which you want to delete.
" + + "The following options WILL be interpreted in the future:
" + + " [!] a special version to delete ALL bookmarks
" + + " -T comma,separated,tag,list
", + 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 :pclose 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 [filter] either in the title or URL.
" + + "The special version :history! will open the default Firefox history window.", completer: function(filter) { return vimperator.completion.get_history_completions(filter); } } ));
QuickMarkURL
    " + marks[i][0] + "" + marks[i][1] + "