Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Added RemoveMenuItem #1193

Closed
wants to merge 14 commits into from
Closed

Added RemoveMenuItem #1193

wants to merge 14 commits into from

Conversation

tpryan
Copy link
Contributor

@tpryan tpryan commented Jun 29, 2012

Added the ability to remove Menu Items. This should be useful for extension writers. It works for both the vanilla menus and context menus.

@peterflynn
Copy link
Member

@tpryan, could you remove the whitespace diffs from your patch?

// function removeMenuItem(id) {
// NOT IMPLEMENTED
// }
function _removeMenuItem(id) {
Copy link
Member

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?

@ghost ghost assigned peterflynn Jun 29, 2012
@tpryan
Copy link
Contributor Author

tpryan commented Jun 29, 2012

@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?

@peterflynn
Copy link
Member

@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 :-)

@peterflynn
Copy link
Member

Adobe is on break this coming week, but I should be able to review the update within a day or two.

@tpryan
Copy link
Contributor Author

tpryan commented Jul 2, 2012

@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.

@peterflynn
Copy link
Member

@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 .id field... but if not, there's really no clean way to get the right id -- and ideally, we'd support that use case too. I wonder if we could hoist out the middle of _getRelativeMenuItem() (finding MenuItem based on command id) so that it could be shared by removeMenuItem() too. @tvoliter, any thoughts on that?

*
* @param {!string} id - the unique identifier for the menu.
*
* Note, keyBindings are not effected at all by removing a menu item.
Copy link
Member

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.

@ghost ghost assigned tvoliter Jul 9, 2012
@tpryan
Copy link
Contributor Author

tpryan commented Jul 11, 2012

@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?

@peterflynn
Copy link
Member

Nice meeting you in person yesterday! For anyone else reading: yes, changing it to accept either command or commandID (like addMenuItem()), seems ideal.

@tpryan
Copy link
Contributor Author

tpryan commented Jul 13, 2012

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();
}
Copy link
Member

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 as menuItemMap[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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Renamed
  2. Removed
  3. 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?

@ghost ghost assigned peterflynn Jul 17, 2012
@peterflynn
Copy link
Member

@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;
Copy link
Member

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

@peterflynn
Copy link
Member

Lastly: needs a merge with master. The merge looked pretty clean when I tested it locally, so hopefully that's fairly easy.

@peterflynn
Copy link
Member

@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.

@tpryan
Copy link
Contributor Author

tpryan commented Nov 5, 2012

@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.

@peterflynn peterflynn mentioned this pull request Nov 7, 2012
@peterflynn
Copy link
Member

Ok, cool. I've opened #2072 with the updated code.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants