Skip to content

Commit

Permalink
Bug 692742 (noscroll): Use options system for Menu
Browse files Browse the repository at this point in the history
and CommandMenu to allow more flexible init
  • Loading branch information
joewalker committed Nov 7, 2011
1 parent 440f953 commit 3db0a9b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
22 changes: 15 additions & 7 deletions lib/gcli/ui/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ var menuHtml = require('text!gcli/ui/menu.html');
/**
* Menu is a display of the commands that are possible given the state of a
* requisition.
* @param document The document from which we create elements.
* @param options A way to customize the menu display. Valid options are:
* - field:true Turns the menu display into a drop-down for use inside a
* JavascriptField.
* - field: [boolean] Turns the menu display into a drop-down for use inside a
* JavascriptField.
* - document: The document to use in creating widgets
* - menuClass: Custom class name when generating the top level element
* which allows different layout systems
*/
function Menu(document, options) {
function Menu(options) {
options = options || {};
this.document = options.document || document;

this.element = dom.createElement(document, 'div');
this.element.className = 'gcliMenu';
if (options && options.field) {
Expand Down Expand Up @@ -107,10 +112,13 @@ exports.Menu = Menu;
/**
* CommandMenu is a special menu that integrates with a Requisition to display
* available commands.
* @param options A way to customize the menu display. Valid options include
* those valid for Menu(), plus:
* - requisition: The Requisition to fill out (required)
*/
function CommandMenu(document, requisition) {
Menu.call(this, document);
this.requisition = requisition;
function CommandMenu(options) {
Menu.call(this, options);
this.requisition = options.requisition;

this.requisition.commandChange.add(this.onCommandChange, this);
canon.canonChange.add(this.onCommandChange, this);
Expand Down
3 changes: 1 addition & 2 deletions lib/gcli/ui/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ function Popup(options) {
this.inputter = options.inputter;
this.autoHide = false;

this.menu = options.menu ||
new CommandMenu(this.document, options.requisition);
this.menu = options.menu || new CommandMenu(options);
this.argFetcher = options.argFetcher || new ArgFetcher(options);

// A container to show either an ArgFetcher or a Menu depending on the state
Expand Down
6 changes: 5 additions & 1 deletion mozilla/gcli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ define(function(require, exports, module) {
}

if (opts.hintElement) {
opts.menu = new CommandMenu(opts.chromeDocument, opts.requisition);
opts.menu = new CommandMenu({
document: opts.contentDocument,
requisition: opts.requisition,
menuClass: 'gcliterm-menu'
});
opts.hintElement.appendChild(opts.menu.element);

opts.argFetcher = new ArgFetcher({
Expand Down

0 comments on commit 3db0a9b

Please sign in to comment.