From 28805f3c5c1dd70a032194c71ad8f20be6eca074 Mon Sep 17 00:00:00 2001 From: Artyom Date: Wed, 23 Sep 2020 01:07:26 +0300 Subject: [PATCH] Use C# events in more controls --- Terminal.Gui/Views/Checkbox.cs | 2 +- Terminal.Gui/Views/ComboBox.cs | 4 ++-- Terminal.Gui/Views/DateField.cs | 2 +- Terminal.Gui/Views/Label.cs | 2 +- UICatalog/Scenarios/DynamicMenuBar.cs | 8 ++++---- UICatalog/Scenarios/LabelsAsButtons.cs | 24 ++++++++++++------------ 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Terminal.Gui/Views/Checkbox.cs b/Terminal.Gui/Views/Checkbox.cs index 4b17a7489..898c4658f 100644 --- a/Terminal.Gui/Views/Checkbox.cs +++ b/Terminal.Gui/Views/Checkbox.cs @@ -25,7 +25,7 @@ namespace Terminal.Gui { /// raised when the is activated either with /// the mouse or the keyboard. The passed bool contains the previous state. /// - public Action Toggled; + public event Action Toggled; /// /// Called when the property changes. Invokes the event. diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 4c867cd14..37bc36e5e 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -57,12 +57,12 @@ namespace Terminal.Gui { /// /// This event is raised when the selected item in the has changed. /// - public Action SelectedItemChanged; + public event Action SelectedItemChanged; /// /// This event is raised when the user Double Clicks on an item or presses ENTER to open the selected item. /// - public Action OpenSelectedItem; + public event Action OpenSelectedItem; IList searchset; ustring text = ""; diff --git a/Terminal.Gui/Views/DateField.cs b/Terminal.Gui/Views/DateField.cs index f22987d51..943f5973a 100644 --- a/Terminal.Gui/Views/DateField.cs +++ b/Terminal.Gui/Views/DateField.cs @@ -38,7 +38,7 @@ namespace Terminal.Gui { /// /// The passed event arguments containing the old value, new value, and format string. /// - public Action> DateChanged; + public event Action> DateChanged; /// /// Initializes a new instance of using layout. diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index 53e787c22..195fd8584 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -53,7 +53,7 @@ namespace Terminal.Gui { /// raised when the button is activated either with /// the mouse or the keyboard. /// - public Action Clicked; + public event Action Clicked; ///// //public new ustring Text { diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs index 3785a5d04..46de9095a 100644 --- a/UICatalog/Scenarios/DynamicMenuBar.cs +++ b/UICatalog/Scenarios/DynamicMenuBar.cs @@ -236,7 +236,7 @@ namespace UICatalog { Y = Pos.Bottom (_ckbIsTopLevel) }; _frmMenuDetails.Add (_ckbSubMenu); - _ckbIsTopLevel.Toggled = (e) => { + _ckbIsTopLevel.Toggled += (e) => { if (_ckbIsTopLevel.Checked && _currentEditMenuBarItem.Parent != null) { MessageBox.ErrorQuery ("Invalid IsTopLevel", "Only menu bar can have top level menu item!", "Ok"); _ckbIsTopLevel.Checked = false; @@ -250,7 +250,7 @@ namespace UICatalog { _txtAction.ReadOnly = true; } }; - _ckbSubMenu.Toggled = (e) => { + _ckbSubMenu.Toggled += (e) => { if (_ckbSubMenu.Checked) { _ckbIsTopLevel.Checked = false; _ckbIsTopLevel.SetNeedsDisplay (); @@ -746,7 +746,7 @@ namespace UICatalog { Y = Pos.Bottom (_ckbIsTopLevel), Checked = menuItem == null }; - _ckbIsTopLevel.Toggled = (e) => { + _ckbIsTopLevel.Toggled += (e) => { if (_ckbIsTopLevel.Checked && menuItem != null) { MessageBox.ErrorQuery ("Invalid IsTopLevel", "Only menu bar can have top level menu item!", "Ok"); _ckbIsTopLevel.Checked = false; @@ -760,7 +760,7 @@ namespace UICatalog { _txtAction.ReadOnly = true; } }; - _ckbSubMenu.Toggled = (e) => { + _ckbSubMenu.Toggled += (e) => { if (_ckbSubMenu.Checked) { _ckbIsTopLevel.Checked = false; _ckbIsTopLevel.SetNeedsDisplay (); diff --git a/UICatalog/Scenarios/LabelsAsButtons.cs b/UICatalog/Scenarios/LabelsAsButtons.cs index 243735f5b..2b4a2edb8 100644 --- a/UICatalog/Scenarios/LabelsAsButtons.cs +++ b/UICatalog/Scenarios/LabelsAsButtons.cs @@ -29,17 +29,17 @@ namespace UICatalog { //TODO: Change to use Pos.AnchorEnd() Y = Pos.Bottom (Win) - 3, //IsDefault = true, - Clicked = () => Application.RequestStop (), HotKeySpecifier = (System.Rune)'_', CanFocus = true, }; + defaultLabel.Clicked += () => Application.RequestStop (); Win.Add (defaultLabel); var swapLabel = new Label (50, 0, "S_wap Default (Absolute Layout)") { HotKeySpecifier = (System.Rune)'_', CanFocus = true, }; - swapLabel.Clicked = () => { + swapLabel.Clicked += () => { //defaultLabel.IsDefault = !defaultLabel.IsDefault; //swapLabel.IsDefault = !swapLabel.IsDefault; }; @@ -47,7 +47,7 @@ namespace UICatalog { static void DoMessage (Label Label, ustring txt) { - Label.Clicked = () => { + Label.Clicked += () => { var btnText = Label.Text.ToString (); MessageBox.Query ("Message", $"Did you click {txt}?", "Yes", "No"); }; @@ -88,10 +88,10 @@ namespace UICatalog { Win.Add (Label = new Label ("a Newline\nin the Label") { X = 2, Y = Pos.Bottom (Label) + 1, - Clicked = () => MessageBox.Query ("Message", "Question?", "Yes", "No"), HotKeySpecifier = (System.Rune)'_', CanFocus = true, }); + Label.Clicked += () => MessageBox.Query ("Message", "Question?", "Yes", "No"); var textChanger = new Label ("Te_xt Changer") { X = 2, @@ -100,7 +100,7 @@ namespace UICatalog { CanFocus = true, }; Win.Add (textChanger); - textChanger.Clicked = () => textChanger.Text += "!"; + textChanger.Clicked += () => textChanger.Text += "!"; Win.Add (Label = new Label ("Lets see if this will move as \"Text Changer\" grows") { X = Pos.Right (textChanger) + 2, @@ -118,7 +118,7 @@ namespace UICatalog { }; Win.Add (removeLabel); // This in intresting test case because `moveBtn` and below are laid out relative to this one! - removeLabel.Clicked = () => Win.Remove (removeLabel); + removeLabel.Clicked += () => Win.Remove (removeLabel); var computedFrame = new FrameView ("Computed Layout") { X = 0, @@ -137,7 +137,7 @@ namespace UICatalog { HotKeySpecifier = (System.Rune)'_', CanFocus = true, }; - moveBtn.Clicked = () => { + moveBtn.Clicked += () => { moveBtn.X = moveBtn.Frame.X + 5; // This is already fixed with the call to SetNeedDisplay() in the Pos Dim. //computedFrame.LayoutSubviews (); // BUGBUG: This call should not be needed. View.X is not causing relayout correctly @@ -154,7 +154,7 @@ namespace UICatalog { HotKeySpecifier = (System.Rune)'_', CanFocus = true, }; - sizeBtn.Clicked = () => { + sizeBtn.Clicked += () => { sizeBtn.Width = sizeBtn.Frame.Width + 5; //computedFrame.LayoutSubviews (); // FIXED: This call should not be needed. View.X is not causing relayout correctly }; @@ -174,7 +174,7 @@ namespace UICatalog { HotKeySpecifier = (System.Rune)'_', CanFocus = true, }; - moveBtnA.Clicked = () => { + moveBtnA.Clicked += () => { moveBtnA.Frame = new Rect (moveBtnA.Frame.X + 5, moveBtnA.Frame.Y, moveBtnA.Frame.Width, moveBtnA.Frame.Height); }; absoluteFrame.Add (moveBtnA); @@ -185,7 +185,7 @@ namespace UICatalog { HotKeySpecifier = (System.Rune)'_', CanFocus = true, }; - sizeBtnA.Clicked = () => { + sizeBtnA.Clicked += () => { sizeBtnA.Frame = new Rect (sizeBtnA.Frame.X, sizeBtnA.Frame.Y, sizeBtnA.Frame.Width + 5, sizeBtnA.Frame.Height); }; absoluteFrame.Add (sizeBtnA); @@ -240,7 +240,7 @@ namespace UICatalog { HotKeySpecifier = (System.Rune)'_', CanFocus = true, }; - moveHotKeyBtn.Clicked = () => { + moveHotKeyBtn.Clicked += () => { moveHotKeyBtn.Text = MoveHotkey (moveHotKeyBtn.Text); }; Win.Add (moveHotKeyBtn); @@ -254,7 +254,7 @@ namespace UICatalog { HotKeySpecifier = (System.Rune)'_', CanFocus = true, }; - moveUnicodeHotKeyBtn.Clicked = () => { + moveUnicodeHotKeyBtn.Clicked += () => { moveUnicodeHotKeyBtn.Text = MoveHotkey (moveUnicodeHotKeyBtn.Text); }; Win.Add (moveUnicodeHotKeyBtn);