Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CommandState.cs « Commanding « TextUI « Def « Text « Editor « src - github.com/microsoft/vs-editor-api.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a6de4a3dce9aefe30f01dce830989587b456127a (plain)
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
using System;

namespace Microsoft.VisualStudio.Commanding
{
    /// <summary>
    /// Returned by <see cref="ICommandHandler{T}.GetCommandState(T)"/> and determines the state of the command.
    /// </summary>
#pragma warning disable CA1815 // Override equals and operator equals on value types
    public struct CommandState
#pragma warning restore CA1815 // Override equals and operator equals on value types
    {
        /// <summary>
        /// If true, the command state is unspecified and should not be taken into account.
        /// </summary>
        public bool IsUnspecified { get; }

        /// <summary>
        /// If true, the command should be visible and enabled in the UI.
        /// </summary>
        public bool IsAvailable { get; }

        /// <summary>
        /// If true, the command should appear as checked (i.e. toggled) in the UI.
        /// </summary>
        public bool IsChecked { get; }

        /// <summary>
        /// If specified, returns the custom text that should be displayed in the UI.
        /// </summary>
        public string DisplayText { get; }

        public CommandState(bool isAvailable = false, bool isChecked = false, string displayText = null, bool isUnspecified = false)
        {
            if (isUnspecified && (isAvailable || isChecked || displayText != null))
            {
                throw new ArgumentException("Unspecified command state cannot be combined with other states or command text.");
            }

            this.IsAvailable = isAvailable;
            this.IsChecked = isChecked;
            this.IsUnspecified = isUnspecified;
            this.DisplayText = displayText;
        }

        /// <summary>
        /// A helper singleton representing an available command state.
        /// </summary>
        public static CommandState Available { get; } = new CommandState(isAvailable: true);

        /// <summary>
        /// A helper singleton representing an unavailable command state.
        /// </summary>
        public static CommandState Unavailable { get; } = new CommandState(isAvailable: false);

        /// <summary>
        /// A helper singleton representing an unspecified command state.
        /// </summary>
        public static CommandState Unspecified { get; } = new CommandState(isUnspecified: true);
    }
}