diff --git a/Example/demo.cs b/Example/demo.cs index 31e26afa1..8e2686117 100644 --- a/Example/demo.cs +++ b/Example/demo.cs @@ -225,10 +225,11 @@ static class Demo { static void NewFile () { - var d = new Dialog ( - "New File", 50, 20, - new Button ("Ok", is_default: true) { Clicked = () => { Application.RequestStop (); } }, - new Button ("Cancel") { Clicked = () => { Application.RequestStop (); } }); + var ok = new Button ("Ok", is_default: true); + ok.Clicked += () => { Application.RequestStop (); }; + var cancel = new Button ("Cancel"); + cancel.Clicked += () => { Application.RequestStop (); }; + var d = new Dialog ("New File", 50, 20, ok, cancel); ml2 = new Label (1, 1, "Mouse Debug Line"); d.Add (ml2); Application.Run (d); @@ -423,9 +424,11 @@ static class Demo { static void ListSelectionDemo (bool multiple) { - var d = new Dialog ("Selection Demo", 60, 20, - new Button ("Ok", is_default: true) { Clicked = () => { Application.RequestStop (); } }, - new Button ("Cancel") { Clicked = () => { Application.RequestStop (); } }); + var ok = new Button ("Ok", is_default: true); + ok.Clicked += () => { Application.RequestStop (); }; + var cancel = new Button ("Cancel"); + cancel.Clicked += () => { Application.RequestStop (); }; + var d = new Dialog ("Selection Demo", 60, 20, ok, cancel); var animals = new List () { "Alpaca", "Llama", "Lion", "Shark", "Goat" }; var msg = new Label ("Use space bar or control-t to toggle selection") { @@ -483,9 +486,9 @@ static class Demo { #region KeyDown / KeyPress / KeyUp Demo private static void OnKeyDownPressUpDemo () { - var container = new Dialog ( - "KeyDown & KeyPress & KeyUp demo", 80, 20, - new Button ("Close") { Clicked = () => { Application.RequestStop (); } }) { + var close = new Button ("Close"); + close.Clicked += () => { Application.RequestStop (); }; + var container = new Dialog ("KeyDown & KeyPress & KeyUp demo", 80, 20, close) { Width = Dim.Fill (), Height = Dim.Fill (), }; diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index 41f6796d4..9492ae68e 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -201,7 +201,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 override bool MouseEvent (MouseEvent me) diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs index 975ca9ee4..43974d741 100644 --- a/UICatalog/Scenarios/Buttons.cs +++ b/UICatalog/Scenarios/Buttons.cs @@ -29,12 +29,12 @@ namespace UICatalog { //TODO: Change to use Pos.AnchorEnd() Y = Pos.Bottom (Win) - 3, IsDefault = true, - Clicked = () => Application.RequestStop (), }; + defaultButton.Clicked += () => Application.RequestStop (); Win.Add (defaultButton); var swapButton = new Button (50, 0, "Swap Default (Absolute Layout)"); - swapButton.Clicked = () => { + swapButton.Clicked += () => { defaultButton.IsDefault = !defaultButton.IsDefault; swapButton.IsDefault = !swapButton.IsDefault; }; @@ -42,7 +42,7 @@ namespace UICatalog { static void DoMessage (Button button, ustring txt) { - button.Clicked = () => { + button.Clicked += () => { var btnText = button.Text.ToString (); MessageBox.Query ("Message", $"Did you click {txt}?", "Yes", "No"); }; @@ -82,15 +82,15 @@ namespace UICatalog { Win.Add (button = new Button ("a Newline\nin the button") { X = 2, Y = Pos.Bottom (button) + 1, - Clicked = () => MessageBox.Query ("Message", "Question?", "Yes", "No") }); + button.Clicked += () => MessageBox.Query ("Message", "Question?", "Yes", "No"); var textChanger = new Button ("Te_xt Changer") { X = 2, Y = Pos.Bottom (button) + 1, }; Win.Add (textChanger); - textChanger.Clicked = () => textChanger.Text += "!"; + textChanger.Clicked += () => textChanger.Text += "!"; Win.Add (button = new Button ("Lets see if this will move as \"Text Changer\" grows") { X = Pos.Right (textChanger) + 2, @@ -104,7 +104,7 @@ namespace UICatalog { }; Win.Add (removeButton); // This in intresting test case because `moveBtn` and below are laid out relative to this one! - removeButton.Clicked = () => Win.Remove (removeButton); + removeButton.Clicked += () => Win.Remove (removeButton); var computedFrame = new FrameView ("Computed Layout") { X = 0, @@ -121,7 +121,7 @@ namespace UICatalog { Width = 30, ColorScheme = Colors.Error, }; - 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 @@ -135,7 +135,7 @@ namespace UICatalog { Width = 30, ColorScheme = Colors.Error, }; - 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 }; @@ -153,7 +153,7 @@ namespace UICatalog { var moveBtnA = new Button (0, 0, "Move This Button via Frame") { ColorScheme = Colors.Error, }; - moveBtnA.Clicked = () => { + moveBtnA.Clicked += () => { moveBtnA.Frame = new Rect (moveBtnA.Frame.X + 5, moveBtnA.Frame.Y, moveBtnA.Frame.Width, moveBtnA.Frame.Height); }; absoluteFrame.Add (moveBtnA); @@ -162,7 +162,7 @@ namespace UICatalog { var sizeBtnA = new Button (0, 2, " ~  s  gui.cs   master ↑10 = Со_хранить") { ColorScheme = Colors.Error, }; - sizeBtnA.Clicked = () => { + sizeBtnA.Clicked += () => { sizeBtnA.Frame = new Rect (sizeBtnA.Frame.X, sizeBtnA.Frame.Y, sizeBtnA.Frame.Width + 5, sizeBtnA.Frame.Height); }; absoluteFrame.Add (sizeBtnA); @@ -213,7 +213,7 @@ namespace UICatalog { Width = Dim.Width (computedFrame) - 2, ColorScheme = Colors.TopLevel, }; - moveHotKeyBtn.Clicked = () => { + moveHotKeyBtn.Clicked += () => { moveHotKeyBtn.Text = MoveHotkey (moveHotKeyBtn.Text); }; Win.Add (moveHotKeyBtn); @@ -225,7 +225,7 @@ namespace UICatalog { Width = Dim.Width (absoluteFrame) - 2, // BUGBUG: Not always the width isn't calculated correctly. ColorScheme = Colors.TopLevel, }; - moveUnicodeHotKeyBtn.Clicked = () => { + moveUnicodeHotKeyBtn.Clicked += () => { moveUnicodeHotKeyBtn.Text = MoveHotkey (moveUnicodeHotKeyBtn.Text); }; Win.Add (moveUnicodeHotKeyBtn); diff --git a/UICatalog/Scenarios/Clipping.cs b/UICatalog/Scenarios/Clipping.cs index 6231efe40..67496d1cb 100644 --- a/UICatalog/Scenarios/Clipping.cs +++ b/UICatalog/Scenarios/Clipping.cs @@ -69,11 +69,12 @@ namespace UICatalog { Height = Dim.Fill (3), ColorScheme = Colors.TopLevel }; - embedded3.Add (new Button (2, 2, "click me") { - Clicked = () => { - MessageBox.Query (10, 5, "Test", "test message", "Ok"); - } - }); + + var testButton = new Button (2, 2, "click me"); + testButton.Clicked += () => { + MessageBox.Query (10, 5, "Test", "test message", "Ok"); + }; + embedded3.Add (testButton); embedded2.Add (embedded3); scrollView.Add (embedded1); diff --git a/UICatalog/Scenarios/ComputedLayout.cs b/UICatalog/Scenarios/ComputedLayout.cs index 7fde004d4..aef345b0b 100644 --- a/UICatalog/Scenarios/ComputedLayout.cs +++ b/UICatalog/Scenarios/ComputedLayout.cs @@ -125,7 +125,7 @@ namespace UICatalog { }; // TODO: Use Pos.Width instead of (Right-Left) when implemented (#502) anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton)); - anchorButton.Clicked = () => { + anchorButton.Clicked += () => { // Ths demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer // The call to Win.LayoutSubviews causes the Computed layout to @@ -152,7 +152,7 @@ namespace UICatalog { var leftButton = new Button ("Left") { Y = Pos.Bottom (Win) - 3 }; - leftButton.Clicked = () => { + leftButton.Clicked += () => { // Ths demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer // The call to Win.LayoutSubviews causes the Computed layout to @@ -167,7 +167,7 @@ namespace UICatalog { X = Pos.Center (), Y = Pos.AnchorEnd () - 1 }; - centerButton.Clicked = () => { + centerButton.Clicked += () => { // Ths demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer // The call to Win.LayoutSubviews causes the Computed layout to @@ -180,7 +180,7 @@ namespace UICatalog { var rightButton = new Button ("Right") { Y = Pos.Y (centerButton) }; - rightButton.Clicked = () => { + rightButton.Clicked += () => { // Ths demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer // The call to Win.LayoutSubviews causes the Computed layout to diff --git a/UICatalog/Scenarios/Dialogs.cs b/UICatalog/Scenarios/Dialogs.cs index 7aa6f52fd..ea1a2abdf 100644 --- a/UICatalog/Scenarios/Dialogs.cs +++ b/UICatalog/Scenarios/Dialogs.cs @@ -116,52 +116,54 @@ namespace UICatalog { X = Pos.Center(), Y = Pos.Bottom (frame) + 2 , IsDefault = true, - Clicked = () => { - try { - int width = int.Parse (widthEdit.Text.ToString ()); - int height = int.Parse (heightEdit.Text.ToString ()); - int numButtons = int.Parse (numButtonsEdit.Text.ToString ()); + }; + showDialogButton.Clicked += () => { + try { + int width = int.Parse (widthEdit.Text.ToString ()); + int height = int.Parse (heightEdit.Text.ToString ()); + int numButtons = int.Parse (numButtonsEdit.Text.ToString ()); - var buttons = new List