mscorlib(4.0.0.0) API with additions
MenuCommand.cs
1 using System.Collections;
5 
7 {
9  [ComVisible(true)]
10  [HostProtection(SecurityAction.LinkDemand, SharedState = true)]
11  [PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")]
12  [PermissionSet(SecurityAction.InheritanceDemand, Name = "FullTrust")]
13  public class MenuCommand
14  {
15  private EventHandler execHandler;
16 
17  private EventHandler statusHandler;
18 
19  private CommandID commandID;
20 
21  private int status;
22 
23  private IDictionary properties;
24 
25  private const int ENABLED = 2;
26 
27  private const int INVISIBLE = 16;
28 
29  private const int CHECKED = 4;
30 
31  private const int SUPPORTED = 1;
32 
36  public virtual bool Checked
37  {
38  get
39  {
40  return (status & 4) != 0;
41  }
42  set
43  {
44  SetStatus(4, value);
45  }
46  }
47 
51  public virtual bool Enabled
52  {
53  get
54  {
55  return (status & 2) != 0;
56  }
57  set
58  {
59  SetStatus(2, value);
60  }
61  }
62 
65  public virtual IDictionary Properties
66  {
67  get
68  {
69  if (properties == null)
70  {
71  properties = new HybridDictionary();
72  }
73  return properties;
74  }
75  }
76 
80  public virtual bool Supported
81  {
82  get
83  {
84  return (status & 1) != 0;
85  }
86  set
87  {
88  SetStatus(1, value);
89  }
90  }
91 
95  public virtual bool Visible
96  {
97  get
98  {
99  return (status & 0x10) == 0;
100  }
101  set
102  {
103  SetStatus(16, !value);
104  }
105  }
106 
109  public virtual CommandID CommandID => commandID;
110 
113  public virtual int OleStatus => status;
114 
116  public event EventHandler CommandChanged
117  {
118  add
119  {
120  statusHandler = (EventHandler)Delegate.Combine(statusHandler, value);
121  }
122  remove
123  {
124  statusHandler = (EventHandler)Delegate.Remove(statusHandler, value);
125  }
126  }
127 
131  public MenuCommand(EventHandler handler, CommandID command)
132  {
133  execHandler = handler;
134  commandID = command;
135  status = 3;
136  }
137 
138  private void SetStatus(int mask, bool value)
139  {
140  int num = status;
141  num = ((!value) ? (num & ~mask) : (num | mask));
142  if (num != status)
143  {
144  status = num;
146  }
147  }
148 
150  public virtual void Invoke()
151  {
152  if (execHandler != null)
153  {
154  try
155  {
156  execHandler(this, EventArgs.Empty);
157  }
158  catch (CheckoutException ex)
159  {
160  if (ex != CheckoutException.Canceled)
161  {
162  throw;
163  }
164  }
165  }
166  }
167 
170  public virtual void Invoke(object arg)
171  {
172  Invoke();
173  }
174 
177  protected virtual void OnCommandChanged(EventArgs e)
178  {
179  if (statusHandler != null)
180  {
181  statusHandler(this, e);
182  }
183  }
184 
187  public override string ToString()
188  {
189  string text = CommandID.ToString() + " : ";
190  if ((status & 1) != 0)
191  {
192  text += "Supported";
193  }
194  if ((status & 2) != 0)
195  {
196  text += "|Enabled";
197  }
198  if ((status & 0x10) == 0)
199  {
200  text += "|Visible";
201  }
202  if ((status & 4) != 0)
203  {
204  text += "|Checked";
205  }
206  return text;
207  }
208  }
209 }
virtual bool Visible
Gets or sets a value indicating whether this menu item is visible.
Definition: MenuCommand.cs:96
virtual void OnCommandChanged(EventArgs e)
Raises the E:System.ComponentModel.Design.MenuCommand.CommandChanged event.
Definition: MenuCommand.cs:177
virtual void Invoke(object arg)
Invokes the command with the given parameter.
Definition: MenuCommand.cs:170
Represents a unique command identifier that consists of a numeric command ID and a GUID menu group id...
Definition: CommandID.cs:12
Definition: __Canon.cs:3
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: EventArgs.cs:9
static Delegate Remove(Delegate source, Delegate value)
Removes the last occurrence of the invocation list of a delegate from the invocation list of another ...
Definition: Delegate.cs:287
static Delegate Combine(Delegate a, Delegate b)
Concatenates the invocation lists of two delegates.
Definition: Delegate.cs:202
SecurityAction
Specifies the security actions that can be performed using declarative security.
static readonly EventArgs Empty
Provides a value to use with events that do not have event data.
Definition: EventArgs.cs:13
delegate void EventHandler(object sender, EventArgs e)
Represents the method that will handle an event that has no event data.
Represents a delegate, which is a data structure that refers to a static method or to a class instanc...
Definition: Delegate.cs:15
virtual int OleStatus
Gets the OLE command status code for this menu item.
Definition: MenuCommand.cs:113
The exception that is thrown when an attempt to check out a file that is checked into a source code m...
virtual bool Supported
Gets or sets a value indicating whether this menu item is supported.
Definition: MenuCommand.cs:81
static readonly CheckoutException Canceled
Initializes a new instance of the T:System.ComponentModel.Design.CheckoutException class that specifi...
EventHandler CommandChanged
Occurs when the menu command changes.
Definition: MenuCommand.cs:117
Represents a Windows menu or toolbar command item.
Definition: MenuCommand.cs:13
MenuCommand(EventHandler handler, CommandID command)
Initializes a new instance of the T:System.ComponentModel.Design.MenuCommand class.
Definition: MenuCommand.cs:131
Implements IDictionary by using a T:System.Collections.Specialized.ListDictionary while the collectio...
override string ToString()
Returns a string representation of this menu command.
Definition: MenuCommand.cs:187
override string ToString()
Returns a T:System.String that represents the current object.
Definition: CommandID.cs:62
virtual IDictionary Properties
Gets the public properties associated with the T:System.ComponentModel.Design.MenuCommand.
Definition: MenuCommand.cs:66
virtual void Invoke()
Invokes the command.
Definition: MenuCommand.cs:150
virtual bool Enabled
Gets a value indicating whether this menu item is available.
Definition: MenuCommand.cs:52
Represents a nongeneric collection of key/value pairs.
Definition: IDictionary.cs:8
virtual bool Checked
Gets or sets a value indicating whether this menu item is checked.
Definition: MenuCommand.cs:37