Enable packages to control order of context menu items#16661
Enable packages to control order of context menu items#16661captbaritone merged 4 commits intoatom:masterfrom
Conversation
maxbrunsfeld
left a comment
There was a problem hiding this comment.
This seems very well designed. Nice work!
Does sorting the menu items ever have a noticeable performance impact when right clicking? It seems like the number of context menu items is usually small, so it's probably not an issue, but it'd be good to look at a profile just in case.
| expect(sortMenuItems(items)).toEqual(items) | ||
| }) | ||
| }) | ||
| describe('dedupes separators', () => { |
There was a problem hiding this comment.
Could you add blank lines between these it and describe calls?
|
@maxbrunsfeld Thanks for taking the time to review. I'll try to construct some reasonable worst-case scenarios and profile them. |
|
For a rather complex context menu of >30 elements containing 20 relationships of various types it takes under 10 milliseconds to sort them. |
|
👍 In a lot of code paths in Atom, ten milliseconds would be pretty significant, but since this only occurs on a fairly course-grained basis (once per right click) it doesn't seem like a big deal here. |
|
Do packages that use a |
|
This should work from either CSON or via |
|
There's no documentation on this feature. Is this intended to be left undocumented, or is this an oversight? To be clear, I believe this JSDoc should've been updated: atom/src/context-menu-manager.coffee Lines 84 to 110 in 42e3a50 |
|
@lierdakil Yeah, this should probably get documented now that it's been accepted. I'll add it to my list. |
Uh... to my understanding, it's not only "accepted", but also released with v1.26.0... so yeah, the feature is released, but documentation isn't there. I'm aware that's how it usually is, but it doesn't mean that's a good thing. I would argue the docstring should've been updated as a part of this PR. This is especially not fun considering Atom had a policy "undocumented means unsupported" since the early days. So this feature is in a kind of an awkward spot right now. To be clear, I'm not trying to start anything, just sharing my point of view. Please don't take it personally. |
|
@lierdakil Not sure about the official stance, but I'm okay with this being an "unsupported" API until it gets documented. In fact, it might be good to get some people trying it out and proving that it doesn't have any unforeseen problems before it's fully blessed. That said, I don't know exactly how these things generally get rolled out. The Nuclide team will be doing some work to adopt this in the near future and we will probably get some additional signal there to see how this works at a larger scale than my initial tests. |
Summary: Back in February I [added support](atom/atom#16661) in Atom for controling the order of context menu items. The API is not particularly pretty, but it works. Responding to alobbFB's report in T26643515, I've added our first use of this API. You'll notice that in this diff, `tree-view:search-in-directory` does not declare its own position. Instead, other entries position themselves relative to it. This is because in some cases (I'm not sure if this is intentional or not) `atom/find-and-replace` provides a context menu entry by the same name. To handle this, "Show in Finder" and "Set to Current Working Root" define themselves relative to both `project-find:show-in-current-directory` and `tree-view:search-in-directory`. This way, whichever entry wins, the ordering is stable. {F134321737} Reviewed By: matthewwithanm Differential Revision: D9070332 fbshipit-source-id: 76dd805ae739e78b8e8275475f1b9e3356b83817
Goals:
Constraints:
Prior work:
-- Extract from the Eclipse documentation.
Proposed Solution:
beforeafterbeforeGroupContainingafterGroupContainingbefore/afterProvide a means for a single context menu item to declare their placement relative to another context menu item. These also imply that menu item in question should be placed in the same “group” as the itembeforeGroupContaining/afterGroupContainingProvide a means for a single context menu to declare the placement of their containing group, relative to the containing group of the specified item. Ideally these could be declared on some entity representing the notion of a “group”, but no such entity exists at this time, and I don't believe it's worth introducing a new construct within this API.Edge case handling:
Possible challenges: