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:
authorCartBlanche <savagesoftware@gmail.com>2019-05-24 07:01:28 +0300
committerCartBlanche <savagesoftware@gmail.com>2019-06-11 12:29:14 +0300
commit45706274e35941d4e599b6ae4d48a2dd4ecf561e (patch)
treebf87b4165a0c328da30f963e503ad126d22debd2 /Xamarin.PropertyEditing.Mac/Controls/Custom
parent807d5c7f6b90c824408971f3bd873ce2a872c5df (diff)
[Mac] NSButton that handles ICommands. Needed for Binding Dialog and Variations PRs. Slight fix to CommandMenuItem too.
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls/Custom')
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/CommandButton.cs40
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/CommandMenuItem.cs4
2 files changed, 43 insertions, 1 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandButton.cs
new file mode 100644
index 0000000..4904bd8
--- /dev/null
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandButton.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Windows.Input;
+using AppKit;
+
+namespace Xamarin.PropertyEditing.Mac.Controls.Custom
+{
+ internal class CommandButton : NSButton
+ {
+ private ICommand command;
+
+ public ICommand Command
+ {
+ get { return this.command; }
+ set
+ {
+ if (this.command != null)
+ this.command.CanExecuteChanged -= CanExecuteChanged;
+
+ this.command = value;
+
+ if (this.command != null)
+ this.command.CanExecuteChanged += CanExecuteChanged;
+ }
+ }
+
+ public CommandButton ()
+ {
+ Activated += (object sender, EventArgs e) => {
+ var button = (CommandButton)sender;
+ button.command?.Execute (null);
+ };
+ }
+
+ private void CanExecuteChanged (object sender, EventArgs e)
+ {
+ if (sender is ICommand cmd)
+ this.Enabled = cmd.CanExecute (null);
+ }
+ }
+}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandMenuItem.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandMenuItem.cs
index c945a80..1a84424 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandMenuItem.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandMenuItem.cs
@@ -15,7 +15,9 @@ namespace Xamarin.PropertyEditing.Mac
this.command.CanExecuteChanged -= CanExecuteChanged;
this.command = value;
- this.command.CanExecuteChanged += CanExecuteChanged;
+
+ if (this.command != null)
+ this.command.CanExecuteChanged += CanExecuteChanged;
}
}