madskristensen / Community.VisualStudio.Toolkit

A community toolkit for writing Visual Studio extensions
Other
24 stars 3 forks source link

VS.MessageBox.ShowXXX to hide the ugliness of VsShellUtilities.ShowMessageBox #1

Closed yannduran closed 3 years ago

yannduran commented 3 years ago

In Luminous Code & in Start Page+'s DialogService, I have various message helpers, but I was using WPF's MessageBox.Show which I learned recently in one of Mads's shows that it shouldn't be done that way. A perfect example of the raison d'etre for VSSDK.Helpers! Or Microsoft.Toolbox.VSSDK as I've suggested in issue #2.

I then built on that to have:

public Result ShowMessage(string message, string title = null, Button button = Button.OK, Icon icon = Icon.None)
    => MessageBox.Show(message, title ?? Vsix.Name, button, icon);

public void ShowExclamation(string message, string title = null)
    => ShowMessage(message, title, button: Button.OK, icon: Icon.Exclamation);

public void ShowWarning(string message, string title = null)
    => ShowMessage(message, title, button: Button.OK, icon: Icon.Warning);

public void ShowError(string message, string title = null)
    => ShowMessage(message, title, button: Button.OK, icon: Icon.Error);

public void ShowError(Exception ex, bool extendedMessage = true)
    => ShowError(extendedMessage ? ex.ExtendedMessage() : ex.Message);

public Result ShowConfirm(string question, string title = null, Button button = Button.YesNo)
    => ShowMessage(question, title: title ?? "Please Confirm", button, icon: Icon.Question);

Building on that idea, we could have:

VS.MessageBox.ShowExclamation
VS.MessageBox.ShowWarning
VS.MessageBox.ShowError
VS.MessageBox.ShowConfirm (or better maybe VS.MessageBox.GetConfirmation)

etc

Writing code like: