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

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominique Louis <savagesoftware@gmail.com>2018-01-24 17:33:33 +0300
committerDominique Louis <savagesoftware@gmail.com>2018-04-20 20:53:27 +0300
commitebdb05abac8cd0fe1ffc995c7ad32b4f34cce6cb (patch)
tree986296f78f562510b5cdab5c65edf1656ee04a20 /Xamarin.PropertyEditing.Mac/Controls/Custom/CommandMenuItem.cs
parent57f5f4430942723a68ebdc8c78f83d0cd948b79d (diff)
Hooking up PropertyButton to ResetCommand.
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls/Custom/CommandMenuItem.cs')
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/CommandMenuItem.cs56
1 files changed, 56 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandMenuItem.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandMenuItem.cs
new file mode 100644
index 0000000..1cdc73e
--- /dev/null
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandMenuItem.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Windows.Input;
+using AppKit;
+
+namespace Xamarin.PropertyEditing.Mac
+{
+ public class CommandMenuItem : NSMenuItem
+ {
+ ICommand command;
+
+ public ICommand Command {
+ get { return command; }
+ set {
+ if (this.command != null)
+ this.command.CanExecuteChanged -= CanExecuteChanged;
+
+ this.command = value;
+ this.command.CanExecuteChanged += CanExecuteChanged;
+ }
+ }
+
+ public CommandMenuItem (string title) : base (title)
+ {
+ HookUpCommandEvents ();
+ }
+
+ public CommandMenuItem (string title, ICommand command) : this (title)
+ {
+ this.Command = command;
+ }
+
+ private void HookUpCommandEvents ()
+ {
+ Activated += (object sender, EventArgs e) => {
+ if (this.command != null)
+ this.command.Execute (null);
+ };
+
+ ValidateMenuItem = ValidatePropertyMenuItem;
+ }
+
+ private bool ValidatePropertyMenuItem (NSMenuItem menuItem)
+ {
+ if (this.command != null)
+ return this.command.CanExecute (null);
+
+ return false;
+ }
+
+ private void CanExecuteChanged (object sender, EventArgs e)
+ {
+ if(sender is ICommand cmd)
+ this.Enabled = cmd.CanExecute (null);
+ }
+ }
+}