fernandoescolar / vscode-solution-explorer

This is a Visual Studio Code extension that provides a (.sln) Visual Studio Solution explorer panel..
MIT License
348 stars 73 forks source link

Fixed issue #5 - keyboard shortcuts not working (second attempt) #256

Closed panoskj closed 1 year ago

panoskj commented 1 year ago

As we discussed in #253 I was going to try merging commands that are activated by the same keybinding. This would work, but the merged commands' menu items would also share the same name (for example "Remove Reference" would become "Delete"). So I took a step back and tried another approach.

The first commit of this PR simply prepares the ground for the next one.

The second commit enables keybindings. Notice the added "multiple-selection" context value, which ensures existing keybindings will not run when multiple items are selected.

The third commit adds an implementation for handling deletion of multiple items at once.

  1. It filters out any children of selected items. For example, if you select a folder and some files inside it and try to delete them, only the parent folder deletion action will run.
  2. It detects what "groups" the selected items belong in. For example, no action is executed if you select a package reference and some files and then try to delete them. All selected items have to be in the same group.

VS IDE works in the same way too. Also note that the clicked item is not necessarily one of the selected items - you can right click and execute a command on an item that is not selected at all, in which case the selected items should be ignored.

There are more commands that can be executed for multiple selected items (e.g. copy, compile, build, etc). As for the "copy" command though, I think there is a bug in its "paste" counterpart anyway, preventing it from working properly (you can paste a folder but not a file).

Finally, it seems possible to define menus that only appear in case multiple items are clicked. For example, when you right click on multiple folder items, the options to "create a file/folder", "paste" and "rename" shouldn't appear at all. Or when you right click on a project and a folder that is inside it, you should only get the option to delete them. VS IDE does this too. I may make a proof of concept after getting this PR merged.

So, let me know what you think about this PR for a start. I didn't like the terse syntax I used in some places for one, but I didn't like the alternatives either.

fernandoescolar commented 1 year ago

I think you have done an excellent job. The command keybindings using the vscode context variables is very impresive and the handling of multiple item selection commands very promising.

panoskj commented 1 year ago

Thanks for the positive feedback! I made some slight optimizations/changes regarding how multiple items are deleted.

  1. If the user has selected multiple categories/groups of tree items (e.g. some files and some package references) there is no need to construct their deletion actions (since they won't be executed). As an optimization, I moved the construction of these actions after the check.

  2. Added check for the edge case when the user manually executes the delete command while having selected tree items that should not be delete-able. I forgot to mention it earlier, but a side effect of this PR is that the user can execute any command without having to pass the tree item as an argument (they can simply select the item(s) in the tree and commands will work).

  3. Disabled deleting multiple package/project references, when both CPS and standard references are selected (this is possible, because there is no checking whether these references are across multiple projects). Otherwise, CPS references would be deleted successfully leaving standard references intact. I think this could be misleading.

  4. Renamed ActionsCommand to SingleItemActionsCommand and ActionsBaseCommand to ActionsCommand. I think these names make more sense now.