Skip to content

Instantly share code, notes, and snippets.

@stepnem
Created January 12, 2012 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stepnem/1602929 to your computer and use it in GitHub Desktop.
Save stepnem/1602929 to your computer and use it in GitHub Desktop.
Search keyword bookmarks trough the mouse context menu
// Almost all of this is courtesy Kris Maglione, I just made some adjustments
XML.prettyPrinting = false;
XML.ignoreWhitespace = true;
let objects = Class({
get eventTarget() this,
fooEvents: {
popupshowing: function onPopupShowing(event) {
mow.contextEvents.popupshowing.call(mow, event);
}
},
events: {
popupshowing: function onPopupShowing(event) {
let menu = DOM(this.menu);
menu.empty().append(
template.map(iter(bookmarks.searchEngines,
values(bookmarkcache.keywords)
.sort(function (a, b) String
.localeCompare(a.title, b.title))),
function ([keyword, item])
<menuitem xmlns={XUL} xmlns:dactyl={NS}
dactyl:command="search.searchSelection"
label={item.title}
image={item.icon}
keyword={item.keyword}/>));
}
}
})();
overlay.overlayWindow(window, {
objects: objects,
after: <e4x xmlns={XUL} xmlns:dactyl={NS}>
<menuitem id="context-searchselect" style="visibility: collapse;">
<menu id="dactyl-context-search"
label="Search Selection"
group="selection"
class="menu-iconic">
<menupopup key="menu" highlight="Events"/>
</menu>
</menuitem>
</e4x>.elements()
});
events.listen(document.getElementById("contentAreaContextMenu"), objects,
"fooEvents");
dactyl.commands["search.searchSelection"] = function searchSelection(event) {
let elem = DOM(event.originalTarget);
dactyl.open(elem.attr("keyword") + " " + buffer.currentWord,
dactyl.NEW_TAB
// { from: "context-search" }
);
};
// options.get("activate")
// .values["context-search"] = "Context menu search";
// options.get("newtab")
// .values["context-search"] = "Context menu search";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment