-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Conversation
@tpryan, could you remove the whitespace diffs from your patch? |
// function removeMenuItem(id) { | ||
// NOT IMPLEMENTED | ||
// } | ||
function _removeMenuItem(id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be broken out as a separate helper function? If it's only ever called from Menu.removeMenuItem()
, could you just inline this code in there?
@peterflynn I'm happy to remove the whitespace changes. But they were preventing jslint from reporting no errors. Can we ignore that prescription before doing a pull request? |
@tpryan: Ah yes, you hit a confusing quirk of Brackets's coding standards. Unlike vanilla JSLint, we're ok with whitespace on a line as long as the line is completely blank otherwise. Since JSLint has no option for turning off that error, the Brackets feature that runs JSLint automatically filters out those errors. But of course if you run JSLint outside Brackets, it will still complain. We should probably document that better :-) |
Adobe is on break this coming week, but I should be able to review the update within a day or two. |
@peterflynn that's a nice way of saying you caught me using another editor. Point taken. I work for Adobe too. We shouldn't be having this conversation. |
@tpryan: heh, no worries about the other editor. We are strict about JSLint though, and using Brackets definitely makes that part easier :-) So I caved to the vacation pressure and didn't re-review until now. Thanks for all the updates! I had two high-level thoughts on this (which I wish I'd thought of a week ago): First -- can you add a unit test or two to Menu-test.js for the new API? (It already has tests for add: append, insert, etc.) Second -- I think it may be a mistake to cast the API in terms of the internal MenuItem objects' ids instead of commands (or command ids). If you own the code that added the menu item in the first place, you can just hang onto the MenuItem and use its |
* | ||
* @param {!string} id - the unique identifier for the menu. | ||
* | ||
* Note, keyBindings are not effected at all by removing a menu item. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, two little nits here: "effected" -> "affected"; and there's an extra space after "a" on the first line.
@peterflynn I'm happy to add tests. I'll get to work on them. As for the API. I'd prefer to pass either a command or commandID like AddMenuItem does. Is that what you're going for? |
Nice meeting you in person yesterday! For anyone else reading: yes, changing it to accept either command or commandID (like |
Added the ability to use commands or id's. I have tested, it works, but I can't get the test runner working. Something's borked with my setup. |
} | ||
} else { | ||
commandID = this.id + "-" + command.getID(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple problems with dropping this code in here:
- The var commandID is not actually a command ID (the Command.id field) -- it's an internal MenuItem id (the MenuItem.id field). Should be renamed.
- There's some unneeded code here:
- the DIVIDER case is unneeded (it won't work anyway since divider IDs are all uniquely generated)
- there's no need to go through menuItemMap since
this.id + "-" + command
is the same thing asmenuItemMap[this.id + "-" + command].id
.
- This is somewhat in conflict with the code in Menu._getRelativeMenuItem(), which maps a command ID to a MenuItem in a much more roundabout way. Could you create a new utility function (e.g. "Menu._menuItemForCommandID()") that is called by both these methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Renamed
- Removed
- But I'm not getting a menu item in this function, I'm getting as you point out the menuItem.id. Am I missing what you want me to do?
@tpryan: now that we're both no longer frantically busy... :-) I have a few bits of smaller feedback and then I think this is ready to merge. |
throw new Error("removeMenuItem(): command not found: " + command); | ||
} | ||
|
||
menuItemID = menuItemMap[this.id + "-" + command].id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to go through menuItemMap here -- you're just mapping the menu item ID back to itself.
Also, both this and lin e385 below can use the new Menu._getMenuItemId() API to simplify this code:
menuItemID = this._getMenuItemId(command)
here, and
menuItemID = this._getMenuItemId(command.getID()
below
Lastly: needs a merge with master. The merge looked pretty clean when I tested it locally, so hopefully that's fairly easy. |
@tpryan: let me know if you're still interested in working on this. Otherwise I'll plan on making the last few changes myself tomorrow and then merging. |
@peterflynn I'm still interested, but if you're close to being able to push it out, I don't want to hold you back. I'll be traveling, so won't be able to do the work for a few days. |
Ok, cool. I've opened #2072 with the updated code. |
Added the ability to remove Menu Items. This should be useful for extension writers. It works for both the vanilla menus and context menus.