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

:cmap + 'nore' support; update on :dialog

This commit is contained in:
Marco Candrian
2007-11-21 09:12:49 +00:00
parent 6003d130c4
commit 46fb0d247e
3 changed files with 135 additions and 58 deletions

View File

@@ -659,33 +659,42 @@ vimperator.Commands = function () //{{{
commandManager.add(new vimperator.Command(["dia[log]"], commandManager.add(new vimperator.Command(["dia[log]"],
function (args, special) function (args, special)
{ {
var openAt = special ? vimperator.NEW_TAB: vimperator.NEW_WINDOW; try
switch (args)
{ {
case "about": openDialog("chrome://browser/content/aboutDialog.xul", "_blank", "chrome,dialog,modal,centerscreen"); break; switch (args)
case "addbookmark": PlacesCommandHook.bookmarkCurrentPage(true, PlacesUtils.bookmarksRootId); break; {
case "addons": BrowserOpenAddonsMgr(); break; case "about": openDialog("chrome://browser/content/aboutDialog.xul", "_blank", "chrome,dialog,modal,centerscreen"); break;
case "bookmarks": openDialog("chrome://browser/content/bookmarks/bookmarksPanel.xul", "Bookmarks", "dialog,centerscreen,width=600,height=600"); break; case "addbookmark": PlacesCommandHook.bookmarkCurrentPage(true, PlacesUtils.bookmarksRootId); break;
case "console": toJavaScriptConsole(); break; case "addons": BrowserOpenAddonsMgr(); break;
case "customizetoolbar": BrowserCustomizeToolbar(); break; case "bookmarks": openDialog("chrome://browser/content/bookmarks/bookmarksPanel.xul", "Bookmarks", "dialog,centerscreen,width=600,height=600"); break;
case "downloads": toOpenWindowByType('Download:Manager', 'chrome://mozapps/content/downloads/downloads.xul', 'chrome,dialog=no,resizable'); break; case "checkupdates": checkForUpdates(); break;
case "history": openDialog("chrome://browser/content/history/history-panel.xul", "History", "dialog,centerscreen,width=600,height=600"); break; case "cleardata": Cc[GLUE_CID].getService(Ci.nsIBrowserGlue).sanitize(window || null); break;
case "import": BrowserImport(); break; case "console": toJavaScriptConsole(); break;
case "openfile": BrowserOpenFileWindow(); break; case "customizetoolbar": BrowserCustomizeToolbar(); break;
case "pageinfo": BrowserPageInfo(); break; case "dominspector": inspectDOMDocument(content.document); break; // XXX: orig: _content.document
case "pagesource": BrowserViewSourceOfDocument(content.document); break; case "downloads": toOpenWindowByType('Download:Manager', 'chrome://mozapps/content/downloads/downloads.xul', 'chrome,dialog=no,resizable'); break;
case "places": PlacesCommandHook.showPlacesOrganizer(ORGANIZER_ROOT_BOOKMARKS); break; case "history": openDialog("chrome://browser/content/history/history-panel.xul", "History", "dialog,centerscreen,width=600,height=600"); break;
case "preferences": openPreferences(); break; case "import": BrowserImport(); break;
// XXX what are onEnter.. and onExit...? case "openfile": BrowserOpenFileWindow(); break;
case "printpreview": PrintUtils.printPreview(onEnterPrintPreview, onExitPrintPreview); break; case "pageinfo": BrowserPageInfo(); break;
case "print": PrintUtils.print(); break; case "pagesource": BrowserViewSourceOfDocument(content.document); break;
case "printsetup": PrintUtils.showPageSetup(); break; case "places": PlacesCommandHook.showPlacesOrganizer(ORGANIZER_ROOT_BOOKMARKS); break;
case "saveframe": saveFrameDocument(); break; case "preferences": openPreferences(); break;
case "savepage": saveDocument(window.content.document); break; // XXX what are onEnter.. and onExit...?
case "searchengines": openDialog("chrome://browser/content/search/engineManager.xul", "_blank", "chrome,dialog,modal,centerscreen"); break; case "printpreview": PrintUtils.printPreview(onEnterPrintPreview, onExitPrintPreview); break;
// TODO add viewPartialSource('selection'); ... case "print": PrintUtils.print(); break;
case "": vimperator.echoerr("E474: Invalid argument"); break; case "printsetup": PrintUtils.showPageSetup(); break;
default: vimperator.echoerr("Dialog '" + args + "' is not available"); case "saveframe": saveFrameDocument(); break;
case "savepage": saveDocument(window.content.document); break;
case "searchengines": openDialog("chrome://browser/content/search/engineManager.xul", "_blank", "chrome,dialog,modal,centerscreen"); break;
// TODO add viewPartialSource('selection'); ...
case "": vimperator.echoerr("E474: Invalid argument"); break;
default: vimperator.echoerr("Dialog '" + args + "' not available");
}
}
catch(err)
{
vimperator.echoerr("Error opening '" + args + "': " + err);
} }
}, },
{ {
@@ -1286,41 +1295,44 @@ vimperator.Commands = function () //{{{
// 0 args -> list all maps // 0 args -> list all maps
// 1 arg -> list the maps starting with args // 1 arg -> list the maps starting with args
// 2 args -> map arg1 to arg* // 2 args -> map arg1 to arg*
function map(args, noremap) function map(args, mode, noremap)
{ {
if (!args) for (var index = 0; index < mode.length; index++) // XXX: actually no multi-modes arrives here
{ {
vimperator.mappings.list(vimperator.modes.NORMAL); if (!args) // TODO: list: function -> allow multiple modes, if once necessary
return; {
} vimperator.mappings.list(mode[index]);
return;
}
var matches = args.match(/^([^\s]+)(?:\s+(.+))?$/); var matches = args.match(/^([^\s]+)(?:\s+(.+))?$/);
var [lhs, rhs] = [matches[1], matches[2]]; var [lhs, rhs] = [matches[1], matches[2]];
var leaderRegexp = /<Leader>/i; var leaderRegexp = /<Leader>/i;
if (leaderRegexp.test(lhs)) if (leaderRegexp.test(lhs))
{ {
var leaderRef = vimperator.variableReference("mapleader"); var leaderRef = vimperator.variableReference("mapleader");
var leader = leaderRef[0] ? leaderRef[0][leaderRef[1]] : "\\"; var leader = leaderRef[0] ? leaderRef[0][leaderRef[1]] : "\\";
lhs = lhs.replace(leaderRegexp, leader); lhs = lhs.replace(leaderRegexp, leader);
} }
if (rhs) if (rhs)
{ {
vimperator.mappings.add(new vimperator.Map([vimperator.modes.NORMAL], [lhs], vimperator.mappings.add(new vimperator.Map([mode[index]], [lhs],
function (count) { vimperator.events.feedkeys((count > 1 ? count : "") + rhs, noremap); }, function (count) { vimperator.events.feedkeys((count > 1 ? count : "") + rhs, noremap); },
{ flags: vimperator.Mappings.flags.COUNT, rhs: rhs } { flags: vimperator.Mappings.flags.COUNT, rhs: rhs, noremapping: noremap}
)); ));
} }
else else
{ {
// FIXME: no filtering for now // FIXME: no filtering for now
vimperator.mappings.list(vimperator.modes.NORMAL, lhs); vimperator.mappings.list(mode[index], lhs);
}
} }
} }
commandManager.add(new vimperator.Command(["map"], commandManager.add(new vimperator.Command(["map"],
function (args) { map(args, false); }, function (args) { map(args, [vimperator.modes.NORMAL], false); },
{ {
usage: ["map {lhs} {rhs}", "map {lhs}", "map"], usage: ["map {lhs} {rhs}", "map {lhs}", "map"],
shortHelp: "Map the key sequence {lhs} to {rhs}", shortHelp: "Map the key sequence {lhs} to {rhs}",
@@ -1328,6 +1340,15 @@ vimperator.Commands = function () //{{{
"Mappings are NOT saved during sessions, make sure you put them in your vimperatorrc file!" "Mappings are NOT saved during sessions, make sure you put them in your vimperatorrc file!"
} }
)); ));
commandManager.add(new vimperator.Command(["cm[ap]"],
function (args) { map(args, [vimperator.modes.COMMAND_LINE], false); },
{
usage: ["cmap {lhs} {rhs}", "cmap {lhs}", "cmap"],
shortHelp: "Map the key sequence {lhs} to {rhs} (in command-line mode)",
help: "The <code class=\"argument\">{rhs}</code> is remapped, allowing for nested and recursive mappings.<br/>" +
"Mappings are NOT saved during sessions, make sure you put them in your vimperatorrc file!"
}
));
commandManager.add(new vimperator.Command(["mapc[lear]"], commandManager.add(new vimperator.Command(["mapc[lear]"],
function (args) function (args)
{ {
@@ -1345,6 +1366,23 @@ vimperator.Commands = function () //{{{
"<code class=\"command\">:map</code> or <code class=\"command\">:noremap</code> are cleared." "<code class=\"command\">:map</code> or <code class=\"command\">:noremap</code> are cleared."
} }
)); ));
commandManager.add(new vimperator.Command(["cmapc[lear]"],
function (args)
{
if (args)
{
vimperator.echoerr("E474: Invalid argument");
return;
}
vimperator.mappings.removeAll(vimperator.modes.COMMAND_LINE);
},
{
shortHelp: "Remove all mappings (in command-line mode)",
help: "All user-defined mappings which were set by " +
"<code class=\"command\">:cmap</code> or <code class=\"command\">:cnoremap</code> are cleared."
}
));
commandManager.add(new vimperator.Command(["ma[rk]"], commandManager.add(new vimperator.Command(["ma[rk]"],
function (args) function (args)
{ {
@@ -1411,10 +1449,14 @@ vimperator.Commands = function () //{{{
line += "\" Mappings\n"; line += "\" Mappings\n";
// TODO: write user maps for all modes when we have mode dependant map support // TODO: write user maps for all modes when we have mode dependant map support
for (var map in vimperator.mappings.getUserIterator(vimperator.modes.NORMAL)) var mode = [[vimperator.modes.NORMAL, ""], [vimperator.modes.COMMAND_LINE, "c"]];
for (var y = 0; y < mode.length; y++)
{ {
for (var i = 0; i < map.names.length; i++) for (var map in vimperator.mappings.getUserIterator(mode[y][0]))
line += "map " + map.names[i] + " " + map.rhs + "\n"; {
for (var i = 0; i < map.names.length; i++)
line += mode[y][1] + (map.noremap ? "nore" : "") + "map " + map.names[i] + " " + map.rhs + "\n";
}
} }
line += "\n\" Options\n"; line += "\n\" Options\n";
@@ -1480,13 +1522,22 @@ vimperator.Commands = function () //{{{
)); ));
// TODO: remove duplication in :map // TODO: remove duplication in :map
commandManager.add(new vimperator.Command(["no[remap]"], commandManager.add(new vimperator.Command(["no[remap]"],
function (args) { map(args, true); }, function (args) { map(args, [vimperator.modes.NORMAL], true); },
{ {
usage: ["no[remap] {lhs} {rhs}", "no[remap] {lhs}", "no[remap]"], usage: ["no[remap] {lhs} {rhs}", "no[remap] {lhs}", "no[remap]"],
shortHelp: "Map the key sequence {lhs} to {rhs}", shortHelp: "Map the key sequence {lhs} to {rhs}",
help: "No remapping of the <code class=\"argument\">{rhs}</code> is performed." help: "No remapping of the <code class=\"argument\">{rhs}</code> is performed."
} }
)); ));
// XXX: TODO: remove duplication in :cmap
commandManager.add(new vimperator.Command(["cno[remap]"],
function (args) { map(args, [vimperator.modes.COMMAND_LINE], true); },
{
usage: ["cno[remap] {lhs} {rhs}", "cno[remap] {lhs}", "cno[remap]"],
shortHelp: "Map the key sequence {lhs} to {rhs} (in command-line mode)",
help: "No remapping of the <code class=\"argument\">{rhs}</code> is performed."
}
));
commandManager.add(new vimperator.Command(["o[pen]", "e[dit]"], commandManager.add(new vimperator.Command(["o[pen]", "e[dit]"],
function (args, special) function (args, special)
{ {
@@ -2293,6 +2344,28 @@ vimperator.Commands = function () //{{{
help: "" help: ""
} }
)); ));
commandManager.add(new vimperator.Command(["cunm[ap]"],
function (args)
{
if (!args)
{
vimperator.echoerr("E474: Invalid argument");
return;
}
var lhs = args;
if (vimperator.mappings.hasMap(vimperator.modes.COMMAND_LINE, lhs))
vimperator.mappings.remove(vimperator.modes.COMMAND_LINE, lhs);
else
vimperator.echoerr("E31: No such mapping");
},
{
usage: ["cunm[ap] {lhs}"],
shortHelp: "Remove the mapping of {lhs} (in command-line mode)",
help: ""
}
));
commandManager.add(new vimperator.Command(["ve[rsion]"], commandManager.add(new vimperator.Command(["ve[rsion]"],
function (args, special) function (args, special)
{ {

View File

@@ -138,8 +138,11 @@ vimperator.Completion = function () //{{{
["addbookmark", "Add bookmarks for the current page"], ["addbookmark", "Add bookmarks for the current page"],
["addons", "Manage Add-ons"], ["addons", "Manage Add-ons"],
["bookmarks", "List your bookmarks"], ["bookmarks", "List your bookmarks"],
["checkupdates", "Check for updates"],
["cleardata", "Clear private data"],
["console", "JavaScript console"], ["console", "JavaScript console"],
["customizetoolbar", "Customize the Toolbar"], ["customizetoolbar", "Customize the Toolbar"],
["dominspector", "DOM Inspector"],
["downloads", "Manage Downloads"], ["downloads", "Manage Downloads"],
["history", "List your history"], ["history", "List your history"],
["import", "Import Preferences, Bookmarks, History, etc. from other browsers"], ["import", "Import Preferences, Bookmarks, History, etc. from other browsers"],

View File

@@ -57,6 +57,7 @@ vimperator.Map = function (modes, cmds, action, extraInfo) //{{{
this.shortHelp = extraInfo.shortHelp || null; this.shortHelp = extraInfo.shortHelp || null;
this.rhs = extraInfo.rhs || null; this.rhs = extraInfo.rhs || null;
this.noremap = extraInfo.noremapping || null; // XXX: needed for mkv; providing feedkeys true/false still neded?
// TODO: are these limited to HINTS mode? // TODO: are these limited to HINTS mode?
// Only set for hints maps // Only set for hints maps
@@ -99,7 +100,7 @@ vimperator.Mappings = function () //{{{
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
var main = []; // array of default Map() objects var main = []; // array of default Map() objects
var user = []; // array of objects created by :map var user = []; // array of objects created by :map or :cmap
for each (var mode in vimperator.modes) for each (var mode in vimperator.modes)
{ {
@@ -300,7 +301,7 @@ vimperator.Mappings = function () //{{{
list += "<tr>"; list += "<tr>";
list += "<td> " + vimperator.util.escapeHTML(maps[i].names[j]) + "</td>"; list += "<td> " + vimperator.util.escapeHTML(maps[i].names[j]) + "</td>";
if (maps[i].rhs) if (maps[i].rhs)
list += "<td> " + vimperator.util.escapeHTML(maps[i].rhs) + "</td>"; list += "<td> " + (maps[i].noremap ? "*" : " ") + "</td>" + "<td>" + vimperator.util.escapeHTML(maps[i].rhs) + "</td>";
list += "</tr>"; list += "</tr>";
} }
} }