Skip to content
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

How to hide context menu commands from command palette? #45119

Closed
DanTup opened this issue Mar 6, 2018 · 8 comments
Closed

How to hide context menu commands from command palette? #45119

DanTup opened this issue Mar 6, 2018 · 8 comments
Assignees
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@DanTup
Copy link
Contributor

DanTup commented Mar 6, 2018

I'm contributing some commands to a custom view via view/item/context in packages.json, but they're showing up in the command palette. I had prefixed them with an _ and also set the when condition in menu/commandPalette to false however they still appear in the command palette:

"menus": {
	"commandPalette": [
		{
			"when": "false",
			"command": "_flutter.outline.refactor.dart.assist.flutter.move.down"
		},
		{
			"when": "false",
			"command": "_flutter.outline.refactor.dart.assist.flutter.removeWidget"
		}

What's the correct way to hide an item from the palette (these commands are actions on a node in the contributed tree and don't make sense to execute without a node).

@vscodebot
Copy link

vscodebot bot commented Mar 6, 2018

(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

@jrieken
Copy link
Member

jrieken commented Mar 6, 2018

As I understand it but they're showing up in the command palette.

Yeah, that's the idea of global commands. Be prepared that your commands are invoked by whomever... You can use the when-trick but false isn't a good condition, use something that exists like "when": "config.noExists"

@jrieken jrieken added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label Mar 6, 2018
@vscodebot
Copy link

vscodebot bot commented Mar 6, 2018

Please ask your question on StackOverflow. We have a great community over there. They have already answered thousands of questions and are happy to answer yours as well. See also our issue reporting guidelines.

Happy Coding!

@vscodebot vscodebot bot closed this as completed Mar 6, 2018
@DanTup
Copy link
Contributor Author

DanTup commented Mar 6, 2018

@jrieken I don't quite understand what you mean. Do you mean to actually use the condition config.noExists or just some made up value? I thought false was the safest value that could never occur. Is there a better way to create internal commands that shouldn't be called/seen by users?

@jrieken
Copy link
Member

jrieken commented Mar 6, 2018

config.noExists or just some made up value?

half and half. config is the generic prefix to reach into a configuration/setting value - in this case noExists which does not exist. Using false should also work but using a value as key might confuse our "parser".

Is there a better way to create internal commands that shouldn't be called/seen by users

That doesn't exist for us, every command is public and when-clauses are recommendations only, albeit very good recommendations.

@DanTup
Copy link
Contributor Author

DanTup commented Mar 6, 2018

That doesn't exist for us, every command is public and when-clauses are recommendations only

What about when there are arguments? (for ex. this one takes an argument that is a TreeItem so the user wouldn't be able to provide it). I do have other "private" commands but I think I don't declare them in package.json so they don't show up - however I'm forced to put this one there so I can declare the text for the context menu.

Let me know if there's a better way to do this!

@DanTup
Copy link
Contributor Author

DanTup commented Mar 6, 2018

Doh - I had a copy/paste error. false is probably working; but I'd missed one of the commands from the commandPalette section and it was the one I was using to test. Apologies, and thanks for info!

@jrieken
Copy link
Member

jrieken commented Mar 8, 2018

What about when there are arguments?

You need to always check them, ideally infer them when missing. We know that's hard... There are ideas about command-preconditions which will control the enablement state but we haven't narrowed down on it yet

@vscodebot vscodebot bot locked and limited conversation to collaborators Apr 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests

2 participants