From bd7610df744a096fe6d9943c19049847f42525c6 Mon Sep 17 00:00:00 2001 From: Artyom Date: Wed, 23 Sep 2020 01:13:52 +0300 Subject: [PATCH] Migrate all controls to C# events --- Terminal.Gui/Views/ListView.cs | 4 ++-- Terminal.Gui/Views/Menu.cs | 4 ++-- Terminal.Gui/Views/RadioGroup.cs | 2 +- Terminal.Gui/Views/ScrollView.cs | 2 +- Terminal.Gui/Views/TextField.cs | 2 +- Terminal.Gui/Views/TextView.cs | 2 +- Terminal.Gui/Views/TimeField.cs | 2 +- Terminal.Gui/Windows/FileDialog.cs | 8 ++++---- UICatalog/Scenarios/AllViewsTester.cs | 8 ++++---- UICatalog/Scenarios/CharacterMap.cs | 2 +- UICatalog/Scenarios/DynamicMenuBar.cs | 4 ++-- UICatalog/Scenarios/TextAlignments.cs | 2 +- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index 6af1a5786..ec8c52b30 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -318,12 +318,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; /// public override bool ProcessKey (KeyEvent kb) diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs index c82c3173a..089ea90a4 100644 --- a/Terminal.Gui/Views/Menu.cs +++ b/Terminal.Gui/Views/Menu.cs @@ -871,12 +871,12 @@ namespace Terminal.Gui { /// /// Raised as a menu is opening. /// - public Action MenuOpening; + public event Action MenuOpening; /// /// Raised when a menu is closing. /// - public Action MenuClosing; + public event Action MenuClosing; internal Menu openMenu; internal Menu openCurrentMenu; diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index 65f2dddb8..8e896f1ae 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -244,7 +244,7 @@ namespace Terminal.Gui { /// /// Invoked when the selected radio label has changed. /// - public Action SelectedItemChanged; + public event Action SelectedItemChanged; /// /// The currently selected item from the list of radio labels diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index 82430ada5..99117ef77 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -60,7 +60,7 @@ namespace Terminal.Gui { /// /// This event is raised when the position on the scrollbar has changed. /// - public Action ChangedPosition; + public event Action ChangedPosition; /// /// The position, relative to , to set the scrollbar at. diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index ab8562338..6ddeb859e 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -41,7 +41,7 @@ namespace Terminal.Gui { /// /// The passed is a containing the old value. /// - public Action TextChanged; + public event Action TextChanged; /// /// Initializes a new instance of the class using positioning. diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 398bd926b..965f90d27 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -300,7 +300,7 @@ namespace Terminal.Gui { /// /// Raised when the of the changes. /// - public Action TextChanged; + public event Action TextChanged; #if false /// diff --git a/Terminal.Gui/Views/TimeField.cs b/Terminal.Gui/Views/TimeField.cs index fcb0099b6..e133f685f 100644 --- a/Terminal.Gui/Views/TimeField.cs +++ b/Terminal.Gui/Views/TimeField.cs @@ -38,7 +38,7 @@ namespace Terminal.Gui { /// /// The passed is a containing the old value, new value, and format string. /// - public Action> TimeChanged; + public event Action> TimeChanged; /// /// Initializes a new instance of using positioning. diff --git a/Terminal.Gui/Windows/FileDialog.cs b/Terminal.Gui/Windows/FileDialog.cs index 0e7894820..f3a50dc46 100644 --- a/Terminal.Gui/Windows/FileDialog.cs +++ b/Terminal.Gui/Windows/FileDialog.cs @@ -506,10 +506,10 @@ namespace Terminal.Gui { X = Pos.Right (dirLabel), Y = 1 + msgLines, Width = Dim.Fill () - 1, - TextChanged = (e) => { - DirectoryPath = dirEntry.Text; - nameEntry.Text = ustring.Empty; - } + }; + dirEntry.TextChanged += (e) => { + DirectoryPath = dirEntry.Text; + nameEntry.Text = ustring.Empty; }; Add (dirLabel, dirEntry); diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index ce36a4ef5..57bfcf8aa 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -133,8 +133,8 @@ namespace UICatalog { _xRadioGroup = new RadioGroup (radioItems) { X = 0, Y = Pos.Bottom (label), - SelectedItemChanged = (selected) => DimPosChanged (_curView), }; + _xRadioGroup.SelectedItemChanged += (selected) => DimPosChanged (_curView); _xText = new TextField ($"{_xVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; _xText.TextChanged += (args) => { try { @@ -164,8 +164,8 @@ namespace UICatalog { _yRadioGroup = new RadioGroup (radioItems) { X = Pos.X (label), Y = Pos.Bottom (label), - SelectedItemChanged = (selected) => DimPosChanged (_curView), }; + _yRadioGroup.SelectedItemChanged += (selected) => DimPosChanged (_curView); _locationFrame.Add (_yRadioGroup); _sizeFrame = new FrameView ("Size (Dim)") { @@ -181,8 +181,8 @@ namespace UICatalog { _wRadioGroup = new RadioGroup (radioItems) { X = 0, Y = Pos.Bottom (label), - SelectedItemChanged = (selected) => DimPosChanged (_curView) }; + _wRadioGroup.SelectedItemChanged += (selected) => DimPosChanged (_curView); _wText = new TextField ($"{_wVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; _wText.TextChanged += (args) => { try { @@ -212,8 +212,8 @@ namespace UICatalog { _hRadioGroup = new RadioGroup (radioItems) { X = Pos.X (label), Y = Pos.Bottom (label), - SelectedItemChanged = (selected) => DimPosChanged (_curView), }; + _hRadioGroup.SelectedItemChanged += (selected) => DimPosChanged (_curView); _sizeFrame.Add (_hRadioGroup); _settingsPane.Add (_sizeFrame); diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index 35f718231..849978f26 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -62,7 +62,7 @@ namespace UICatalog { jumpList.X = Pos.X (label); jumpList.Y = Pos.Bottom (label); jumpList.Width = Dim.Fill (); - jumpList.SelectedItemChanged = (args) => { + jumpList.SelectedItemChanged += (args) => { _charMap.Start = radioItems[args.SelectedItem].start; }; diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs index 46de9095a..edc21b892 100644 --- a/UICatalog/Scenarios/DynamicMenuBar.cs +++ b/UICatalog/Scenarios/DynamicMenuBar.cs @@ -498,12 +498,12 @@ namespace UICatalog { SelectCurrentMenuBarItem (); }; - _lstMenus.SelectedItemChanged = (e) => { + _lstMenus.SelectedItemChanged += (e) => { var menuBarItem = DataContext.Menus.Count > 0 ? DataContext.Menus [e.Item].MenuItem : null; EditMenuBarItem (menuBarItem); }; - _lstMenus.OpenSelectedItem = (e) => { + _lstMenus.OpenSelectedItem += (e) => { _currentMenuBarItem = DataContext.Menus [e.Item].MenuItem; DataContext.Parent = _currentMenuBarItem.Title; DataContext.Menus = new List (); diff --git a/UICatalog/Scenarios/TextAlignments.cs b/UICatalog/Scenarios/TextAlignments.cs index 207d883dc..107a12ab5 100644 --- a/UICatalog/Scenarios/TextAlignments.cs +++ b/UICatalog/Scenarios/TextAlignments.cs @@ -40,7 +40,7 @@ namespace UICatalog { ColorScheme = Colors.TopLevel, Text = txt, }; - edit.TextChanged = () => { + edit.TextChanged += () => { foreach (var alignment in alignments) { singleLines [(int)alignment].Text = edit.Text; multipleLines [(int)alignment].Text = edit.Text;