-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Gray and ungray commands depending on conditions #428
Comments
@madskristensen See also: UPDATE I am referring to the post that is linked above. I enabled my extension to just not be loaded unless a Solution is currently open, which, in principle, addressed the issue I was concerned about. However, the preferred UI/UX is to always show the command on the Edit menu, but just gray it out when it does not apply. |
UPDATE I located this Stack Overflow post but I cannot find the I do see a
However, this does me no good, since -- and I am not trying to criticize -- but you hide the
@madskristensen the overridable version of the method hides the As an example, the code I'd write in my
See my changes? First of all, make the Secondly, I suggest you append Thirdly, I suggest that you make the return type The last change is needed so I can ask Visual Studio whether a solution is currently open using your Thank you for your consideration. |
The this.Command.Enabled = ...
The problem with that is If you need to call async methods from a synchronous method (like protected override void BeforeQueryStatus(EventArgs e)
{
Package.JoinableTaskFactory.Run(async () =>
{
Command.Enabled = await VS.Solutions.IsOpenAsync();
});
} Alternatively, you can avoid the asynchronous call completely. private IVsSolution? _solution;
protected async override Task InitializeCompletedAsync()
{
_solution = await VS.Services.GetSolutionAsync();
}
protected override void BeforeQueryStatus(EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
Command.Enabled = _solution?.IsOpen() ?? false;
} |
@madskristensen I am making a new extension with this toolkit. In my extension, I want to take a certain action but only if a Solution is currently loaded.
I have been following the tutorial:
https://www.vsixcookbook.com/getting-started/your-first-extension.html
Great tutorial by the way, and I am also thrilled that this package has been put together.
One recipe I think you forgot to add to your "cookbook" was graying out/ungraying commands, showing/hiding menu commands, and/or changing the text of a menu command. I also am struggling to implement those tips that I've Googled, with your package.
My command appears on the Edit menu in Visual Studio. I'd like to gray out my command if there is no solution currently open.
I am drawing a blank as to how to correctly implement this. Any assistance would be appreciated. Thank you.
The text was updated successfully, but these errors were encountered: