forked from microsoft/VSExtensibility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyToolWindowData.cs
82 lines (72 loc) · 2.31 KB
/
MyToolWindowData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace ToolWindowSample;
using System.Runtime.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Microsoft;
using Microsoft.VisualStudio.Extensibility;
using Microsoft.VisualStudio.Extensibility.Shell;
using Microsoft.VisualStudio.Extensibility.UI;
/// <summary>
/// A sample data context object to use with tool window UI content.
/// </summary>
[DataContract]
internal class MyToolWindowData : NotifyPropertyChangedObject
{
private readonly VisualStudioExtensibility extensibility;
private bool hasError;
private string message = "My custom message";
/// <summary>
/// Initializes a new instance of the <see cref="MyToolWindowData" /> class.
/// </summary>
/// <param name="extensibility">
/// Extensibility object instance.
/// </param>
public MyToolWindowData(VisualStudioExtensibility extensibility)
{
this.extensibility = Requires.NotNull(extensibility, nameof(extensibility));
this.ShowMessageCommand = new AsyncCommand(this.ShowMessageAsync);
}
/// <summary>
/// Gets the async command used to show a message prompt.
/// </summary>
[DataMember]
public IAsyncCommand ShowMessageCommand
{
get;
}
/// <summary>
/// Gets or sets a value indicating whether there is an error in the data context.
/// </summary>
[DataMember]
public bool HasError
{
get => this.hasError;
set => this.SetProperty(ref this.hasError, value);
}
/// <summary>
/// Gets or sets the message to display in the message prompt.
/// </summary>
[DataMember]
public string Message
{
get => this.message;
set
{
if (string.IsNullOrWhiteSpace(value))
{
this.HasError = true;
}
else
{
this.HasError = false;
}
this.SetProperty(ref this.message, value);
}
}
private async Task ShowMessageAsync(object? commandParameter, CancellationToken cancellationToken)
{
await this.extensibility.Shell().ShowPromptAsync(this.Message, PromptOptions.OK, cancellationToken);
}
}