mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 23:27:58 +01:00
added QuickMarks
This commit is contained in:
@@ -458,12 +458,12 @@ function Marks() //{{{
|
||||
else
|
||||
{
|
||||
var pattern = new RegExp("[" + marks_str.replace(/\s+/g, '') + "]");
|
||||
for (mark in url_marks)
|
||||
for (var mark in url_marks)
|
||||
{
|
||||
if (pattern.test(mark))
|
||||
removeURLMark(mark);
|
||||
}
|
||||
for (mark in local_marks)
|
||||
for (var mark in local_marks)
|
||||
{
|
||||
if (pattern.test(mark))
|
||||
removeLocalMark(mark);
|
||||
@@ -554,4 +554,83 @@ function Marks() //{{{
|
||||
//}}}
|
||||
} //}}}
|
||||
|
||||
function QuickMarks() //{{{
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
var marks = {};
|
||||
// load the commandline history -- TODO: change to sqlite
|
||||
var saved_marks = Options.getPref("quickmarks", "").split("\n");
|
||||
for (var i=0; i < saved_marks.length -1; i+= 2)
|
||||
{
|
||||
marks[saved_marks[i]] = saved_marks[i+1];
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
this.add = function(mark, location)
|
||||
{
|
||||
marks[mark] = location;
|
||||
}
|
||||
|
||||
this.remove = function(marks_str)
|
||||
{
|
||||
var pattern = new RegExp("[" + marks_str.replace(/\s+/g, '') + "]");
|
||||
for (var mark in marks)
|
||||
{
|
||||
if (pattern.test(mark))
|
||||
delete marks[mark];
|
||||
}
|
||||
}
|
||||
|
||||
this.jumpTo = function(mark, newtab)
|
||||
{
|
||||
var url = marks[mark];
|
||||
if (url)
|
||||
{
|
||||
if(newtab)
|
||||
openURLsInNewTab(url, true);
|
||||
else
|
||||
openURLs(url);
|
||||
}
|
||||
else
|
||||
vimperator.echoerr("E20: QuickMark not set"); // FIXME: move up?
|
||||
}
|
||||
|
||||
this.list = function()
|
||||
{
|
||||
// FIXME: hashes don't have a .length property --mst
|
||||
// if (local_marks.length + url_marks.length < 1)
|
||||
// {
|
||||
// vimperator.echoerr("No marks defined");
|
||||
// return;
|
||||
// }
|
||||
|
||||
var list = "<table><tr style=\"color: magenta\"><td>mark</td><td>URL</td></tr>";
|
||||
for (var i in marks)
|
||||
{
|
||||
list += "<tr><td> " + i + "</td><td align=\"right\">"
|
||||
+ marks[i] + "</td></tr>";
|
||||
}
|
||||
list += "</table>";
|
||||
vimperator.commandline.echo(list, true); // TODO: force of multiline widget a better way
|
||||
}
|
||||
|
||||
this.destroy = function()
|
||||
{
|
||||
// save the marks
|
||||
var saved_marks = "";
|
||||
for (var i in marks)
|
||||
{
|
||||
saved_marks += i + "\n";
|
||||
saved_marks += marks[i] + "\n";
|
||||
}
|
||||
Options.setPref("quickmarks", saved_marks);
|
||||
}
|
||||
//}}}
|
||||
} //}}}
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
@@ -515,7 +515,6 @@ function Commands() //{{{
|
||||
));
|
||||
addDefaultCommand(new Command(["marks"],
|
||||
function(args) {
|
||||
//vimperator.echo("marks not implemented yet");
|
||||
vimperator.marks.list(args)
|
||||
},
|
||||
{
|
||||
@@ -743,37 +742,35 @@ function Commands() //{{{
|
||||
));
|
||||
addDefaultCommand(new Command(["qmarka[dd]", "qma[dd]"],
|
||||
function(args) {
|
||||
vimperator.echo("qmarkadd not implemented yet");
|
||||
//set_url_mark("mark", "url");
|
||||
}, // FIXME
|
||||
var split = args.split(/\s+/);
|
||||
vimperator.quickmarks.add(split[0], split[1] ? split[1] : getCurrentLocation());
|
||||
},
|
||||
{
|
||||
usage: ["qmarka[dd] {a-zA-Z0-9} [url]"],
|
||||
short_help: "Mark a URL with a letter for quick access",
|
||||
help: "Not implemented yet.",
|
||||
help: "TODO.",
|
||||
completer: function(filter) { return [["a", ""], ["b", ""]]; }
|
||||
}
|
||||
));
|
||||
addDefaultCommand(new Command(["qmarkd[el]", "qmd[el]"],
|
||||
function(args) {
|
||||
vimperator.echo("qmarkdel not implemented yet");
|
||||
//set_url_mark("mark", "url");
|
||||
}, // FIXME
|
||||
vimperator.quickmarks.remove(args);
|
||||
},
|
||||
{
|
||||
usage: ["qmarkd[el] {a-zA-Z0-9}"],
|
||||
short_help: "Remove a marked URL",
|
||||
help: "Not implemented yet.",
|
||||
help: "TODO.",
|
||||
completer: function(filter) { return [["a", ""], ["b", ""]]; }
|
||||
}
|
||||
));
|
||||
addDefaultCommand(new Command(["qmarks", "qms"],
|
||||
function(args) {
|
||||
vimperator.echo("qmarks not implemented yet");
|
||||
//show_url_marks(args);
|
||||
}, // FIXME
|
||||
vimperator.quickmarks.list(args);
|
||||
},
|
||||
{
|
||||
usage: ["qmarks"],
|
||||
short_help: "Shows marked URLs",
|
||||
help: "Not implemented yet."
|
||||
help: "TODO."
|
||||
}
|
||||
));
|
||||
addDefaultCommand(new Command(["ve[rsion]"],
|
||||
|
||||
@@ -248,6 +248,24 @@ function Mappings() //{{{
|
||||
help: "Opens the homepage in a new tab."
|
||||
}
|
||||
));
|
||||
addDefaultMap(new Map(vimperator.modes.NORMAL, ["go"],
|
||||
function (mark) { vimperator.quickmarks.jumpTo(mark, false) },
|
||||
{
|
||||
short_help: "Jump to a QuickMark in the current buffer",
|
||||
usage: ["go{a-zA-Z0-9}"],
|
||||
help: "TODO",
|
||||
flags: Mappings.flags.ARGUMENT
|
||||
}
|
||||
));
|
||||
addDefaultMap(new Map(vimperator.modes.NORMAL, ["gO"],
|
||||
function (mark) { vimperator.quickmarks.jumpTo(mark, true) },
|
||||
{
|
||||
short_help: "Jump to a QuickMark in a new buffer",
|
||||
usage: ["gO{a-zA-Z0-9}"],
|
||||
help: "TODO",
|
||||
flags: Mappings.flags.ARGUMENT
|
||||
}
|
||||
));
|
||||
addDefaultMap(new Map(vimperator.modes.NORMAL, ["gP"],
|
||||
function(count) { openURLsInNewTab(readFromClipboard(), false); },
|
||||
{
|
||||
@@ -280,6 +298,15 @@ function Mappings() //{{{
|
||||
flags: Mappings.flags.ARGUMENT
|
||||
}
|
||||
));
|
||||
addDefaultMap(new Map(vimperator.modes.NORMAL, ["M"],
|
||||
function(mark) { vimperator.quickmarks.add(mark, getCurrentLocation()) },
|
||||
{
|
||||
short_help: "Add new QuickMark for current URL",
|
||||
usage: ["M{a-zA-Z0-9}"],
|
||||
help: "TODO.",
|
||||
flags: Mappings.flags.ARGUMENT
|
||||
}
|
||||
));
|
||||
addDefaultMap(new Map(vimperator.modes.NORMAL, ["o"],
|
||||
function(count) { vimperator.commandline.open(":", "open ", vimperator.modes.EX); },
|
||||
{
|
||||
|
||||
@@ -73,6 +73,8 @@ function init() //{{{
|
||||
Vimperator.prototype.tabs = new Tabs();
|
||||
vimperator.log("Loading module marks...", 3);
|
||||
Vimperator.prototype.marks = new Marks();
|
||||
vimperator.log("Loading module quickmarks...", 3);
|
||||
Vimperator.prototype.quickmarks = new QuickMarks();
|
||||
vimperator.log("Loading module hints...", 3);
|
||||
Vimperator.prototype.hints = new Hints();
|
||||
vimperator.log("All modules loaded", 3);
|
||||
@@ -136,8 +138,8 @@ function unload() //{{{
|
||||
{
|
||||
/*** save our preferences ***/
|
||||
vimperator.commandline.destroy();
|
||||
|
||||
vimperator.events.destroy();
|
||||
vimperator.quickmarks.destroy();
|
||||
|
||||
// reset some modified firefox prefs
|
||||
if (Options.getFirefoxPref('dom.popup_allowed_events', 'change click dblclick mouseup reset submit')
|
||||
|
||||
Reference in New Issue
Block a user