-
Notifications
You must be signed in to change notification settings - Fork 29.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support dynamically contributed commands for contributed trees context menus #45325
Comments
(Experimental duplicate detection) |
@DanTup Not sure if I understand your scenario. Can you please explain a bit more
|
I'm rendering a tree where the items that should be on the context menu vary for each node and are (relatively) expensive to compute. Currently the API requires that I set the I would like to be able to lazily provide the context menu/ Hope that makes sense! |
@DanTup I see. If it is expensive to compute the context menu, then delaying it until context menu appears will make context menu to be async (not instinctive). This might not be expected by the user when user does right click? |
@sandy081 Computing a single one is hopefully not very slow (hopefully < 10ms), but computing them for every node of the tree in a single-threaded server would be. I understand the concerns with making the context menu async, but we hope it'd be fast enough to not affect the experience here. |
But you will only compute when the node is shown (when |
Yeah, but if we want the tree to default to expanded, that's basically everything in a very short space of time?
Yeah, it's more about the resource usage and total time for all the round trips we're trying to minimise. It seems wasteful for us to compute the context menus for 100 nodes if the user only ever invokes the context menu on one (or none). |
@sandy081 Another possibility - what if we could provide an update the enabled/disabled status of the context menu asynchronously? That way the menu can render immediately, but items may become greyed later. It's up to the provider to ensure it's fast and handle the case where the item was still clicked but wasn't intended to be visible? |
I'm not sure what exactly you have in mind, but as long as we can provide info at the time the menu is being shown (and not at the time of constructing TreeItem) then it should work for us. |
There are ideas to have a
We don't plan for dynamic menus, the tree might want to accept |
I'm not sure I understand. I already have the ability to control the visibility using |
Like keybindings, menu-definitions are static and cannot be computed dynamically. We do that to eventually support user-custimizable menus (like user customisable keybindings) and we have no plans for dynamic menus. The only thing you might be able to get is something special with the tree, e.g. a property that you need to provide with the TreeItem - that's up to @sandy081 |
That's fine, the commands are already predefined in
@sandy081 Let me know your thoughts on this, as it may influence dev we do elsewhere. The simplest way would be for me to provide an async method on the tree provider that given a |
@jrieken What is the thinking behind exposing a property in TreeItem for dynamic custom menus? We already expose a property
@DanTup Correct me if I am wrong. |
@sandy081 Blocking/delaying the right click with extension code won't happen therefore I propose middle ground. Instead of going through |
@sandy081 Your understanding is correct. @jrieken I'm already able to provide the set of commands dynamically using a regex in the
How about letting the menu appear immediately, but an async call is able to disable (grey out) items? I'm sure we can easily respond in < 50ms so the user won't notice them update from black to grey and I'm happy to be responsible for handling the command graceful if the user is able to click one because I didn't respond fast enough. |
This is like contributing commands when |
Btw, it seems like the explorer menu may already be doing this - eg. Paste is only available when you have a file in the clipboard. I can't figure out from the source how this works though - is it something we can piggy-back? |
@DanTup This is done by using |
Ah, gotcha :( |
@DanTup Please provide your suggestion of having Thanks |
@sandy081 My comment on the other issue was actually unrelated to dynamic context menus; but rather what's in that case. In this comment there's a screenshot suggesting we could contribute buttons to above the tree. If that's the case, then having That seems like a reasonable way for me to achieve what I wanted here, but is not possible (that is, provide some actions that are available/not available depending on the selected node). |
Are you saying you can update the context (which a menu command depends on) by listening to selection change event? |
@sandy081 I might be missing something, but I was thinking that if we had an onSelectionChange for the tree, then we can set a context with |
Yes title bar buttons are
|
@sandy081 That's great - going back to this comment could we have an onSelectionChange event then? This seems like a reasonable use case? :-) |
Oh, one other question (slightly off-topic for this issue, but hey)... those title bar buttons - can we have them visible-but-disabled? So they don't jump around as the user clicks between nodes (just become disabled/enabled)? |
@DanTup You can only show/hide them but not disable. I think there is a request for this in general. Closing this. |
Currently we have to know what items should appear on a TreeItem's context menu at the time that we render the tree. This means if we want to display a fully expanded tree at startup but add context menu items, we have to fetch them all immediately.
Would it be possible to have an async method that asks us for the items at the time of selection so we can lazily-fetch these items (I understand this will delay rendering of the context menu until the promise resolves).
The text was updated successfully, but these errors were encountered: