From e7950433d8159a5570cd08a4c8b685830e798ce5 Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 11 Mar 2023 09:02:33 +0000 Subject: [PATCH 01/46] Standardize on EventHandler --- Terminal.Gui/Core/Border.cs | 6 +++--- Terminal.Gui/Core/CollectionNavigator.cs | 6 +++--- Terminal.Gui/Core/Window.cs | 2 +- Terminal.Gui/Views/FrameView.cs | 2 +- Terminal.Gui/Views/PanelView.cs | 2 +- UICatalog/Scenarios/CollectionNavigatorTester.cs | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Terminal.Gui/Core/Border.cs b/Terminal.Gui/Core/Border.cs index 1fdb7f48e6..8f28b6e472 100644 --- a/Terminal.Gui/Core/Border.cs +++ b/Terminal.Gui/Core/Border.cs @@ -131,7 +131,7 @@ public override Border Border { } } - void Border_BorderChanged (Border border) + void Border_BorderChanged (object sender, EventArgs e) { Rect frame; if (Border.Child != null && (Border.Child.Width is Dim || Border.Child.Height is Dim)) { @@ -319,7 +319,7 @@ public override bool MouseEvent (MouseEvent mouseEvent) /// /// Invoked when any property of Border changes (except ). /// - public event Action BorderChanged; + public event EventHandler BorderChanged; private BorderStyle borderStyle; private bool drawMarginFrame; @@ -1113,7 +1113,7 @@ public void DrawTitle (View view, Rect rect) /// public virtual void OnBorderChanged () { - BorderChanged?.Invoke (this); + BorderChanged?.Invoke (this, new EventArgs()); } } } \ No newline at end of file diff --git a/Terminal.Gui/Core/CollectionNavigator.cs b/Terminal.Gui/Core/CollectionNavigator.cs index 6637daf209..054fce1067 100644 --- a/Terminal.Gui/Core/CollectionNavigator.cs +++ b/Terminal.Gui/Core/CollectionNavigator.cs @@ -47,7 +47,7 @@ public CollectionNavigator () { } /// /// Event arguments for the event. /// - public class KeystrokeNavigatorEventArgs { + public class KeystrokeNavigatorEventArgs : EventArgs{ /// /// he current . /// @@ -66,7 +66,7 @@ public KeystrokeNavigatorEventArgs (string searchString) /// /// This event is invoked when changes. Useful for debugging. /// - public event Action SearchStringChanged; + public event EventHandler SearchStringChanged; private string _searchString = ""; /// @@ -87,7 +87,7 @@ private set { /// public virtual void OnSearchStringChanged (KeystrokeNavigatorEventArgs e) { - SearchStringChanged?.Invoke (e); + SearchStringChanged?.Invoke (this, e); } /// diff --git a/Terminal.Gui/Core/Window.cs b/Terminal.Gui/Core/Window.cs index 795d360ec2..c647a3afdb 100644 --- a/Terminal.Gui/Core/Window.cs +++ b/Terminal.Gui/Core/Window.cs @@ -70,7 +70,7 @@ public override Border Border { } } - void Border_BorderChanged (Border border) + void Border_BorderChanged (object sender, EventArgs e) { Rect frame; if (contentView != null && (contentView.Width is Dim || contentView.Height is Dim)) { diff --git a/Terminal.Gui/Views/FrameView.cs b/Terminal.Gui/Views/FrameView.cs index 8b1865108f..e6a8be99f1 100644 --- a/Terminal.Gui/Views/FrameView.cs +++ b/Terminal.Gui/Views/FrameView.cs @@ -97,7 +97,7 @@ public override Border Border { } } - void Border_BorderChanged (Border border) + void Border_BorderChanged (object sender, EventArgs e) { Rect frame; if (contentView != null && (contentView.Width is Dim || contentView.Height is Dim)) { diff --git a/Terminal.Gui/Views/PanelView.cs b/Terminal.Gui/Views/PanelView.cs index 2bcef27459..edd35ed20c 100644 --- a/Terminal.Gui/Views/PanelView.cs +++ b/Terminal.Gui/Views/PanelView.cs @@ -128,7 +128,7 @@ private void Child_Initialized (object sender, EventArgs e) Child.Initialized -= Child_Initialized; } - private void Border_BorderChanged (Border obj) + private void Border_BorderChanged (object sender, EventArgs e) { AdjustContainer (); } diff --git a/UICatalog/Scenarios/CollectionNavigatorTester.cs b/UICatalog/Scenarios/CollectionNavigatorTester.cs index 102db475b2..9846c7fa3c 100644 --- a/UICatalog/Scenarios/CollectionNavigatorTester.cs +++ b/UICatalog/Scenarios/CollectionNavigatorTester.cs @@ -142,8 +142,8 @@ private void CreateListView () _listView.SetSource (_items); - _listView.KeystrokeNavigator.SearchStringChanged += (state) => { - label.Text = $"ListView: {state.SearchString}"; + _listView.KeystrokeNavigator.SearchStringChanged += (s,e) => { + label.Text = $"ListView: {e.SearchString}"; }; } @@ -179,8 +179,8 @@ private void CreateTreeView () _treeView.ExpandAll (); _treeView.GoToFirst (); - _treeView.KeystrokeNavigator.SearchStringChanged += (state) => { - label.Text = $"TreeView: {state.SearchString}"; + _treeView.KeystrokeNavigator.SearchStringChanged += (s,e) => { + label.Text = $"TreeView: {e.SearchString}"; }; } From 83ed8ec958df1177114f7e8cb86c47b9faac8e84 Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 11 Mar 2023 09:14:33 +0000 Subject: [PATCH 02/46] AddTimeout now uses sender/event args --- .../Core/EventArgs/TimeoutEventArgs.cs | 31 +++++++++++++++++++ Terminal.Gui/Core/MainLoop.cs | 4 +-- UnitTests/Application/MainLoopTests.cs | 29 +++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 Terminal.Gui/Core/EventArgs/TimeoutEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/TimeoutEventArgs.cs b/Terminal.Gui/Core/EventArgs/TimeoutEventArgs.cs new file mode 100644 index 0000000000..cfb2b3ecd1 --- /dev/null +++ b/Terminal.Gui/Core/EventArgs/TimeoutEventArgs.cs @@ -0,0 +1,31 @@ +using System; +using Terminal.Gui; +using static Terminal.Gui.MainLoop; + +/// +/// for timeout events (e.g. ) +/// +public class TimeoutEventArgs : EventArgs { + /// + /// Gets the timeout callback handler + /// + public Timeout Timeout { get; } + + /// + /// Gets the in UTC time when the + /// will next execute after. + /// + public long Ticks { get; } + + + /// + /// Creates a new instance of the class. + /// + /// + /// + public TimeoutEventArgs (Timeout timeout, long ticks) + { + this.Timeout = timeout; + this.Ticks = ticks; + } +} \ No newline at end of file diff --git a/Terminal.Gui/Core/MainLoop.cs b/Terminal.Gui/Core/MainLoop.cs index 4ec3824f6f..b48fe2a77b 100644 --- a/Terminal.Gui/Core/MainLoop.cs +++ b/Terminal.Gui/Core/MainLoop.cs @@ -97,7 +97,7 @@ public ReadOnlyCollection> IdleHandlers { /// Invoked when a new timeout is added. To be used in the case /// when is . /// - public event Action TimeoutAdded; + public event EventHandler TimeoutAdded; /// /// Creates a new Mainloop. @@ -161,7 +161,7 @@ void AddTimeout (TimeSpan time, Timeout timeout) lock (timeoutsLockToken) { var k = (DateTime.UtcNow + time).Ticks; timeouts.Add (NudgeToUniqueKey (k), timeout); - TimeoutAdded?.Invoke (k); + TimeoutAdded?.Invoke (this, new TimeoutEventArgs(timeout, k)); } } diff --git a/UnitTests/Application/MainLoopTests.cs b/UnitTests/Application/MainLoopTests.cs index 46a0a9b329..b88ffbb418 100644 --- a/UnitTests/Application/MainLoopTests.cs +++ b/UnitTests/Application/MainLoopTests.cs @@ -264,6 +264,35 @@ public void AddTimer_Adds_Removes_NoFaults () Assert.False (ml.RemoveTimeout (token)); } + // Timeout Handler Tests + [Fact] + public void AddTimer_EventFired () + { + var ml = new MainLoop (new FakeMainLoop ()); + var ms = 100; + + var originTicks = DateTime.UtcNow.Ticks; + + var callbackCount = 0; + Func callback = (loop) => { + callbackCount++; + return true; + }; + + object sender = null; + TimeoutEventArgs args = null; + ml.TimeoutAdded += (s, e) => { + sender = s; + args = e; + }; + + var token = ml.AddTimeout (TimeSpan.FromMilliseconds (ms), callback); + + Assert.Same (ml,sender); + Assert.NotNull (args.Timeout); + Assert.True (args.Ticks - originTicks >= 100 * TimeSpan.TicksPerMillisecond); + + } [Fact] public void AddTimer_Run_Called () { From a949b790ec8187a4d851278d805d8199964f49fa Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 11 Mar 2023 09:57:54 +0000 Subject: [PATCH 03/46] Refactor HotKeyChanged event --- .../Core/EventArgs/HotKeyChangedEventArgs.cs | 29 ++++++++++++ .../Core/EventArgs/TimeoutEventArgs.cs | 45 ++++++++++--------- Terminal.Gui/Core/TextFormatter.cs | 4 +- Terminal.Gui/Core/View.cs | 6 +-- UnitTests/Views/ButtonTests.cs | 40 +++++++++++++++++ 5 files changed, 98 insertions(+), 26 deletions(-) create mode 100644 Terminal.Gui/Core/EventArgs/HotKeyChangedEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/HotKeyChangedEventArgs.cs b/Terminal.Gui/Core/EventArgs/HotKeyChangedEventArgs.cs new file mode 100644 index 0000000000..83b825b2a6 --- /dev/null +++ b/Terminal.Gui/Core/EventArgs/HotKeyChangedEventArgs.cs @@ -0,0 +1,29 @@ +using System; + +namespace Terminal.Gui { + + /// + /// Event args for when a is changed from + /// one value to a new value (e.g. in ) + /// + public class KeyChangedEventArgs : EventArgs { + + /// + /// Gets the old that was set before the event. + /// Use to check for empty. + /// + public Key OldKey { get; } + + /// + /// Gets the new that is being used. + /// Use to check for empty. + /// + public Key NewKey { get; } + + public KeyChangedEventArgs (Key oldKey, Key newKey) + { + this.OldKey = oldKey; + this.NewKey = newKey; + } + } +} diff --git a/Terminal.Gui/Core/EventArgs/TimeoutEventArgs.cs b/Terminal.Gui/Core/EventArgs/TimeoutEventArgs.cs index cfb2b3ecd1..6a8e04c3f8 100644 --- a/Terminal.Gui/Core/EventArgs/TimeoutEventArgs.cs +++ b/Terminal.Gui/Core/EventArgs/TimeoutEventArgs.cs @@ -2,30 +2,33 @@ using Terminal.Gui; using static Terminal.Gui.MainLoop; -/// -/// for timeout events (e.g. ) -/// -public class TimeoutEventArgs : EventArgs { +namespace Terminal.Gui { /// - /// Gets the timeout callback handler + /// for timeout events (e.g. ) /// - public Timeout Timeout { get; } + public class TimeoutEventArgs : EventArgs { + /// + /// Gets the timeout callback handler + /// + public Timeout Timeout { get; } - /// - /// Gets the in UTC time when the - /// will next execute after. - /// - public long Ticks { get; } + /// + /// Gets the in UTC time when the + /// will next execute after. + /// + public long Ticks { get; } - /// - /// Creates a new instance of the class. - /// - /// - /// - public TimeoutEventArgs (Timeout timeout, long ticks) - { - this.Timeout = timeout; - this.Ticks = ticks; + /// + /// Creates a new instance of the class. + /// + /// + /// + public TimeoutEventArgs (Timeout timeout, long ticks) + { + this.Timeout = timeout; + this.Ticks = ticks; + } } -} \ No newline at end of file +} + diff --git a/Terminal.Gui/Core/TextFormatter.cs b/Terminal.Gui/Core/TextFormatter.cs index 5d71066e44..c601970aad 100644 --- a/Terminal.Gui/Core/TextFormatter.cs +++ b/Terminal.Gui/Core/TextFormatter.cs @@ -126,7 +126,7 @@ public class TextFormatter { /// /// Event invoked when the is changed. /// - public event Action HotKeyChanged; + public event EventHandler HotKeyChanged; /// /// The text to be displayed. This text is never modified. @@ -288,7 +288,7 @@ internal set { if (hotKey != value) { var oldKey = hotKey; hotKey = value; - HotKeyChanged?.Invoke (oldKey); + HotKeyChanged?.Invoke (this, new KeyChangedEventArgs(oldKey,value)); } } } diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index 91755ff403..3a0c475ce9 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -169,7 +169,7 @@ internal enum Direction { /// /// Event invoked when the is changed. /// - public event Action HotKeyChanged; + public event EventHandler HotKeyChanged; Key hotKey = Key.Null; @@ -825,9 +825,9 @@ protected virtual void ProcessResizeView () SetNeedsDisplay (); } - void TextFormatter_HotKeyChanged (Key obj) + void TextFormatter_HotKeyChanged (object sender, KeyChangedEventArgs e) { - HotKeyChanged?.Invoke (obj); + HotKeyChanged?.Invoke (this,e); } /// diff --git a/UnitTests/Views/ButtonTests.cs b/UnitTests/Views/ButtonTests.cs index 01fd330f26..9585b4bba4 100644 --- a/UnitTests/Views/ButtonTests.cs +++ b/UnitTests/Views/ButtonTests.cs @@ -584,5 +584,45 @@ public void Pos_Center_Layout_AutoSize_False () TestHelpers.AssertDriverContentsWithFrameAre (expected, output); } + [Fact, AutoInitShutdown] + public void Button_HotKeyChanged_EventFires () + { + var btn = new Button ("Yar"); + + object sender = null; + KeyChangedEventArgs args = null; + + btn.HotKeyChanged += (s, e) =>{ + sender = s; + args = e; + + }; + + btn.HotKey = Key.r; + Assert.Same (btn, sender); + Assert.Equal (Key.Y, args.OldKey); + Assert.Equal (Key.r, args.NewKey); + + } + [Fact, AutoInitShutdown] + public void Button_HotKeyChanged_EventFires_WithNone () + { + var btn = new Button (); + + object sender = null; + KeyChangedEventArgs args = null; + + btn.HotKeyChanged += (s, e) => { + sender = s; + args = e; + + }; + + btn.HotKey = Key.r; + Assert.Same (btn, sender); + Assert.Equal (Key.Null, args.OldKey); + Assert.Equal (Key.r, args.NewKey); + + } } } From 58c267fd7c06e0af10f655d9326128c35a9bdd6a Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 11 Mar 2023 10:08:36 +0000 Subject: [PATCH 04/46] Switch to EventHandler for TopLevel methods - Loaded, - Ready - Unloaded - AllChildClosed --- Terminal.Gui/Core/Toplevel.cs | 16 ++-- Terminal.Gui/Windows/Wizard.cs | 2 +- UICatalog/Scenarios/Buttons.cs | 2 +- UICatalog/Scenarios/Dialogs.cs | 2 +- UICatalog/Scenarios/LabelsAsButtons.cs | 4 +- UICatalog/Scenarios/MessageBoxes.cs | 2 +- UICatalog/Scenarios/ProgressBarStyles.cs | 2 +- UICatalog/Scenarios/Scrolling.cs | 4 +- UICatalog/Scenarios/Threading.cs | 2 +- UICatalog/Scenarios/TileViewNesting.cs | 2 +- UICatalog/Scenarios/Wizards.cs | 2 +- UICatalog/UICatalog.cs | 4 +- UnitTests/Application/ApplicationTests.cs | 16 ++-- UnitTests/Core/ViewTests.cs | 14 ++-- UnitTests/TopLevels/DialogTests.cs | 2 +- UnitTests/TopLevels/MdiTests.cs | 92 +++++++++++------------ UnitTests/TopLevels/ToplevelTests.cs | 12 +-- UnitTests/Types/DimTests.cs | 10 +-- UnitTests/Types/PosTests.cs | 8 +- UnitTests/Views/ScrollBarViewTests.cs | 4 +- 20 files changed, 101 insertions(+), 101 deletions(-) diff --git a/Terminal.Gui/Core/Toplevel.cs b/Terminal.Gui/Core/Toplevel.cs index 08952f48b0..55efac8f66 100644 --- a/Terminal.Gui/Core/Toplevel.cs +++ b/Terminal.Gui/Core/Toplevel.cs @@ -48,7 +48,7 @@ public class Toplevel : View { /// A Loaded event handler is a good place to finalize initialization before calling /// . /// - public event Action Loaded; + public event EventHandler Loaded; /// /// Invoked when the Toplevel has started it's first iteration. @@ -57,13 +57,13 @@ public class Toplevel : View { /// A Ready event handler is a good place to finalize initialization after calling /// on this Toplevel. /// - public event Action Ready; + public event EventHandler Ready; /// /// Invoked when the Toplevel has been unloaded. /// A Unloaded event handler is a good place to dispose objects after calling . /// - public event Action Unloaded; + public event EventHandler Unloaded; /// /// Invoked when the Toplevel becomes the Toplevel. @@ -85,7 +85,7 @@ public class Toplevel : View { /// Invoked when the last child of the Toplevel is closed from /// by . /// - public event Action AllChildClosed; + public event EventHandler AllChildClosed; /// /// Invoked when the Toplevel's is being closed by @@ -141,7 +141,7 @@ internal virtual bool OnClosing (ToplevelClosingEventArgs ev) internal virtual void OnAllChildClosed () { - AllChildClosed?.Invoke (); + AllChildClosed?.Invoke (this, EventArgs.Empty); } internal virtual void OnChildClosed (Toplevel top) @@ -171,7 +171,7 @@ virtual public void OnLoaded () foreach (Toplevel tl in Subviews.Where (v => v is Toplevel)) { tl.OnLoaded (); } - Loaded?.Invoke (); + Loaded?.Invoke (this, EventArgs.Empty); } /// @@ -183,7 +183,7 @@ internal virtual void OnReady () foreach (Toplevel tl in Subviews.Where (v => v is Toplevel)) { tl.OnReady (); } - Ready?.Invoke (); + Ready?.Invoke (this, EventArgs.Empty); } /// @@ -194,7 +194,7 @@ internal virtual void OnUnloaded () foreach (Toplevel tl in Subviews.Where (v => v is Toplevel)) { tl.OnUnloaded (); } - Unloaded?.Invoke (); + Unloaded?.Invoke (this, EventArgs.Empty); } /// diff --git a/Terminal.Gui/Windows/Wizard.cs b/Terminal.Gui/Windows/Wizard.cs index 0ffc3bd6e4..34b11bcfe1 100644 --- a/Terminal.Gui/Windows/Wizard.cs +++ b/Terminal.Gui/Windows/Wizard.cs @@ -385,7 +385,7 @@ public Wizard (ustring title) : base (title) } - private void Wizard_Loaded () + private void Wizard_Loaded (object sender, EventArgs args) { CurrentStep = GetFirstStep (); // gets the first step if CurrentStep == null } diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs index 7269d53d36..9b085a66b0 100644 --- a/UICatalog/Scenarios/Buttons.cs +++ b/UICatalog/Scenarios/Buttons.cs @@ -272,7 +272,7 @@ ustring MoveHotkey (ustring txt) } }; - Application.Top.Ready += () => radioGroup.Refresh (); + Application.Top.Ready += (s,e) => radioGroup.Refresh (); } } } \ No newline at end of file diff --git a/UICatalog/Scenarios/Dialogs.cs b/UICatalog/Scenarios/Dialogs.cs index 47c3d35caa..d53977ad31 100644 --- a/UICatalog/Scenarios/Dialogs.cs +++ b/UICatalog/Scenarios/Dialogs.cs @@ -112,7 +112,7 @@ public override void Setup () }; frame.Add (styleRadioGroup); - void Top_Loaded () + void Top_Loaded (object sender, EventArgs args) { frame.Height = Dim.Height (widthEdit) + Dim.Height (heightEdit) + Dim.Height (titleEdit) + Dim.Height (numButtonsEdit) + Dim.Height (styleRadioGroup) + Dim.Height (glyphsNotWords) + 2; diff --git a/UICatalog/Scenarios/LabelsAsButtons.cs b/UICatalog/Scenarios/LabelsAsButtons.cs index 29c2b98afc..739a01f4c9 100644 --- a/UICatalog/Scenarios/LabelsAsButtons.cs +++ b/UICatalog/Scenarios/LabelsAsButtons.cs @@ -73,7 +73,7 @@ static void DoMessage (Label Label, ustring txt) Win.Add (colorLabel); x += colorLabel.Text.Length + 2; } - Application.Top.Ready += () => Application.Top.Redraw (Application.Top.Bounds); + Application.Top.Ready += (s,e) => Application.Top.Redraw (Application.Top.Bounds); Label Label; Win.Add (Label = new Label ("A super long _Label that will probably expose a bug in clipping or wrapping of text. Will it?") { @@ -306,7 +306,7 @@ ustring MoveHotkey (ustring txt) } }; - Application.Top.Ready += () => radioGroup.Refresh (); + Application.Top.Ready += (s,e) => radioGroup.Refresh (); } } } \ No newline at end of file diff --git a/UICatalog/Scenarios/MessageBoxes.cs b/UICatalog/Scenarios/MessageBoxes.cs index d7826d6111..f28f0b01a5 100644 --- a/UICatalog/Scenarios/MessageBoxes.cs +++ b/UICatalog/Scenarios/MessageBoxes.cs @@ -152,7 +152,7 @@ public override void Setup () }; frame.Add (ckbEffect3D); - void Top_Loaded () + void Top_Loaded (object sender, EventArgs args) { frame.Height = Dim.Height (widthEdit) + Dim.Height (heightEdit) + Dim.Height (titleEdit) + Dim.Height (messageEdit) + Dim.Height (numButtonsEdit) + Dim.Height (defaultButtonEdit) + Dim.Height (styleRadioGroup) + 2 + Dim.Height (ckbEffect3D); diff --git a/UICatalog/Scenarios/ProgressBarStyles.cs b/UICatalog/Scenarios/ProgressBarStyles.cs index 4d87eadb4f..8d381ebdc9 100644 --- a/UICatalog/Scenarios/ProgressBarStyles.cs +++ b/UICatalog/Scenarios/ProgressBarStyles.cs @@ -133,7 +133,7 @@ public override void Setup () Application.Top.Unloaded += Top_Unloaded; - void Top_Unloaded () + void Top_Unloaded (object sender, EventArgs args) { if (_fractionTimer != null) { _fractionTimer.Dispose (); diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index d79e4d44c4..888cfb9617 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -151,7 +151,7 @@ public override void Setup () }; scrollView.Add (verticalRuler); - void Top_Loaded () + void Top_Loaded (object sender, EventArgs args) { horizontalRuler.Text = rule.Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)] + "\n" + "| ".Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)]; @@ -310,7 +310,7 @@ bool timer (MainLoop caller) } Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (300), timer); - void Top_Unloaded () + void Top_Unloaded (object sender, EventArgs args) { pulsing = false; Application.Top.Unloaded -= Top_Unloaded; diff --git a/UICatalog/Scenarios/Threading.cs b/UICatalog/Scenarios/Threading.cs index 6bd159497e..19df3ab95d 100644 --- a/UICatalog/Scenarios/Threading.cs +++ b/UICatalog/Scenarios/Threading.cs @@ -93,7 +93,7 @@ public override void Setup () Win.Add (_itemsList, _btnActionCancel, _logJob, text, _btnAction, _btnLambda, _btnHandler, _btnSync, _btnMethod, _btnClearData, _btnQuit); - void Top_Loaded () + void Top_Loaded (object sender, EventArgs args) { _btnActionCancel.SetFocus (); Application.Top.Loaded -= Top_Loaded; diff --git a/UICatalog/Scenarios/TileViewNesting.cs b/UICatalog/Scenarios/TileViewNesting.cs index c14a69c5d8..b977b86d5a 100644 --- a/UICatalog/Scenarios/TileViewNesting.cs +++ b/UICatalog/Scenarios/TileViewNesting.cs @@ -83,7 +83,7 @@ public override void Setup () Application.Top.Add (menu); - Win.Loaded += () => loaded = true; + Win.Loaded += (s,e) => loaded = true; } private void SetupTileView () diff --git a/UICatalog/Scenarios/Wizards.cs b/UICatalog/Scenarios/Wizards.cs index 573c475b73..1a1be2f075 100644 --- a/UICatalog/Scenarios/Wizards.cs +++ b/UICatalog/Scenarios/Wizards.cs @@ -70,7 +70,7 @@ public override void Setup () }; frame.Add (titleEdit); - void Top_Loaded () + void Top_Loaded (object sender, EventArgs args) { frame.Height = Dim.Height (widthEdit) + Dim.Height (heightEdit) + Dim.Height (titleEdit) + 2; Application.Top.Loaded -= Top_Loaded; diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 49faf0ddd4..64d5dd6a2e 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -352,7 +352,7 @@ public UICatalogTopLevel () ConfigurationManager.Applied += ConfigAppliedHandler; } - void LoadedHandler () + void LoadedHandler (object sender, EventArgs args) { ConfigChanged (); @@ -381,7 +381,7 @@ void LoadedHandler () Loaded -= LoadedHandler; } - private void UnloadedHandler () + private void UnloadedHandler (object sender, EventArgs args) { ConfigurationManager.Applied -= ConfigAppliedHandler; Unloaded -= UnloadedHandler; diff --git a/UnitTests/Application/ApplicationTests.cs b/UnitTests/Application/ApplicationTests.cs index 637174d172..3e6590fe02 100644 --- a/UnitTests/Application/ApplicationTests.cs +++ b/UnitTests/Application/ApplicationTests.cs @@ -420,9 +420,9 @@ public void Run_Loaded_Ready_Unlodaded_Events () Init (); var top = Application.Top; var count = 0; - top.Loaded += () => count++; - top.Ready += () => count++; - top.Unloaded += () => count++; + top.Loaded += (s,e) => count++; + top.Ready += (s,e) => count++; + top.Unloaded += (s,e) => count++; Application.Iteration = () => Application.RequestStop (); Application.Run (); Application.Shutdown (); @@ -473,23 +473,23 @@ public void SetCurrentAsTop_Run_A_Not_Modal_Toplevel_Make_It_The_Current_Applica // t1, t2, t3, d, t4 var iterations = 5; - t1.Ready += () => { + t1.Ready += (s,e) => { Assert.Equal (t1, Application.Top); Application.Run (t2); }; - t2.Ready += () => { + t2.Ready += (s,e) => { Assert.Equal (t2, Application.Top); Application.Run (t3); }; - t3.Ready += () => { + t3.Ready += (s,e) => { Assert.Equal (t3, Application.Top); Application.Run (d); }; - d.Ready += () => { + d.Ready += (s, e) => { Assert.Equal (t3, Application.Top); Application.Run (t4); }; - t4.Ready += () => { + t4.Ready += (s, e) => { Assert.Equal (t4, Application.Top); t4.RequestStop (); d.RequestStop (); diff --git a/UnitTests/Core/ViewTests.cs b/UnitTests/Core/ViewTests.cs index db4d54299b..a76af4ebc6 100644 --- a/UnitTests/Core/ViewTests.cs +++ b/UnitTests/Core/ViewTests.cs @@ -899,7 +899,7 @@ public void CanFocus_Faced_With_Container_After_Run () w.Add (f); t.Add (w); - t.Ready += () => { + t.Ready += (s, e) => { Assert.True (t.CanFocus); Assert.True (w.CanFocus); Assert.True (f.CanFocus); @@ -943,7 +943,7 @@ public void CanFocus_Container_ToFalse_Turns_All_Subviews_ToFalse_Too () w.Add (f); t.Add (w); - t.Ready += () => { + t.Ready += (s, e) => { Assert.True (t.CanFocus); Assert.True (w.CanFocus); Assert.True (f.CanFocus); @@ -978,7 +978,7 @@ public void CanFocus_Container_Toggling_All_Subviews_To_Old_Value_When_Is_True ( w.Add (f); t.Add (w); - t.Ready += () => { + t.Ready += (s, e) => { Assert.True (t.CanFocus); Assert.True (w.CanFocus); Assert.True (f.CanFocus); @@ -1012,7 +1012,7 @@ public void Navigation_With_Null_Focused_View () Application.Init (new FakeDriver ()); - Application.Top.Ready += () => { + Application.Top.Ready += (s, e) => { Assert.Null (Application.Top.Focused); }; @@ -1072,10 +1072,10 @@ public void Multi_Thread_Toplevels () t.Ready += FirstDialogToplevel; - void FirstDialogToplevel () + void FirstDialogToplevel (object sender, EventArgs args) { var od = new OpenDialog (); - od.Ready += SecoundDialogToplevel; + od.Ready += SecondDialogToplevel; Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), (_) => { count1++; @@ -1096,7 +1096,7 @@ void FirstDialogToplevel () Application.Run (od); } - void SecoundDialogToplevel () + void SecondDialogToplevel (object sender, EventArgs args) { var d = new Dialog (); diff --git a/UnitTests/TopLevels/DialogTests.cs b/UnitTests/TopLevels/DialogTests.cs index 3dea9ccb13..fc59769044 100644 --- a/UnitTests/TopLevels/DialogTests.cs +++ b/UnitTests/TopLevels/DialogTests.cs @@ -582,7 +582,7 @@ public void FileDialog_FileSystemWatcher () { for (int i = 0; i < 8; i++) { var fd = new FileDialog (); - fd.Ready += () => Application.RequestStop (); + fd.Ready += (s,e) => Application.RequestStop (); Application.Run (fd); } } diff --git a/UnitTests/TopLevels/MdiTests.cs b/UnitTests/TopLevels/MdiTests.cs index ef41e3c94f..59b94dc408 100644 --- a/UnitTests/TopLevels/MdiTests.cs +++ b/UnitTests/TopLevels/MdiTests.cs @@ -67,24 +67,24 @@ public void Application_RequestStop_With_Params_On_A_Not_MdiContainer_Always_Use // top1, top2, top3, d1 = 4 var iterations = 4; - top1.Ready += () => { + top1.Ready += (s, e) => { Assert.Null (Application.MdiChildes); Application.Run (top2); }; - top2.Ready += () => { + top2.Ready += (s, e) => { Assert.Null (Application.MdiChildes); Application.Run (top3); }; - top3.Ready += () => { + top3.Ready += (s, e) => { Assert.Null (Application.MdiChildes); Application.Run (top4); }; - top4.Ready += () => { + top4.Ready += (s, e) => { Assert.Null (Application.MdiChildes); Application.Run (d); }; - d.Ready += () => { + d.Ready += (s, e) => { Assert.Null (Application.MdiChildes); // This will close the d because on a not MdiContainer the Application.Current it always used. Application.RequestStop (top1); @@ -130,25 +130,25 @@ public void MdiContainer_With_Toplevel_RequestStop_Balanced () // d1 = 1 var iterations = 4; - mdi.Ready += () => { + mdi.Ready += (s, e) => { Assert.Empty (Application.MdiChildes); Application.Run (c1); }; - c1.Ready += () => { + c1.Ready += (s, e) => { Assert.Single (Application.MdiChildes); Application.Run (c2); }; - c2.Ready += () => { + c2.Ready += (s, e) => { Assert.Equal (2, Application.MdiChildes.Count); Application.Run (c3); }; - c3.Ready += () => { + c3.Ready += (s, e) => { Assert.Equal (3, Application.MdiChildes.Count); Application.Run (d); }; // More easy because the Mdi Container handles all at once - d.Ready += () => { + d.Ready += (s, e) => { Assert.Equal (3, Application.MdiChildes.Count); // This will not close the MdiContainer because d is a modal toplevel and will be closed. mdi.RequestStop (); @@ -190,25 +190,25 @@ public void MdiContainer_With_Application_RequestStop_MdiTop_With_Params () // d1 = 1 var iterations = 4; - mdi.Ready += () => { + mdi.Ready += (s, e) => { Assert.Empty (Application.MdiChildes); Application.Run (c1); }; - c1.Ready += () => { + c1.Ready += (s, e) => { Assert.Single (Application.MdiChildes); Application.Run (c2); }; - c2.Ready += () => { + c2.Ready += (s, e) => { Assert.Equal (2, Application.MdiChildes.Count); Application.Run (c3); }; - c3.Ready += () => { + c3.Ready += (s, e) => { Assert.Equal (3, Application.MdiChildes.Count); Application.Run (d); }; // Also easy because the Mdi Container handles all at once - d.Ready += () => { + d.Ready += (s, e) => { Assert.Equal (3, Application.MdiChildes.Count); // This will not close the MdiContainer because d is a modal toplevel Application.RequestStop (mdi); @@ -248,25 +248,25 @@ public void MdiContainer_With_Application_RequestStop_MdiTop_Without_Params () // d1 = 1 var iterations = 4; - mdi.Ready += () => { + mdi.Ready += (s, e) => { Assert.Empty (Application.MdiChildes); Application.Run (c1); }; - c1.Ready += () => { + c1.Ready += (s, e) => { Assert.Single (Application.MdiChildes); Application.Run (c2); }; - c2.Ready += () => { + c2.Ready += (s, e) => { Assert.Equal (2, Application.MdiChildes.Count); Application.Run (c3); }; - c3.Ready += () => { + c3.Ready += (s, e) => { Assert.Equal (3, Application.MdiChildes.Count); Application.Run (d); }; //More harder because it's sequential. - d.Ready += () => { + d.Ready += (s, e) => { Assert.Equal (3, Application.MdiChildes.Count); // Close the Dialog Application.RequestStop (); @@ -331,28 +331,28 @@ public void Modal_Toplevel_Can_Open_Another_Modal_Toplevel_But_RequestStop_To_Th // d1, d2 = 2 var iterations = 5; - mdi.Ready += () => { + mdi.Ready += (s, e) => { Assert.Empty (Application.MdiChildes); Application.Run (c1); }; - c1.Ready += () => { + c1.Ready += (s, e) => { Assert.Single (Application.MdiChildes); Application.Run (c2); }; - c2.Ready += () => { + c2.Ready += (s, e) => { Assert.Equal (2, Application.MdiChildes.Count); Application.Run (c3); }; - c3.Ready += () => { + c3.Ready += (s, e) => { Assert.Equal (3, Application.MdiChildes.Count); Application.Run (d1); }; - d1.Ready += () => { + d1.Ready += (s, e) => { Assert.Equal (3, Application.MdiChildes.Count); Application.Run (d2); }; - d2.Ready += () => { + d2.Ready += (s, e) => { Assert.Equal (3, Application.MdiChildes.Count); Assert.True (Application.Current == d2); Assert.True (Application.Current.Running); @@ -406,28 +406,28 @@ public void Modal_Toplevel_Can_Open_Another_Not_Modal_Toplevel_But_RequestStop_T // d1 = 1 var iterations = 5; - mdi.Ready += () => { + mdi.Ready += (s, e) => { Assert.Empty (Application.MdiChildes); Application.Run (c1); }; - c1.Ready += () => { + c1.Ready += (s, e) => { Assert.Single (Application.MdiChildes); Application.Run (c2); }; - c2.Ready += () => { + c2.Ready += (s, e) => { Assert.Equal (2, Application.MdiChildes.Count); Application.Run (c3); }; - c3.Ready += () => { + c3.Ready += (s, e) => { Assert.Equal (3, Application.MdiChildes.Count); Application.Run (d1); }; - d1.Ready += () => { + d1.Ready += (s, e) => { Assert.Equal (3, Application.MdiChildes.Count); Application.Run (c4); }; - c4.Ready += () => { + c4.Ready += (s, e) => { Assert.Equal (4, Application.MdiChildes.Count); // Trying to close the Dialog1 d1.RequestStop (); @@ -471,19 +471,19 @@ public void MoveCurrent_Returns_False_If_The_Current_And_Top_Parameter_Are_Both_ // MdiChild = c1, c2, c3 var iterations = 3; - mdi.Ready += () => { + mdi.Ready += (s, e) => { Assert.Empty (Application.MdiChildes); Application.Run (c1); }; - c1.Ready += () => { + c1.Ready += (s, e) => { Assert.Single (Application.MdiChildes); Application.Run (c2); }; - c2.Ready += () => { + c2.Ready += (s, e) => { Assert.Equal (2, Application.MdiChildes.Count); Application.Run (c3); }; - c3.Ready += () => { + c3.Ready += (s, e) => { Assert.Equal (3, Application.MdiChildes.Count); c3.RequestStop (); c1.RequestStop (); @@ -532,7 +532,7 @@ public void MdiContainer_Throws_If_More_Than_One () var mdi = new Mdi (); var mdi2 = new Mdi (); - mdi.Ready += () => { + mdi.Ready += (s, e) => { Assert.Throws (() => Application.Run (mdi2)); mdi.RequestStop (); }; @@ -553,19 +553,19 @@ public void MdiContainer_Open_And_Close_Modal_And_Open_Not_Modal_Toplevels_Rando var allStageClosed = false; var mdiRequestStop = false; - mdi.Ready += () => { + mdi.Ready += (s, e) => { Assert.Empty (Application.MdiChildes); Application.Run (logger); }; - logger.Ready += () => Assert.Single (Application.MdiChildes); + logger.Ready += (s, e) => Assert.Single (Application.MdiChildes); Application.Iteration += () => { if (stageCompleted && running) { stageCompleted = false; var stage = new Window () { Modal = true }; - stage.Ready += () => { + stage.Ready += (s, e) => { Assert.Equal (iterations, Application.MdiChildes.Count); stage.RequestStop (); }; @@ -578,7 +578,7 @@ public void MdiContainer_Open_And_Close_Modal_And_Open_Not_Modal_Toplevels_Rando var rpt = new Window (); - rpt.Ready += () => { + rpt.Ready += (s, e) => { iterations++; Assert.Equal (iterations, Application.MdiChildes.Count); }; @@ -618,26 +618,26 @@ public void AllChildClosed_Event_Test () // MdiChild = c1, c2, c3 var iterations = 3; - mdi.Ready += () => { + mdi.Ready += (s, e) => { Assert.Empty (Application.MdiChildes); Application.Run (c1); }; - c1.Ready += () => { + c1.Ready += (s, e) => { Assert.Single (Application.MdiChildes); Application.Run (c2); }; - c2.Ready += () => { + c2.Ready += (s, e) => { Assert.Equal (2, Application.MdiChildes.Count); Application.Run (c3); }; - c3.Ready += () => { + c3.Ready += (s, e) => { Assert.Equal (3, Application.MdiChildes.Count); c3.RequestStop (); c2.RequestStop (); c1.RequestStop (); }; // Now this will close the MdiContainer when all MdiChildes was closed - mdi.AllChildClosed += () => { + mdi.AllChildClosed += (s, e) => { mdi.RequestStop (); }; Application.Iteration += () => { diff --git a/UnitTests/TopLevels/ToplevelTests.cs b/UnitTests/TopLevels/ToplevelTests.cs index a6f803af07..ac08ba23c7 100644 --- a/UnitTests/TopLevels/ToplevelTests.cs +++ b/UnitTests/TopLevels/ToplevelTests.cs @@ -166,7 +166,7 @@ public void Internal_Tests () top.Closing += (e) => eventInvoked = "Closing"; top.OnClosing (new ToplevelClosingEventArgs (top)); Assert.Equal ("Closing", eventInvoked); - top.AllChildClosed += () => eventInvoked = "AllChildClosed"; + top.AllChildClosed += (s, e) => eventInvoked = "AllChildClosed"; top.OnAllChildClosed (); Assert.Equal ("AllChildClosed", eventInvoked); top.ChildClosed += (e) => eventInvoked = "ChildClosed"; @@ -178,13 +178,13 @@ public void Internal_Tests () top.Activate += (e) => eventInvoked = "Activate"; top.OnActivate (top); Assert.Equal ("Activate", eventInvoked); - top.Loaded += () => eventInvoked = "Loaded"; + top.Loaded += (s, e) => eventInvoked = "Loaded"; top.OnLoaded (); Assert.Equal ("Loaded", eventInvoked); - top.Ready += () => eventInvoked = "Ready"; + top.Ready += (s, e) => eventInvoked = "Ready"; top.OnReady (); Assert.Equal ("Ready", eventInvoked); - top.Unloaded += () => eventInvoked = "Unloaded"; + top.Unloaded += (s, e) => eventInvoked = "Unloaded"; top.OnUnloaded (); Assert.Equal ("Unloaded", eventInvoked); @@ -355,7 +355,7 @@ public void KeyBindings_Command () var top = Application.Top; top.Add (win1, win2); - top.Loaded += () => isRunning = true; + top.Loaded += (s, e) => isRunning = true; top.Closing += (_) => isRunning = false; Application.Begin (top); top.Running = true; @@ -668,7 +668,7 @@ public void FileDialog_FileSystemWatcher () { for (int i = 0; i < 8; i++) { var fd = new FileDialog (); - fd.Ready += () => Application.RequestStop (); + fd.Ready += (s, e) => Application.RequestStop (); Application.Run (fd); } } diff --git a/UnitTests/Types/DimTests.cs b/UnitTests/Types/DimTests.cs index e04a4b8188..ebcfefe679 100644 --- a/UnitTests/Types/DimTests.cs +++ b/UnitTests/Types/DimTests.cs @@ -268,7 +268,7 @@ public void ForceValidatePosDim_True_Dim_Validation_Throws_If_NewValue_Is_DimAbs w.Add (v); t.Add (w); - t.Ready += () => { + t.Ready += (s, e) => { Assert.Equal (2, w.Width = 2); Assert.Equal (2, w.Height = 2); Assert.Throws (() => v.Width = 2); @@ -298,7 +298,7 @@ public void Dim_Validation_Do_Not_Throws_If_NewValue_Is_DimAbsolute_And_OldValue var w = new Window (new Rect (1, 2, 4, 5), "w"); t.Add (w); - t.Ready += () => { + t.Ready += (s, e) => { Assert.Equal (3, w.Width = 3); Assert.Equal (4, w.Height = 4); }; @@ -328,7 +328,7 @@ public void Dim_Validation_Do_Not_Throws_If_NewValue_Is_DimAbsolute_And_OldValue w.Add (v); t.Add (w); - t.Ready += () => { + t.Ready += (s, e) => { v.LayoutStyle = LayoutStyle.Absolute; Assert.Equal (2, v.Width = 2); Assert.Equal (2, v.Height = 2); @@ -419,7 +419,7 @@ public void Only_DimAbsolute_And_DimFactor_As_A_Different_Procedure_For_Assignin w.Add (f1, f2, v1, v2, v3, v4, v5, v6); t.Add (w); - t.Ready += () => { + t.Ready += (s, e) => { Assert.Equal ("Absolute(100)", w.Width.ToString ()); Assert.Equal ("Absolute(100)", w.Height.ToString ()); Assert.Equal (100, w.Frame.Width); @@ -565,7 +565,7 @@ public void DimCombine_Do_Not_Throws () f.Width = Dim.Width (t) - Dim.Width (v2); f.Height = Dim.Height (t) - Dim.Height (v2); - t.Ready += () => { + t.Ready += (s, e) => { Assert.Equal (80, t.Frame.Width); Assert.Equal (25, t.Frame.Height); Assert.Equal (78, w.Frame.Width); diff --git a/UnitTests/Types/PosTests.cs b/UnitTests/Types/PosTests.cs index 44b43dd7d4..bec2a82611 100644 --- a/UnitTests/Types/PosTests.cs +++ b/UnitTests/Types/PosTests.cs @@ -716,7 +716,7 @@ public void ForceValidatePosDim_True_Pos_Validation_Throws_If_NewValue_Is_PosAbs w.Add (v); t.Add (w); - t.Ready += () => { + t.Ready += (s, e) => { Assert.Equal (2, w.X = 2); Assert.Equal (2, w.Y = 2); Assert.Throws (() => v.X = 2); @@ -739,7 +739,7 @@ public void Pos_Validation_Do_Not_Throws_If_NewValue_Is_PosAbsolute_And_OldValue var w = new Window (new Rect (1, 2, 4, 5), "w"); t.Add (w); - t.Ready += () => { + t.Ready += (s, e) => { Assert.Equal (2, w.X = 2); Assert.Equal (2, w.Y = 2); }; @@ -770,7 +770,7 @@ public void Pos_Validation_Do_Not_Throws_If_NewValue_Is_PosAbsolute_And_OldValue w.Add (v); t.Add (w); - t.Ready += () => { + t.Ready += (s, e) => { v.LayoutStyle = LayoutStyle.Absolute; Assert.Equal (2, v.X = 2); Assert.Equal (2, v.Y = 2); @@ -812,7 +812,7 @@ public void PosCombine_Do_Not_Throws () f.X = Pos.X (t) + Pos.X (v2) - Pos.X (v1); f.Y = Pos.Y (t) + Pos.Y (v2) - Pos.Y (v1); - t.Ready += () => { + t.Ready += (s, e) => { Assert.Equal (0, t.Frame.X); Assert.Equal (0, t.Frame.Y); Assert.Equal (2, w.Frame.X); diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 78b1c568b3..5f3a3be72b 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -495,7 +495,7 @@ public void Constructor_ShowBothScrollIndicator_False_And_IsVertical_True_Refres newScrollBarView.Refresh (); }; - top.Ready += () => { + top.Ready += (s, e) => { newScrollBarView.Position = 45; Assert.Equal (newScrollBarView.Position, newScrollBarView.Size - listView.TopItem + (listView.TopItem - listView.Bounds.Height)); Assert.Equal (newScrollBarView.Position, listView.TopItem); @@ -570,7 +570,7 @@ public void Constructor_ShowBothScrollIndicator_False_And_IsVertical_False_Refre newScrollBarView.Refresh (); }; - top.Ready += () => { + top.Ready += (s, e) => { newScrollBarView.Position = 100; Assert.Equal (newScrollBarView.Position, newScrollBarView.Size - listView.LeftItem + (listView.LeftItem - listView.Bounds.Width)); Assert.Equal (newScrollBarView.Position, listView.LeftItem); From bdcbd558560ceac7cfd26d8a133813de89fb93b9 Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 11 Mar 2023 10:18:39 +0000 Subject: [PATCH 05/46] Switch to EventHandler for - Activate - Deactivate - ChildClosed - Closed - ChildLoaded - ChildUnloaded --- .../Core/EventArgs/ToplevelEventArgs.cs | 21 ++++++++++++++++ Terminal.Gui/Core/Toplevel.cs | 24 +++++++++---------- .../Scenarios/BackgroundWorkerCollection.cs | 10 ++++---- UICatalog/Scenarios/ContextMenus.cs | 2 +- UICatalog/Scenarios/Dialogs.cs | 2 +- UICatalog/Scenarios/Editor.cs | 2 +- UnitTests/Application/ApplicationTests.cs | 2 +- UnitTests/TopLevels/MdiTests.cs | 16 ++++++------- UnitTests/TopLevels/ToplevelTests.cs | 12 +++++----- UnitTests/TopLevels/WizardTests.cs | 6 ++--- 10 files changed, 59 insertions(+), 38 deletions(-) create mode 100644 Terminal.Gui/Core/EventArgs/ToplevelEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/ToplevelEventArgs.cs b/Terminal.Gui/Core/EventArgs/ToplevelEventArgs.cs new file mode 100644 index 0000000000..e1cc2198e5 --- /dev/null +++ b/Terminal.Gui/Core/EventArgs/ToplevelEventArgs.cs @@ -0,0 +1,21 @@ +using System; + +namespace Terminal.Gui { + public class ToplevelEventArgs : EventArgs{ + + public ToplevelEventArgs (Toplevel toplevel) + { + Toplevel = toplevel; + } + + /// + /// Gets the that the event is about. + /// + /// This is usually but may not always be the same as the sender + /// in . For example if the reported event + /// is about a different or the event is + /// raised by a separate class. + /// + public Toplevel Toplevel { get; } + } +} diff --git a/Terminal.Gui/Core/Toplevel.cs b/Terminal.Gui/Core/Toplevel.cs index 55efac8f66..f59991befc 100644 --- a/Terminal.Gui/Core/Toplevel.cs +++ b/Terminal.Gui/Core/Toplevel.cs @@ -68,18 +68,18 @@ public class Toplevel : View { /// /// Invoked when the Toplevel becomes the Toplevel. /// - public event Action Activate; + public event EventHandler Activate; /// /// Invoked when the Toplevel ceases to be the Toplevel. /// - public event Action Deactivate; + public event EventHandler Deactivate; /// /// Invoked when a child of the Toplevel is closed by /// . /// - public event Action ChildClosed; + public event EventHandler ChildClosed; /// /// Invoked when the last child of the Toplevel is closed from @@ -96,17 +96,17 @@ public class Toplevel : View { /// /// Invoked when the Toplevel's is closed by . /// - public event Action Closed; + public event EventHandler Closed; /// /// Invoked when a child Toplevel's has been loaded. /// - public event Action ChildLoaded; + public event EventHandler ChildLoaded; /// /// Invoked when a cjhild Toplevel's has been unloaded. /// - public event Action ChildUnloaded; + public event EventHandler ChildUnloaded; /// /// Invoked when the terminal has been resized. The new of the terminal is provided. @@ -120,17 +120,17 @@ internal virtual void OnResized (Size size) internal virtual void OnChildUnloaded (Toplevel top) { - ChildUnloaded?.Invoke (top); + ChildUnloaded?.Invoke (this, new ToplevelEventArgs(top)); } internal virtual void OnChildLoaded (Toplevel top) { - ChildLoaded?.Invoke (top); + ChildLoaded?.Invoke (this, new ToplevelEventArgs (top)); } internal virtual void OnClosed (Toplevel top) { - Closed?.Invoke (top); + Closed?.Invoke (this, new ToplevelEventArgs (top)); } internal virtual bool OnClosing (ToplevelClosingEventArgs ev) @@ -149,17 +149,17 @@ internal virtual void OnChildClosed (Toplevel top) if (IsMdiContainer) { SetChildNeedsDisplay (); } - ChildClosed?.Invoke (top); + ChildClosed?.Invoke (this, new ToplevelEventArgs (top)); } internal virtual void OnDeactivate (Toplevel activated) { - Deactivate?.Invoke (activated); + Deactivate?.Invoke (this, new ToplevelEventArgs (activated)); } internal virtual void OnActivate (Toplevel deactivated) { - Activate?.Invoke (deactivated); + Activate?.Invoke (this, new ToplevelEventArgs(deactivated)); } /// diff --git a/UICatalog/Scenarios/BackgroundWorkerCollection.cs b/UICatalog/Scenarios/BackgroundWorkerCollection.cs index de83d57596..201bb3b63b 100644 --- a/UICatalog/Scenarios/BackgroundWorkerCollection.cs +++ b/UICatalog/Scenarios/BackgroundWorkerCollection.cs @@ -63,7 +63,7 @@ public MdiMain () }; } - private void MdiMain_Closed (Toplevel obj) + private void MdiMain_Closed (object sender, ToplevelEventArgs e) { workerApp.Dispose (); Dispose (); @@ -82,14 +82,14 @@ private void Menu_MenuOpening (MenuOpeningEventArgs menu) } } - private void MdiMain_Deactivate (Toplevel top) + private void MdiMain_Deactivate (object sender, ToplevelEventArgs top) { - workerApp.WriteLog ($"{top.Data} deactivate."); + workerApp.WriteLog ($"{top.Toplevel.Data} deactivate."); } - private void MdiMain_Activate (Toplevel top) + private void MdiMain_Activate (object sender, ToplevelEventArgs top) { - workerApp.WriteLog ($"{top.Data} activate."); + workerApp.WriteLog ($"{top.Toplevel.Data} activate."); } private MenuBarItem View () diff --git a/UICatalog/Scenarios/ContextMenus.cs b/UICatalog/Scenarios/ContextMenus.cs index e45c3e50d9..03acd5b262 100644 --- a/UICatalog/Scenarios/ContextMenus.cs +++ b/UICatalog/Scenarios/ContextMenus.cs @@ -81,7 +81,7 @@ void Application_RootMouseEvent (MouseEvent me) Win.WantMousePositionReports = true; - Application.Top.Closed += (_) => { + Application.Top.Closed += (s,e) => { Thread.CurrentThread.CurrentUICulture = new CultureInfo ("en-US"); Application.RootMouseEvent -= Application_RootMouseEvent; }; diff --git a/UICatalog/Scenarios/Dialogs.cs b/UICatalog/Scenarios/Dialogs.cs index d53977ad31..50d0c3f5ea 100644 --- a/UICatalog/Scenarios/Dialogs.cs +++ b/UICatalog/Scenarios/Dialogs.cs @@ -226,7 +226,7 @@ void Top_Loaded (object sender, EventArgs args) } dialog.LayoutSubviews (); }; - dialog.Closed += (args) => { + dialog.Closed += (s,e) => { buttonPressedLabel.Text = $"{clicked}"; }; dialog.Add (addChar); diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index ec9774776f..f451bd37b7 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -196,7 +196,7 @@ public override void Init (ColorScheme colorScheme) } }; - Application.Top.Closed += (_) => Thread.CurrentThread.CurrentUICulture = new CultureInfo ("en-US"); + Application.Top.Closed += (s,e) => Thread.CurrentThread.CurrentUICulture = new CultureInfo ("en-US"); } private void DisposeWinDialog () diff --git a/UnitTests/Application/ApplicationTests.cs b/UnitTests/Application/ApplicationTests.cs index 3e6590fe02..222057f728 100644 --- a/UnitTests/Application/ApplicationTests.cs +++ b/UnitTests/Application/ApplicationTests.cs @@ -497,7 +497,7 @@ public void SetCurrentAsTop_Run_A_Not_Modal_Toplevel_Make_It_The_Current_Applica t2.RequestStop (); }; // Now this will close the MdiContainer when all MdiChildes was closed - t2.Closed += (_) => { + t2.Closed += (s,_) => { t1.RequestStop (); }; Application.Iteration += () => { diff --git a/UnitTests/TopLevels/MdiTests.cs b/UnitTests/TopLevels/MdiTests.cs index 59b94dc408..72af89035e 100644 --- a/UnitTests/TopLevels/MdiTests.cs +++ b/UnitTests/TopLevels/MdiTests.cs @@ -91,7 +91,7 @@ public void Application_RequestStop_With_Params_On_A_Not_MdiContainer_Always_Use Assert.True (Application.Current == d); }; - d.Closed += (e) => Application.RequestStop (top1); + d.Closed += (s,e) => Application.RequestStop (top1); Application.Iteration += () => { Assert.Null (Application.MdiChildes); @@ -155,7 +155,7 @@ public void MdiContainer_With_Toplevel_RequestStop_Balanced () }; // Now this will close the MdiContainer propagating through the MdiChildes. - d.Closed += (e) => { + d.Closed += (s,e) => { mdi.RequestStop (); }; @@ -215,7 +215,7 @@ public void MdiContainer_With_Application_RequestStop_MdiTop_With_Params () }; // Now this will close the MdiContainer propagating through the MdiChildes. - d.Closed += (e) => Application.RequestStop (mdi); + d.Closed += (s,e) => Application.RequestStop (mdi); Application.Iteration += () => { if (iterations == 4) { @@ -273,7 +273,7 @@ public void MdiContainer_With_Application_RequestStop_MdiTop_Without_Params () }; // Now this will close the MdiContainer propagating through the MdiChildes. - d.Closed += (e) => Application.RequestStop (mdi); + d.Closed += (s, e) => Application.RequestStop (mdi); Application.Iteration += () => { if (iterations == 4) { @@ -361,7 +361,7 @@ public void Modal_Toplevel_Can_Open_Another_Modal_Toplevel_But_RequestStop_To_Th }; // Now this will close the MdiContainer propagating through the MdiChildes. - d1.Closed += (e) => { + d1.Closed += (s, e) => { Assert.True (Application.Current == d1); Assert.False (Application.Current.Running); mdi.RequestStop (); @@ -434,7 +434,7 @@ public void Modal_Toplevel_Can_Open_Another_Not_Modal_Toplevel_But_RequestStop_T }; // Now this will close the MdiContainer propagating through the MdiChildes. - d1.Closed += (e) => { + d1.Closed += (s, e) => { mdi.RequestStop (); }; @@ -489,7 +489,7 @@ public void MoveCurrent_Returns_False_If_The_Current_And_Top_Parameter_Are_Both_ c1.RequestStop (); }; // Now this will close the MdiContainer propagating through the MdiChildes. - c1.Closed += (e) => { + c1.Closed += (s, e) => { mdi.RequestStop (); }; Application.Iteration += () => { @@ -570,7 +570,7 @@ public void MdiContainer_Open_And_Close_Modal_And_Open_Not_Modal_Toplevels_Rando stage.RequestStop (); }; - stage.Closed += (_) => { + stage.Closed += (_, _) => { if (iterations == 11) allStageClosed = true; Assert.Equal (iterations, Application.MdiChildes.Count); if (running) { diff --git a/UnitTests/TopLevels/ToplevelTests.cs b/UnitTests/TopLevels/ToplevelTests.cs index ac08ba23c7..7c092fda78 100644 --- a/UnitTests/TopLevels/ToplevelTests.cs +++ b/UnitTests/TopLevels/ToplevelTests.cs @@ -154,13 +154,13 @@ public void Internal_Tests () var eventInvoked = ""; - top.ChildUnloaded += (e) => eventInvoked = "ChildUnloaded"; + top.ChildUnloaded += (s,e) => eventInvoked = "ChildUnloaded"; top.OnChildUnloaded (top); Assert.Equal ("ChildUnloaded", eventInvoked); - top.ChildLoaded += (e) => eventInvoked = "ChildLoaded"; + top.ChildLoaded += (s,e) => eventInvoked = "ChildLoaded"; top.OnChildLoaded (top); Assert.Equal ("ChildLoaded", eventInvoked); - top.Closed += (e) => eventInvoked = "Closed"; + top.Closed += (s, e) => eventInvoked = "Closed"; top.OnClosed (top); Assert.Equal ("Closed", eventInvoked); top.Closing += (e) => eventInvoked = "Closing"; @@ -169,13 +169,13 @@ public void Internal_Tests () top.AllChildClosed += (s, e) => eventInvoked = "AllChildClosed"; top.OnAllChildClosed (); Assert.Equal ("AllChildClosed", eventInvoked); - top.ChildClosed += (e) => eventInvoked = "ChildClosed"; + top.ChildClosed += (s,e) => eventInvoked = "ChildClosed"; top.OnChildClosed (top); Assert.Equal ("ChildClosed", eventInvoked); - top.Deactivate += (e) => eventInvoked = "Deactivate"; + top.Deactivate += (s,e) => eventInvoked = "Deactivate"; top.OnDeactivate (top); Assert.Equal ("Deactivate", eventInvoked); - top.Activate += (e) => eventInvoked = "Activate"; + top.Activate += (s,e) => eventInvoked = "Activate"; top.OnActivate (top); Assert.Equal ("Activate", eventInvoked); top.Loaded += (s, e) => eventInvoked = "Loaded"; diff --git a/UnitTests/TopLevels/WizardTests.cs b/UnitTests/TopLevels/WizardTests.cs index b48d306d59..b10d862e80 100644 --- a/UnitTests/TopLevels/WizardTests.cs +++ b/UnitTests/TopLevels/WizardTests.cs @@ -523,7 +523,7 @@ public void Finish_Button_Closes () }; var closedFired = false; - wizard.Closed += (args) => { + wizard.Closed += (s, e) => { closedFired = true; }; @@ -553,7 +553,7 @@ public void Finish_Button_Closes () }; closedFired = false; - wizard.Closed += (args) => { + wizard.Closed += (s,e) => { closedFired = true; }; @@ -591,7 +591,7 @@ public void Finish_Button_Closes () }; closedFired = false; - wizard.Closed += (args) => { + wizard.Closed += (s,e) => { closedFired = true; }; From 5187310b9adf9dda844560f64d60c321432e22bd Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 11 Mar 2023 10:35:03 +0000 Subject: [PATCH 06/46] Refactor 'AlternateKey' events in Toplevel to use new signature --- Terminal.Gui/Core/Application.cs | 16 +++++++-------- Terminal.Gui/Core/Toplevel.cs | 30 ++++++++++++++-------------- Terminal.Gui/Views/TextView.cs | 8 ++++---- UnitTests/TopLevels/ToplevelTests.cs | 12 +++++------ 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index a646cbddb0..207ef3c7b3 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -162,15 +162,15 @@ public static Key AlternateForwardKey { if (alternateForwardKey != value) { var oldKey = alternateForwardKey; alternateForwardKey = value; - OnAlternateForwardKeyChanged (oldKey); + OnAlternateForwardKeyChanged (new KeyChangedEventArgs(oldKey,value)); } } } - static void OnAlternateForwardKeyChanged (Key oldKey) + static void OnAlternateForwardKeyChanged (KeyChangedEventArgs e) { foreach (var top in toplevels.ToArray ()) { - top.OnAlternateForwardKeyChanged (oldKey); + top.OnAlternateForwardKeyChanged (e); } } @@ -186,12 +186,12 @@ public static Key AlternateBackwardKey { if (alternateBackwardKey != value) { var oldKey = alternateBackwardKey; alternateBackwardKey = value; - OnAlternateBackwardKeyChanged (oldKey); + OnAlternateBackwardKeyChanged (new KeyChangedEventArgs(oldKey,value)); } } } - static void OnAlternateBackwardKeyChanged (Key oldKey) + static void OnAlternateBackwardKeyChanged (KeyChangedEventArgs oldKey) { foreach (var top in toplevels.ToArray ()) { top.OnAlternateBackwardKeyChanged (oldKey); @@ -210,7 +210,7 @@ public static Key QuitKey { if (quitKey != value) { var oldKey = quitKey; quitKey = value; - OnQuitKeyChanged (oldKey); + OnQuitKeyChanged (new KeyChangedEventArgs(oldKey,value)); } } } @@ -222,11 +222,11 @@ public static Key QuitKey { /// public static List SupportedCultures => supportedCultures; - static void OnQuitKeyChanged (Key oldKey) + static void OnQuitKeyChanged (KeyChangedEventArgs e) { // Duplicate the list so if it changes during enumeration we're safe foreach (var top in toplevels.ToArray ()) { - top.OnQuitKeyChanged (oldKey); + top.OnQuitKeyChanged (e); } } diff --git a/Terminal.Gui/Core/Toplevel.cs b/Terminal.Gui/Core/Toplevel.cs index f59991befc..1032ad9129 100644 --- a/Terminal.Gui/Core/Toplevel.cs +++ b/Terminal.Gui/Core/Toplevel.cs @@ -259,46 +259,46 @@ void Initialize () /// /// Invoked when the is changed. /// - public event Action AlternateForwardKeyChanged; + public event EventHandler AlternateForwardKeyChanged; /// /// Virtual method to invoke the event. /// - /// - public virtual void OnAlternateForwardKeyChanged (Key oldKey) + /// + public virtual void OnAlternateForwardKeyChanged (KeyChangedEventArgs e) { - ReplaceKeyBinding (oldKey, Application.AlternateForwardKey); - AlternateForwardKeyChanged?.Invoke (oldKey); + ReplaceKeyBinding (e.OldKey, e.NewKey); + AlternateForwardKeyChanged?.Invoke (this, e); } /// /// Invoked when the is changed. /// - public event Action AlternateBackwardKeyChanged; + public event EventHandler AlternateBackwardKeyChanged; /// /// Virtual method to invoke the event. /// - /// - public virtual void OnAlternateBackwardKeyChanged (Key oldKey) + /// + public virtual void OnAlternateBackwardKeyChanged (KeyChangedEventArgs e) { - ReplaceKeyBinding (oldKey, Application.AlternateBackwardKey); - AlternateBackwardKeyChanged?.Invoke (oldKey); + ReplaceKeyBinding (e.OldKey, e.NewKey); + AlternateBackwardKeyChanged?.Invoke (this, e); } /// /// Invoked when the is changed. /// - public event Action QuitKeyChanged; + public event EventHandler QuitKeyChanged; /// /// Virtual method to invoke the event. /// - /// - public virtual void OnQuitKeyChanged (Key oldKey) + /// + public virtual void OnQuitKeyChanged (KeyChangedEventArgs e) { - ReplaceKeyBinding (oldKey, Application.QuitKey); - QuitKeyChanged?.Invoke (oldKey); + ReplaceKeyBinding (e.OldKey, e.NewKey); + QuitKeyChanged?.Invoke (this, e); } /// diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 7cb797b11c..91472cd3bf 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -1446,14 +1446,14 @@ void TextView_Initialized (object sender, EventArgs e) OnContentsChanged (); } - void Top_AlternateBackwardKeyChanged (Key obj) + void Top_AlternateBackwardKeyChanged (object sender, KeyChangedEventArgs e) { - ReplaceKeyBinding (obj, Application.AlternateBackwardKey); + ReplaceKeyBinding (e.OldKey, e.NewKey); } - void Top_AlternateForwardKeyChanged (Key obj) + void Top_AlternateForwardKeyChanged (object sender, KeyChangedEventArgs e) { - ReplaceKeyBinding (obj, Application.AlternateForwardKey); + ReplaceKeyBinding (e.OldKey, e.NewKey); } /// diff --git a/UnitTests/TopLevels/ToplevelTests.cs b/UnitTests/TopLevels/ToplevelTests.cs index 7c092fda78..2466333b65 100644 --- a/UnitTests/TopLevels/ToplevelTests.cs +++ b/UnitTests/TopLevels/ToplevelTests.cs @@ -589,9 +589,9 @@ public void Added_Event_Should_Not_Be_Used_To_Initialize_Toplevel_Events () void View_Added (View obj) { - Assert.Throws (() => Application.Top.AlternateForwardKeyChanged += (e) => alternateForwardKey = e); - Assert.Throws (() => Application.Top.AlternateBackwardKeyChanged += (e) => alternateBackwardKey = e); - Assert.Throws (() => Application.Top.QuitKeyChanged += (e) => quitKey = e); + Assert.Throws (() => Application.Top.AlternateForwardKeyChanged += (s,e) => alternateForwardKey = e.OldKey); + Assert.Throws (() => Application.Top.AlternateBackwardKeyChanged += (s,e) => alternateBackwardKey = e.OldKey); + Assert.Throws (() => Application.Top.QuitKeyChanged += (s,e) => quitKey = e.OldKey); Assert.False (wasAdded); wasAdded = true; view.Added -= View_Added; @@ -621,9 +621,9 @@ public void AlternateForwardKeyChanged_AlternateBackwardKeyChanged_QuitKeyChange void View_Initialized (object sender, EventArgs e) { - Application.Top.AlternateForwardKeyChanged += (e) => alternateForwardKey = e; - Application.Top.AlternateBackwardKeyChanged += (e) => alternateBackwardKey = e; - Application.Top.QuitKeyChanged += (e) => quitKey = e; + Application.Top.AlternateForwardKeyChanged += (s,e) => alternateForwardKey = e.OldKey; + Application.Top.AlternateBackwardKeyChanged += (s, e) => alternateBackwardKey = e.OldKey; + Application.Top.QuitKeyChanged += (s, e) => quitKey = e.OldKey; } var win = new Window (); From 17e2d1d341ccc034635cf66b469132aa6bcc95f4 Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 11 Mar 2023 10:43:10 +0000 Subject: [PATCH 07/46] Refactor Action events to EventHandler --- Terminal.Gui/ConsoleDrivers/WindowsDriver.cs | 10 +++++----- Terminal.Gui/Core/Application.cs | 2 +- ...angedEventArgs.cs => KeyChangedEventArgs.cs} | 0 .../Core/EventArgs/SizeChangedEventArgs.cs | 17 +++++++++++++++++ Terminal.Gui/Core/Toplevel.cs | 6 +++--- Terminal.Gui/Views/ContextMenu.cs | 2 +- 6 files changed, 27 insertions(+), 10 deletions(-) rename Terminal.Gui/Core/EventArgs/{HotKeyChangedEventArgs.cs => KeyChangedEventArgs.cs} (100%) create mode 100644 Terminal.Gui/Core/EventArgs/SizeChangedEventArgs.cs diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index 5de19fa85a..094b79be65 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -743,8 +743,8 @@ public override void PrepareToRun (MainLoop mainLoop, Action keyHandle mLoop.ProcessInput = (e) => ProcessInput (e); - mLoop.WinChanged = (e) => { - ChangeWin (e); + mLoop.WinChanged = (s,e) => { + ChangeWin (e.Size); }; } @@ -1868,8 +1868,8 @@ internal class WindowsMainLoop : IMainLoopDriver { /// /// Invoked when the window is changed. /// - public Action WinChanged; - + public EventHandler WinChanged; + public WindowsMainLoop (ConsoleDriver consoleDriver = null) { this.consoleDriver = consoleDriver ?? throw new ArgumentNullException ("Console driver instance must be provided."); @@ -1991,7 +1991,7 @@ void IMainLoopDriver.MainIteration () } if (winChanged) { winChanged = false; - WinChanged?.Invoke (windowSize); + WinChanged?.Invoke (this, new SizeChangedEventArgs(windowSize)); } } } diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index 207ef3c7b3..83be1867ca 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -1530,7 +1530,7 @@ static void TerminalResized () t.SetRelativeLayout (full); t.LayoutSubviews (); t.PositionToplevels (); - t.OnResized (full.Size); + t.OnResized (new SizeChangedEventArgs(full.Size)); } Refresh (); } diff --git a/Terminal.Gui/Core/EventArgs/HotKeyChangedEventArgs.cs b/Terminal.Gui/Core/EventArgs/KeyChangedEventArgs.cs similarity index 100% rename from Terminal.Gui/Core/EventArgs/HotKeyChangedEventArgs.cs rename to Terminal.Gui/Core/EventArgs/KeyChangedEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/SizeChangedEventArgs.cs b/Terminal.Gui/Core/EventArgs/SizeChangedEventArgs.cs new file mode 100644 index 0000000000..1fec64f91d --- /dev/null +++ b/Terminal.Gui/Core/EventArgs/SizeChangedEventArgs.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Terminal.Gui{ + public class SizeChangedEventArgs : EventArgs { + + public SizeChangedEventArgs (Size size) + { + Size = size; + } + + public Size Size { get; } + } +} diff --git a/Terminal.Gui/Core/Toplevel.cs b/Terminal.Gui/Core/Toplevel.cs index 1032ad9129..fd4a405ef1 100644 --- a/Terminal.Gui/Core/Toplevel.cs +++ b/Terminal.Gui/Core/Toplevel.cs @@ -111,11 +111,11 @@ public class Toplevel : View { /// /// Invoked when the terminal has been resized. The new of the terminal is provided. /// - public event Action Resized; + public event EventHandler Resized; - internal virtual void OnResized (Size size) + internal virtual void OnResized (SizeChangedEventArgs size) { - Resized?.Invoke (size); + Resized?.Invoke (this, size); } internal virtual void OnChildUnloaded (Toplevel top) diff --git a/Terminal.Gui/Views/ContextMenu.cs b/Terminal.Gui/Views/ContextMenu.cs index 84e4db4da7..309f460354 100644 --- a/Terminal.Gui/Views/ContextMenu.cs +++ b/Terminal.Gui/Views/ContextMenu.cs @@ -145,7 +145,7 @@ public void Show () menuBar.OpenMenu (); } - private void Container_Resized (Size obj) + private void Container_Resized (object sender, SizeChangedEventArgs e) { if (IsShow) { Show (); From 776400693251493459951c19db87b712a78d2033 Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 11 Mar 2023 10:49:47 +0000 Subject: [PATCH 08/46] Add ViewEventArgs --- Terminal.Gui/Configuration/ThemeScope.cs | 4 ++-- Terminal.Gui/Core/Application.cs | 12 ++++++------ Terminal.Gui/Core/EventArgs/ViewEventArgs.cs | 16 ++++++++++++++++ UnitTests/Application/ApplicationTests.cs | 16 ++++++++-------- 4 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 Terminal.Gui/Core/EventArgs/ViewEventArgs.cs diff --git a/Terminal.Gui/Configuration/ThemeScope.cs b/Terminal.Gui/Configuration/ThemeScope.cs index 22da7e4f20..35b568b320 100644 --- a/Terminal.Gui/Configuration/ThemeScope.cs +++ b/Terminal.Gui/Configuration/ThemeScope.cs @@ -176,14 +176,14 @@ public ThemeManagerEventArgs (string newTheme) internal void OnThemeChanged (string theme) { Debug.WriteLine ($"Themes.OnThemeChanged({theme}) -> {Theme}"); - ThemeChanged?.Invoke (new ThemeManagerEventArgs (theme)); + ThemeChanged?.Invoke (this, new ThemeManagerEventArgs (theme)); } /// /// Event fired he selected theme has changed. /// application. /// - public event Action? ThemeChanged; + public event EventHandler? ThemeChanged; /// /// Holds the definitions. diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index 83be1867ca..e21be44718 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -267,7 +267,7 @@ static void OnQuitKeyChanged (KeyChangedEventArgs e) /// must also subscribe to /// and manually dispose of the token when the application is done. /// - public static event Action NotifyStopRunState; + public static event EventHandler NotifyStopRunState; /// /// This event is raised on each iteration of the . @@ -723,12 +723,12 @@ static View FindTopFromView (View view) /// /// Event to be invoked when a view grab the mouse. /// - public static event Action GrabbedMouse; + public static event EventHandler GrabbedMouse; /// /// Event to be invoked when a view ungrab the mouse. /// - public static event Action UnGrabbedMouse; + public static event EventHandler UnGrabbedMouse; /// /// Grabs the mouse, forcing all mouse events to be routed to the specified view until UngrabMouse is called. @@ -760,14 +760,14 @@ static void OnGrabbedMouse (View view) { if (view == null) return; - GrabbedMouse?.Invoke (view); + GrabbedMouse?.Invoke (view, new ViewEventArgs(view)); } static void OnUnGrabbedMouse (View view) { if (view == null) return; - UnGrabbedMouse?.Invoke (view); + UnGrabbedMouse?.Invoke (view, new ViewEventArgs (view)); } /// @@ -1497,7 +1497,7 @@ public static void RequestStop (Toplevel top = null) static void OnNotifyStopRunState (Toplevel top) { if (ExitRunLoopAfterFirstIteration) { - NotifyStopRunState?.Invoke (top); + NotifyStopRunState?.Invoke (top, new ToplevelEventArgs(top)); } } diff --git a/Terminal.Gui/Core/EventArgs/ViewEventArgs.cs b/Terminal.Gui/Core/EventArgs/ViewEventArgs.cs new file mode 100644 index 0000000000..4dbafcc1a7 --- /dev/null +++ b/Terminal.Gui/Core/EventArgs/ViewEventArgs.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Terminal.Gui{ + public class ViewEventArgs :EventArgs{ + public ViewEventArgs (View view) + { + View = view; + } + + public View View { get; } + } +} diff --git a/UnitTests/Application/ApplicationTests.cs b/UnitTests/Application/ApplicationTests.cs index 222057f728..dda3083722 100644 --- a/UnitTests/Application/ApplicationTests.cs +++ b/UnitTests/Application/ApplicationTests.cs @@ -978,27 +978,27 @@ public void MouseGrabView_GrabbedMouse_UnGrabbedMouse () Assert.Equal (grabView, view2); Assert.Null (Application.MouseGrabView); - void Application_GrabbedMouse (View obj) + void Application_GrabbedMouse (object sender, ViewEventArgs e) { if (count == 0) { - Assert.Equal (view1, obj); + Assert.Equal (view1, e.View); grabView = view1; } else { - Assert.Equal (view2, obj); + Assert.Equal (view2, e.View); grabView = view2; } Application.GrabbedMouse -= Application_GrabbedMouse; } - void Application_UnGrabbedMouse (View obj) + void Application_UnGrabbedMouse (object sender, ViewEventArgs e) { if (count == 0) { - Assert.Equal (view1, obj); - Assert.Equal (grabView, obj); + Assert.Equal (view1, e.View); + Assert.Equal (grabView, e.View); } else { - Assert.Equal (view2, obj); - Assert.Equal (grabView, obj); + Assert.Equal (view2, e.View); + Assert.Equal (grabView, e.View); } count++; From 9c4f3eda16fa0ef017d6eb56773cee360c491bfc Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 11 Mar 2023 11:05:20 +0000 Subject: [PATCH 09/46] Update Added/Removed and other events to use `EventHandler --- .../Configuration/ConfigurationManager.cs | 8 ++--- Terminal.Gui/Core/Application.cs | 4 +-- .../Core/Autocomplete/Autocomplete.cs | 2 +- Terminal.Gui/Core/Border.cs | 2 +- .../Core/EventArgs/RunStateEventArgs.cs | 18 +++++++++++ Terminal.Gui/Core/Toplevel.cs | 4 +-- Terminal.Gui/Core/View.cs | 20 +++++++------ Terminal.Gui/Views/ComboBox.cs | 2 +- Terminal.Gui/Views/ContextMenu.cs | 2 +- Terminal.Gui/Windows/Wizard.cs | 2 +- UICatalog/KeyBindingsDialog.cs | 2 +- UICatalog/UICatalog.cs | 2 +- UnitTests/Application/ApplicationTests.cs | 14 ++++----- .../Configuration/ConfigurationMangerTests.cs | 4 +-- UnitTests/Core/ViewTests.cs | 30 +++++++++---------- UnitTests/TopLevels/ToplevelTests.cs | 8 ++--- 16 files changed, 72 insertions(+), 52 deletions(-) create mode 100644 Terminal.Gui/Core/EventArgs/RunStateEventArgs.cs diff --git a/Terminal.Gui/Configuration/ConfigurationManager.cs b/Terminal.Gui/Configuration/ConfigurationManager.cs index fac2fa85bb..8222195a4a 100644 --- a/Terminal.Gui/Configuration/ConfigurationManager.cs +++ b/Terminal.Gui/Configuration/ConfigurationManager.cs @@ -353,14 +353,14 @@ private static void ClearJsonErrors () public static void OnUpdated () { Debug.WriteLine ($"ConfigurationManager.OnApplied()"); - Updated?.Invoke (new ConfigurationManagerEventArgs ()); + Updated?.Invoke (null, new ConfigurationManagerEventArgs ()); } /// /// Event fired when the configuration has been updated from a configuration source. /// application. /// - public static event Action? Updated; + public static event EventHandler? Updated; /// /// Resets the state of . Should be called whenever a new app session @@ -440,14 +440,14 @@ public static void Apply () public static void OnApplied () { Debug.WriteLine ($"ConfigurationManager.OnApplied()"); - Applied?.Invoke (new ConfigurationManagerEventArgs ()); + Applied?.Invoke (null, new ConfigurationManagerEventArgs ()); } /// /// Event fired when an updated configuration has been applied to the /// application. /// - public static event Action? Applied; + public static event EventHandler? Applied; /// /// Name of the running application. By default this property is set to the application's assembly name. diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index e21be44718..f38e31b210 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -257,7 +257,7 @@ static void OnQuitKeyChanged (KeyChangedEventArgs e) /// must also subscribe to /// and manually dispose of the token when the application is done. /// - public static event Action NotifyNewRunState; + public static event EventHandler NotifyNewRunState; /// /// Notify that a existent is stopping ( was called). @@ -1029,7 +1029,7 @@ public static RunState Begin (Toplevel toplevel) Driver.Refresh (); } - NotifyNewRunState?.Invoke (rs); + NotifyNewRunState?.Invoke (toplevel, new RunStateEventArgs(rs)); return rs; } diff --git a/Terminal.Gui/Core/Autocomplete/Autocomplete.cs b/Terminal.Gui/Core/Autocomplete/Autocomplete.cs index 7283327732..26f4adf98b 100644 --- a/Terminal.Gui/Core/Autocomplete/Autocomplete.cs +++ b/Terminal.Gui/Core/Autocomplete/Autocomplete.cs @@ -74,7 +74,7 @@ public virtual View HostControl { } } - private void Top_Removed (View obj) + private void Top_Removed (object sender, ViewEventArgs e) { Visible = false; ManipulatePopup (); diff --git a/Terminal.Gui/Core/Border.cs b/Terminal.Gui/Core/Border.cs index 8f28b6e472..2e8197ab33 100644 --- a/Terminal.Gui/Core/Border.cs +++ b/Terminal.Gui/Core/Border.cs @@ -460,7 +460,7 @@ public View Child { } } - private void Parent_Removed (View obj) + private void Parent_Removed (object sender, ViewEventArgs e) { BorderBrush = default; Background = default; diff --git a/Terminal.Gui/Core/EventArgs/RunStateEventArgs.cs b/Terminal.Gui/Core/EventArgs/RunStateEventArgs.cs new file mode 100644 index 0000000000..60e8b87ff3 --- /dev/null +++ b/Terminal.Gui/Core/EventArgs/RunStateEventArgs.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static Terminal.Gui.Application; + +namespace Terminal.Gui { + public class RunStateEventArgs : EventArgs { + + public RunStateEventArgs (RunState state) + { + State = state; + } + + public RunState State { get; } + } +} diff --git a/Terminal.Gui/Core/Toplevel.cs b/Terminal.Gui/Core/Toplevel.cs index fd4a405ef1..ca53bb8acf 100644 --- a/Terminal.Gui/Core/Toplevel.cs +++ b/Terminal.Gui/Core/Toplevel.cs @@ -91,7 +91,7 @@ public class Toplevel : View { /// Invoked when the Toplevel's is being closed by /// . /// - public event Action Closing; + public event EventHandler Closing; /// /// Invoked when the Toplevel's is closed by . @@ -135,7 +135,7 @@ internal virtual void OnClosed (Toplevel top) internal virtual bool OnClosing (ToplevelClosingEventArgs ev) { - Closing?.Invoke (ev); + Closing?.Invoke (this, ev); return ev.Cancel; } diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index 3a0c475ce9..dde23a2366 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -119,12 +119,12 @@ internal enum Direction { /// /// Event fired when a subview is being added to this view. /// - public event Action Added; + public event EventHandler Added; /// /// Event fired when a subview is being removed from this view. /// - public event Action Removed; + public event EventHandler Removed; /// /// Event fired when the view gets focus. @@ -942,7 +942,7 @@ public virtual void Add (View view) } SetNeedsLayout (); SetNeedsDisplay (); - OnAdded (view); + OnAdded (new ViewEventArgs(view)); if (IsInitialized) { view.BeginInit (); view.EndInit (); @@ -1002,7 +1002,7 @@ public virtual void Remove (View view) if (v.Frame.IntersectsWith (touched)) view.SetNeedsDisplay (); } - OnRemoved (view); + OnRemoved (new ViewEventArgs(view)); if (focused == view) { focused = null; } @@ -1354,26 +1354,28 @@ public class FocusEventArgs : EventArgs { /// /// Method invoked when a subview is being added to this view. /// - /// The subview being added. - public virtual void OnAdded (View view) + /// Event where is the subview being added. + public virtual void OnAdded (ViewEventArgs e) { + var view = e.View; view.IsAdded = true; view.x ??= view.frame.X; view.y ??= view.frame.Y; view.width ??= view.frame.Width; view.height ??= view.frame.Height; - view.Added?.Invoke (this); + view.Added?.Invoke (this,e); } /// /// Method invoked when a subview is being removed from this view. /// /// The subview being removed. - public virtual void OnRemoved (View view) + public virtual void OnRemoved (ViewEventArgs e) { + var view = e.View; view.IsAdded = false; - view.Removed?.Invoke (this); + view.Removed?.Invoke (this, e); } /// diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 4fb87d7e5b..4f015c1f49 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -316,7 +316,7 @@ private void Initialize () } }; - Added += (View v) => { + Added += (s, e) => { // Determine if this view is hosted inside a dialog and is the only control for (View view = this.SuperView; view != null; view = view.SuperView) { diff --git a/Terminal.Gui/Views/ContextMenu.cs b/Terminal.Gui/Views/ContextMenu.cs index 309f460354..2c7d0d109a 100644 --- a/Terminal.Gui/Views/ContextMenu.cs +++ b/Terminal.Gui/Views/ContextMenu.cs @@ -152,7 +152,7 @@ private void Container_Resized (object sender, SizeChangedEventArgs e) } } - private void Container_Closing (ToplevelClosingEventArgs obj) + private void Container_Closing (object sender, ToplevelClosingEventArgs obj) { Hide (); } diff --git a/Terminal.Gui/Windows/Wizard.cs b/Terminal.Gui/Windows/Wizard.cs index 34b11bcfe1..7ca438a675 100644 --- a/Terminal.Gui/Windows/Wizard.cs +++ b/Terminal.Gui/Windows/Wizard.cs @@ -392,7 +392,7 @@ private void Wizard_Loaded (object sender, EventArgs args) private bool finishedPressed = false; - private void Wizard_Closing (ToplevelClosingEventArgs obj) + private void Wizard_Closing (object sender, ToplevelClosingEventArgs obj) { if (!finishedPressed) { var args = new WizardButtonEventArgs (); diff --git a/UICatalog/KeyBindingsDialog.cs b/UICatalog/KeyBindingsDialog.cs index 95b1fcf91e..5c21166d7b 100644 --- a/UICatalog/KeyBindingsDialog.cs +++ b/UICatalog/KeyBindingsDialog.cs @@ -61,7 +61,7 @@ private void RecordView (View view) RecordView (sub); } - view.Added += RecordView; + view.Added += (s,e)=>RecordView(e.View); } internal static void Initialize () diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 64d5dd6a2e..8f72ca7a61 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -387,7 +387,7 @@ private void UnloadedHandler (object sender, EventArgs args) Unloaded -= UnloadedHandler; } - void ConfigAppliedHandler (ConfigurationManagerEventArgs a) + void ConfigAppliedHandler (object sender, ConfigurationManagerEventArgs a) { ConfigChanged (); } diff --git a/UnitTests/Application/ApplicationTests.cs b/UnitTests/Application/ApplicationTests.cs index dda3083722..e2433beb18 100644 --- a/UnitTests/Application/ApplicationTests.cs +++ b/UnitTests/Application/ApplicationTests.cs @@ -143,9 +143,9 @@ public void Init_Begin_End_Cleans_Up () }; Application.RunState runstate = null; - Action NewRunStateFn = (rs) => { - Assert.NotNull (rs); - runstate = rs; + EventHandler NewRunStateFn = (s, e) => { + Assert.NotNull (e.State); + runstate = e.State; }; Application.NotifyNewRunState += NewRunStateFn; @@ -188,9 +188,9 @@ public void InitWithTopLevelFactory_Begin_End_Cleans_Up () Application.InternalInit (() => topLevel = new TestToplevel (), new FakeDriver ()); Application.RunState runstate = null; - Action NewRunStateFn = (rs) => { - Assert.NotNull (rs); - runstate = rs; + EventHandler NewRunStateFn = (s, e) => { + Assert.NotNull (e.State); + runstate = e.State; }; Application.NotifyNewRunState += NewRunStateFn; @@ -730,7 +730,7 @@ public void QuitKey_Getter_Setter () var top = Application.Top; var isQuiting = false; - top.Closing += (e) => { + top.Closing += (s,e) => { isQuiting = true; e.Cancel = true; }; diff --git a/UnitTests/Configuration/ConfigurationMangerTests.cs b/UnitTests/Configuration/ConfigurationMangerTests.cs index 5e5c34b3d6..a37833a0c2 100644 --- a/UnitTests/Configuration/ConfigurationMangerTests.cs +++ b/UnitTests/Configuration/ConfigurationMangerTests.cs @@ -775,7 +775,7 @@ public void Load_FiresUpdated () ConfigurationManager.Updated += ConfigurationManager_Updated; bool fired = false; - void ConfigurationManager_Updated (ConfigurationManager.ConfigurationManagerEventArgs obj) + void ConfigurationManager_Updated (object sender, ConfigurationManager.ConfigurationManagerEventArgs obj) { fired = true; // assert @@ -801,7 +801,7 @@ public void Apply_FiresApplied () ConfigurationManager.Reset (); ConfigurationManager.Applied += ConfigurationManager_Applied; bool fired = false; - void ConfigurationManager_Applied (ConfigurationManager.ConfigurationManagerEventArgs obj) + void ConfigurationManager_Applied (object sender, ConfigurationManager.ConfigurationManagerEventArgs obj) { fired = true; // assert diff --git a/UnitTests/Core/ViewTests.cs b/UnitTests/Core/ViewTests.cs index a76af4ebc6..ed958029ee 100644 --- a/UnitTests/Core/ViewTests.cs +++ b/UnitTests/Core/ViewTests.cs @@ -238,11 +238,11 @@ public void Added_Removed () var v = new View (new Rect (0, 0, 10, 24)); var t = new View (); - v.Added += (View e) => { - Assert.True (v.SuperView == e); + v.Added += (s,e) => { + Assert.True (v.SuperView == e.View); }; - v.Removed += (View e) => { + v.Removed += (s, e) => { Assert.True (v.SuperView == null); }; @@ -654,21 +654,21 @@ public void Initialized_Event_Comparing_With_Added_Event () int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0; - w.Added += (e) => { - Assert.Equal (e.Frame.Width, w.Frame.Width); - Assert.Equal (e.Frame.Height, w.Frame.Height); + w.Added += (s,e) => { + Assert.Equal (e.View.Frame.Width, w.Frame.Width); + Assert.Equal (e.View.Frame.Height, w.Frame.Height); }; - v1.Added += (e) => { - Assert.Equal (e.Frame.Width, v1.Frame.Width); - Assert.Equal (e.Frame.Height, v1.Frame.Height); + v1.Added += (s, e) => { + Assert.Equal (e.View.Frame.Width, v1.Frame.Width); + Assert.Equal (e.View.Frame.Height, v1.Frame.Height); }; - v2.Added += (e) => { - Assert.Equal (e.Frame.Width, v2.Frame.Width); - Assert.Equal (e.Frame.Height, v2.Frame.Height); + v2.Added += (s, e) => { + Assert.Equal (e.View.Frame.Width, v2.Frame.Width); + Assert.Equal (e.View.Frame.Height, v2.Frame.Height); }; - sv1.Added += (e) => { - Assert.Equal (e.Frame.Width, sv1.Frame.Width); - Assert.Equal (e.Frame.Height, sv1.Frame.Height); + sv1.Added += (s, e) => { + Assert.Equal (e.View.Frame.Width, sv1.Frame.Width); + Assert.Equal (e.View.Frame.Height, sv1.Frame.Height); }; t.Initialized += (s, e) => { diff --git a/UnitTests/TopLevels/ToplevelTests.cs b/UnitTests/TopLevels/ToplevelTests.cs index 2466333b65..2fee5f48d8 100644 --- a/UnitTests/TopLevels/ToplevelTests.cs +++ b/UnitTests/TopLevels/ToplevelTests.cs @@ -163,7 +163,7 @@ public void Internal_Tests () top.Closed += (s, e) => eventInvoked = "Closed"; top.OnClosed (top); Assert.Equal ("Closed", eventInvoked); - top.Closing += (e) => eventInvoked = "Closing"; + top.Closing += (s,e) => eventInvoked = "Closing"; top.OnClosing (new ToplevelClosingEventArgs (top)); Assert.Equal ("Closing", eventInvoked); top.AllChildClosed += (s, e) => eventInvoked = "AllChildClosed"; @@ -356,7 +356,7 @@ public void KeyBindings_Command () var top = Application.Top; top.Add (win1, win2); top.Loaded += (s, e) => isRunning = true; - top.Closing += (_) => isRunning = false; + top.Closing += (s,e) => isRunning = false; Application.Begin (top); top.Running = true; @@ -465,7 +465,7 @@ public void KeyBindings_Command_With_MdiTop () var tf2W2 = new TextField ("Text2 on Win2") { X = Pos.Left (tf1W2), Width = Dim.Fill () }; win2.Add (lblTf1W2, tf1W2, lblTvW2, tvW2, lblTf2W2, tf2W2); - win1.Closing += (_) => isRunning = false; + win1.Closing += (s, e) => isRunning = false; Assert.Null (top.Focused); Assert.Equal (top, Application.Current); Assert.True (top.IsCurrentTop); @@ -587,7 +587,7 @@ public void Added_Event_Should_Not_Be_Used_To_Initialize_Toplevel_Events () var view = new View (); view.Added += View_Added; - void View_Added (View obj) + void View_Added (object sender, ViewEventArgs e) { Assert.Throws (() => Application.Top.AlternateForwardKeyChanged += (s,e) => alternateForwardKey = e.OldKey); Assert.Throws (() => Application.Top.AlternateBackwardKeyChanged += (s,e) => alternateBackwardKey = e.OldKey); From 1491e01d6abb2f87e622990e979870ae6f10a96b Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 11 Mar 2023 11:11:41 +0000 Subject: [PATCH 10/46] Fix xmldoc --- .../Core/EventArgs/KeyChangedEventArgs.cs | 5 +++++ .../Core/EventArgs/RunStateEventArgs.cs | 14 ++++++++++---- .../Core/EventArgs/SizeChangedEventArgs.cs | 19 ++++++++++++++----- .../Core/EventArgs/ToplevelEventArgs.cs | 7 +++++++ Terminal.Gui/Core/EventArgs/ViewEventArgs.cs | 18 ++++++++++++++++++ Terminal.Gui/Core/View.cs | 2 +- UnitTests/Views/TableViewTests.cs | 2 +- 7 files changed, 56 insertions(+), 11 deletions(-) diff --git a/Terminal.Gui/Core/EventArgs/KeyChangedEventArgs.cs b/Terminal.Gui/Core/EventArgs/KeyChangedEventArgs.cs index 83b825b2a6..eb1b37e9a6 100644 --- a/Terminal.Gui/Core/EventArgs/KeyChangedEventArgs.cs +++ b/Terminal.Gui/Core/EventArgs/KeyChangedEventArgs.cs @@ -20,6 +20,11 @@ public class KeyChangedEventArgs : EventArgs { /// public Key NewKey { get; } + /// + /// Creates a new instance of the class + /// + /// + /// public KeyChangedEventArgs (Key oldKey, Key newKey) { this.OldKey = oldKey; diff --git a/Terminal.Gui/Core/EventArgs/RunStateEventArgs.cs b/Terminal.Gui/Core/EventArgs/RunStateEventArgs.cs index 60e8b87ff3..9b77f7c91d 100644 --- a/Terminal.Gui/Core/EventArgs/RunStateEventArgs.cs +++ b/Terminal.Gui/Core/EventArgs/RunStateEventArgs.cs @@ -1,18 +1,24 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using static Terminal.Gui.Application; namespace Terminal.Gui { + /// + /// Event arguments for events about + /// public class RunStateEventArgs : EventArgs { + /// + /// Creates a new instance of the class + /// + /// public RunStateEventArgs (RunState state) { State = state; } + /// + /// The state being reported on by the event + /// public RunState State { get; } } } diff --git a/Terminal.Gui/Core/EventArgs/SizeChangedEventArgs.cs b/Terminal.Gui/Core/EventArgs/SizeChangedEventArgs.cs index 1fec64f91d..771643cb95 100644 --- a/Terminal.Gui/Core/EventArgs/SizeChangedEventArgs.cs +++ b/Terminal.Gui/Core/EventArgs/SizeChangedEventArgs.cs @@ -1,17 +1,26 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace Terminal.Gui{ +namespace Terminal.Gui { + + /// + /// Args for events about about Size (e.g. Resized) + /// public class SizeChangedEventArgs : EventArgs { + /// + /// Creates a new instance of the class. + /// + /// public SizeChangedEventArgs (Size size) { Size = size; } + /// + /// Gets the size the event describes. This should + /// reflect the new/current size after the event + /// resolved. + /// public Size Size { get; } } } diff --git a/Terminal.Gui/Core/EventArgs/ToplevelEventArgs.cs b/Terminal.Gui/Core/EventArgs/ToplevelEventArgs.cs index e1cc2198e5..76be6603cf 100644 --- a/Terminal.Gui/Core/EventArgs/ToplevelEventArgs.cs +++ b/Terminal.Gui/Core/EventArgs/ToplevelEventArgs.cs @@ -1,8 +1,15 @@ using System; namespace Terminal.Gui { + /// + /// Args for events that relate to a specific . + /// public class ToplevelEventArgs : EventArgs{ + /// + /// Creates a new instance of the class. + /// + /// public ToplevelEventArgs (Toplevel toplevel) { Toplevel = toplevel; diff --git a/Terminal.Gui/Core/EventArgs/ViewEventArgs.cs b/Terminal.Gui/Core/EventArgs/ViewEventArgs.cs index 4dbafcc1a7..ed47068013 100644 --- a/Terminal.Gui/Core/EventArgs/ViewEventArgs.cs +++ b/Terminal.Gui/Core/EventArgs/ViewEventArgs.cs @@ -5,12 +5,30 @@ using System.Threading.Tasks; namespace Terminal.Gui{ + + /// + /// Args for events that relate to specific + /// public class ViewEventArgs :EventArgs{ + + /// + /// Creates a new instance of the class. + /// + /// public ViewEventArgs (View view) { View = view; } + /// + /// The view that the event is about. + /// + /// + /// Can be different from the sender of the + /// for example if event describes the adding a child then sender may + /// be the parent while is the child + /// being added. + /// public View View { get; } } } diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index dde23a2366..edba716cf1 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -1370,7 +1370,7 @@ public virtual void OnAdded (ViewEventArgs e) /// /// Method invoked when a subview is being removed from this view. /// - /// The subview being removed. + /// Event args describing the subview being removed. public virtual void OnRemoved (ViewEventArgs e) { var view = e.View; diff --git a/UnitTests/Views/TableViewTests.cs b/UnitTests/Views/TableViewTests.cs index 2bcc46d950..e4c46aa7bf 100644 --- a/UnitTests/Views/TableViewTests.cs +++ b/UnitTests/Views/TableViewTests.cs @@ -1652,7 +1652,7 @@ public void TestToggleCells_MultiSelectOn_SquareSelectToggled () Assert.Equal(4,tableView.GetAllSelectedCells().Count()); tableView.ProcessKey (new KeyEvent { Key = Key.Space }); - Assert.Equal(1,tableView.GetAllSelectedCells().Count()); + Assert.Single(tableView.GetAllSelectedCells()); } From 02825d89baf65d5ec820ddf714b79267ef4aaebd Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 11 Mar 2023 12:01:04 +0000 Subject: [PATCH 11/46] Added SuperViewChangedEventArgs for Added/Removed to clarify situation --- .../Core/Autocomplete/Autocomplete.cs | 2 +- Terminal.Gui/Core/Border.cs | 2 +- .../EventArgs/SuperViewChangedEventArgs.cs | 33 +++++++++++++++++++ Terminal.Gui/Core/EventArgs/ViewEventArgs.cs | 3 +- Terminal.Gui/Core/View.cs | 20 +++++------ UICatalog/KeyBindingsDialog.cs | 5 ++- UnitTests/Core/ViewTests.cs | 22 ++++++++----- UnitTests/TopLevels/ToplevelTests.cs | 2 +- 8 files changed, 64 insertions(+), 25 deletions(-) create mode 100644 Terminal.Gui/Core/EventArgs/SuperViewChangedEventArgs.cs diff --git a/Terminal.Gui/Core/Autocomplete/Autocomplete.cs b/Terminal.Gui/Core/Autocomplete/Autocomplete.cs index 26f4adf98b..ea987c16b8 100644 --- a/Terminal.Gui/Core/Autocomplete/Autocomplete.cs +++ b/Terminal.Gui/Core/Autocomplete/Autocomplete.cs @@ -74,7 +74,7 @@ public virtual View HostControl { } } - private void Top_Removed (object sender, ViewEventArgs e) + private void Top_Removed (object sender, SuperViewChangedEventArgs e) { Visible = false; ManipulatePopup (); diff --git a/Terminal.Gui/Core/Border.cs b/Terminal.Gui/Core/Border.cs index 2e8197ab33..de005f990f 100644 --- a/Terminal.Gui/Core/Border.cs +++ b/Terminal.Gui/Core/Border.cs @@ -460,7 +460,7 @@ public View Child { } } - private void Parent_Removed (object sender, ViewEventArgs e) + private void Parent_Removed (object sender, SuperViewChangedEventArgs e) { BorderBrush = default; Background = default; diff --git a/Terminal.Gui/Core/EventArgs/SuperViewChangedEventArgs.cs b/Terminal.Gui/Core/EventArgs/SuperViewChangedEventArgs.cs new file mode 100644 index 0000000000..fdd4da3cf2 --- /dev/null +++ b/Terminal.Gui/Core/EventArgs/SuperViewChangedEventArgs.cs @@ -0,0 +1,33 @@ +using System; + +namespace Terminal.Gui { + /// + /// Args for events where the of a is changed + /// (e.g. / events). + /// + public class SuperViewChangedEventArgs : EventArgs + { + /// + /// Creates a new instance of the class. + /// + /// + /// + public SuperViewChangedEventArgs (View parent, View child) + { + Parent = parent; + Child = child; + } + + /// + /// The parent. For this is the old + /// parent (new parent now being null). For + /// it is the new parent to whom view now belongs. + /// + public View Parent { get; } + + /// + /// The view that is having it's changed + /// + public View Child { get; } + } +} diff --git a/Terminal.Gui/Core/EventArgs/ViewEventArgs.cs b/Terminal.Gui/Core/EventArgs/ViewEventArgs.cs index ed47068013..53b1a985b6 100644 --- a/Terminal.Gui/Core/EventArgs/ViewEventArgs.cs +++ b/Terminal.Gui/Core/EventArgs/ViewEventArgs.cs @@ -4,8 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace Terminal.Gui{ - +namespace Terminal.Gui { /// /// Args for events that relate to specific /// diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index edba716cf1..3147c61ac5 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -117,14 +117,14 @@ internal enum Direction { ShortcutHelper shortcutHelper; /// - /// Event fired when a subview is being added to this view. + /// Event fired when this view is added to another. /// - public event EventHandler Added; + public event EventHandler Added; /// - /// Event fired when a subview is being removed from this view. + /// Event fired when this view is removed from another. /// - public event EventHandler Removed; + public event EventHandler Removed; /// /// Event fired when the view gets focus. @@ -942,7 +942,7 @@ public virtual void Add (View view) } SetNeedsLayout (); SetNeedsDisplay (); - OnAdded (new ViewEventArgs(view)); + OnAdded (new SuperViewChangedEventArgs (this,view)); if (IsInitialized) { view.BeginInit (); view.EndInit (); @@ -1002,7 +1002,7 @@ public virtual void Remove (View view) if (v.Frame.IntersectsWith (touched)) view.SetNeedsDisplay (); } - OnRemoved (new ViewEventArgs(view)); + OnRemoved (new SuperViewChangedEventArgs (this, view)); if (focused == view) { focused = null; } @@ -1355,9 +1355,9 @@ public class FocusEventArgs : EventArgs { /// Method invoked when a subview is being added to this view. /// /// Event where is the subview being added. - public virtual void OnAdded (ViewEventArgs e) + public virtual void OnAdded (SuperViewChangedEventArgs e) { - var view = e.View; + var view = e.Child; view.IsAdded = true; view.x ??= view.frame.X; view.y ??= view.frame.Y; @@ -1371,9 +1371,9 @@ public virtual void OnAdded (ViewEventArgs e) /// Method invoked when a subview is being removed from this view. /// /// Event args describing the subview being removed. - public virtual void OnRemoved (ViewEventArgs e) + public virtual void OnRemoved (SuperViewChangedEventArgs e) { - var view = e.View; + var view = e.Child; view.IsAdded = false; view.Removed?.Invoke (this, e); } diff --git a/UICatalog/KeyBindingsDialog.cs b/UICatalog/KeyBindingsDialog.cs index 5c21166d7b..ac46bbdb7e 100644 --- a/UICatalog/KeyBindingsDialog.cs +++ b/UICatalog/KeyBindingsDialog.cs @@ -60,8 +60,11 @@ private void RecordView (View view) foreach (var sub in view.Subviews) { RecordView (sub); } + // TODO: BUG: Based on my new understanding of Added event I think this is wrong + // (and always was wrong). Parents don't get to be told when new views are added + // to them - view.Added += (s,e)=>RecordView(e.View); + view.Added += (s,e)=>RecordView(e.Child); } internal static void Initialize () diff --git a/UnitTests/Core/ViewTests.cs b/UnitTests/Core/ViewTests.cs index ed958029ee..3128bea484 100644 --- a/UnitTests/Core/ViewTests.cs +++ b/UnitTests/Core/ViewTests.cs @@ -239,10 +239,14 @@ public void Added_Removed () var t = new View (); v.Added += (s,e) => { - Assert.True (v.SuperView == e.View); + Assert.Same (v.SuperView, e.Parent); + Assert.Same (t, e.Parent); + Assert.Same (v, e.Child); }; v.Removed += (s, e) => { + Assert.Same (t, e.Parent); + Assert.Same (v, e.Child); Assert.True (v.SuperView == null); }; @@ -655,20 +659,20 @@ public void Initialized_Event_Comparing_With_Added_Event () int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0; w.Added += (s,e) => { - Assert.Equal (e.View.Frame.Width, w.Frame.Width); - Assert.Equal (e.View.Frame.Height, w.Frame.Height); + Assert.Equal (e.Parent.Frame.Width, w.Frame.Width); + Assert.Equal (e.Parent.Frame.Height, w.Frame.Height); }; v1.Added += (s, e) => { - Assert.Equal (e.View.Frame.Width, v1.Frame.Width); - Assert.Equal (e.View.Frame.Height, v1.Frame.Height); + Assert.Equal (e.Parent.Frame.Width, v1.Frame.Width); + Assert.Equal (e.Parent.Frame.Height, v1.Frame.Height); }; v2.Added += (s, e) => { - Assert.Equal (e.View.Frame.Width, v2.Frame.Width); - Assert.Equal (e.View.Frame.Height, v2.Frame.Height); + Assert.Equal (e.Parent.Frame.Width, v2.Frame.Width); + Assert.Equal (e.Parent.Frame.Height, v2.Frame.Height); }; sv1.Added += (s, e) => { - Assert.Equal (e.View.Frame.Width, sv1.Frame.Width); - Assert.Equal (e.View.Frame.Height, sv1.Frame.Height); + Assert.Equal (e.Parent.Frame.Width, sv1.Frame.Width); + Assert.Equal (e.Parent.Frame.Height, sv1.Frame.Height); }; t.Initialized += (s, e) => { diff --git a/UnitTests/TopLevels/ToplevelTests.cs b/UnitTests/TopLevels/ToplevelTests.cs index 2fee5f48d8..a42b732d49 100644 --- a/UnitTests/TopLevels/ToplevelTests.cs +++ b/UnitTests/TopLevels/ToplevelTests.cs @@ -587,7 +587,7 @@ public void Added_Event_Should_Not_Be_Used_To_Initialize_Toplevel_Events () var view = new View (); view.Added += View_Added; - void View_Added (object sender, ViewEventArgs e) + void View_Added (object sender, SuperViewChangedEventArgs e) { Assert.Throws (() => Application.Top.AlternateForwardKeyChanged += (s,e) => alternateForwardKey = e.OldKey); Assert.Throws (() => Application.Top.AlternateBackwardKeyChanged += (s,e) => alternateBackwardKey = e.OldKey); From 17a33f3b1115816f5ad7ef0506fe0918157bdc42 Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 11 Mar 2023 19:26:00 +0000 Subject: [PATCH 12/46] Refactor `Action Toggled` to `EventHandler` --- .../Core/EventArgs/ToggleEventArgs.cs | 34 +++++++++++++++++++ Terminal.Gui/Views/CheckBox.cs | 9 ++--- UICatalog/Scenarios/AllViewsTester.cs | 4 +-- .../Scenarios/AutoSizeAndDirectionText.cs | 8 ++--- UICatalog/Scenarios/Borders.cs | 6 ++-- UICatalog/Scenarios/BordersOnContainers.cs | 4 +-- UICatalog/Scenarios/DynamicMenuBar.cs | 6 ++-- UICatalog/Scenarios/Editor.cs | 8 ++--- UICatalog/Scenarios/ListViewWithSelection.cs | 14 ++++---- UICatalog/Scenarios/MessageBoxes.cs | 4 +-- UICatalog/Scenarios/ProgressBarStyles.cs | 4 +-- UICatalog/Scenarios/Scrolling.cs | 8 ++--- UICatalog/Scenarios/Text.cs | 10 +++--- UICatalog/Scenarios/TextAlignments.cs | 6 ++-- .../Scenarios/TextAlignmentsAndDirection.cs | 4 +-- UICatalog/Scenarios/TextFormatterDemo.cs | 6 ++-- UICatalog/Scenarios/TileViewNesting.cs | 8 ++--- UICatalog/Scenarios/Unicode.cs | 2 +- UICatalog/Scenarios/Wizards.cs | 4 +-- UnitTests/UICatalog/ScenarioTests.cs | 4 +-- UnitTests/Views/CheckBoxTests.cs | 2 +- 21 files changed, 95 insertions(+), 60 deletions(-) create mode 100644 Terminal.Gui/Core/EventArgs/ToggleEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/ToggleEventArgs.cs b/Terminal.Gui/Core/EventArgs/ToggleEventArgs.cs new file mode 100644 index 0000000000..a1d5993554 --- /dev/null +++ b/Terminal.Gui/Core/EventArgs/ToggleEventArgs.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Terminal.Gui { + /// + /// for the event + /// + public class ToggleEventArgs : EventArgs { + + /// + /// Creates a new instance of the class. + /// + /// + /// + public ToggleEventArgs (bool? oldValue, bool? newValue) + { + OldValue = oldValue; + NewValue = newValue; + } + + /// + /// The previous checked state + /// + public bool? OldValue { get; } + + /// + /// The new checked state + /// + public bool? NewValue { get; } + } +} diff --git a/Terminal.Gui/Views/CheckBox.cs b/Terminal.Gui/Views/CheckBox.cs index f891be42f2..1dcd8b9736 100644 --- a/Terminal.Gui/Views/CheckBox.cs +++ b/Terminal.Gui/Views/CheckBox.cs @@ -27,14 +27,14 @@ public class CheckBox : View { /// raised when the is activated either with /// the mouse or the keyboard. The passed bool contains the previous state. /// - public event Action Toggled; + public event EventHandler Toggled; /// /// Called when the property changes. Invokes the event. /// - public virtual void OnToggled (bool? previousChecked) + public virtual void OnToggled (ToggleEventArgs e) { - Toggled?.Invoke (previousChecked); + Toggled?.Invoke (this, e); } /// @@ -203,7 +203,8 @@ bool ToggleChecked () } else { Checked = !Checked; } - OnToggled (previousChecked); + + OnToggled (new ToggleEventArgs (previousChecked, Checked)); SetNeedsDisplay (); return true; } diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index 862e4b3baf..ddfa05bb8e 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -101,9 +101,9 @@ public override void Setup () ColorScheme = Colors.TopLevel, }; _computedCheckBox = new CheckBox ("Computed Layout", true) { X = 0, Y = 0 }; - _computedCheckBox.Toggled += (previousState) => { + _computedCheckBox.Toggled += (s,e) => { if (_curView != null) { - _curView.LayoutStyle = previousState == true ? LayoutStyle.Absolute : LayoutStyle.Computed; + _curView.LayoutStyle = e.OldValue == true ? LayoutStyle.Absolute : LayoutStyle.Computed; _hostPane.LayoutSubviews (); } }; diff --git a/UICatalog/Scenarios/AutoSizeAndDirectionText.cs b/UICatalog/Scenarios/AutoSizeAndDirectionText.cs index 2f54cd10e2..af43bcde9f 100644 --- a/UICatalog/Scenarios/AutoSizeAndDirectionText.cs +++ b/UICatalog/Scenarios/AutoSizeAndDirectionText.cs @@ -44,7 +44,7 @@ public override void Setup () X = Pos.Center (), Y = Pos.Center () + 3 }; - ckbDirection.Toggled += (_) => { + ckbDirection.Toggled += (s,e) => { if (labelH.TextDirection == TextDirection.LeftRight_TopBottom) { labelH.TextDirection = TextDirection.TopBottom_LeftRight; labelV.TextDirection = TextDirection.LeftRight_TopBottom; @@ -60,7 +60,7 @@ public override void Setup () Y = Pos.Center () + 5, Checked = labelH.AutoSize = labelV.AutoSize }; - ckbAutoSize.Toggled += (_) => labelH.AutoSize = labelV.AutoSize = (bool)ckbAutoSize.Checked; + ckbAutoSize.Toggled += (s,e) => labelH.AutoSize = labelV.AutoSize = (bool)ckbAutoSize.Checked; Win.Add (ckbAutoSize); var ckbPreserveTrailingSpaces = new CheckBox ("Preserve Trailing Spaces") { @@ -68,7 +68,7 @@ public override void Setup () Y = Pos.Center () + 7, Checked = labelH.PreserveTrailingSpaces = labelV.PreserveTrailingSpaces }; - ckbPreserveTrailingSpaces.Toggled += (_) => + ckbPreserveTrailingSpaces.Toggled += (s, e) => labelH.PreserveTrailingSpaces = labelV.PreserveTrailingSpaces = (bool)ckbPreserveTrailingSpaces.Checked; Win.Add (ckbPreserveTrailingSpaces); @@ -76,7 +76,7 @@ public override void Setup () X = Pos.Center (), Y = Pos.Center () + 9 }; - ckbWideText.Toggled += (_) => { + ckbWideText.Toggled += (s, e) => { if (ckbWideText.Checked == true) { labelH.Text = labelV.Text = editText.Text = wideText; labelH.Width = 14; diff --git a/UICatalog/Scenarios/Borders.cs b/UICatalog/Scenarios/Borders.cs index 4016b1ed4a..c176ed0401 100644 --- a/UICatalog/Scenarios/Borders.cs +++ b/UICatalog/Scenarios/Borders.cs @@ -206,7 +206,7 @@ public override void Setup () Y = Pos.Y (replacePadding) + 1, Checked = smartPanel.UsePanelFrame }; - cbUseUsePanelFrame.Toggled += (e) => smartPanel.UsePanelFrame = (bool)!e; + cbUseUsePanelFrame.Toggled += (s,e) => smartPanel.UsePanelFrame = (bool)!e.OldValue; Win.Add (cbUseUsePanelFrame); Win.Add (new Label ("Border:") { @@ -337,7 +337,7 @@ public override void Setup () Y = 0, Width = 5 }; - cbDrawMarginFrame.Toggled += (e) => { + cbDrawMarginFrame.Toggled += (s,e) => { try { smartPanel.Child.Border.DrawMarginFrame = cbDrawMarginFrame.Checked == true; smartLabel.Border.DrawMarginFrame = cbDrawMarginFrame.Checked == true; @@ -420,7 +420,7 @@ public override void Setup () effect3DOffsetY.Text = $"{smartLabel.Border.Effect3DOffset.Y}"; Win.Add (effect3DOffsetY); - cbEffect3D.Toggled += (e) => { + cbEffect3D.Toggled += (s,e) => { try { smartPanel.Child.Border.Effect3D = smartLabel.Border.Effect3D = effect3DOffsetX.Enabled = effect3DOffsetY.Enabled = cbEffect3D.Checked == true; diff --git a/UICatalog/Scenarios/BordersOnContainers.cs b/UICatalog/Scenarios/BordersOnContainers.cs index 039ac521d7..0debccc76b 100644 --- a/UICatalog/Scenarios/BordersOnContainers.cs +++ b/UICatalog/Scenarios/BordersOnContainers.cs @@ -262,7 +262,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie Y = 0, Width = 5 }; - cbDrawMarginFrame.Toggled += (e) => { + cbDrawMarginFrame.Toggled += (s, e) => { try { smartView.Border.DrawMarginFrame = (bool)cbDrawMarginFrame.Checked; if (cbDrawMarginFrame.Checked != smartView.Border.DrawMarginFrame) { @@ -337,7 +337,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie effect3DOffsetY.Text = $"{smartView.Border.Effect3DOffset.Y}"; Add (effect3DOffsetY); - cbEffect3D.Toggled += (e) => { + cbEffect3D.Toggled += (s, e) => { try { smartView.Border.Effect3D = effect3DOffsetX.Enabled = effect3DOffsetY.Enabled = (bool)cbEffect3D.Checked; diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs index eca4ba9ffa..30e3929e1f 100644 --- a/UICatalog/Scenarios/DynamicMenuBar.cs +++ b/UICatalog/Scenarios/DynamicMenuBar.cs @@ -789,7 +789,7 @@ bool CheckShortcut (Key k, bool pre) }; Add (_btnShortcut); - _ckbIsTopLevel.Toggled += (e) => { + _ckbIsTopLevel.Toggled += (s, e) => { if ((_menuItem != null && _menuItem.Parent != null && (bool)_ckbIsTopLevel.Checked) || _menuItem == null && hasParent && (bool)_ckbIsTopLevel.Checked) { MessageBox.ErrorQuery ("Invalid IsTopLevel", "Only menu bar can have top level menu item!", "Ok"); @@ -814,7 +814,7 @@ bool CheckShortcut (Key k, bool pre) _txtAction.Enabled = false; } }; - _ckbSubMenu.Toggled += (e) => { + _ckbSubMenu.Toggled += (s, e) => { if ((bool)_ckbSubMenu.Checked) { _ckbIsTopLevel.Checked = false; _ckbIsTopLevel.SetNeedsDisplay (); @@ -835,7 +835,7 @@ bool CheckShortcut (Key k, bool pre) _txtShortcut.Enabled = _ckbIsTopLevel.Checked == false && _ckbSubMenu.Checked == false; } }; - _ckbNullCheck.Toggled += (e) => { + _ckbNullCheck.Toggled += (s,e) => { if (_menuItem != null) { _menuItem.AllowNullChecked = (bool)_ckbNullCheck.Checked; } diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index f451bd37b7..430ed0ffd8 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -837,7 +837,7 @@ private View FindTab () Y = Pos.Top (txtToFind) + 2, Checked = _matchCase }; - ckbMatchCase.Toggled += (e) => _matchCase = (bool)ckbMatchCase.Checked; + ckbMatchCase.Toggled += (s, e) => _matchCase = (bool)ckbMatchCase.Checked; d.Add (ckbMatchCase); var ckbMatchWholeWord = new CheckBox ("Match _whole word") { @@ -845,7 +845,7 @@ private View FindTab () Y = Pos.Top (ckbMatchCase) + 1, Checked = _matchWholeWord }; - ckbMatchWholeWord.Toggled += (e) => _matchWholeWord = (bool)ckbMatchWholeWord.Checked; + ckbMatchWholeWord.Toggled += (s, e) => _matchWholeWord = (bool)ckbMatchWholeWord.Checked; d.Add (ckbMatchWholeWord); d.Width = label.Width + txtToFind.Width + btnFindNext.Width + 2; @@ -958,7 +958,7 @@ private View ReplaceTab () Y = Pos.Top (txtToFind) + 2, Checked = _matchCase }; - ckbMatchCase.Toggled += (e) => _matchCase = (bool)ckbMatchCase.Checked; + ckbMatchCase.Toggled += (s, e) => _matchCase = (bool)ckbMatchCase.Checked; d.Add (ckbMatchCase); var ckbMatchWholeWord = new CheckBox ("Match _whole word") { @@ -966,7 +966,7 @@ private View ReplaceTab () Y = Pos.Top (ckbMatchCase) + 1, Checked = _matchWholeWord }; - ckbMatchWholeWord.Toggled += (e) => _matchWholeWord = (bool)ckbMatchWholeWord.Checked; + ckbMatchWholeWord.Toggled += (s, e) => _matchWholeWord = (bool)ckbMatchWholeWord.Checked; d.Add (ckbMatchWholeWord); d.Width = lblWidth + txtToFind.Width + btnFindNext.Width + 2; diff --git a/UICatalog/Scenarios/ListViewWithSelection.cs b/UICatalog/Scenarios/ListViewWithSelection.cs index cb0de388ed..2ccbcd51c6 100644 --- a/UICatalog/Scenarios/ListViewWithSelection.cs +++ b/UICatalog/Scenarios/ListViewWithSelection.cs @@ -93,7 +93,7 @@ public override void Setup () X = Pos.AnchorEnd (k.Length + 3), Y = 0, }; - keepCheckBox.Toggled += (_) => _scrollBar.KeepContentAlwaysInViewport = (bool)keepCheckBox.Checked; + keepCheckBox.Toggled += (s,e) => _scrollBar.KeepContentAlwaysInViewport = (bool)keepCheckBox.Checked; Win.Add (keepCheckBox); } @@ -113,9 +113,9 @@ private void ListView_RowRender (ListViewRowEventArgs obj) } } - private void _customRenderCB_Toggled (bool? prev) + private void _customRenderCB_Toggled (object sender, ToggleEventArgs e) { - if (prev == true) { + if (e.OldValue == true) { _listView.SetSource (_scenarios); } else { _listView.Source = new ScenarioListDataSource (_scenarios); @@ -124,16 +124,16 @@ private void _customRenderCB_Toggled (bool? prev) Win.SetNeedsDisplay (); } - private void AllowMarkingCB_Toggled (bool? prev) + private void AllowMarkingCB_Toggled (object sender, ToggleEventArgs e) { - _listView.AllowsMarking = (bool)!prev; + _listView.AllowsMarking = (bool)!e.OldValue; _allowMultipleCB.Visible = _listView.AllowsMarking; Win.SetNeedsDisplay (); } - private void AllowMultipleCB_Toggled (bool? prev) + private void AllowMultipleCB_Toggled (object sender, ToggleEventArgs e) { - _listView.AllowsMultipleSelection = (bool)!prev; + _listView.AllowsMultipleSelection = (bool)!e.OldValue; Win.SetNeedsDisplay (); } diff --git a/UICatalog/Scenarios/MessageBoxes.cs b/UICatalog/Scenarios/MessageBoxes.cs index f28f0b01a5..f1b3fad110 100644 --- a/UICatalog/Scenarios/MessageBoxes.cs +++ b/UICatalog/Scenarios/MessageBoxes.cs @@ -147,8 +147,8 @@ public override void Setup () X = Pos.Right (label) + 1, Y = Pos.Top (label) + 2 }; - ckbEffect3D.Toggled += (e) => { - border.Effect3D = (bool)!e; + ckbEffect3D.Toggled += (s,e) => { + border.Effect3D = (bool)!e.OldValue; }; frame.Add (ckbEffect3D); diff --git a/UICatalog/Scenarios/ProgressBarStyles.cs b/UICatalog/Scenarios/ProgressBarStyles.cs index 8d381ebdc9..72b2d4a27e 100644 --- a/UICatalog/Scenarios/ProgressBarStyles.cs +++ b/UICatalog/Scenarios/ProgressBarStyles.cs @@ -120,8 +120,8 @@ public override void Setup () marqueesContinuousPB.ProgressBarFormat = (ProgressBarFormat)e.SelectedItem; }; - ckbBidirectional.Toggled += (e) => { - ckbBidirectional.Checked = marqueesBlocksPB.BidirectionalMarquee = marqueesContinuousPB.BidirectionalMarquee = (bool)!e; + ckbBidirectional.Toggled += (s,e) => { + ckbBidirectional.Checked = marqueesBlocksPB.BidirectionalMarquee = marqueesContinuousPB.BidirectionalMarquee = (bool)!e.OldValue; }; _pulseTimer = new Timer ((_) => { diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index 888cfb9617..11535de46f 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -236,7 +236,7 @@ void Top_Loaded (object sender, EventArgs args) X = Pos.Left (scrollView) + (scrollView.Bounds.Width / 2) - (k.Length / 2), Y = Pos.Bottom (scrollView) + 4, }; - hCheckBox.Toggled += (_) => { + hCheckBox.Toggled += (s, e) => { if (ahCheckBox.Checked == false) { scrollView.ShowHorizontalScrollIndicator = (bool)hCheckBox.Checked; } else { @@ -244,7 +244,7 @@ void Top_Loaded (object sender, EventArgs args) MessageBox.Query ("Message", "Disable Auto Hide Scrollbars first.", "Ok"); } }; - vCheckBox.Toggled += (_) => { + vCheckBox.Toggled += (s, e) => { if (ahCheckBox.Checked == false) { scrollView.ShowVerticalScrollIndicator = (bool)vCheckBox.Checked; } else { @@ -252,14 +252,14 @@ void Top_Loaded (object sender, EventArgs args) MessageBox.Query ("Message", "Disable Auto Hide Scrollbars first.", "Ok"); } }; - ahCheckBox.Toggled += (_) => { + ahCheckBox.Toggled += (s, e) => { scrollView.AutoHideScrollBars = (bool)ahCheckBox.Checked; hCheckBox.Checked = true; vCheckBox.Checked = true; }; Win.Add (ahCheckBox); - keepCheckBox.Toggled += (_) => scrollView.KeepContentAlwaysInViewport = (bool)keepCheckBox.Checked; + keepCheckBox.Toggled += (s,e) => scrollView.KeepContentAlwaysInViewport = (bool)keepCheckBox.Checked; Win.Add (keepCheckBox); var scrollView2 = new ScrollView (new Rect (55, 2, 20, 8)) { diff --git a/UICatalog/Scenarios/Text.cs b/UICatalog/Scenarios/Text.cs index 2a515998d8..00ddf3af07 100644 --- a/UICatalog/Scenarios/Text.cs +++ b/UICatalog/Scenarios/Text.cs @@ -87,14 +87,14 @@ void TextView_DrawContent (Rect e) Y = Pos.Bottom (textView), Checked = true }; - chxMultiline.Toggled += (b) => textView.Multiline = (bool)b; + chxMultiline.Toggled += (s,e) => textView.Multiline = (bool)e.OldValue; Win.Add (chxMultiline); var chxWordWrap = new CheckBox ("Word Wrap") { X = Pos.Right (chxMultiline) + 2, Y = Pos.Top (chxMultiline) }; - chxWordWrap.Toggled += (b) => textView.WordWrap = (bool)b; + chxWordWrap.Toggled += (s,e) => textView.WordWrap = (bool)e.OldValue; Win.Add (chxWordWrap); // TextView captures Tabs (so users can enter /t into text) by default; @@ -108,15 +108,15 @@ void TextView_DrawContent (Rect e) Key keyTab = textView.GetKeyFromCommand (Command.Tab); Key keyBackTab = textView.GetKeyFromCommand (Command.BackTab); - chxCaptureTabs.Toggled += (b) => { - if (b == true) { + chxCaptureTabs.Toggled += (s,e) => { + if (e.OldValue == true) { textView.AddKeyBinding (keyTab, Command.Tab); textView.AddKeyBinding (keyBackTab, Command.BackTab); } else { textView.ClearKeybinding (keyTab); textView.ClearKeybinding (keyBackTab); } - textView.WordWrap = (bool)b; + textView.WordWrap = (bool)e.OldValue; }; Win.Add (chxCaptureTabs); diff --git a/UICatalog/Scenarios/TextAlignments.cs b/UICatalog/Scenarios/TextAlignments.cs index 65b0de6be7..b9b36ca35a 100644 --- a/UICatalog/Scenarios/TextAlignments.cs +++ b/UICatalog/Scenarios/TextAlignments.cs @@ -98,10 +98,10 @@ public override void Setup () label = multipleLines [(int)alignment]; } - enableHotKeyCheckBox.Toggled += (previous) => { + enableHotKeyCheckBox.Toggled += (s,e) => { foreach (var alignment in alignments) { - singleLines [(int)alignment].HotKeySpecifier = previous == true ? (Rune)0xffff : (Rune)'_'; - multipleLines [(int)alignment].HotKeySpecifier = previous == true ? (Rune)0xffff : (Rune)'_'; + singleLines [(int)alignment].HotKeySpecifier = e.OldValue == true ? (Rune)0xffff : (Rune)'_'; + multipleLines [(int)alignment].HotKeySpecifier = e.OldValue == true ? (Rune)0xffff : (Rune)'_'; } Win.SetNeedsDisplay (); Win.LayoutSubviews (); diff --git a/UICatalog/Scenarios/TextAlignmentsAndDirection.cs b/UICatalog/Scenarios/TextAlignmentsAndDirection.cs index cd17b2e0c3..82d263ba1b 100644 --- a/UICatalog/Scenarios/TextAlignmentsAndDirection.cs +++ b/UICatalog/Scenarios/TextAlignmentsAndDirection.cs @@ -141,8 +141,8 @@ public override void Setup () Height = 1 }; - justifyCheckbox.Toggled += (prevtoggled) => { - if (prevtoggled == true) { + justifyCheckbox.Toggled += (s,e) => { + if (e.OldValue == true) { foreach (var t in mtxts) { t.TextAlignment = (TextAlignment)((dynamic)t.Data).h; t.VerticalTextAlignment = (VerticalTextAlignment)((dynamic)t.Data).v; diff --git a/UICatalog/Scenarios/TextFormatterDemo.cs b/UICatalog/Scenarios/TextFormatterDemo.cs index 28482043af..697a05f02e 100644 --- a/UICatalog/Scenarios/TextFormatterDemo.cs +++ b/UICatalog/Scenarios/TextFormatterDemo.cs @@ -80,10 +80,10 @@ public override void Setup () label = multipleLines [(int)alignment]; } - unicodeCheckBox.Toggled += (previous) => { + unicodeCheckBox.Toggled += (s,e) => { foreach (var alignment in alignments) { - singleLines [(int)alignment].Text = previous == true ? text : unicode; - multipleLines [(int)alignment].Text = previous == true ? text : unicode; + singleLines [(int)alignment].Text = e.OldValue == true ? text : unicode; + multipleLines [(int)alignment].Text = e.OldValue == true ? text : unicode; } }; } diff --git a/UICatalog/Scenarios/TileViewNesting.cs b/UICatalog/Scenarios/TileViewNesting.cs index b977b86d5a..3cee1b1954 100644 --- a/UICatalog/Scenarios/TileViewNesting.cs +++ b/UICatalog/Scenarios/TileViewNesting.cs @@ -42,22 +42,22 @@ public override void Setup () cbHorizontal = new CheckBox ("Horizontal") { X = Pos.Right (textField) + 1 }; - cbHorizontal.Toggled += (s) => SetupTileView (); + cbHorizontal.Toggled += (s, e) => SetupTileView (); cbBorder = new CheckBox ("Border") { X = Pos.Right (cbHorizontal) + 1 }; - cbBorder.Toggled += (s) => SetupTileView (); + cbBorder.Toggled += (s, e) => SetupTileView (); cbTitles = new CheckBox ("Titles") { X = Pos.Right (cbBorder) + 1 }; - cbTitles.Toggled += (s) => SetupTileView (); + cbTitles.Toggled += (s,e) => SetupTileView (); cbUseLabels = new CheckBox ("Use Labels") { X = Pos.Right (cbTitles) + 1 }; - cbUseLabels.Toggled += (s) => SetupTileView (); + cbUseLabels.Toggled += (s, e) => SetupTileView (); workArea = new View { X = 0, diff --git a/UICatalog/Scenarios/Unicode.cs b/UICatalog/Scenarios/Unicode.cs index eb92847bd5..566c0085d3 100644 --- a/UICatalog/Scenarios/Unicode.cs +++ b/UICatalog/Scenarios/Unicode.cs @@ -62,7 +62,7 @@ public override void Setup () Win.Add (label); var checkBox = new CheckBox (gitString) { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50) }; var ckbAllowNull = new CheckBox ("Allow null checked") { X = Pos.Right (checkBox) + 1, Y = Pos.Y (label) }; - ckbAllowNull.Toggled += (e) => checkBox.AllowNullChecked = (bool)!e; + ckbAllowNull.Toggled += (s,e) => checkBox.AllowNullChecked = (bool)!e.OldValue; Win.Add (checkBox, ckbAllowNull); label = new Label ("ComboBox:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 }; diff --git a/UICatalog/Scenarios/Wizards.cs b/UICatalog/Scenarios/Wizards.cs index 1a1be2f075..85c4ee887f 100644 --- a/UICatalog/Scenarios/Wizards.cs +++ b/UICatalog/Scenarios/Wizards.cs @@ -202,7 +202,7 @@ void Top_Loaded (object sender, EventArgs args) }; thirdStep.Add (progLbl, progressBar); thirdStep.Enabled = (bool)thirdStepEnabledCeckBox.Checked; - thirdStepEnabledCeckBox.Toggled += (args) => { + thirdStepEnabledCeckBox.Toggled += (s, e) => { thirdStep.Enabled = (bool)thirdStepEnabledCeckBox.Checked; }; @@ -277,7 +277,7 @@ void Top_Loaded (object sender, EventArgs args) wizard.AddStep (finalFinalStep); finalFinalStep.HelpText = "This step only shows if it was enabled on the other last step."; finalFinalStep.Enabled = (bool)thirdStepEnabledCeckBox.Checked; - finalFinalStepEnabledCeckBox.Toggled += (args) => { + finalFinalStepEnabledCeckBox.Toggled += (s, e) => { finalFinalStep.Enabled = (bool)finalFinalStepEnabledCeckBox.Checked; }; diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index d86e01c209..89f75fe9b9 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -303,9 +303,9 @@ public void Run_All_Views_Tester_Scenario () _curView = CreateClass (_viewClasses.Values.ToArray () [_classListView.SelectedItem]); }; - _computedCheckBox.Toggled += (previousState) => { + _computedCheckBox.Toggled += (s,e) => { if (_curView != null) { - _curView.LayoutStyle = previousState == true ? LayoutStyle.Absolute : LayoutStyle.Computed; + _curView.LayoutStyle = e.OldValue == true ? LayoutStyle.Absolute : LayoutStyle.Computed; _hostPane.LayoutSubviews (); } }; diff --git a/UnitTests/Views/CheckBoxTests.cs b/UnitTests/Views/CheckBoxTests.cs index 847b9f22cc..fdbc1d46a1 100644 --- a/UnitTests/Views/CheckBoxTests.cs +++ b/UnitTests/Views/CheckBoxTests.cs @@ -61,7 +61,7 @@ public void KeyBindings_Command () { var isChecked = false; CheckBox ckb = new CheckBox (); - ckb.Toggled += (e) => isChecked = true; + ckb.Toggled += (s, e) => isChecked = true; Application.Top.Add (ckb); Application.Begin (Application.Top); From fcc75e7147ac20b23b184a21b9f72ed67e65e41d Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 11 Mar 2023 19:46:46 +0000 Subject: [PATCH 13/46] Update View Action events to EventHandler events --- Terminal.Gui/Core/View.cs | 32 +++++++++---------- Terminal.Gui/Views/ScrollBarView.cs | 6 ++-- Terminal.Gui/Views/ScrollView.cs | 4 +-- Terminal.Gui/Windows/Wizard.cs | 6 ++-- UICatalog/Scenarios/ASCIICustomButton.cs | 4 +-- UICatalog/Scenarios/CharacterMap.cs | 2 +- UICatalog/Scenarios/ConfigurationEditor.cs | 2 +- UICatalog/Scenarios/ContextMenus.cs | 2 +- UICatalog/Scenarios/DynamicMenuBar.cs | 4 +-- UICatalog/Scenarios/DynamicStatusBar.cs | 2 +- UICatalog/Scenarios/Editor.cs | 8 ++--- UICatalog/Scenarios/Notepad.cs | 4 +-- UICatalog/Scenarios/TableEditor.cs | 2 +- .../Scenarios/TextAlignmentsAndDirection.cs | 2 +- UICatalog/Scenarios/TreeViewFileSystem.cs | 2 +- UICatalog/Scenarios/Wizards.cs | 2 +- UICatalog/UICatalog.cs | 2 +- UnitTests/Core/ViewTests.cs | 6 ++-- UnitTests/Menus/ContextMenuTests.cs | 2 +- UnitTests/TopLevels/ToplevelTests.cs | 4 +-- UnitTests/Views/AllViewsTests.cs | 8 ++--- UnitTests/Views/ScrollBarViewTests.cs | 4 +-- UnitTests/Views/TextFieldTests.cs | 2 +- 23 files changed, 56 insertions(+), 56 deletions(-) diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index 3147c61ac5..e0796bbe29 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -129,42 +129,42 @@ internal enum Direction { /// /// Event fired when the view gets focus. /// - public event Action Enter; + public event EventHandler Enter; /// /// Event fired when the view looses focus. /// - public event Action Leave; + public event EventHandler Leave; /// /// Event fired when the view receives the mouse event for the first time. /// - public event Action MouseEnter; + public event EventHandler MouseEnter; /// /// Event fired when the view receives a mouse event for the last time. /// - public event Action MouseLeave; + public event EventHandler MouseLeave; /// /// Event fired when a mouse event is generated. /// - public event Action MouseClick; + public event EventHandler MouseClick; /// /// Event fired when the value is being changed. /// - public event Action CanFocusChanged; + public event EventHandler CanFocusChanged; /// /// Event fired when the value is being changed. /// - public event Action EnabledChanged; + public event EventHandler EnabledChanged; /// /// Event fired when the value is being changed. /// - public event Action VisibleChanged; + public event EventHandler VisibleChanged; /// /// Event invoked when the is changed. @@ -1382,7 +1382,7 @@ public virtual void OnRemoved (SuperViewChangedEventArgs e) public override bool OnEnter (View view) { var args = new FocusEventArgs (view); - Enter?.Invoke (args); + Enter?.Invoke (this, args); if (args.Handled) return true; if (base.OnEnter (view)) @@ -1395,7 +1395,7 @@ public override bool OnEnter (View view) public override bool OnLeave (View view) { var args = new FocusEventArgs (view); - Leave?.Invoke (args); + Leave?.Invoke (this, args); if (args.Handled) return true; if (base.OnLeave (view)) @@ -2875,7 +2875,7 @@ public override bool OnMouseEnter (MouseEvent mouseEvent) } var args = new MouseEventArgs (mouseEvent); - MouseEnter?.Invoke (args); + MouseEnter?.Invoke (this, args); return args.Handled || base.OnMouseEnter (mouseEvent); } @@ -2892,7 +2892,7 @@ public override bool OnMouseLeave (MouseEvent mouseEvent) } var args = new MouseEventArgs (mouseEvent); - MouseLeave?.Invoke (args); + MouseLeave?.Invoke (this, args); return args.Handled || base.OnMouseLeave (mouseEvent); } @@ -2938,18 +2938,18 @@ protected bool OnMouseClick (MouseEventArgs args) return true; } - MouseClick?.Invoke (args); + MouseClick?.Invoke (this, args); return args.Handled; } /// - public override void OnCanFocusChanged () => CanFocusChanged?.Invoke (); + public override void OnCanFocusChanged () => CanFocusChanged?.Invoke (this, EventArgs.Empty); /// - public override void OnEnabledChanged () => EnabledChanged?.Invoke (); + public override void OnEnabledChanged () => EnabledChanged?.Invoke (this, EventArgs.Empty); /// - public override void OnVisibleChanged () => VisibleChanged?.Invoke (); + public override void OnVisibleChanged () => VisibleChanged?.Invoke (this, EventArgs.Empty); /// protected override void Dispose (bool disposing) diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index ad0f469f59..6870e08486 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -119,7 +119,7 @@ public ScrollBarView (View host, bool isVertical, bool showBothScrollIndicator = ClearOnVisibleFalse = false; } - private void Host_VisibleChanged () + private void Host_VisibleChanged (object sender, EventArgs e) { if (!Host.Visible) { Visible = Host.Visible; @@ -132,7 +132,7 @@ private void Host_VisibleChanged () } } - private void Host_EnabledChanged () + private void Host_EnabledChanged (object sender, EventArgs e) { Enabled = Host.Enabled; if (otherScrollBarView != null) { @@ -149,7 +149,7 @@ private void Host_EnabledChanged () // } //} - void ContentBottomRightCorner_MouseClick (MouseEventArgs me) + void ContentBottomRightCorner_MouseClick (object sender, MouseEventArgs me) { if (me.MouseEvent.Flags == MouseFlags.WheeledDown || me.MouseEvent.Flags == MouseFlags.WheeledUp || me.MouseEvent.Flags == MouseFlags.WheeledRight || me.MouseEvent.Flags == MouseFlags.WheeledLeft) { diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index 23bfedbce3..659589521b 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -237,14 +237,14 @@ public override void Add (View view) SetNeedsLayout (); } - void View_MouseLeave (MouseEventArgs e) + void View_MouseLeave (object sender, MouseEventArgs e) { if (Application.MouseGrabView != null && Application.MouseGrabView != vertical && Application.MouseGrabView != horizontal) { Application.UngrabMouse (); } } - void View_MouseEnter (MouseEventArgs e) + void View_MouseEnter (object sender, MouseEventArgs e) { Application.GrabMouse (this); } diff --git a/Terminal.Gui/Windows/Wizard.cs b/Terminal.Gui/Windows/Wizard.cs index 7ca438a675..b0ab0ff63a 100644 --- a/Terminal.Gui/Windows/Wizard.cs +++ b/Terminal.Gui/Windows/Wizard.cs @@ -227,7 +227,7 @@ public WizardStep (ustring title) helpTextView.SetNeedsDisplay (); }; - scrollBar.VisibleChanged += () => { + scrollBar.VisibleChanged += (s,e) => { if (scrollBar.Visible && helpTextView.RightOffset == 0) { helpTextView.RightOffset = 1; } else if (!scrollBar.Visible && helpTextView.RightOffset == 1) { @@ -235,7 +235,7 @@ public WizardStep (ustring title) } }; - scrollBar.OtherScrollBarView.VisibleChanged += () => { + scrollBar.OtherScrollBarView.VisibleChanged += (s,e) => { if (scrollBar.OtherScrollBarView.Visible && helpTextView.BottomOffset == 0) { helpTextView.BottomOffset = 1; } else if (!scrollBar.OtherScrollBarView.Visible && helpTextView.BottomOffset == 1) { @@ -590,7 +590,7 @@ public void AddStep (WizardStep newStep) { SizeStep (newStep); - newStep.EnabledChanged += UpdateButtonsAndTitle; + newStep.EnabledChanged += (s,e)=> UpdateButtonsAndTitle(); newStep.TitleChanged += (args) => UpdateButtonsAndTitle (); steps.AddLast (newStep); this.Add (newStep); diff --git a/UICatalog/Scenarios/ASCIICustomButton.cs b/UICatalog/Scenarios/ASCIICustomButton.cs index a58b2200cb..d28acfec5b 100644 --- a/UICatalog/Scenarios/ASCIICustomButton.cs +++ b/UICatalog/Scenarios/ASCIICustomButton.cs @@ -106,7 +106,7 @@ private void CustomInitialize (string id, string text, Pos x, Pos y, int width, Add (border, fill, title); } - private void This_MouseClick (MouseEventArgs obj) + private void This_MouseClick (object sender, MouseEventArgs obj) { OnMouseEvent (obj.MouseEvent); } @@ -258,7 +258,7 @@ private void Button_KeyPress (KeyEventEventArgs obj) } } - private void Button_MouseClick (MouseEventArgs obj) + private void Button_MouseClick (object sender, MouseEventArgs obj) { if (obj.MouseEvent.Flags == MouseFlags.WheeledDown) { scrollView.ContentOffset = new Point (scrollView.ContentOffset.X, diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index 8042022ee1..88aa62cf89 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -280,7 +280,7 @@ private void CharMap_DrawContent (Rect viewport) } ContextMenu _contextMenu = new ContextMenu (); - void Handle_MouseClick (MouseEventArgs args) + void Handle_MouseClick (object sender, MouseEventArgs args) { var me = args.MouseEvent; if (me.Flags == MouseFlags.ReportMousePosition || (me.Flags != MouseFlags.Button1Clicked && diff --git a/UICatalog/Scenarios/ConfigurationEditor.cs b/UICatalog/Scenarios/ConfigurationEditor.cs index 792b8cc0eb..6b29ebd944 100644 --- a/UICatalog/Scenarios/ConfigurationEditor.cs +++ b/UICatalog/Scenarios/ConfigurationEditor.cs @@ -165,7 +165,7 @@ private void Open () textView.Read (); - textView.Enter += (a) => { + textView.Enter += (s,e) => { _lenStatusItem.Title = $"Len:{textView.Text.Length}"; }; diff --git a/UICatalog/Scenarios/ContextMenus.cs b/UICatalog/Scenarios/ContextMenus.cs index 03acd5b262..1e223034fc 100644 --- a/UICatalog/Scenarios/ContextMenus.cs +++ b/UICatalog/Scenarios/ContextMenus.cs @@ -65,7 +65,7 @@ public override void Setup () } }; - Win.MouseClick += (e) => { + Win.MouseClick += (s, e) => { if (e.MouseEvent.Flags == contextMenu.MouseFlags) { ShowContextMenu (e.MouseEvent.X, e.MouseEvent.Y); e.Handled = true; diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs index 30e3929e1f..6f96aee718 100644 --- a/UICatalog/Scenarios/DynamicMenuBar.cs +++ b/UICatalog/Scenarios/DynamicMenuBar.cs @@ -404,7 +404,7 @@ public DynamicMenuBarSample (ustring title) : base (title) SetFrameDetails (menuBarItem); }; - _lstMenus.Enter += (_) => { + _lstMenus.Enter += (s, e) => { var menuBarItem = DataContext.Menus.Count > 0 ? DataContext.Menus [_lstMenus.SelectedItem].MenuItem : null; SetFrameDetails (menuBarItem); }; @@ -423,7 +423,7 @@ public DynamicMenuBarSample (ustring title) : base (title) SelectCurrentMenuBarItem (); }; - _lblMenuBar.Enter += (e) => { + _lblMenuBar.Enter += (s, e) => { if (_menuBar?.Menus != null) { _currentMenuBarItem = _menuBar.Menus [_currentSelectedMenuBar]; SetFrameDetails (_menuBar.Menus [_currentSelectedMenuBar]); diff --git a/UICatalog/Scenarios/DynamicStatusBar.cs b/UICatalog/Scenarios/DynamicStatusBar.cs index a61f366c0c..d76a05b69c 100644 --- a/UICatalog/Scenarios/DynamicStatusBar.cs +++ b/UICatalog/Scenarios/DynamicStatusBar.cs @@ -240,7 +240,7 @@ public DynamicStatusBarSample (ustring title) : base (title) } }; - _lstItems.Enter += (_) => { + _lstItems.Enter += (s, e) => { var statusItem = DataContext.Items.Count > 0 ? DataContext.Items [_lstItems.SelectedItem].StatusItem : null; SetFrameDetails (statusItem); }; diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index 430ed0ffd8..e4941f6b9a 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -144,7 +144,7 @@ public override void Init (ColorScheme colorScheme) _textView.SetNeedsDisplay (); }; - _scrollBar.VisibleChanged += () => { + _scrollBar.VisibleChanged += (s,e) => { if (_scrollBar.Visible && _textView.RightOffset == 0) { _textView.RightOffset = 1; } else if (!_scrollBar.Visible && _textView.RightOffset == 1) { @@ -152,7 +152,7 @@ public override void Init (ColorScheme colorScheme) } }; - _scrollBar.OtherScrollBarView.VisibleChanged += () => { + _scrollBar.OtherScrollBarView.VisibleChanged += (s,e) => { if (_scrollBar.OtherScrollBarView.Visible && _textView.BottomOffset == 0) { _textView.BottomOffset = 1; } else if (!_scrollBar.OtherScrollBarView.Visible && _textView.BottomOffset == 1) { @@ -787,7 +787,7 @@ private View FindTab () Y = Pos.Top (label), Width = 20 }; - txtToFind.Enter += (_) => txtToFind.Text = _textToFind; + txtToFind.Enter += (s, e) => txtToFind.Text = _textToFind; d.Add (txtToFind); var btnFindNext = new Button ("Find _Next") { @@ -879,7 +879,7 @@ private View ReplaceTab () Y = Pos.Top (label), Width = 20 }; - txtToFind.Enter += (_) => txtToFind.Text = _textToFind; + txtToFind.Enter += (s, e) => txtToFind.Text = _textToFind; d.Add (txtToFind); var btnFindNext = new Button ("Replace _Next") { diff --git a/UICatalog/Scenarios/Notepad.cs b/UICatalog/Scenarios/Notepad.cs index 009f0b92b5..46ed509168 100644 --- a/UICatalog/Scenarios/Notepad.cs +++ b/UICatalog/Scenarios/Notepad.cs @@ -67,7 +67,7 @@ public override void Setup () }); focusedTabView = tabView; tabView.SelectedTabChanged += TabView_SelectedTabChanged; - tabView.Enter += (e) => focusedTabView = tabView; + tabView.Enter += (s, e) => focusedTabView = tabView; Application.Top.Add (statusBar); @@ -174,7 +174,7 @@ private TabView CreateNewTabView () tv.TabClicked += TabView_TabClicked; tv.SelectedTabChanged += TabView_SelectedTabChanged; - tv.Enter += (e) => focusedTabView = tv; + tv.Enter += (s, e) => focusedTabView = tv; return tv; } diff --git a/UICatalog/Scenarios/TableEditor.cs b/UICatalog/Scenarios/TableEditor.cs index f34b81da4f..c045eefefb 100644 --- a/UICatalog/Scenarios/TableEditor.cs +++ b/UICatalog/Scenarios/TableEditor.cs @@ -132,7 +132,7 @@ public override void Setup () }; // if user clicks the mouse in TableView - tableView.MouseClick += e => { + tableView.MouseClick += (s,e) => { tableView.ScreenToCell (e.MouseEvent.X, e.MouseEvent.Y, out DataColumn clickedCol); diff --git a/UICatalog/Scenarios/TextAlignmentsAndDirection.cs b/UICatalog/Scenarios/TextAlignmentsAndDirection.cs index 82d263ba1b..2bf02d45e6 100644 --- a/UICatalog/Scenarios/TextAlignmentsAndDirection.cs +++ b/UICatalog/Scenarios/TextAlignmentsAndDirection.cs @@ -109,7 +109,7 @@ public override void Setup () Text = txt }; - editText.MouseClick += (m) => { + editText.MouseClick += (s, m) => { foreach (var v in txts) { v.Text = editText.Text; } diff --git a/UICatalog/Scenarios/TreeViewFileSystem.cs b/UICatalog/Scenarios/TreeViewFileSystem.cs index be72c5bf81..6d45e34d57 100644 --- a/UICatalog/Scenarios/TreeViewFileSystem.cs +++ b/UICatalog/Scenarios/TreeViewFileSystem.cs @@ -129,7 +129,7 @@ private void TreeViewFiles_KeyPress (View.KeyEventEventArgs obj) } } - private void TreeViewFiles_MouseClick (View.MouseEventArgs obj) + private void TreeViewFiles_MouseClick (object sender, View.MouseEventArgs obj) { // if user right clicks if (obj.MouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)) { diff --git a/UICatalog/Scenarios/Wizards.cs b/UICatalog/Scenarios/Wizards.cs index 85c4ee887f..7078dd321f 100644 --- a/UICatalog/Scenarios/Wizards.cs +++ b/UICatalog/Scenarios/Wizards.cs @@ -245,7 +245,7 @@ void Top_Loaded (object sender, EventArgs args) someText.SetNeedsDisplay (); }; - scrollBar.VisibleChanged += () => { + scrollBar.VisibleChanged += (s, e) => { if (scrollBar.Visible && someText.RightOffset == 0) { someText.RightOffset = 1; } else if (!scrollBar.Visible && someText.RightOffset == 1) { diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 8f72ca7a61..52e152147f 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -369,7 +369,7 @@ void LoadedHandler (object sender, EventArgs args) ScenarioListView.SetFocus (); } - StatusBar.VisibleChanged += () => { + StatusBar.VisibleChanged += (s, e) => { UICatalogApp.ShowStatusBar = StatusBar.Visible; var height = (StatusBar.Visible ? 1 : 0);// + (MenuBar.Visible ? 1 : 0); diff --git a/UnitTests/Core/ViewTests.cs b/UnitTests/Core/ViewTests.cs index 3128bea484..be32cee2c0 100644 --- a/UnitTests/Core/ViewTests.cs +++ b/UnitTests/Core/ViewTests.cs @@ -2441,15 +2441,15 @@ public void SetHasFocus_Do_Not_Throws_If_OnLeave_Remove_Focused_Changing_To_Null var view1 = new View { CanFocus = true }; var subView1 = new View { CanFocus = true }; var subView1subView1 = new View { CanFocus = true }; - view1.Leave += (e) => { + view1.Leave += (s,e) => { view1Leave = true; }; - subView1.Leave += (e) => { + subView1.Leave += (s,e) => { subView1.Remove (subView1subView1); subView1Leave = true; }; view1.Add (subView1); - subView1subView1.Leave += (e) => { + subView1subView1.Leave += (s,e) => { // This is never invoked subView1subView1Leave = true; }; diff --git a/UnitTests/Menus/ContextMenuTests.cs b/UnitTests/Menus/ContextMenuTests.cs index 4e21849986..314993794a 100644 --- a/UnitTests/Menus/ContextMenuTests.cs +++ b/UnitTests/Menus/ContextMenuTests.cs @@ -202,7 +202,7 @@ public void MouseFlags_Changing () var cm = new ContextMenu (); - lbl.MouseClick += (e) => { + lbl.MouseClick += (s, e) => { if (e.MouseEvent.Flags == cm.MouseFlags) { lbl.Text = "Replaced"; e.Handled = true; diff --git a/UnitTests/TopLevels/ToplevelTests.cs b/UnitTests/TopLevels/ToplevelTests.cs index a42b732d49..691c906305 100644 --- a/UnitTests/TopLevels/ToplevelTests.cs +++ b/UnitTests/TopLevels/ToplevelTests.cs @@ -983,8 +983,8 @@ public void OnEnter_OnLeave_Triggered_On_Application_Begin_End () var isEnter = false; var isLeave = false; var v = new View (); - v.Enter += (_) => isEnter = true; - v.Leave += (_) => isLeave = true; + v.Enter += (s, _) => isEnter = true; + v.Leave += (s, _) => isLeave = true; var top = Application.Top; top.Add (v); diff --git a/UnitTests/Views/AllViewsTests.cs b/UnitTests/Views/AllViewsTests.cs index 24721e2701..b47d37dc36 100644 --- a/UnitTests/Views/AllViewsTests.cs +++ b/UnitTests/Views/AllViewsTests.cs @@ -152,10 +152,10 @@ public void AllViews_Enter_Leave_Events () var viewEnter = 0; var viewLeave = 0; - vType.Enter += _ => vTypeEnter++; - vType.Leave += _ => vTypeLeave++; - view.Enter += _ => viewEnter++; - view.Leave += _ => viewLeave++; + vType.Enter += (s,e) => vTypeEnter++; + vType.Leave += (s, e) => vTypeLeave++; + view.Enter += (s, e) => viewEnter++; + view.Leave += (s, e) => viewLeave++; top.Add (vType, view); Application.Begin (top); diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 5f3a3be72b..d5526c1a69 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -668,7 +668,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible () textView.SetNeedsDisplay (); }; - scrollBar.VisibleChanged += () => { + scrollBar.VisibleChanged += (s,e) => { if (scrollBar.Visible && textView.RightOffset == 0) { textView.RightOffset = 1; } else if (!scrollBar.Visible && textView.RightOffset == 1) { @@ -676,7 +676,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible () } }; - scrollBar.OtherScrollBarView.VisibleChanged += () => { + scrollBar.OtherScrollBarView.VisibleChanged += (s,e) => { if (scrollBar.OtherScrollBarView.Visible && textView.BottomOffset == 0) { textView.BottomOffset = 1; } else if (!scrollBar.OtherScrollBarView.Visible && textView.BottomOffset == 1) { diff --git a/UnitTests/Views/TextFieldTests.cs b/UnitTests/Views/TextFieldTests.cs index 1c0ddb34e6..531b35120b 100644 --- a/UnitTests/Views/TextFieldTests.cs +++ b/UnitTests/Views/TextFieldTests.cs @@ -1235,7 +1235,7 @@ public void Test_RootMouseKeyEvent_Cancel () var tf = new TextField () { Width = 10 }; int clickCounter = 0; - tf.MouseClick += (m) => { clickCounter++; }; + tf.MouseClick += (s, m) => { clickCounter++; }; Application.Top.Add (tf); Application.Begin (Application.Top); From 43f67a63871247405c4691a1d9b27f069ef9f8f7 Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 11 Mar 2023 19:55:08 +0000 Subject: [PATCH 14/46] Convert more Actions to EventHandlers in View --- Terminal.Gui/Core/View.cs | 32 ++++++++--------- Terminal.Gui/Views/ComboBox.cs | 2 +- Terminal.Gui/Windows/Dialog.cs | 2 +- Terminal.Gui/Windows/FileDialog.cs | 2 +- UICatalog/KeyBindingsDialog.cs | 2 +- UICatalog/Scenarios/ASCIICustomButton.cs | 2 +- UICatalog/Scenarios/AllViewsTester.cs | 2 +- .../Scenarios/AutoSizeAndDirectionText.cs | 2 +- .../Scenarios/BackgroundWorkerCollection.cs | 4 +-- UICatalog/Scenarios/CharacterMap.cs | 2 +- UICatalog/Scenarios/ComputedLayout.cs | 2 +- UICatalog/Scenarios/ContextMenus.cs | 2 +- UICatalog/Scenarios/CsvEditor.cs | 2 +- UICatalog/Scenarios/DynamicMenuBar.cs | 4 +-- UICatalog/Scenarios/DynamicStatusBar.cs | 4 +-- UICatalog/Scenarios/Editor.cs | 2 +- UICatalog/Scenarios/InteractiveTree.cs | 2 +- UICatalog/Scenarios/Keys.cs | 8 ++--- UICatalog/Scenarios/Notepad.cs | 2 +- UICatalog/Scenarios/SendKeys.cs | 4 +-- UICatalog/Scenarios/SingleBackgroundWorker.cs | 2 +- UICatalog/Scenarios/TableEditor.cs | 2 +- .../Scenarios/TextAlignmentsAndDirection.cs | 2 +- .../Scenarios/TextViewAutocompletePopup.cs | 2 +- UICatalog/Scenarios/TreeViewFileSystem.cs | 2 +- UICatalog/Scenarios/VkeyPacketSimulator.cs | 12 +++---- UICatalog/UICatalog.cs | 2 +- UnitTests/Application/ApplicationTests.cs | 2 +- UnitTests/Core/ViewTests.cs | 34 +++++++++---------- UnitTests/Drivers/ConsoleDriverTests.cs | 6 ++-- UnitTests/Menus/ContextMenuTests.cs | 2 +- UnitTests/TopLevels/ToplevelTests.cs | 2 +- UnitTests/Types/DimTests.cs | 8 ++--- UnitTests/Types/PosTests.cs | 4 +-- UnitTests/UICatalog/ScenarioTests.cs | 4 +-- 35 files changed, 85 insertions(+), 85 deletions(-) diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index e0796bbe29..fa67b1c52d 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -1713,7 +1713,7 @@ public class KeyEventEventArgs : EventArgs { /// /// Invoked when a character key is pressed and occurs after the key up event. /// - public event Action KeyPress; + public event EventHandler KeyPress; /// public override bool ProcessKey (KeyEvent keyEvent) @@ -1723,11 +1723,11 @@ public override bool ProcessKey (KeyEvent keyEvent) } var args = new KeyEventEventArgs (keyEvent); - KeyPress?.Invoke (args); + KeyPress?.Invoke (this, args); if (args.Handled) return true; if (Focused?.Enabled == true) { - Focused?.KeyPress?.Invoke (args); + Focused?.KeyPress?.Invoke (this, args); if (args.Handled) return true; } @@ -1899,7 +1899,7 @@ public override bool ProcessHotKey (KeyEvent keyEvent) var args = new KeyEventEventArgs (keyEvent); if (MostFocused?.Enabled == true) { - MostFocused?.KeyPress?.Invoke (args); + MostFocused?.KeyPress?.Invoke (this, args); if (args.Handled) return true; } @@ -1922,11 +1922,11 @@ public override bool ProcessColdKey (KeyEvent keyEvent) } var args = new KeyEventEventArgs (keyEvent); - KeyPress?.Invoke (args); + KeyPress?.Invoke (this, args); if (args.Handled) return true; if (MostFocused?.Enabled == true) { - MostFocused?.KeyPress?.Invoke (args); + MostFocused?.KeyPress?.Invoke (this, args); if (args.Handled) return true; } @@ -1944,7 +1944,7 @@ public override bool ProcessColdKey (KeyEvent keyEvent) /// /// Invoked when a key is pressed. /// - public event Action KeyDown; + public event EventHandler KeyDown; /// public override bool OnKeyDown (KeyEvent keyEvent) @@ -1954,12 +1954,12 @@ public override bool OnKeyDown (KeyEvent keyEvent) } var args = new KeyEventEventArgs (keyEvent); - KeyDown?.Invoke (args); + KeyDown?.Invoke (this, args); if (args.Handled) { return true; } if (Focused?.Enabled == true) { - Focused.KeyDown?.Invoke (args); + Focused.KeyDown?.Invoke (this, args); if (args.Handled) { return true; } @@ -1974,7 +1974,7 @@ public override bool OnKeyDown (KeyEvent keyEvent) /// /// Invoked when a key is released. /// - public event Action KeyUp; + public event EventHandler KeyUp; /// public override bool OnKeyUp (KeyEvent keyEvent) @@ -1984,12 +1984,12 @@ public override bool OnKeyUp (KeyEvent keyEvent) } var args = new KeyEventEventArgs (keyEvent); - KeyUp?.Invoke (args); + KeyUp?.Invoke (this, args); if (args.Handled) { return true; } if (Focused?.Enabled == true) { - Focused.KeyUp?.Invoke (args); + Focused.KeyUp?.Invoke (this, args); if (args.Handled) { return true; } @@ -2295,14 +2295,14 @@ public class LayoutEventArgs : EventArgs { /// /// Subscribe to this event to perform tasks when the has been resized or the layout has otherwise changed. /// - public event Action LayoutStarted; + public event EventHandler LayoutStarted; /// /// Raises the event. Called from before any subviews have been laid out. /// internal virtual void OnLayoutStarted (LayoutEventArgs args) { - LayoutStarted?.Invoke (args); + LayoutStarted?.Invoke (this, args); } /// @@ -2311,7 +2311,7 @@ internal virtual void OnLayoutStarted (LayoutEventArgs args) /// /// Subscribe to this event to perform tasks when the has been resized or the layout has otherwise changed. /// - public event Action LayoutComplete; + public event EventHandler LayoutComplete; /// /// Event called only once when the is being initialized for the first time. @@ -2325,7 +2325,7 @@ internal virtual void OnLayoutStarted (LayoutEventArgs args) /// internal virtual void OnLayoutComplete (LayoutEventArgs args) { - LayoutComplete?.Invoke (args); + LayoutComplete?.Invoke (this, args); } internal void CollectPos (Pos pos, View from, ref HashSet nNodes, ref HashSet<(View, View)> nEdges) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 4f015c1f49..9bc6a80eca 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -299,7 +299,7 @@ private void Initialize () this.Add (search, listview); // On resize - LayoutComplete += (LayoutEventArgs a) => { + LayoutComplete += (object sender, LayoutEventArgs a) => { if ((!autoHide && Bounds.Width > 0 && search.Frame.Width != Bounds.Width) || (autoHide && Bounds.Width > 0 && search.Frame.Width != Bounds.Width - 1)) { search.Width = listview.Width = autoHide ? Bounds.Width - 1 : Bounds.Width; diff --git a/Terminal.Gui/Windows/Dialog.cs b/Terminal.Gui/Windows/Dialog.cs index f1ff80a69c..64205357e4 100644 --- a/Terminal.Gui/Windows/Dialog.cs +++ b/Terminal.Gui/Windows/Dialog.cs @@ -88,7 +88,7 @@ public Dialog (ustring title, int width, int height, params Button [] buttons) : } } - LayoutStarted += (args) => { + LayoutStarted += (s, args) => { LayoutStartedHandler (); }; } diff --git a/Terminal.Gui/Windows/FileDialog.cs b/Terminal.Gui/Windows/FileDialog.cs index c2d20f3f12..6eee497fb2 100644 --- a/Terminal.Gui/Windows/FileDialog.cs +++ b/Terminal.Gui/Windows/FileDialog.cs @@ -745,7 +745,7 @@ public FileDialog (ustring title, ustring prompt, ustring nameDirLabel, ustring // On success, we will set this to false. canceled = true; - KeyPress += (e) => { + KeyPress += (s, e) => { if (e.KeyEvent.Key == Key.Esc) { Cancel (); e.Handled = true; diff --git a/UICatalog/KeyBindingsDialog.cs b/UICatalog/KeyBindingsDialog.cs index ac46bbdb7e..5bcb5611c1 100644 --- a/UICatalog/KeyBindingsDialog.cs +++ b/UICatalog/KeyBindingsDialog.cs @@ -179,7 +179,7 @@ private void RemapKey () // prompt user to hit a key var dlg = new Dialog ("Enter Key"); - dlg.KeyPress += (k) => { + dlg.KeyPress += (s, k) => { key = k.KeyEvent.Key; Application.RequestStop (); }; diff --git a/UICatalog/Scenarios/ASCIICustomButton.cs b/UICatalog/Scenarios/ASCIICustomButton.cs index d28acfec5b..802709f632 100644 --- a/UICatalog/Scenarios/ASCIICustomButton.cs +++ b/UICatalog/Scenarios/ASCIICustomButton.cs @@ -230,7 +230,7 @@ public ScrollViewTestWindow () } } - private void Button_KeyPress (KeyEventEventArgs obj) + private void Button_KeyPress (object sender, KeyEventEventArgs obj) { switch (obj.KeyEvent.Key) { case Key.End: diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index ddfa05bb8e..4387a8d9be 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -424,7 +424,7 @@ View CreateClass (Type type) return view; } - void LayoutCompleteHandler (View.LayoutEventArgs args) + void LayoutCompleteHandler (object sender, View.LayoutEventArgs args) { UpdateTitle (_curView); } diff --git a/UICatalog/Scenarios/AutoSizeAndDirectionText.cs b/UICatalog/Scenarios/AutoSizeAndDirectionText.cs index af43bcde9f..e4737f70d1 100644 --- a/UICatalog/Scenarios/AutoSizeAndDirectionText.cs +++ b/UICatalog/Scenarios/AutoSizeAndDirectionText.cs @@ -90,7 +90,7 @@ public override void Setup () }; Win.Add (ckbWideText); - Win.KeyUp += (_) => + Win.KeyUp += (s,e) => labelH.Text = labelV.Text = text = editText.Text.ToString (); } } diff --git a/UICatalog/Scenarios/BackgroundWorkerCollection.cs b/UICatalog/Scenarios/BackgroundWorkerCollection.cs index 201bb3b63b..d2448e1562 100644 --- a/UICatalog/Scenarios/BackgroundWorkerCollection.cs +++ b/UICatalog/Scenarios/BackgroundWorkerCollection.cs @@ -338,13 +338,13 @@ public StagingUIController () close.Clicked += OnReportClosed; Add (close); - KeyPress += (e) => { + KeyPress += (s, e) => { if (e.KeyEvent.Key == Key.Esc) { OnReportClosed (); } }; - LayoutStarted += (_) => { + LayoutStarted += (s,e) => { var btnsWidth = start.Bounds.Width + close.Bounds.Width + 2 - 1; var shiftLeft = Math.Max ((Bounds.Width - btnsWidth) / 2 - 2, 0); diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index 88aa62cf89..0018d825f3 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -157,7 +157,7 @@ public CharMap () ContentSize = new Size (CharMap.RowWidth, (int)(MaxCodePointVal / 16 + 1)); ShowVerticalScrollIndicator = true; ShowHorizontalScrollIndicator = false; - LayoutComplete += (args) => { + LayoutComplete += (s, args) => { if (Bounds.Width < RowWidth) { ShowHorizontalScrollIndicator = true; } else { diff --git a/UICatalog/Scenarios/ComputedLayout.cs b/UICatalog/Scenarios/ComputedLayout.cs index c0954375fa..9427cad847 100644 --- a/UICatalog/Scenarios/ComputedLayout.cs +++ b/UICatalog/Scenarios/ComputedLayout.cs @@ -49,7 +49,7 @@ public override void Setup () ColorScheme = Colors.Error }; - Application.Top.LayoutComplete += (a) => { + Application.Top.LayoutComplete += (s, a) => { horizontalRuler.Text = rule.Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)]; verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height*2)]; }; diff --git a/UICatalog/Scenarios/ContextMenus.cs b/UICatalog/Scenarios/ContextMenus.cs index 1e223034fc..3026ba43ef 100644 --- a/UICatalog/Scenarios/ContextMenus.cs +++ b/UICatalog/Scenarios/ContextMenus.cs @@ -58,7 +58,7 @@ public override void Setup () Point mousePos = default; - Win.KeyPress += (e) => { + Win.KeyPress += (s, e) => { if (e.KeyEvent.Key == (Key.Space | Key.CtrlMask)) { ShowContextMenu (mousePos.X, mousePos.Y); e.Handled = true; diff --git a/UICatalog/Scenarios/CsvEditor.cs b/UICatalog/Scenarios/CsvEditor.cs index 6bdb8554bd..17eb9a873f 100644 --- a/UICatalog/Scenarios/CsvEditor.cs +++ b/UICatalog/Scenarios/CsvEditor.cs @@ -472,7 +472,7 @@ private void SetupScrollBar () } - private void TableViewKeyPress (View.KeyEventEventArgs e) + private void TableViewKeyPress (object sender, View.KeyEventEventArgs e) { if (e.KeyEvent.Key == Key.DeleteChar) { diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs index 6f96aee718..b03dd24f4b 100644 --- a/UICatalog/Scenarios/DynamicMenuBar.cs +++ b/UICatalog/Scenarios/DynamicMenuBar.cs @@ -729,7 +729,7 @@ public DynamicMenuBarDetails (ustring title) : base (title) Width = Dim.Fill (), ReadOnly = true }; - _txtShortcut.KeyDown += (e) => { + _txtShortcut.KeyDown += (s, e) => { if (!ProcessKey (e.KeyEvent)) { return; } @@ -772,7 +772,7 @@ bool CheckShortcut (Key k, bool pre) return true; } - _txtShortcut.KeyUp += (e) => { + _txtShortcut.KeyUp += (s, e) => { var k = ShortcutHelper.GetModifiersKey (e.KeyEvent); if (CheckShortcut (k, false)) { e.Handled = true; diff --git a/UICatalog/Scenarios/DynamicStatusBar.cs b/UICatalog/Scenarios/DynamicStatusBar.cs index d76a05b69c..7da6352b73 100644 --- a/UICatalog/Scenarios/DynamicStatusBar.cs +++ b/UICatalog/Scenarios/DynamicStatusBar.cs @@ -401,7 +401,7 @@ public DynamicStatusBarDetails (ustring title) : base (title) Width = Dim.Fill (), ReadOnly = true }; - _txtShortcut.KeyDown += (e) => { + _txtShortcut.KeyDown += (s, e) => { if (!ProcessKey (e.KeyEvent)) { return; } @@ -445,7 +445,7 @@ bool CheckShortcut (Key k, bool pre) return true; } - _txtShortcut.KeyUp += (e) => { + _txtShortcut.KeyUp += (s, e) => { var k = ShortcutHelper.GetModifiersKey (e.KeyEvent); if (CheckShortcut (k, false)) { e.Handled = true; diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index e4941f6b9a..3cf2376e78 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -171,7 +171,7 @@ public override void Init (ColorScheme colorScheme) _scrollBar.Refresh (); }; - Win.KeyPress += (e) => { + Win.KeyPress += (s, e) => { var keys = ShortcutHelper.GetModifiersKey (e.KeyEvent); if (_winDialog != null && (e.KeyEvent.Key == Key.Esc || e.KeyEvent.Key == (Key.Q | Key.CtrlMask))) { diff --git a/UICatalog/Scenarios/InteractiveTree.cs b/UICatalog/Scenarios/InteractiveTree.cs index f51f102381..a8da38ca21 100644 --- a/UICatalog/Scenarios/InteractiveTree.cs +++ b/UICatalog/Scenarios/InteractiveTree.cs @@ -49,7 +49,7 @@ public override void Setup () } - private void TreeView_KeyPress (View.KeyEventEventArgs obj) + private void TreeView_KeyPress (object sender, View.KeyEventEventArgs obj) { if (obj.KeyEvent.Key == Key.DeleteChar) { diff --git a/UICatalog/Scenarios/Keys.cs b/UICatalog/Scenarios/Keys.cs index 21b567f6d6..3278b146d4 100644 --- a/UICatalog/Scenarios/Keys.cs +++ b/UICatalog/Scenarios/Keys.cs @@ -92,7 +92,7 @@ public override void Setup () }; Win.Add (labelKeypress); - Win.KeyPress += (a) => labelKeypress.Text = a.KeyEvent.ToString (); + Win.KeyPress += (s,e) => labelKeypress.Text = e.KeyEvent.ToString (); // Key stroke log: var keyLogLabel = new Label ("Key stroke log:") { @@ -169,9 +169,9 @@ public override void Setup () Height = Dim.Fill (), }; - Win.KeyDown += (a) => KeyDownPressUp (a.KeyEvent, "Down"); - Win.KeyPress += (a) => KeyDownPressUp (a.KeyEvent, "Press"); - Win.KeyUp += (a) => KeyDownPressUp (a.KeyEvent, "Up"); + Win.KeyDown += (s,a) => KeyDownPressUp (a.KeyEvent, "Down"); + Win.KeyPress += (s, a) => KeyDownPressUp (a.KeyEvent, "Press"); + Win.KeyUp += (s, a) => KeyDownPressUp (a.KeyEvent, "Up"); void KeyDownPressUp (KeyEvent keyEvent, string updown) { diff --git a/UICatalog/Scenarios/Notepad.cs b/UICatalog/Scenarios/Notepad.cs index 46ed509168..5fc6edbed0 100644 --- a/UICatalog/Scenarios/Notepad.cs +++ b/UICatalog/Scenarios/Notepad.cs @@ -352,7 +352,7 @@ private void RegisterTextViewEvents (TabView parent) { var textView = (TextView)View; // when user makes changes rename tab to indicate unsaved - textView.KeyUp += (k) => { + textView.KeyUp += (s, k) => { // if current text doesn't match saved text var areDiff = this.UnsavedChanges; diff --git a/UICatalog/Scenarios/SendKeys.cs b/UICatalog/Scenarios/SendKeys.cs index b38076cc74..0359c7d179 100644 --- a/UICatalog/Scenarios/SendKeys.cs +++ b/UICatalog/Scenarios/SendKeys.cs @@ -57,7 +57,7 @@ public override void Setup () var IsAlt = false; var IsCtrl = false; - txtResult.KeyPress += (e) => { + txtResult.KeyPress += (s, e) => { rKeys += (char)e.KeyEvent.Key; if (!IsShift && e.KeyEvent.IsShift) { rControlKeys += " Shift "; @@ -116,7 +116,7 @@ void ProcessInput () button.Clicked += () => ProcessInput (); - Win.KeyPress += (e) => { + Win.KeyPress += (s, e) => { if (e.KeyEvent.Key == Key.Enter) { ProcessInput (); e.Handled = true; diff --git a/UICatalog/Scenarios/SingleBackgroundWorker.cs b/UICatalog/Scenarios/SingleBackgroundWorker.cs index e0268ab419..352f608b42 100644 --- a/UICatalog/Scenarios/SingleBackgroundWorker.cs +++ b/UICatalog/Scenarios/SingleBackgroundWorker.cs @@ -133,7 +133,7 @@ public class StagingUIController : Window { public StagingUIController (DateTime? start, List list) { top = new Toplevel (Application.Top.Frame); - top.KeyPress += (e) => { + top.KeyPress += (s,e) => { // Prevents Ctrl+Q from closing this. // Only Ctrl+C is allowed. if (e.KeyEvent.Key == (Key.Q | Key.CtrlMask)) { diff --git a/UICatalog/Scenarios/TableEditor.cs b/UICatalog/Scenarios/TableEditor.cs index c045eefefb..b9b1e168b3 100644 --- a/UICatalog/Scenarios/TableEditor.cs +++ b/UICatalog/Scenarios/TableEditor.cs @@ -345,7 +345,7 @@ private void SetupScrollBar () } - private void TableViewKeyPress (View.KeyEventEventArgs e) + private void TableViewKeyPress (object sender, View.KeyEventEventArgs e) { if (e.KeyEvent.Key == Key.DeleteChar) { diff --git a/UICatalog/Scenarios/TextAlignmentsAndDirection.cs b/UICatalog/Scenarios/TextAlignmentsAndDirection.cs index 2bf02d45e6..a78a4e9b8b 100644 --- a/UICatalog/Scenarios/TextAlignmentsAndDirection.cs +++ b/UICatalog/Scenarios/TextAlignmentsAndDirection.cs @@ -118,7 +118,7 @@ public override void Setup () } }; - Win.KeyUp += (m) => { + Win.KeyUp += (s, m) => { foreach (var v in txts) { v.Text = editText.Text; } diff --git a/UICatalog/Scenarios/TextViewAutocompletePopup.cs b/UICatalog/Scenarios/TextViewAutocompletePopup.cs index cf740e7124..e37019cd9c 100644 --- a/UICatalog/Scenarios/TextViewAutocompletePopup.cs +++ b/UICatalog/Scenarios/TextViewAutocompletePopup.cs @@ -94,7 +94,7 @@ public override void Setup () Win.LayoutStarted += Win_LayoutStarted; } - private void Win_LayoutStarted (View.LayoutEventArgs obj) + private void Win_LayoutStarted (object sender, View.LayoutEventArgs obj) { miMultiline.Checked = textViewTopLeft.Multiline; miWrap.Checked = textViewTopLeft.WordWrap; diff --git a/UICatalog/Scenarios/TreeViewFileSystem.cs b/UICatalog/Scenarios/TreeViewFileSystem.cs index 6d45e34d57..56fcc7d4dc 100644 --- a/UICatalog/Scenarios/TreeViewFileSystem.cs +++ b/UICatalog/Scenarios/TreeViewFileSystem.cs @@ -106,7 +106,7 @@ private void TreeViewFiles_SelectionChanged (object sender, SelectionChangedEven ShowPropertiesOf (e.NewValue); } - private void TreeViewFiles_KeyPress (View.KeyEventEventArgs obj) + private void TreeViewFiles_KeyPress (object sender, View.KeyEventEventArgs obj) { if (obj.KeyEvent.Key == (Key.R | Key.CtrlMask)) { diff --git a/UICatalog/Scenarios/VkeyPacketSimulator.cs b/UICatalog/Scenarios/VkeyPacketSimulator.cs index ff587e0422..d9a8f3ffa5 100644 --- a/UICatalog/Scenarios/VkeyPacketSimulator.cs +++ b/UICatalog/Scenarios/VkeyPacketSimulator.cs @@ -88,7 +88,7 @@ public override void Setup () ReadOnly = true }; - tvOutput.KeyDown += (e) => { + tvOutput.KeyDown += (s, e) => { //System.Diagnostics.Debug.WriteLine ($"Output - KeyDown: {e.KeyEvent.Key}"); e.Handled = true; if (e.KeyEvent.Key == Key.Unknown) { @@ -96,7 +96,7 @@ public override void Setup () } }; - tvOutput.KeyPress += (e) => { + tvOutput.KeyPress += (s, e) => { //System.Diagnostics.Debug.WriteLine ($"Output - KeyPress - _keyboardStrokes: {_keyboardStrokes.Count}"); if (_outputStarted && _keyboardStrokes.Count > 0) { var ev = ShortcutHelper.GetModifiersKey (e.KeyEvent); @@ -114,7 +114,7 @@ public override void Setup () Win.Add (tvOutput); - tvInput.KeyDown += (e) => { + tvInput.KeyDown += (s, e) => { //System.Diagnostics.Debug.WriteLine ($"Input - KeyDown: {e.KeyEvent.Key}"); e.Handled = true; if (e.KeyEvent.Key == Key.Unknown) { @@ -124,7 +124,7 @@ public override void Setup () View.KeyEventEventArgs unknownChar = null; - tvInput.KeyPress += (e) => { + tvInput.KeyPress += (s, e) => { if (e.KeyEvent.Key == (Key.Q | Key.CtrlMask)) { Application.RequestStop (); return; @@ -152,7 +152,7 @@ public override void Setup () //System.Diagnostics.Debug.WriteLine ($"Input - KeyPress - _keyboardStrokes: {_keyboardStrokes.Count}"); }; - tvInput.KeyUp += (e) => { + tvInput.KeyUp += (s, e) => { //System.Diagnostics.Debug.WriteLine ($"Input - KeyUp: {e.KeyEvent.Key}"); //var ke = e.KeyEvent; var ke = ShortcutHelper.GetModifiersKey (e.KeyEvent); @@ -221,7 +221,7 @@ public override void Setup () tvInput.SetFocus (); - Win.LayoutComplete += (_) => { + Win.LayoutComplete += (s, e) => { inputHorizontalRuler.Text = outputHorizontalRuler.Text = ruler.Repeat ((int)Math.Ceiling ((double)(inputHorizontalRuler.Bounds.Width) / (double)ruler.Length)) [0..(inputHorizontalRuler.Bounds.Width)]; inputVerticalRuler.Height = tvInput.Frame.Height + 1; inputVerticalRuler.Text = ruler.Repeat ((int)Math.Ceiling ((double)(inputVerticalRuler.Bounds.Height) / (double)ruler.Length)) [0..(inputVerticalRuler.Bounds.Height)]; diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 52e152147f..b4977eab62 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -651,7 +651,7 @@ public void ConfigChanged () Application.Top.SetNeedsDisplay (); } - void KeyDownHandler (View.KeyEventEventArgs a) + void KeyDownHandler (object sender, View.KeyEventEventArgs a) { if (a.KeyEvent.IsCapslock) { Capslock.Title = "Caps: On"; diff --git a/UnitTests/Application/ApplicationTests.cs b/UnitTests/Application/ApplicationTests.cs index e2433beb18..ad73e43ea6 100644 --- a/UnitTests/Application/ApplicationTests.cs +++ b/UnitTests/Application/ApplicationTests.cs @@ -582,7 +582,7 @@ public void KeyUp_Event () int keyUps = 0; var output = string.Empty; - Application.Top.KeyUp += (View.KeyEventEventArgs args) => { + Application.Top.KeyUp += (object sender, View.KeyEventEventArgs args) => { if (args.KeyEvent.Key != (Key.CtrlMask | Key.Q)) { output += (char)args.KeyEvent.KeyValue; } diff --git a/UnitTests/Core/ViewTests.cs b/UnitTests/Core/ViewTests.cs index be32cee2c0..89afa229f3 100644 --- a/UnitTests/Core/ViewTests.cs +++ b/UnitTests/Core/ViewTests.cs @@ -1134,7 +1134,7 @@ public void KeyPress_Handled_To_True_Prevents_Changes () var top = Application.Top; var text = new TextField (""); - text.KeyPress += (e) => { + text.KeyPress += (s, e) => { e.Handled = true; Assert.True (e.Handled); Assert.Equal (Key.N, e.KeyEvent.Key); @@ -1232,10 +1232,10 @@ public void Internal_Tests () Assert.Equal (80, view.Bounds.Width); Assert.Equal (25, view.Bounds.Height); bool layoutStarted = false; - view.LayoutStarted += (_) => layoutStarted = true; + view.LayoutStarted += (s,e) => layoutStarted = true; view.OnLayoutStarted (null); Assert.True (layoutStarted); - view.LayoutComplete += (_) => layoutStarted = false; + view.LayoutComplete += (s,e) => layoutStarted = false; view.OnLayoutComplete (null); Assert.False (layoutStarted); view.X = Pos.Center () - 41; @@ -1539,7 +1539,7 @@ public void ProcessHotKey_Will_Invoke_ProcessKey_Only_For_The_MostFocused_With_T var tf = new TextField (); tf.KeyPress += Tf_KeyPress; - void Tf_KeyPress (View.KeyEventEventArgs obj) + void Tf_KeyPress (object sender, View.KeyEventEventArgs obj) { if (obj.KeyEvent.Key == (Key.Q | Key.CtrlMask)) { obj.Handled = tfQuiting = true; @@ -1551,7 +1551,7 @@ void Tf_KeyPress (View.KeyEventEventArgs obj) var top = Application.Top; top.KeyPress += Top_KeyPress; - void Top_KeyPress (View.KeyEventEventArgs obj) + void Top_KeyPress (object sender, View.KeyEventEventArgs obj) { if (obj.KeyEvent.Key == (Key.Q | Key.CtrlMask)) { obj.Handled = topQuiting = true; @@ -1599,7 +1599,7 @@ public void ProcessHotKey_Will_Invoke_ProcessKey_Only_For_The_MostFocused_Withou var tf = new TextField (); tf.KeyPress += Tf_KeyPress; - void Tf_KeyPress (View.KeyEventEventArgs obj) + void Tf_KeyPress (object sender, View.KeyEventEventArgs obj) { if (obj.KeyEvent.Key == (Key.Q | Key.CtrlMask)) { obj.Handled = tfQuiting = true; @@ -2287,21 +2287,21 @@ public void KeyDown_And_KeyUp_Events_Must_Called_Before_OnKeyDown_And_OnKeyUp () var keyUp = false; var view = new DerivedView (); - view.KeyDown += (e) => { + view.KeyDown += (s, e) => { Assert.Equal (Key.a, e.KeyEvent.Key); Assert.False (keyDown); Assert.False (view.IsKeyDown); e.Handled = true; keyDown = true; }; - view.KeyPress += (e) => { + view.KeyPress += (s,e) => { Assert.Equal (Key.a, e.KeyEvent.Key); Assert.False (keyPress); Assert.False (view.IsKeyPress); e.Handled = true; keyPress = true; }; - view.KeyUp += (e) => { + view.KeyUp += (s, e) => { Assert.Equal (Key.a, e.KeyEvent.Key); Assert.False (keyUp); Assert.False (view.IsKeyUp); @@ -2390,7 +2390,7 @@ public void KeyDown_And_KeyUp_Events_With_Only_Key_Modifiers (bool shift, bool a var keyUp = false; var view = new DerivedView (); - view.KeyDown += (e) => { + view.KeyDown += (s,e) => { Assert.Equal (-1, e.KeyEvent.KeyValue); Assert.Equal (shift, e.KeyEvent.IsShift); Assert.Equal (alt, e.KeyEvent.IsAlt); @@ -2399,10 +2399,10 @@ public void KeyDown_And_KeyUp_Events_With_Only_Key_Modifiers (bool shift, bool a Assert.False (view.IsKeyDown); keyDown = true; }; - view.KeyPress += (e) => { + view.KeyPress += (s, e) => { keyPress = true; }; - view.KeyUp += (e) => { + view.KeyUp += (s, e) => { Assert.Equal (-1, e.KeyEvent.KeyValue); Assert.Equal (shift, e.KeyEvent.IsShift); Assert.Equal (alt, e.KeyEvent.IsAlt); @@ -2908,15 +2908,15 @@ public void Frame_Set_After_Initialze_Update_NeededDisplay () Assert.Equal (new Rect (0, 0, 30, 1), label.NeedDisplay); Assert.Equal (new Rect (0, 0, 13, 1), button.NeedDisplay); - top.LayoutComplete += e => { + top.LayoutComplete += (s,e) => { Assert.Equal (new Rect (0, 0, 80, 25), top.NeedDisplay); }; - frame.LayoutComplete += e => { + frame.LayoutComplete += (s, e) => { Assert.Equal (new Rect (0, 0, 40, 8), frame.NeedDisplay); }; - frame.Subviews [0].LayoutComplete += e => { + frame.Subviews [0].LayoutComplete += (s, e) => { if (top.IsLoaded) { Assert.Equal (new Rect (0, 0, 38, 6), frame.Subviews [0].NeedDisplay); } else { @@ -2924,11 +2924,11 @@ public void Frame_Set_After_Initialze_Update_NeededDisplay () } }; - label.LayoutComplete += e => { + label.LayoutComplete += (s, e) => { Assert.Equal (new Rect (0, 0, 38, 1), label.NeedDisplay); }; - button.LayoutComplete += e => { + button.LayoutComplete += (s, e) => { Assert.Equal (new Rect (0, 0, 13, 1), button.NeedDisplay); }; diff --git a/UnitTests/Drivers/ConsoleDriverTests.cs b/UnitTests/Drivers/ConsoleDriverTests.cs index 6444b8f1c0..804ae83d7b 100644 --- a/UnitTests/Drivers/ConsoleDriverTests.cs +++ b/UnitTests/Drivers/ConsoleDriverTests.cs @@ -82,7 +82,7 @@ public void FakeDriver_Only_Sends_Keystrokes_Through_MockKeyPresses (Type driver var count = 0; var wasKeyPressed = false; - view.KeyPress += (e) => { + view.KeyPress += (s, e) => { wasKeyPressed = true; }; top.Add (view); @@ -121,7 +121,7 @@ public void FakeDriver_MockKeyPresses (Type driverType) var rText = ""; var idx = 0; - view.KeyPress += (e) => { + view.KeyPress += (s, e) => { Assert.Equal (text [idx], (char)e.KeyEvent.Key); rText += (char)e.KeyEvent.Key; Assert.Equal (rText, text.Substring (0, idx + 1)); @@ -473,7 +473,7 @@ public void TestVKPacket (uint unicodeCharacter, bool shift, bool alt, bool cont var top = Application.Top; - top.KeyPress += (e) => { + top.KeyPress += (s, e) => { var after = ShortcutHelper.GetModifiersKey (e.KeyEvent); Assert.Equal (expectedRemapping, after); e.Handled = true; diff --git a/UnitTests/Menus/ContextMenuTests.cs b/UnitTests/Menus/ContextMenuTests.cs index 314993794a..e08f84efb0 100644 --- a/UnitTests/Menus/ContextMenuTests.cs +++ b/UnitTests/Menus/ContextMenuTests.cs @@ -175,7 +175,7 @@ public void Key_Changing () var cm = new ContextMenu (); - lbl.KeyPress += (e) => { + lbl.KeyPress += (s, e) => { if (e.KeyEvent.Key == cm.Key) { lbl.Text = "Replaced"; e.Handled = true; diff --git a/UnitTests/TopLevels/ToplevelTests.cs b/UnitTests/TopLevels/ToplevelTests.cs index 691c906305..1da5891e5e 100644 --- a/UnitTests/TopLevels/ToplevelTests.cs +++ b/UnitTests/TopLevels/ToplevelTests.cs @@ -1060,7 +1060,7 @@ public void IsLoaded_With_Sub_Toplevel_Application_Begin_NeedDisplay () view.LayoutStarted += view_LayoutStarted; - void view_LayoutStarted (View.LayoutEventArgs e) + void view_LayoutStarted (object sender, View.LayoutEventArgs e) { Assert.Equal (new Rect (0, 0, 20, 10), view.NeedDisplay); view.LayoutStarted -= view_LayoutStarted; diff --git a/UnitTests/Types/DimTests.cs b/UnitTests/Types/DimTests.cs index ebcfefe679..7d174647fb 100644 --- a/UnitTests/Types/DimTests.cs +++ b/UnitTests/Types/DimTests.cs @@ -629,7 +629,7 @@ public void Dim_Add_Operator () var field = new TextField () { X = 0, Y = Pos.Bottom (view), Width = 20 }; var count = 0; - field.KeyDown += (k) => { + field.KeyDown += (s, k) => { if (k.KeyEvent.Key == Key.Enter) { field.Text = $"Label {count}"; var label = new Label (field.Text) { X = 0, Y = view.Bounds.Height, Width = 20 }; @@ -996,7 +996,7 @@ public void Dim_Add_Operator_With_Text () var count = 0; var listLabels = new List - public event Action TitleChanging; + public event EventHandler TitleChanging; /// /// Called when the has been changed. Invokes the event. @@ -401,12 +401,12 @@ public virtual bool OnTitleChanging (ustring oldTitle, ustring newTitle) public virtual void OnTitleChanged (ustring oldTitle, ustring newTitle) { var args = new TitleEventArgs (oldTitle, newTitle); - TitleChanged?.Invoke (args); + TitleChanged?.Invoke (this, args); } /// /// Event fired after the has been changed. /// - public event Action TitleChanged; + public event EventHandler TitleChanged; } } diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index c5995f838d..f86b9e28e6 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -231,7 +231,7 @@ bool AcceptKey () /// public virtual void OnClicked () { - Clicked?.Invoke (); + Clicked?.Invoke (this, EventArgs.Empty); } /// @@ -243,7 +243,7 @@ public virtual void OnClicked () /// raised when the button is activated either with /// the mouse or the keyboard. /// - public event Action Clicked; + public event EventHandler Clicked; /// public override bool MouseEvent (MouseEvent me) diff --git a/Terminal.Gui/Views/ColorPicker.cs b/Terminal.Gui/Views/ColorPicker.cs index 07472279a6..5d3a915511 100644 --- a/Terminal.Gui/Views/ColorPicker.cs +++ b/Terminal.Gui/Views/ColorPicker.cs @@ -51,7 +51,7 @@ public Point Cursor { /// /// Fired when a color is picked. /// - public event Action ColorChanged; + public event EventHandler ColorChanged; private int selectColorIndex = (int)Color.Black; @@ -65,7 +65,7 @@ public Color SelectedColor { set { selectColorIndex = (int)value; - ColorChanged?.Invoke (); + ColorChanged?.Invoke (this, EventArgs.Empty); SetNeedsDisplay (); } } diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 9bc6a80eca..b204d33b80 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -214,22 +214,22 @@ public void SetSource (IList source) /// /// This event is raised when the selected item in the has changed. /// - public event Action SelectedItemChanged; + public event EventHandler SelectedItemChanged; /// /// This event is raised when the drop-down list is expanded. /// - public event Action Expanded; + public event EventHandler Expanded; /// /// This event is raised when the drop-down list is collapsed. /// - public event Action Collapsed; + public event EventHandler Collapsed; /// /// This event is raised when the user Double Clicks on an item or presses ENTER to open the selected item. /// - public event Action OpenSelectedItem; + public event EventHandler OpenSelectedItem; readonly IList searchset = new List (); ustring text = ""; @@ -294,7 +294,7 @@ private void Initialize () search.TextChanged += Search_Changed; listview.Y = Pos.Bottom (search); - listview.OpenSelectedItem += (ListViewItemEventArgs a) => Selected (); + listview.OpenSelectedItem += (object sender, ListViewItemEventArgs a) => Selected (); this.Add (search, listview); @@ -309,7 +309,7 @@ private void Initialize () } }; - listview.SelectedItemChanged += (ListViewItemEventArgs e) => { + listview.SelectedItemChanged += (object sender, ListViewItemEventArgs e) => { if (!HideDropdownListOnClick && searchset.Count > 0) { SetValue (searchset [listview.SelectedItem]); @@ -466,7 +466,7 @@ private void FocusSelectedItem () /// public virtual void OnExpanded () { - Expanded?.Invoke (); + Expanded?.Invoke (this, EventArgs.Empty); } /// @@ -474,7 +474,7 @@ public virtual void OnExpanded () /// public virtual void OnCollapsed () { - Collapsed?.Invoke (); + Collapsed?.Invoke (this, EventArgs.Empty); } /// @@ -515,7 +515,7 @@ public virtual bool OnSelectedChanged () { // Note: Cannot rely on "listview.SelectedItem != lastSelectedItem" because the list is dynamic. // So we cannot optimize. Ie: Don't call if not changed - SelectedItemChanged?.Invoke (new ListViewItemEventArgs (SelectedItem, search.Text)); + SelectedItemChanged?.Invoke (this, new ListViewItemEventArgs (SelectedItem, search.Text)); return true; } @@ -528,7 +528,7 @@ public virtual bool OnOpenSelectedItem () { var value = search.Text; lastSelectedItem = SelectedItem; - OpenSelectedItem?.Invoke (new ListViewItemEventArgs (SelectedItem, value)); + OpenSelectedItem?.Invoke (this, new ListViewItemEventArgs (SelectedItem, value)); return true; } diff --git a/Terminal.Gui/Views/ContextMenu.cs b/Terminal.Gui/Views/ContextMenu.cs index 2c7d0d109a..e4cd03d06f 100644 --- a/Terminal.Gui/Views/ContextMenu.cs +++ b/Terminal.Gui/Views/ContextMenu.cs @@ -169,7 +169,7 @@ public void Hide () /// /// Event invoked when the is changed. /// - public event Action KeyChanged; + public event EventHandler KeyChanged; /// /// Event invoked when the is changed. @@ -194,7 +194,7 @@ public Key Key { set { var oldKey = key; key = value; - KeyChanged?.Invoke (oldKey); + KeyChanged?.Invoke (this, new KeyChangedEventArgs(oldKey,key)); } } diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index 0a1d795b3d..444d4926ad 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -68,7 +68,7 @@ void Initialize (bool autosize = true) /// raised when the button is activated either with /// the mouse or the keyboard. /// - public event Action Clicked; + public event EventHandler Clicked; ///// //public new ustring Text { @@ -139,7 +139,7 @@ public override bool ProcessHotKey (KeyEvent ke) /// public virtual void OnClicked () { - Clicked?.Invoke (); + Clicked?.Invoke (this, EventArgs.Empty); } } } diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index 498c494fd4..506cf7019e 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -395,17 +395,17 @@ public override void Redraw (Rect bounds) /// /// This event is raised when the selected item in the has changed. /// - public event Action SelectedItemChanged; + public event EventHandler SelectedItemChanged; /// /// This event is raised when the user Double Clicks on an item or presses ENTER to open the selected item. /// - public event Action OpenSelectedItem; + public event EventHandler OpenSelectedItem; /// /// This event is invoked when this is being drawn before rendering. /// - public event Action RowRender; + public event EventHandler RowRender; /// /// Gets the that searches the collection as @@ -685,7 +685,7 @@ public virtual bool OnSelectedChanged () { if (selected != lastSelectedItem) { var value = source?.Count > 0 ? source.ToList () [selected] : null; - SelectedItemChanged?.Invoke (new ListViewItemEventArgs (selected, value)); + SelectedItemChanged?.Invoke (this, new ListViewItemEventArgs (selected, value)); if (HasFocus) { lastSelectedItem = selected; } @@ -707,7 +707,7 @@ public virtual bool OnOpenSelectedItem () var value = source.ToList () [selected]; - OpenSelectedItem?.Invoke (new ListViewItemEventArgs (selected, value)); + OpenSelectedItem?.Invoke (this, new ListViewItemEventArgs (selected, value)); return true; } @@ -718,7 +718,7 @@ public virtual bool OnOpenSelectedItem () /// public virtual void OnRowRender (ListViewRowEventArgs rowEventArgs) { - RowRender?.Invoke (rowEventArgs); + RowRender?.Invoke (this, rowEventArgs); } /// diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs index e4019237fa..3eaed4c9d3 100644 --- a/Terminal.Gui/Views/Menu.cs +++ b/Terminal.Gui/Views/Menu.cs @@ -1196,7 +1196,7 @@ void Selected (MenuItem item) /// /// Raised as a menu is opening. /// - public event Action MenuOpening; + public event EventHandler MenuOpening; /// /// Raised when a menu is opened. @@ -1244,7 +1244,7 @@ internal Menu openCurrentMenu { public virtual MenuOpeningEventArgs OnMenuOpening (MenuBarItem currentMenu) { var ev = new MenuOpeningEventArgs (currentMenu); - MenuOpening?.Invoke (ev); + MenuOpening?.Invoke (this, ev); return ev; } diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index fecc2cb420..7b0f88e335 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -228,9 +228,9 @@ private MenuBarItem BuildContextMenuBarItem () }); } - private void ContextMenu_KeyChanged (Key obj) + private void ContextMenu_KeyChanged (object sender, KeyChangedEventArgs e) { - ReplaceKeyBinding (obj, ContextMenu.Key); + ReplaceKeyBinding (e.OldKey, e.NewKey); } private void HistoryText_ChangeText (HistoryText.HistoryTextItem obj) diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 91472cd3bf..8556b6cfb6 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -1378,9 +1378,9 @@ private MenuBarItem BuildContextMenuBarItem () }); } - private void ContextMenu_KeyChanged (Key obj) + private void ContextMenu_KeyChanged (object sender, KeyChangedEventArgs e) { - ReplaceKeyBinding (obj, ContextMenu.Key); + ReplaceKeyBinding (e.OldKey, e.NewKey); } private void Model_LinesLoaded () diff --git a/Terminal.Gui/Windows/FileDialog.cs b/Terminal.Gui/Windows/FileDialog.cs index 6eee497fb2..2d23079673 100644 --- a/Terminal.Gui/Windows/FileDialog.cs +++ b/Terminal.Gui/Windows/FileDialog.cs @@ -678,7 +678,7 @@ public FileDialog (ustring title, ustring prompt, ustring nameDirLabel, ustring HideDropdownListOnClick = true }; cmbAllowedTypes.SetSource (allowedTypes ?? new List ()); - cmbAllowedTypes.OpenSelectedItem += (e) => { + cmbAllowedTypes.OpenSelectedItem += (s, e) => { dirListView.AllowedFileTypes = cmbAllowedTypes.Text.ToString ().Split (';'); dirListView.Reload (); }; @@ -698,7 +698,7 @@ public FileDialog (ustring title, ustring prompt, ustring nameDirLabel, ustring dirListView.FileChanged = (file) => nameEntry.Text = file == ".." ? "" : file; dirListView.SelectedChanged = (file) => nameEntry.Text = file.Item1 == ".." ? "" : file.Item1; this.cancel = new Button ("Cancel"); - this.cancel.Clicked += () => { + this.cancel.Clicked += (s,e) => { Cancel (); }; AddButton (cancel); @@ -707,7 +707,7 @@ public FileDialog (ustring title, ustring prompt, ustring nameDirLabel, ustring IsDefault = true, Enabled = nameEntry.Text.IsEmpty ? false : true }; - this.prompt.Clicked += () => { + this.prompt.Clicked += (s,e) => { if (this is OpenDialog) { if (!dirListView.GetValidFilesName (nameEntry.Text.ToString (), out string res)) { nameEntry.Text = res; diff --git a/Terminal.Gui/Windows/MessageBox.cs b/Terminal.Gui/Windows/MessageBox.cs index 4f509f146a..0ac9e8a945 100644 --- a/Terminal.Gui/Windows/MessageBox.cs +++ b/Terminal.Gui/Windows/MessageBox.cs @@ -311,7 +311,7 @@ static int QueryFull (bool useErrorColors, int width, int height, ustring title, for (int n = 0; n < buttonList.Count; n++) { int buttonId = n; var b = buttonList [n]; - b.Clicked += () => { + b.Clicked += (s,e) => { Clicked = buttonId; Application.RequestStop (); }; diff --git a/Terminal.Gui/Windows/Wizard.cs b/Terminal.Gui/Windows/Wizard.cs index b0ab0ff63a..846cb440d8 100644 --- a/Terminal.Gui/Windows/Wizard.cs +++ b/Terminal.Gui/Windows/Wizard.cs @@ -400,7 +400,7 @@ private void Wizard_Closing (object sender, ToplevelClosingEventArgs obj) } } - private void NextfinishBtn_Clicked () + private void NextfinishBtn_Clicked (object sender, EventArgs e) { if (CurrentStep == GetLastStep ()) { var args = new WizardButtonEventArgs (); @@ -486,7 +486,7 @@ public WizardStep GetNextStep () return null; } - private void BackBtn_Clicked () + private void BackBtn_Clicked (object sender, EventArgs e) { var args = new WizardButtonEventArgs (); MovingBack?.Invoke (args); diff --git a/UICatalog/KeyBindingsDialog.cs b/UICatalog/KeyBindingsDialog.cs index 5bcb5611c1..278f9981aa 100644 --- a/UICatalog/KeyBindingsDialog.cs +++ b/UICatalog/KeyBindingsDialog.cs @@ -154,14 +154,14 @@ public KeyBindingsDialog () : base("Keybindings", 50,10) btnChange.Clicked += RemapKey; var close = new Button ("Ok"); - close.Clicked += () => { + close.Clicked += (s,e) => { Application.RequestStop (); ViewTracker.Instance.StartUsingNewKeyMap (CurrentBindings); }; AddButton (close); var cancel = new Button ("Cancel"); - cancel.Clicked += ()=>Application.RequestStop(); + cancel.Clicked += (s,e)=>Application.RequestStop(); AddButton (cancel); // Register event handler as the last thing in constructor to prevent early calls @@ -172,7 +172,7 @@ public KeyBindingsDialog () : base("Keybindings", 50,10) SetTextBoxToShowBinding (commands.First()); } - private void RemapKey () + private void RemapKey (object sender, EventArgs e) { var cmd = commands [commandsListView.SelectedItem]; Key? key = null; @@ -201,7 +201,7 @@ private void SetTextBoxToShowBinding (Command cmd) SetNeedsDisplay (); } - private void CommandsListView_SelectedItemChanged (ListViewItemEventArgs obj) + private void CommandsListView_SelectedItemChanged (object sender, ListViewItemEventArgs obj) { SetTextBoxToShowBinding ((Command)obj.Value); } diff --git a/UICatalog/Scenarios/ASCIICustomButton.cs b/UICatalog/Scenarios/ASCIICustomButton.cs index 802709f632..c731d187c6 100644 --- a/UICatalog/Scenarios/ASCIICustomButton.cs +++ b/UICatalog/Scenarios/ASCIICustomButton.cs @@ -271,7 +271,7 @@ private void Button_MouseClick (object sender, MouseEventArgs obj) } } - private void Button_Clicked () + private void Button_Clicked (object sender, EventArgs e) { MessageBox.Query ("Button clicked.", $"'{selected.Text}' clicked!", "Ok"); if (selected.Text == "Close") { diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index 4387a8d9be..7ef9ff4d6f 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -83,10 +83,10 @@ public override void Setup () AllowsMarking = false, ColorScheme = Colors.TopLevel, }; - _classListView.OpenSelectedItem += (a) => { + _classListView.OpenSelectedItem += (s, a) => { _settingsPane.SetFocus (); }; - _classListView.SelectedItemChanged += (args) => { + _classListView.SelectedItemChanged += (s,args) => { ClearClass (_curView); _curView = CreateClass (_viewClasses.Values.ToArray () [_classListView.SelectedItem]); }; diff --git a/UICatalog/Scenarios/BackgroundWorkerCollection.cs b/UICatalog/Scenarios/BackgroundWorkerCollection.cs index d2448e1562..2573b00e5f 100644 --- a/UICatalog/Scenarios/BackgroundWorkerCollection.cs +++ b/UICatalog/Scenarios/BackgroundWorkerCollection.cs @@ -69,7 +69,7 @@ private void MdiMain_Closed (object sender, ToplevelEventArgs e) Dispose (); } - private void Menu_MenuOpening (MenuOpeningEventArgs menu) + private void Menu_MenuOpening (object sender, MenuOpeningEventArgs menu) { if (!canOpenWorkerApp) { canOpenWorkerApp = true; @@ -328,7 +328,7 @@ public StagingUIController () Add (listView); start = new Button ("Start") { IsDefault = true }; - start.Clicked += () => { + start.Clicked += (s,e) => { Staging = new Staging (DateTime.Now); RequestStop (); }; @@ -340,7 +340,7 @@ public StagingUIController () KeyPress += (s, e) => { if (e.KeyEvent.Key == Key.Esc) { - OnReportClosed (); + OnReportClosed (this, EventArgs.Empty); } }; @@ -358,7 +358,7 @@ public StagingUIController () }; } - private void OnReportClosed () + private void OnReportClosed (object sender, EventArgs e) { if (Staging?.StartStaging != null) { ReportClosed?.Invoke (this); diff --git a/UICatalog/Scenarios/Borders.cs b/UICatalog/Scenarios/Borders.cs index c176ed0401..f1ed391af6 100644 --- a/UICatalog/Scenarios/Borders.cs +++ b/UICatalog/Scenarios/Borders.cs @@ -191,7 +191,7 @@ public override void Setup () X = Pos.Left (paddingLeftEdit), Y = 5 }; - replacePadding.Clicked += () => { + replacePadding.Clicked += (s,e) => { smartPanel.Child.Border.Padding = new Thickness (smartPanel.Child.Border.Padding.Top); smartLabel.Border.Padding = new Thickness (smartLabel.Border.Padding.Top); if (paddingTopEdit.Text.IsEmpty) { @@ -310,7 +310,7 @@ public override void Setup () X = Pos.Left (borderLeftEdit), Y = 5 }; - replaceBorder.Clicked += () => { + replaceBorder.Clicked += (s,e) => { smartPanel.Child.Border.BorderThickness = new Thickness (smartPanel.Child.Border.BorderThickness.Top); smartLabel.Border.BorderThickness = new Thickness (smartLabel.Border.BorderThickness.Top); if (borderTopEdit.Text.IsEmpty) { diff --git a/UICatalog/Scenarios/BordersComparisons.cs b/UICatalog/Scenarios/BordersComparisons.cs index 3ea642d3b9..2ecb4fbcbb 100644 --- a/UICatalog/Scenarios/BordersComparisons.cs +++ b/UICatalog/Scenarios/BordersComparisons.cs @@ -35,7 +35,7 @@ public override void Init (ColorScheme colorScheme) X = Pos.Center (), Y = Pos.Center (), }; - button.Clicked += () => MessageBox.Query (20, 7, "Hi", "I'm a Window?", "Yes", "No"); + button.Clicked += (s,e) => MessageBox.Query (20, 7, "Hi", "I'm a Window?", "Yes", "No"); var label = new Label ("I'm a Window") { X = Pos.Center (), Y = Pos.Center () - 1, @@ -74,7 +74,7 @@ public override void Init (ColorScheme colorScheme) X = Pos.Center (), Y = Pos.Center (), }; - button2.Clicked += () => MessageBox.Query (20, 7, "Hi", "I'm a Toplevel?", "Yes", "No"); + button2.Clicked += (s,e) => MessageBox.Query (20, 7, "Hi", "I'm a Toplevel?", "Yes", "No"); var label2 = new Label ("I'm a Toplevel") { X = Pos.Center (), Y = Pos.Center () - 1, @@ -110,7 +110,7 @@ public override void Init (ColorScheme colorScheme) X = Pos.Center (), Y = Pos.Center (), }; - button3.Clicked += () => MessageBox.Query (20, 7, "Hi", "I'm a FrameView?", "Yes", "No"); + button3.Clicked += (s,e) => MessageBox.Query (20, 7, "Hi", "I'm a FrameView?", "Yes", "No"); var label3 = new Label ("I'm a FrameView") { X = Pos.Center (), Y = Pos.Center () - 1, diff --git a/UICatalog/Scenarios/BordersOnContainers.cs b/UICatalog/Scenarios/BordersOnContainers.cs index 0debccc76b..2b17284ae4 100644 --- a/UICatalog/Scenarios/BordersOnContainers.cs +++ b/UICatalog/Scenarios/BordersOnContainers.cs @@ -37,7 +37,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie X = Pos.Center (), Y = Pos.Center (), }; - button.Clicked += () => MessageBox.Query (20, 7, "Hi", $"I'm a {typeName}?", "Yes", "No"); + button.Clicked += (s,e) => MessageBox.Query (20, 7, "Hi", $"I'm a {typeName}?", "Yes", "No"); var label = new Label ($"I'm a {typeName}") { X = Pos.Center (), Y = Pos.Center () - 1, @@ -140,7 +140,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie X = Pos.Left (paddingLeftEdit), Y = 5 }; - replacePadding.Clicked += () => { + replacePadding.Clicked += (s,e) => { smartView.Border.Padding = new Thickness (smartView.Border.Padding.Top); if (paddingTopEdit.Text.IsEmpty) { paddingTopEdit.Text = "0"; @@ -234,7 +234,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie X = Pos.Left (borderLeftEdit), Y = 5 }; - replaceBorder.Clicked += () => { + replaceBorder.Clicked += (s,e) => { smartView.Border.BorderThickness = new Thickness (smartView.Border.BorderThickness.Top); if (borderTopEdit.Text.IsEmpty) { borderTopEdit.Text = "0"; diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs index 9b085a66b0..6789141702 100644 --- a/UICatalog/Scenarios/Buttons.cs +++ b/UICatalog/Scenarios/Buttons.cs @@ -30,11 +30,11 @@ public override void Setup () Y = Pos.Bottom (Win) - 3, IsDefault = true, }; - defaultButton.Clicked += () => Application.RequestStop (); + defaultButton.Clicked += (s,e) => Application.RequestStop (); Win.Add (defaultButton); var swapButton = new Button (50, 0, "Swap Default (Absolute Layout)"); - swapButton.Clicked += () => { + swapButton.Clicked += (s,e) => { defaultButton.IsDefault = !defaultButton.IsDefault; swapButton.IsDefault = !swapButton.IsDefault; }; @@ -42,7 +42,7 @@ public override void Setup () static void DoMessage (Button button, ustring txt) { - button.Clicked += () => { + button.Clicked += (s,e) => { var btnText = button.Text.ToString (); MessageBox.Query ("Message", $"Did you click {txt}?", "Yes", "No"); }; @@ -83,14 +83,14 @@ static void DoMessage (Button button, ustring txt) X = 2, Y = Pos.Bottom (button) + 1, }); - button.Clicked += () => MessageBox.Query ("Message", "Question?", "Yes", "No"); + button.Clicked += (s,e) => 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 += (s,e) => 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 @@ static void DoMessage (Button button, ustring txt) }; Win.Add (removeButton); // This in interesting test case because `moveBtn` and below are laid out relative to this one! - removeButton.Clicked += () => { + removeButton.Clicked += (s,e) => { // Now this throw a InvalidOperationException on the TopologicalSort method as is expected. //Win.Remove (removeButton); @@ -126,7 +126,7 @@ static void DoMessage (Button button, ustring txt) Width = 30, ColorScheme = Colors.Error, }; - moveBtn.Clicked += () => { + moveBtn.Clicked += (s,e) => { 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 @@ -140,7 +140,7 @@ static void DoMessage (Button button, ustring txt) Width = 30, ColorScheme = Colors.Error, }; - sizeBtn.Clicked += () => { + sizeBtn.Clicked += (s,e) => { sizeBtn.Width = sizeBtn.Frame.Width + 5; //computedFrame.LayoutSubviews (); // FIXED: This call should not be needed. View.X is not causing relayout correctly }; @@ -158,7 +158,7 @@ static void DoMessage (Button button, ustring txt) var moveBtnA = new Button (0, 0, "Move This Button via Frame") { ColorScheme = Colors.Error, }; - moveBtnA.Clicked += () => { + moveBtnA.Clicked += (s,e) => { moveBtnA.Frame = new Rect (moveBtnA.Frame.X + 5, moveBtnA.Frame.Y, moveBtnA.Frame.Width, moveBtnA.Frame.Height); }; absoluteFrame.Add (moveBtnA); @@ -167,7 +167,7 @@ static void DoMessage (Button button, ustring txt) var sizeBtnA = new Button (0, 2, " ~  s  gui.cs   master ↑10 = Со_хранить") { ColorScheme = Colors.Error, }; - sizeBtnA.Clicked += () => { + sizeBtnA.Clicked += (s,e) => { sizeBtnA.Frame = new Rect (sizeBtnA.Frame.X, sizeBtnA.Frame.Y, sizeBtnA.Frame.Width + 5, sizeBtnA.Frame.Height); }; absoluteFrame.Add (sizeBtnA); @@ -218,7 +218,7 @@ ustring MoveHotkey (ustring txt) Width = Dim.Width (computedFrame) - 2, ColorScheme = Colors.TopLevel, }; - moveHotKeyBtn.Clicked += () => { + moveHotKeyBtn.Clicked += (s,e) => { moveHotKeyBtn.Text = MoveHotkey (moveHotKeyBtn.Text); }; Win.Add (moveHotKeyBtn); @@ -230,7 +230,7 @@ ustring MoveHotkey (ustring txt) Width = Dim.Width (absoluteFrame) - 2, // BUGBUG: Not always the width isn't calculated correctly. ColorScheme = Colors.TopLevel, }; - moveUnicodeHotKeyBtn.Clicked += () => { + moveUnicodeHotKeyBtn.Clicked += (s,e) => { moveUnicodeHotKeyBtn.Text = MoveHotkey (moveUnicodeHotKeyBtn.Text); }; Win.Add (moveUnicodeHotKeyBtn); diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index 0018d825f3..b89d2fa5a9 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -84,7 +84,7 @@ public override void Setup () Height = Dim.Fill(1), SelectedItem = 0 }; - jumpList.SelectedItemChanged += (args) => { + jumpList.SelectedItemChanged += (s, args) => { _charMap.StartGlyph = radioItems [jumpList.SelectedItem].start; }; diff --git a/UICatalog/Scenarios/Clipping.cs b/UICatalog/Scenarios/Clipping.cs index 0d68229a93..606902bd41 100644 --- a/UICatalog/Scenarios/Clipping.cs +++ b/UICatalog/Scenarios/Clipping.cs @@ -58,7 +58,7 @@ public override void Setup () }; var testButton = new Button (2, 2, "click me"); - testButton.Clicked += () => { + testButton.Clicked += (s,e) => { MessageBox.Query (10, 5, "Test", "test message", "Ok"); }; embedded3.Add (testButton); diff --git a/UICatalog/Scenarios/ColorPicker.cs b/UICatalog/Scenarios/ColorPicker.cs index 29ead81aef..290dd7899b 100644 --- a/UICatalog/Scenarios/ColorPicker.cs +++ b/UICatalog/Scenarios/ColorPicker.cs @@ -78,7 +78,7 @@ public override void Setup () /// /// Fired when foreground color is changed. /// - private void ForegroundColor_ColorChanged () + private void ForegroundColor_ColorChanged (object sender, EventArgs e) { UpdateColorLabel (foregroundColorLabel, foregroundColorPicker); UpdateDemoLabel (); @@ -87,7 +87,7 @@ private void ForegroundColor_ColorChanged () /// /// Fired when background color is changed. /// - private void BackgroundColor_ColorChanged () + private void BackgroundColor_ColorChanged (object sender, EventArgs e) { UpdateColorLabel (backgroundColorLabel, backgroundColorPicker); UpdateDemoLabel (); diff --git a/UICatalog/Scenarios/ComboBoxIteration.cs b/UICatalog/Scenarios/ComboBoxIteration.cs index 1c9e670028..d3062763bf 100644 --- a/UICatalog/Scenarios/ComboBoxIteration.cs +++ b/UICatalog/Scenarios/ComboBoxIteration.cs @@ -38,12 +38,12 @@ public override void Setup () }; comboBox.SetSource (items); - listview.SelectedItemChanged += (e) => { + listview.SelectedItemChanged += (s,e) => { lbListView.Text = items [e.Item]; comboBox.SelectedItem = e.Item; }; - comboBox.SelectedItemChanged += (ListViewItemEventArgs text) => { + comboBox.SelectedItemChanged += (object sender, ListViewItemEventArgs text) => { if (text.Item != -1) { lbComboBox.Text = text.Value.ToString (); listview.SelectedItem = text.Item; @@ -55,7 +55,7 @@ public override void Setup () var btnTwo = new Button ("Two") { X = Pos.Right (comboBox) + 1, }; - btnTwo.Clicked += () => { + btnTwo.Clicked += (s,e) => { items = new List () { "one", "two" }; comboBox.SetSource (items); listview.SetSource (items); @@ -67,7 +67,7 @@ public override void Setup () X = Pos.Right (comboBox) + 1, Y = Pos.Top (comboBox) }; - btnThree.Clicked += () => { + btnThree.Clicked += (s,e) => { items = new List () { "one", "two", "three" }; comboBox.SetSource (items); listview.SetSource (items); diff --git a/UICatalog/Scenarios/ComputedLayout.cs b/UICatalog/Scenarios/ComputedLayout.cs index 9427cad847..4d3d1dfd45 100644 --- a/UICatalog/Scenarios/ComputedLayout.cs +++ b/UICatalog/Scenarios/ComputedLayout.cs @@ -207,7 +207,7 @@ public override void Setup () Y = Pos.AnchorEnd () - 1, }; anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton)); - anchorButton.Clicked += () => { + anchorButton.Clicked += (s,e) => { // Ths demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer // The call to Application.Top.LayoutSubviews causes the Computed layout to @@ -243,7 +243,7 @@ public override void Setup () var leftButton = new Button ("Left") { Y = Pos.AnchorEnd () - 1 // Pos.Combine }; - leftButton.Clicked += () => { + leftButton.Clicked += (s,e) => { // Ths demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer // The call to Application.Top.LayoutSubviews causes the Computed layout to @@ -258,7 +258,7 @@ public override void Setup () X = Pos.Center (), Y = Pos.AnchorEnd (1) // Pos.AnchorEnd(1) }; - centerButton.Clicked += () => { + centerButton.Clicked += (s,e) => { // Ths demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer // The call to Application.Top.LayoutSubviews causes the Computed layout to @@ -271,7 +271,7 @@ public override void Setup () var rightButton = new Button ("Right") { Y = Pos.Y (centerButton) }; - rightButton.Clicked += () => { + rightButton.Clicked += (s,e) => { // Ths demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer // The call to Application.Top.LayoutSubviews causes the Computed layout to diff --git a/UICatalog/Scenarios/CsvEditor.cs b/UICatalog/Scenarios/CsvEditor.cs index 17eb9a873f..89062a7e6b 100644 --- a/UICatalog/Scenarios/CsvEditor.cs +++ b/UICatalog/Scenarios/CsvEditor.cs @@ -514,9 +514,9 @@ private bool GetText (string title, string label, string initialText, out string bool okPressed = false; var ok = new Button ("Ok", is_default: true); - ok.Clicked += () => { okPressed = true; Application.RequestStop (); }; + ok.Clicked += (s,e) => { okPressed = true; Application.RequestStop (); }; var cancel = new Button ("Cancel"); - cancel.Clicked += () => { Application.RequestStop (); }; + cancel.Clicked += (s,e) => { Application.RequestStop (); }; var d = new Dialog (title, 60, 20, ok, cancel); var lbl = new Label () { diff --git a/UICatalog/Scenarios/Dialogs.cs b/UICatalog/Scenarios/Dialogs.cs index 50d0c3f5ea..e864a67918 100644 --- a/UICatalog/Scenarios/Dialogs.cs +++ b/UICatalog/Scenarios/Dialogs.cs @@ -144,7 +144,7 @@ void Top_Loaded (object sender, EventArgs args) Y = Pos.Bottom (frame) + 2, IsDefault = true, }; - showDialogButton.Clicked += () => { + showDialogButton.Clicked += (s,e) => { try { Dialog dialog = null; @@ -168,7 +168,7 @@ void Top_Loaded (object sender, EventArgs args) button = new Button (NumberToWords.Convert (buttonId), is_default: buttonId == 0); } - button.Clicked += () => { + button.Clicked += (s,e) => { clicked = buttonId; Application.RequestStop (); }; @@ -193,7 +193,7 @@ void Top_Loaded (object sender, EventArgs args) X = Pos.Center (), Y = Pos.Center () }; - add.Clicked += () => { + add.Clicked += (s,e) => { var buttonId = buttons.Count; Button button; if (glyphsNotWords.Checked == true) { @@ -203,7 +203,7 @@ void Top_Loaded (object sender, EventArgs args) button = new Button (NumberToWords.Convert (buttonId), is_default: buttonId == 0); } - button.Clicked += () => { + button.Clicked += (s,e) => { clicked = buttonId; Application.RequestStop (); @@ -220,7 +220,7 @@ void Top_Loaded (object sender, EventArgs args) X = Pos.Center (), Y = Pos.Center () + 1 }; - addChar.Clicked += () => { + addChar.Clicked += (s,e) => { foreach (var button in buttons) { button.Text += Char.ConvertFromUtf32 (CODE_POINT); } diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs index b03dd24f4b..542c6897a1 100644 --- a/UICatalog/Scenarios/DynamicMenuBar.cs +++ b/UICatalog/Scenarios/DynamicMenuBar.cs @@ -209,7 +209,7 @@ public DynamicMenuBarSample (ustring title) : base (title) }; Add (_frmMenuDetails); - _btnMenuBarUp.Clicked += () => { + _btnMenuBarUp.Clicked += (s,e) => { var i = _currentSelectedMenuBar; var menuItem = _menuBar != null && _menuBar.Menus.Length > 0 ? _menuBar.Menus [i] : null; if (menuItem != null) { @@ -223,7 +223,7 @@ public DynamicMenuBarSample (ustring title) : base (title) } }; - _btnMenuBarDown.Clicked += () => { + _btnMenuBarDown.Clicked += (s,e) => { var i = _currentSelectedMenuBar; var menuItem = _menuBar != null && _menuBar.Menus.Length > 0 ? _menuBar.Menus [i] : null; if (menuItem != null) { @@ -237,7 +237,7 @@ public DynamicMenuBarSample (ustring title) : base (title) } }; - _btnUp.Clicked += () => { + _btnUp.Clicked += (s,e) => { var i = _lstMenus.SelectedItem; var menuItem = DataContext.Menus.Count > 0 ? DataContext.Menus [i].MenuItem : null; if (menuItem != null) { @@ -252,7 +252,7 @@ public DynamicMenuBarSample (ustring title) : base (title) } }; - _btnDown.Clicked += () => { + _btnDown.Clicked += (s,e) => { var i = _lstMenus.SelectedItem; var menuItem = DataContext.Menus.Count > 0 ? DataContext.Menus [i].MenuItem : null; if (menuItem != null) { @@ -267,7 +267,7 @@ public DynamicMenuBarSample (ustring title) : base (title) } }; - _btnPreviowsParent.Clicked += () => { + _btnPreviowsParent.Clicked += (s,e) => { if (_currentMenuBarItem != null && _currentMenuBarItem.Parent != null) { var mi = _currentMenuBarItem; _currentMenuBarItem = _currentMenuBarItem.Parent as MenuBarItem; @@ -297,16 +297,16 @@ public DynamicMenuBarSample (ustring title) : base (title) X = Pos.Right (_btnOk) + 3, Y = Pos.Top (_btnOk), }; - _btnCancel.Clicked += () => { + _btnCancel.Clicked += (s,e) => { SetFrameDetails (_currentEditMenuBarItem); }; Add (_btnCancel); - _lstMenus.SelectedItemChanged += (e) => { + _lstMenus.SelectedItemChanged += (s,e) => { SetFrameDetails (); }; - _btnOk.Clicked += () => { + _btnOk.Clicked += (s,e) => { if (ustring.IsNullOrEmpty (_frmMenuDetails._txtTitle.Text) && _currentEditMenuBarItem != null) { MessageBox.ErrorQuery ("Invalid title", "Must enter a valid title!.", "Ok"); } else if (_currentEditMenuBarItem != null) { @@ -322,7 +322,7 @@ public DynamicMenuBarSample (ustring title) : base (title) } }; - _btnAdd.Clicked += () => { + _btnAdd.Clicked += (s,e) => { if (MenuBar == null) { MessageBox.ErrorQuery ("Menu Bar Error", "Must add a MenuBar first!", "Ok"); _btnAddMenuBar.SetFocus (); @@ -359,7 +359,7 @@ public DynamicMenuBarSample (ustring title) : base (title) } }; - _btnRemove.Clicked += () => { + _btnRemove.Clicked += (s,e) => { var menuItem = DataContext.Menus.Count > 0 ? DataContext.Menus [_lstMenus.SelectedItem].MenuItem : null; if (menuItem != null) { var childrens = ((MenuBarItem)_currentMenuBarItem).Children; @@ -391,7 +391,7 @@ public DynamicMenuBarSample (ustring title) : base (title) } }; - _lstMenus.OpenSelectedItem += (e) => { + _lstMenus.OpenSelectedItem += (s,e) => { _currentMenuBarItem = DataContext.Menus [e.Item].MenuItem; if (!(_currentMenuBarItem is MenuBarItem)) { MessageBox.ErrorQuery ("Menu Open Error", "Must allows sub menus first!", "Ok"); @@ -409,14 +409,14 @@ public DynamicMenuBarSample (ustring title) : base (title) SetFrameDetails (menuBarItem); }; - _btnNext.Clicked += () => { + _btnNext.Clicked += (s,e) => { if (_menuBar != null && _currentSelectedMenuBar + 1 < _menuBar.Menus.Length) { _currentSelectedMenuBar++; } SelectCurrentMenuBarItem (); }; - _btnPrevious.Clicked += () => { + _btnPrevious.Clicked += (s,e) => { if (_currentSelectedMenuBar - 1 > -1) { _currentSelectedMenuBar--; } @@ -430,7 +430,7 @@ public DynamicMenuBarSample (ustring title) : base (title) } }; - _btnAddMenuBar.Clicked += () => { + _btnAddMenuBar.Clicked += (s,e) => { var frameDetails = new DynamicMenuBarDetails (null, false); var item = frameDetails.EnterMenuItem (); if (item == null) { @@ -457,7 +457,7 @@ public DynamicMenuBarSample (ustring title) : base (title) _menuBar.SetNeedsDisplay (); }; - _btnRemoveMenuBar.Clicked += () => { + _btnRemoveMenuBar.Clicked += (s,e) => { if (_menuBar == null || _menuBar.Menus.Length == 0) { return; } @@ -784,7 +784,7 @@ bool CheckShortcut (Key k, bool pre) X = Pos.X (_lblShortcut), Y = Pos.Bottom (_txtShortcut) + 1 }; - _btnShortcut.Clicked += () => { + _btnShortcut.Clicked += (s,e) => { _txtShortcut.Text = ""; }; Add (_btnShortcut); @@ -868,7 +868,7 @@ public DynamicMenuItem EnterMenuItem () var _btnOk = new Button ("Ok") { IsDefault = true, }; - _btnOk.Clicked += () => { + _btnOk.Clicked += (s,e) => { if (ustring.IsNullOrEmpty (_txtTitle.Text)) { MessageBox.ErrorQuery ("Invalid title", "Must enter a valid title!.", "Ok"); } else { @@ -877,7 +877,7 @@ public DynamicMenuItem EnterMenuItem () } }; var _btnCancel = new Button ("Cancel"); - _btnCancel.Clicked += () => { + _btnCancel.Clicked += (s,e) => { _txtTitle.Text = ustring.Empty; Application.RequestStop (); }; diff --git a/UICatalog/Scenarios/DynamicStatusBar.cs b/UICatalog/Scenarios/DynamicStatusBar.cs index 7da6352b73..d78327a63e 100644 --- a/UICatalog/Scenarios/DynamicStatusBar.cs +++ b/UICatalog/Scenarios/DynamicStatusBar.cs @@ -142,7 +142,7 @@ public DynamicStatusBarSample (ustring title) : base (title) }; Add (_frmStatusBarDetails); - _btnUp.Clicked += () => { + _btnUp.Clicked += (s,e) => { var i = _lstItems.SelectedItem; var statusItem = DataContext.Items.Count > 0 ? DataContext.Items [i].StatusItem : null; if (statusItem != null) { @@ -158,7 +158,7 @@ public DynamicStatusBarSample (ustring title) : base (title) } }; - _btnDown.Clicked += () => { + _btnDown.Clicked += (s,e) => { var i = _lstItems.SelectedItem; var statusItem = DataContext.Items.Count > 0 ? DataContext.Items [i].StatusItem : null; if (statusItem != null) { @@ -184,16 +184,16 @@ public DynamicStatusBarSample (ustring title) : base (title) X = Pos.Right (_btnOk) + 3, Y = Pos.Top (_btnOk), }; - _btnCancel.Clicked += () => { + _btnCancel.Clicked += (s,e) => { SetFrameDetails (_currentEditStatusItem); }; Add (_btnCancel); - _lstItems.SelectedItemChanged += (e) => { + _lstItems.SelectedItemChanged += (s, e) => { SetFrameDetails (); }; - _btnOk.Clicked += () => { + _btnOk.Clicked += (s,e) => { if (ustring.IsNullOrEmpty (_frmStatusBarDetails._txtTitle.Text) && _currentEditStatusItem != null) { MessageBox.ErrorQuery ("Invalid title", "Must enter a valid title!.", "Ok"); } else if (_currentEditStatusItem != null) { @@ -206,7 +206,7 @@ public DynamicStatusBarSample (ustring title) : base (title) } }; - _btnAdd.Clicked += () => { + _btnAdd.Clicked += (s,e) => { if (StatusBar == null) { MessageBox.ErrorQuery ("StatusBar Bar Error", "Must add a StatusBar first!", "Ok"); _btnAddStatusBar.SetFocus (); @@ -227,7 +227,7 @@ public DynamicStatusBarSample (ustring title) : base (title) SetFrameDetails (); }; - _btnRemove.Clicked += () => { + _btnRemove.Clicked += (s,e) => { var statusItem = DataContext.Items.Count > 0 ? DataContext.Items [_lstItems.SelectedItem].StatusItem : null; if (statusItem != null) { _statusBar.RemoveItem (_currentSelectedStatusBar); @@ -245,7 +245,7 @@ public DynamicStatusBarSample (ustring title) : base (title) SetFrameDetails (statusItem); }; - _btnAddStatusBar.Clicked += () => { + _btnAddStatusBar.Clicked += (s,e) => { if (_statusBar != null) { return; } @@ -254,7 +254,7 @@ public DynamicStatusBarSample (ustring title) : base (title) Add (_statusBar); }; - _btnRemoveStatusBar.Clicked += () => { + _btnRemoveStatusBar.Clicked += (s,e) => { if (_statusBar == null) { return; } @@ -457,7 +457,7 @@ bool CheckShortcut (Key k, bool pre) X = Pos.X (_lblShortcut), Y = Pos.Bottom (_txtShortcut) + 1 }; - _btnShortcut.Clicked += () => { + _btnShortcut.Clicked += (s,e) => { _txtShortcut.Text = ""; }; Add (_btnShortcut); @@ -479,7 +479,7 @@ public DynamicStatusItem EnterStatusItem () var _btnOk = new Button ("Ok") { IsDefault = true, }; - _btnOk.Clicked += () => { + _btnOk.Clicked += (s,e) => { if (ustring.IsNullOrEmpty (_txtTitle.Text)) { MessageBox.ErrorQuery ("Invalid title", "Must enter a valid title!.", "Ok"); } else { @@ -492,7 +492,7 @@ public DynamicStatusItem EnterStatusItem () } }; var _btnCancel = new Button ("Cancel"); - _btnCancel.Clicked += () => { + _btnCancel.Clicked += (s,e) => { _txtTitle.Text = ustring.Empty; Application.RequestStop (); }; diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index 3cf2376e78..a39b420cc2 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -799,7 +799,7 @@ private View FindTab () IsDefault = true, AutoSize = false }; - btnFindNext.Clicked += () => FindNext (); + btnFindNext.Clicked += (s,e) => FindNext (); d.Add (btnFindNext); var btnFindPrevious = new Button ("Find _Previous") { @@ -810,7 +810,7 @@ private View FindTab () TextAlignment = TextAlignment.Centered, AutoSize = false }; - btnFindPrevious.Clicked += () => FindPrevious (); + btnFindPrevious.Clicked += (s,e) => FindPrevious (); d.Add (btnFindPrevious); txtToFind.TextChanged += (e) => { @@ -827,7 +827,7 @@ private View FindTab () TextAlignment = TextAlignment.Centered, AutoSize = false }; - btnCancel.Clicked += () => { + btnCancel.Clicked += (s,e) => { DisposeWinDialog (); }; d.Add (btnCancel); @@ -891,7 +891,7 @@ private View ReplaceTab () IsDefault = true, AutoSize = false }; - btnFindNext.Clicked += () => ReplaceNext (); + btnFindNext.Clicked += (s,e) => ReplaceNext (); d.Add (btnFindNext); label = new Label ("Replace:") { @@ -919,7 +919,7 @@ private View ReplaceTab () TextAlignment = TextAlignment.Centered, AutoSize = false }; - btnFindPrevious.Clicked += () => ReplacePrevious (); + btnFindPrevious.Clicked += (s,e) => ReplacePrevious (); d.Add (btnFindPrevious); var btnReplaceAll = new Button ("Replace _All") { @@ -930,7 +930,7 @@ private View ReplaceTab () TextAlignment = TextAlignment.Centered, AutoSize = false }; - btnReplaceAll.Clicked += () => ReplaceAll (); + btnReplaceAll.Clicked += (s,e) => ReplaceAll (); d.Add (btnReplaceAll); txtToFind.TextChanged += (e) => { @@ -948,7 +948,7 @@ private View ReplaceTab () TextAlignment = TextAlignment.Centered, AutoSize = false }; - btnCancel.Clicked += () => { + btnCancel.Clicked += (s,e) => { DisposeWinDialog (); }; d.Add (btnCancel); diff --git a/UICatalog/Scenarios/Generic.cs b/UICatalog/Scenarios/Generic.cs index 076ed7d92a..9b787c468d 100644 --- a/UICatalog/Scenarios/Generic.cs +++ b/UICatalog/Scenarios/Generic.cs @@ -32,7 +32,7 @@ public override void Setup () X = Pos.Center (), Y = Pos.Center (), }; - button.Clicked += () => MessageBox.Query (20, 7, "Hi", "Neat?", "Yes", "No"); + button.Clicked += (s,e) => MessageBox.Query (20, 7, "Hi", "Neat?", "Yes", "No"); Win.Add (button); } } diff --git a/UICatalog/Scenarios/InteractiveTree.cs b/UICatalog/Scenarios/InteractiveTree.cs index a8da38ca21..6cfd71fd1c 100644 --- a/UICatalog/Scenarios/InteractiveTree.cs +++ b/UICatalog/Scenarios/InteractiveTree.cs @@ -116,9 +116,9 @@ private bool GetText (string title, string label, string initialText, out string bool okPressed = false; var ok = new Button ("Ok", is_default: true); - ok.Clicked += () => { okPressed = true; Application.RequestStop (); }; + ok.Clicked += (s,e) => { okPressed = true; Application.RequestStop (); }; var cancel = new Button ("Cancel"); - cancel.Clicked += () => { Application.RequestStop (); }; + cancel.Clicked += (s,e) => { Application.RequestStop (); }; var d = new Dialog (title, 60, 20, ok, cancel); var lbl = new Label () { diff --git a/UICatalog/Scenarios/InvertColors.cs b/UICatalog/Scenarios/InvertColors.cs index b342b935ef..66499789d5 100644 --- a/UICatalog/Scenarios/InvertColors.cs +++ b/UICatalog/Scenarios/InvertColors.cs @@ -33,7 +33,7 @@ public override void Setup () X = Pos.Center (), Y = foreColors.Length + 1, }; - button.Clicked += () => { + button.Clicked += (s,e) => { foreach (var label in labels) { var color = label.ColorScheme.Normal; diff --git a/UICatalog/Scenarios/LabelsAsButtons.cs b/UICatalog/Scenarios/LabelsAsButtons.cs index 739a01f4c9..0c58c82a3e 100644 --- a/UICatalog/Scenarios/LabelsAsButtons.cs +++ b/UICatalog/Scenarios/LabelsAsButtons.cs @@ -32,14 +32,14 @@ public override void Setup () HotKeySpecifier = (System.Rune)'_', CanFocus = true, }; - defaultLabel.Clicked += () => Application.RequestStop (); + defaultLabel.Clicked += (s,e) => 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 += (s,e) => { //defaultLabel.IsDefault = !defaultLabel.IsDefault; //swapLabel.IsDefault = !swapLabel.IsDefault; }; @@ -47,7 +47,7 @@ public override void Setup () static void DoMessage (Label Label, ustring txt) { - Label.Clicked += () => { + Label.Clicked += (s,e) => { var btnText = Label.Text.ToString (); MessageBox.Query ("Message", $"Did you click {txt}?", "Yes", "No"); }; @@ -93,7 +93,7 @@ static void DoMessage (Label Label, ustring txt) TextAlignment = TextAlignment.Centered, VerticalTextAlignment = VerticalTextAlignment.Middle }); - Label.Clicked += () => MessageBox.Query ("Message", "Question?", "Yes", "No"); + Label.Clicked += (s,e) => MessageBox.Query ("Message", "Question?", "Yes", "No"); var textChanger = new Label ("Te_xt Changer") { X = 2, @@ -102,7 +102,7 @@ static void DoMessage (Label Label, ustring txt) CanFocus = true, }; Win.Add (textChanger); - textChanger.Clicked += () => textChanger.Text += "!"; + textChanger.Clicked += (s,e) => textChanger.Text += "!"; Win.Add (Label = new Label ("Lets see if this will move as \"Text Changer\" grows") { X = Pos.Right (textChanger) + 2, @@ -120,7 +120,7 @@ static void DoMessage (Label Label, ustring txt) }; Win.Add (removeLabel); // This in interesting test case because `moveBtn` and below are laid out relative to this one! - removeLabel.Clicked += () => { + removeLabel.Clicked += (s,e) => { // Now this throw a InvalidOperationException on the TopologicalSort method as is expected. //Win.Remove (removeLabel); @@ -145,7 +145,7 @@ static void DoMessage (Label Label, ustring txt) HotKeySpecifier = (System.Rune)'_', CanFocus = true, }; - moveBtn.Clicked += () => { + moveBtn.Clicked += (s,e) => { 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 @@ -163,7 +163,7 @@ static void DoMessage (Label Label, ustring txt) CanFocus = true, AutoSize = false }; - sizeBtn.Clicked += () => { + sizeBtn.Clicked += (s,e) => { sizeBtn.Width = sizeBtn.Frame.Width + 5; //computedFrame.LayoutSubviews (); // FIXED: This call should not be needed. View.X is not causing relayout correctly }; @@ -183,7 +183,7 @@ static void DoMessage (Label Label, ustring txt) HotKeySpecifier = (System.Rune)'_', CanFocus = true, }; - moveBtnA.Clicked += () => { + moveBtnA.Clicked += (s,e) => { moveBtnA.Frame = new Rect (moveBtnA.Frame.X + 5, moveBtnA.Frame.Y, moveBtnA.Frame.Width, moveBtnA.Frame.Height); }; absoluteFrame.Add (moveBtnA); @@ -195,7 +195,7 @@ static void DoMessage (Label Label, ustring txt) CanFocus = true, AutoSize = false }; - sizeBtnA.Clicked += () => { + sizeBtnA.Clicked += (s,e) => { sizeBtnA.Frame = new Rect (sizeBtnA.Frame.X, sizeBtnA.Frame.Y, sizeBtnA.Frame.Width + 5, sizeBtnA.Frame.Height); }; absoluteFrame.Add (sizeBtnA); @@ -250,7 +250,7 @@ ustring MoveHotkey (ustring txt) HotKeySpecifier = (System.Rune)'_', CanFocus = true, }; - moveHotKeyBtn.Clicked += () => { + moveHotKeyBtn.Clicked += (s,e) => { moveHotKeyBtn.Text = MoveHotkey (moveHotKeyBtn.Text); }; Win.Add (moveHotKeyBtn); @@ -264,7 +264,7 @@ ustring MoveHotkey (ustring txt) HotKeySpecifier = (System.Rune)'_', CanFocus = true, }; - moveUnicodeHotKeyBtn.Clicked += () => { + moveUnicodeHotKeyBtn.Clicked += (s,e) => { moveUnicodeHotKeyBtn.Text = MoveHotkey (moveUnicodeHotKeyBtn.Text); }; Win.Add (moveUnicodeHotKeyBtn); diff --git a/UICatalog/Scenarios/ListViewWithSelection.cs b/UICatalog/Scenarios/ListViewWithSelection.cs index 2ccbcd51c6..c1d333290b 100644 --- a/UICatalog/Scenarios/ListViewWithSelection.cs +++ b/UICatalog/Scenarios/ListViewWithSelection.cs @@ -97,7 +97,7 @@ public override void Setup () Win.Add (keepCheckBox); } - private void ListView_RowRender (ListViewRowEventArgs obj) + private void ListView_RowRender (object sender, ListViewRowEventArgs obj) { if (obj.Row == _listView.SelectedItem) { return; diff --git a/UICatalog/Scenarios/ListsAndCombos.cs b/UICatalog/Scenarios/ListsAndCombos.cs index cd4ae69c89..bd1881955c 100644 --- a/UICatalog/Scenarios/ListsAndCombos.cs +++ b/UICatalog/Scenarios/ListsAndCombos.cs @@ -36,7 +36,7 @@ public override void Setup () Height = Dim.Fill(2), Width = Dim.Percent (40) }; - listview.SelectedItemChanged += (ListViewItemEventArgs e) => lbListView.Text = items [listview.SelectedItem]; + listview.SelectedItemChanged += (object s, ListViewItemEventArgs e) => lbListView.Text = items [listview.SelectedItem]; Win.Add (lbListView, listview); var _scrollBar = new ScrollBarView (listview, true); @@ -80,7 +80,7 @@ public override void Setup () }; comboBox.SetSource (items); - comboBox.SelectedItemChanged += (ListViewItemEventArgs text) => lbComboBox.Text = text.Value.ToString (); + comboBox.SelectedItemChanged += (object s, ListViewItemEventArgs text) => lbComboBox.Text = text.Value.ToString (); Win.Add (lbComboBox, comboBox); var scrollBarCbx = new ScrollBarView (comboBox.Subviews [1], true); @@ -114,7 +114,7 @@ public override void Setup () X = 1, Y = Pos.Bottom(lbListView), }; - btnMoveUp.Clicked += () => { + btnMoveUp.Clicked += (s,e) => { listview.MoveUp (); }; @@ -122,7 +122,7 @@ public override void Setup () X = Pos.Right (btnMoveUp) + 1, Y = Pos.Bottom (lbListView), }; - btnMoveDown.Clicked += () => { + btnMoveDown.Clicked += (s,e) => { listview.MoveDown (); }; diff --git a/UICatalog/Scenarios/MessageBoxes.cs b/UICatalog/Scenarios/MessageBoxes.cs index f1b3fad110..5e523171b5 100644 --- a/UICatalog/Scenarios/MessageBoxes.cs +++ b/UICatalog/Scenarios/MessageBoxes.cs @@ -183,7 +183,7 @@ void Top_Loaded (object sender, EventArgs args) Y = Pos.Bottom (frame) + 2, IsDefault = true, }; - showMessageBoxButton.Clicked += () => { + showMessageBoxButton.Clicked += (s,e) => { try { int width = int.Parse (widthEdit.Text.ToString ()); int height = int.Parse (heightEdit.Text.ToString ()); diff --git a/UICatalog/Scenarios/MultiColouredTable.cs b/UICatalog/Scenarios/MultiColouredTable.cs index d1d9b40597..6bce14ff65 100644 --- a/UICatalog/Scenarios/MultiColouredTable.cs +++ b/UICatalog/Scenarios/MultiColouredTable.cs @@ -72,9 +72,9 @@ private bool GetText (string title, string label, string initialText, out string bool okPressed = false; var ok = new Button ("Ok", is_default: true); - ok.Clicked += () => { okPressed = true; Application.RequestStop (); }; + ok.Clicked += (s,e) => { okPressed = true; Application.RequestStop (); }; var cancel = new Button ("Cancel"); - cancel.Clicked += () => { Application.RequestStop (); }; + cancel.Clicked += (s,e) => { Application.RequestStop (); }; var d = new Dialog (title, 60, 20, ok, cancel); var lbl = new Label () { diff --git a/UICatalog/Scenarios/Progress.cs b/UICatalog/Scenarios/Progress.cs index b5c4d9000f..a6869607dc 100644 --- a/UICatalog/Scenarios/Progress.cs +++ b/UICatalog/Scenarios/Progress.cs @@ -58,17 +58,17 @@ internal ProgressDemo (ustring title) : base (title) X = Pos.Right (LeftFrame) + 1, Y = 0, }; - startButton.Clicked += () => Start (); + startButton.Clicked += (s,e) => Start (); var pulseButton = new Button ("Pulse") { X = Pos.Right (startButton) + 2, Y = Pos.Y (startButton), }; - pulseButton.Clicked += () => Pulse (); + pulseButton.Clicked += (s,e) => Pulse (); var stopbutton = new Button ("Stop Timer") { X = Pos.Right (pulseButton) + 2, Y = Pos.Top (pulseButton), }; - stopbutton.Clicked += () => Stop (); + stopbutton.Clicked += (s,e) => Stop (); Add (startButton); Add (pulseButton); @@ -225,7 +225,7 @@ public override void Setup () X = Pos.Center (), Y = Pos.Bottom(mainLoopTimeoutDemo) + 1, }; - startBoth.Clicked += () => { + startBoth.Clicked += (s,e) => { systemTimerDemo.Start (); mainLoopTimeoutDemo.Start (); }; diff --git a/UICatalog/Scenarios/ProgressBarStyles.cs b/UICatalog/Scenarios/ProgressBarStyles.cs index 72b2d4a27e..bad40aae75 100644 --- a/UICatalog/Scenarios/ProgressBarStyles.cs +++ b/UICatalog/Scenarios/ProgressBarStyles.cs @@ -64,7 +64,7 @@ public override void Setup () X = Pos.Center (), Y = Pos.Bottom (continuousPB) + 1 }; - button.Clicked += () => { + button.Clicked += (s,e) => { if (_fractionTimer == null) { button.Enabled = false; blocksPB.Fraction = 0; diff --git a/UICatalog/Scenarios/RunTExample.cs b/UICatalog/Scenarios/RunTExample.cs index 98d421d7e6..8a7c9c3baa 100644 --- a/UICatalog/Scenarios/RunTExample.cs +++ b/UICatalog/Scenarios/RunTExample.cs @@ -58,7 +58,7 @@ public ExampleWindow () }; // When login button is clicked display a message popup - btnLogin.Clicked += () => { + btnLogin.Clicked += (s,e) => { if (usernameText.Text == "admin" && passwordText.Text == "password") { MessageBox.Query ("Login Successful", $"Username: {usernameText.Text}", "Ok"); Application.RequestStop (); diff --git a/UICatalog/Scenarios/RuneWidthGreaterThanOne.cs b/UICatalog/Scenarios/RuneWidthGreaterThanOne.cs index 4e4105778b..5c6ed98595 100644 --- a/UICatalog/Scenarios/RuneWidthGreaterThanOne.cs +++ b/UICatalog/Scenarios/RuneWidthGreaterThanOne.cs @@ -91,17 +91,17 @@ private void UnsetClickedEvent () } } - private void MixedMessage () + private void MixedMessage (object sender, EventArgs e) { MessageBox.Query ("Say Hello 你", $"Hello {_text.Text}", "Ok"); } - private void NarrowMessage () + private void NarrowMessage (object sender, EventArgs e) { MessageBox.Query ("Say Hello", $"Hello {_text.Text}", "Ok"); } - private void WideMessage () + private void WideMessage (object sender, EventArgs e) { MessageBox.Query ("こんにちはと言う", $"こんにちは {_text.Text}", "Ok"); } diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index 11535de46f..a6ca4ff19c 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -164,7 +164,7 @@ void Top_Loaded (object sender, EventArgs args) X = 3, Y = 3, }; - pressMeButton.Clicked += () => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No"); + pressMeButton.Clicked += (s,e) => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No"); scrollView.Add (pressMeButton); var aLongButton = new Button ("A very long button. Should be wide enough to demo clipping!") { @@ -172,7 +172,7 @@ void Top_Loaded (object sender, EventArgs args) Y = 4, Width = Dim.Fill (3), }; - aLongButton.Clicked += () => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No"); + aLongButton.Clicked += (s,e) => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No"); scrollView.Add (aLongButton); scrollView.Add (new TextField ("This is a test of...") { @@ -202,7 +202,7 @@ void Top_Loaded (object sender, EventArgs args) }; // 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 += (s,e) => { // 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/SendKeys.cs b/UICatalog/Scenarios/SendKeys.cs index 0359c7d179..2cd4163e58 100644 --- a/UICatalog/Scenarios/SendKeys.cs +++ b/UICatalog/Scenarios/SendKeys.cs @@ -114,7 +114,7 @@ void ProcessInput () txtInput.SetFocus (); } - button.Clicked += () => ProcessInput (); + button.Clicked += (s,e) => ProcessInput (); Win.KeyPress += (s, e) => { if (e.KeyEvent.Key == Key.Enter) { diff --git a/UICatalog/Scenarios/SingleBackgroundWorker.cs b/UICatalog/Scenarios/SingleBackgroundWorker.cs index 352f608b42..fd27f26847 100644 --- a/UICatalog/Scenarios/SingleBackgroundWorker.cs +++ b/UICatalog/Scenarios/SingleBackgroundWorker.cs @@ -63,7 +63,7 @@ private void RunWorker () worker = new BackgroundWorker () { WorkerSupportsCancellation = true }; var cancel = new Button ("Cancel Worker"); - cancel.Clicked += () => { + cancel.Clicked += (s,e) => { if (worker == null) { log.Add ($"Worker is not running at {DateTime.Now}!"); listLog.SetNeedsDisplay (); diff --git a/UICatalog/Scenarios/TableEditor.cs b/UICatalog/Scenarios/TableEditor.cs index b9b1e168b3..a11fddd25d 100644 --- a/UICatalog/Scenarios/TableEditor.cs +++ b/UICatalog/Scenarios/TableEditor.cs @@ -278,9 +278,9 @@ private void RunColumnWidthDialog (DataColumn col, string prompt, Action { accepted = true; Application.RequestStop (); }; + ok.Clicked += (s,e) => { accepted = true; Application.RequestStop (); }; var cancel = new Button ("Cancel"); - cancel.Clicked += () => { Application.RequestStop (); }; + cancel.Clicked += (s,e) => { Application.RequestStop (); }; var d = new Dialog (prompt, 60, 20, ok, cancel); var style = tableView.Style.GetOrCreateColumnStyle (col); @@ -760,9 +760,9 @@ private void EditCurrentCell (TableView.CellActivatedEventArgs e) bool okPressed = false; var ok = new Button ("Ok", is_default: true); - ok.Clicked += () => { okPressed = true; Application.RequestStop (); }; + ok.Clicked += (s,e) => { okPressed = true; Application.RequestStop (); }; var cancel = new Button ("Cancel"); - cancel.Clicked += () => { Application.RequestStop (); }; + cancel.Clicked += (s,e) => { Application.RequestStop (); }; var d = new Dialog (title, 60, 20, ok, cancel); var lbl = new Label () { diff --git a/UICatalog/Scenarios/TextAlignments.cs b/UICatalog/Scenarios/TextAlignments.cs index b9b36ca35a..defc68eb4d 100644 --- a/UICatalog/Scenarios/TextAlignments.cs +++ b/UICatalog/Scenarios/TextAlignments.cs @@ -52,7 +52,7 @@ public override void Setup () X = Pos.Right (edit) + 1, Y = 0, }; - unicodeSample.Clicked += () => { + unicodeSample.Clicked += (s,e) => { edit.Text = unicodeSampleText; }; Win.Add (unicodeSample); @@ -62,7 +62,7 @@ public override void Setup () Y = Pos.Bottom (edit) - 1, }; - update.Clicked += () => { + update.Clicked += (s,e) => { foreach (var alignment in alignments) { singleLines [(int)alignment].Text = edit.Text; multipleLines [(int)alignment].Text = edit.Text; diff --git a/UICatalog/Scenarios/Threading.cs b/UICatalog/Scenarios/Threading.cs index 19df3ab95d..40f44cb292 100644 --- a/UICatalog/Scenarios/Threading.cs +++ b/UICatalog/Scenarios/Threading.cs @@ -46,7 +46,7 @@ public override void Setup () _btnActionCancel = new Button (1, 1, "Cancelable Load Items"); - _btnActionCancel.Clicked += () => Application.MainLoop.Invoke (CallLoadItemsAsync); + _btnActionCancel.Clicked += (s,e) => Application.MainLoop.Invoke (CallLoadItemsAsync); Win.Add (new Label ("Data Items:") { X = Pos.X (_btnActionCancel), @@ -77,19 +77,19 @@ public override void Setup () var text = new TextField (1, 3, 100, "Type anything after press the button"); var _btnAction = new Button (80, 10, "Load Data Action"); - _btnAction.Clicked += () => _action.Invoke (); + _btnAction.Clicked += (s,e) => _action.Invoke (); var _btnLambda = new Button (80, 12, "Load Data Lambda"); - _btnLambda.Clicked += () => _lambda.Invoke (); + _btnLambda.Clicked += (s,e) => _lambda.Invoke (); var _btnHandler = new Button (80, 14, "Load Data Handler"); - _btnHandler.Clicked += () => _handler.Invoke (null, new EventArgs ()); + _btnHandler.Clicked += (s,e) => _handler.Invoke (null, new EventArgs ()); var _btnSync = new Button (80, 16, "Load Data Synchronous"); - _btnSync.Clicked += () => _sync.Invoke (); + _btnSync.Clicked += (s,e) => _sync.Invoke (); var _btnMethod = new Button (80, 18, "Load Data Method"); - _btnMethod.Clicked += async () => await MethodAsync (); + _btnMethod.Clicked += async (s,e) => await MethodAsync (); var _btnClearData = new Button (80, 20, "Clear Data"); - _btnClearData.Clicked += () => { _itemsList.Source = null; LogJob ("Cleaning Data"); }; + _btnClearData.Clicked += (s,e) => { _itemsList.Source = null; LogJob ("Cleaning Data"); }; var _btnQuit = new Button (80, 22, "Quit"); - _btnQuit.Clicked += () => Application.RequestStop (); + _btnQuit.Clicked += (s,e) => Application.RequestStop (); Win.Add (_itemsList, _btnActionCancel, _logJob, text, _btnAction, _btnLambda, _btnHandler, _btnSync, _btnMethod, _btnClearData, _btnQuit); diff --git a/UICatalog/Scenarios/TimeAndDate.cs b/UICatalog/Scenarios/TimeAndDate.cs index dc88faa89d..7885c3dd28 100644 --- a/UICatalog/Scenarios/TimeAndDate.cs +++ b/UICatalog/Scenarios/TimeAndDate.cs @@ -102,7 +102,7 @@ public override void Setup () X = Pos.Center (), Y = Pos.Bottom (Win) - 5, }; - swapButton.Clicked += () => { + swapButton.Clicked += (s,e) => { longTime.ReadOnly = !longTime.ReadOnly; shortTime.ReadOnly = !shortTime.ReadOnly; diff --git a/UICatalog/Scenarios/VkeyPacketSimulator.cs b/UICatalog/Scenarios/VkeyPacketSimulator.cs index d9a8f3ffa5..c760509104 100644 --- a/UICatalog/Scenarios/VkeyPacketSimulator.cs +++ b/UICatalog/Scenarios/VkeyPacketSimulator.cs @@ -207,13 +207,13 @@ public override void Setup () } }; - btnInput.Clicked += () => { + btnInput.Clicked += (s,e) => { if (!tvInput.HasFocus && _keyboardStrokes.Count == 0) { tvInput.SetFocus (); } }; - btnOutput.Clicked += () => { + btnOutput.Clicked += (s,e) => { if (!tvOutput.HasFocus && _keyboardStrokes.Count == 0) { tvOutput.SetFocus (); } diff --git a/UICatalog/Scenarios/WindowsAndFrameViews.cs b/UICatalog/Scenarios/WindowsAndFrameViews.cs index 417dbe810f..54ca84b9e7 100644 --- a/UICatalog/Scenarios/WindowsAndFrameViews.cs +++ b/UICatalog/Scenarios/WindowsAndFrameViews.cs @@ -38,7 +38,7 @@ static int About () Y = 0, ColorScheme = Colors.Error, }; - paddingButton.Clicked += () => About (); + paddingButton.Clicked += (s,e) => About (); Win.Add (paddingButton); Win.Add (new Button ("Press ME! (Y = Pos.AnchorEnd(1))") { X = Pos.Center (), @@ -71,7 +71,7 @@ static int About () Y = 0, ColorScheme = Colors.Error, }; - pressMeButton.Clicked += () => + pressMeButton.Clicked += (s,e) => MessageBox.ErrorQuery (win.Title.ToString (), "Neat?", "Yes", "No"); win.Add (pressMeButton); var subWin = new Window ("Sub Window") { diff --git a/UICatalog/Scenarios/WizardAsView.cs b/UICatalog/Scenarios/WizardAsView.cs index e7be175525..e4ed7f4e52 100644 --- a/UICatalog/Scenarios/WizardAsView.cs +++ b/UICatalog/Scenarios/WizardAsView.cs @@ -76,7 +76,7 @@ public override void Init (ColorScheme colorScheme) X = Pos.Right (buttonLbl), Y = Pos.Top (buttonLbl) }; - button.Clicked += () => { + button.Clicked += (s,e) => { secondStep.Title = "2nd Step"; MessageBox.Query ("Wizard Scenario", "This Wizard Step's title was changed to '2nd Step'", "Ok"); }; diff --git a/UICatalog/Scenarios/Wizards.cs b/UICatalog/Scenarios/Wizards.cs index 7078dd321f..b358aada0c 100644 --- a/UICatalog/Scenarios/Wizards.cs +++ b/UICatalog/Scenarios/Wizards.cs @@ -97,7 +97,7 @@ void Top_Loaded (object sender, EventArgs args) IsDefault = true, }; - showWizardButton.Clicked += () => { + showWizardButton.Clicked += (s,e) => { try { int width = 0; int.TryParse (widthEdit.Text.ToString (), out width); @@ -153,7 +153,7 @@ void Top_Loaded (object sender, EventArgs args) X = Pos.Right (buttonLbl), Y = Pos.Top (buttonLbl) }; - button.Clicked += () => { + button.Clicked += (s,e) => { secondStep.Title = "2nd Step"; MessageBox.Query ("Wizard Scenario", "This Wizard Step's title was changed to '2nd Step'"); }; @@ -226,7 +226,7 @@ void Top_Loaded (object sender, EventArgs args) X = Pos.Center (), Y = Pos.AnchorEnd (1) }; - hideHelpBtn.Clicked += () => { + hideHelpBtn.Clicked += (s,e) => { if (fourthStep.HelpText.Length > 0) { fourthStep.HelpText = ustring.Empty; } else { diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index b4977eab62..e8e243af50 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -312,7 +312,7 @@ public UICatalogTopLevel () AllowsMarking = false, CanFocus = true, }; - CategoryListView.OpenSelectedItem += (a) => { + CategoryListView.OpenSelectedItem += (s,a) => { ScenarioListView.SetFocus (); }; CategoryListView.SelectedItemChanged += CategoryListView_SelectedChanged; @@ -396,7 +396,7 @@ void ConfigAppliedHandler (object sender, ConfigurationManagerEventArgs a) /// Launches the selected scenario, setting the global _selectedScenario /// /// - void ScenarioListView_OpenSelectedItem (EventArgs e) + void ScenarioListView_OpenSelectedItem (object sender, EventArgs e) { if (_selectedScenario is null) { // Save selected item state @@ -678,7 +678,7 @@ void KeyDownHandler (object sender, View.KeyEventEventArgs a) } } - void CategoryListView_SelectedChanged (ListViewItemEventArgs e) + void CategoryListView_SelectedChanged (object sender, ListViewItemEventArgs e) { var item = _categories [e.Item]; List newlist; diff --git a/UnitTests/Application/MainLoopTests.cs b/UnitTests/Application/MainLoopTests.cs index b88ffbb418..6498d4745b 100644 --- a/UnitTests/Application/MainLoopTests.cs +++ b/UnitTests/Application/MainLoopTests.cs @@ -636,7 +636,7 @@ public void Mainloop_Invoke_Or_AddIdle_Can_Be_Used_For_Events_Or_Actions (Action var btnLaunch = new Button ("Open Window"); - btnLaunch.Clicked += () => action (); + btnLaunch.Clicked += (s,e) => action (); Application.Top.Add (btnLaunch); @@ -700,7 +700,7 @@ private static void StartWindow () Text = "total" }; - totalbtn.Clicked += () => { + totalbtn.Clicked += (s,e) => { MessageBox.Query ("Count", $"Count is {total}", "Ok"); }; @@ -715,7 +715,7 @@ private static void StartWindow () Application.RequestStop (); } - private static async void RunAsyncTest () + private static async void RunAsyncTest (object sender, EventArgs e) { Assert.Equal (clickMe, btn.Text); Assert.Equal (zero, total); diff --git a/UnitTests/Core/ViewTests.cs b/UnitTests/Core/ViewTests.cs index 89afa229f3..bd45d853c3 100644 --- a/UnitTests/Core/ViewTests.cs +++ b/UnitTests/Core/ViewTests.cs @@ -1252,7 +1252,7 @@ public void Enabled_False_Sets_HasFocus_To_False () { var wasClicked = false; var view = new Button ("Click Me"); - view.Clicked += () => wasClicked = !wasClicked; + view.Clicked += (s,e) => wasClicked = !wasClicked; Application.Top.Add (view); view.ProcessKey (new KeyEvent (Key.Enter, null)); @@ -1281,7 +1281,7 @@ public void Enabled_Sets_Also_Sets_Subviews () { var wasClicked = false; var button = new Button ("Click Me"); - button.Clicked += () => wasClicked = !wasClicked; + button.Clicked += (s,e) => wasClicked = !wasClicked; var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () }; win.Add (button); Application.Top.Add (win); diff --git a/UnitTests/Menus/ContextMenuTests.cs b/UnitTests/Menus/ContextMenuTests.cs index e08f84efb0..9062e05aa0 100644 --- a/UnitTests/Menus/ContextMenuTests.cs +++ b/UnitTests/Menus/ContextMenuTests.cs @@ -228,7 +228,7 @@ public void KeyChanged_Event () var oldKey = Key.Null; var cm = new ContextMenu (); - cm.KeyChanged += (e) => oldKey = e; + cm.KeyChanged += (s,e) => oldKey = e.OldKey; cm.Key = Key.Space | Key.CtrlMask; Assert.Equal (Key.Space | Key.CtrlMask, cm.Key); diff --git a/UnitTests/Menus/MenuTests.cs b/UnitTests/Menus/MenuTests.cs index 1f822c2cc8..972e0e84bb 100644 --- a/UnitTests/Menus/MenuTests.cs +++ b/UnitTests/Menus/MenuTests.cs @@ -109,7 +109,7 @@ public void MenuOpening_MenuOpened_MenuClosing_Events () new MenuItem ("_New", "Creates new file.", New) }) }); - menu.MenuOpening += (e) => { + menu.MenuOpening += (s,e) => { Assert.Equal ("_File", e.CurrentMenu.Title); Assert.Equal ("_New", e.CurrentMenu.Children [0].Title); Assert.Equal ("Creates new file.", e.CurrentMenu.Children [0].Help); @@ -378,7 +378,7 @@ public void KeyBindings_Command () }), new MenuBarItem ("_About", "Top-Level", () => miAction ="About") }); - menu.MenuOpening += (e) => mbiCurrent = e.CurrentMenu; + menu.MenuOpening += (s,e) => mbiCurrent = e.CurrentMenu; menu.MenuOpened += (e) => { miCurrent = e; mCurrent = menu.openCurrentMenu; diff --git a/UnitTests/TopLevels/WindowTests.cs b/UnitTests/TopLevels/WindowTests.cs index 840105f1ae..21efaca615 100644 --- a/UnitTests/TopLevels/WindowTests.cs +++ b/UnitTests/TopLevels/WindowTests.cs @@ -107,7 +107,7 @@ public void Set_Title_Fires_TitleChanging () string expectedDuring = null; string expectedAfter = null; bool cancel = false; - r.TitleChanging += (args) => { + r.TitleChanging += (s, args) => { Assert.Equal (expectedOld, args.OldTitle); Assert.Equal (expectedDuring, args.NewTitle); args.Cancel = cancel; @@ -138,7 +138,7 @@ public void Set_Title_Fires_TitleChanged () string expectedOld = null; string expected = null; - r.TitleChanged += (args) => { + r.TitleChanged += (s,args) => { Assert.Equal (expectedOld, args.OldTitle); Assert.Equal (r.Title, args.NewTitle); }; diff --git a/UnitTests/TopLevels/WizardTests.cs b/UnitTests/TopLevels/WizardTests.cs index b10d862e80..1502e2eb8d 100644 --- a/UnitTests/TopLevels/WizardTests.cs +++ b/UnitTests/TopLevels/WizardTests.cs @@ -47,7 +47,7 @@ public void WizardStep_Set_Title_Fires_TitleChanging () string expectedAfter = string.Empty; string expectedDuring = string.Empty; bool cancel = false; - r.TitleChanging += (args) => { + r.TitleChanging += (s,args) => { Assert.Equal (expectedDuring, args.NewTitle); args.Cancel = cancel; }; @@ -73,7 +73,7 @@ public void WizardStep_Set_Title_Fires_TitleChanged () Assert.Equal (ustring.Empty, r.Title); string expected = string.Empty; - r.TitleChanged += (args) => { + r.TitleChanged += (s,args) => { Assert.Equal (r.Title, args.NewTitle); }; diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index 7a8c733d30..a1ea6e14e1 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -295,10 +295,10 @@ public void Run_All_Views_Tester_Scenario () ColorScheme = Colors.Dialog, }; - _classListView.OpenSelectedItem += (a) => { + _classListView.OpenSelectedItem += (s, a) => { _settingsPane.SetFocus (); }; - _classListView.SelectedItemChanged += (args) => { + _classListView.SelectedItemChanged += (s, args) => { ClearClass (_curView); _curView = CreateClass (_viewClasses.Values.ToArray () [_classListView.SelectedItem]); }; diff --git a/UnitTests/Views/ButtonTests.cs b/UnitTests/Views/ButtonTests.cs index 9585b4bba4..4017714a70 100644 --- a/UnitTests/Views/ButtonTests.cs +++ b/UnitTests/Views/ButtonTests.cs @@ -76,7 +76,7 @@ public void KeyBindings_Command () { var clicked = false; Button btn = new Button ("Test"); - btn.Clicked += () => clicked = true; + btn.Clicked += (s,e) => clicked = true; Application.Top.Add (btn); Application.Begin (Application.Top); @@ -119,7 +119,7 @@ public void ChangeHotKey () { var clicked = false; Button btn = new Button ("Test"); - btn.Clicked += () => clicked = true; + btn.Clicked += (s,e) => clicked = true; Application.Top.Add (btn); Application.Begin (Application.Top); @@ -146,7 +146,7 @@ public void KeyBindingExample () { int pressed = 0; var btn = new Button ("Press Me"); - btn.Clicked += () => pressed++; + btn.Clicked += (s,e) => pressed++; // The Button class supports the Accept command Assert.Contains (Command.Accept, btn.GetSupportedCommands ()); diff --git a/UnitTests/Views/ComboBoxTests.cs b/UnitTests/Views/ComboBoxTests.cs index 3314614730..74c2a33a7e 100644 --- a/UnitTests/Views/ComboBoxTests.cs +++ b/UnitTests/Views/ComboBoxTests.cs @@ -88,7 +88,7 @@ public void KeyBindings_Command () Assert.Equal (-1, cb.SelectedItem); Assert.Equal (string.Empty, cb.Text); var opened = false; - cb.OpenSelectedItem += (_) => opened = true; + cb.OpenSelectedItem += (s,_) => opened = true; Assert.True (cb.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); Assert.False (opened); cb.Text = "Tw"; @@ -274,7 +274,7 @@ public void HideDropdownListOnClick_Gets_Sets () Width = 5 }; cb.SetSource (new List { "One", "Two", "Three" }); - cb.OpenSelectedItem += (e) => selected = e.Value.ToString (); + cb.OpenSelectedItem += (s,e) => selected = e.Value.ToString (); Application.Top.Add (cb); Application.Begin (Application.Top); @@ -369,7 +369,7 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_And HideDropdownListOnClick = true }; cb.SetSource (new List { "One", "Two", "Three" }); - cb.OpenSelectedItem += (e) => selected = e.Value.ToString (); + cb.OpenSelectedItem += (s,e) => selected = e.Value.ToString (); Application.Top.Add (cb); Application.Begin (Application.Top); @@ -431,7 +431,7 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_Cur HideDropdownListOnClick = true }; cb.SetSource (new List { "One", "Two", "Three" }); - cb.OpenSelectedItem += (e) => selected = e.Value.ToString (); + cb.OpenSelectedItem += (s,e) => selected = e.Value.ToString (); Application.Top.Add (cb); Application.Begin (Application.Top); @@ -490,7 +490,7 @@ public void HideDropdownListOnClick_False_OpenSelectedItem_With_Mouse_And_Key_Cu HideDropdownListOnClick = false }; cb.SetSource (new List { "One", "Two", "Three" }); - cb.OpenSelectedItem += (e) => selected = e.Value.ToString (); + cb.OpenSelectedItem += (s, e) => selected = e.Value.ToString (); Application.Top.Add (cb); Application.Begin (Application.Top); @@ -551,7 +551,7 @@ public void HideDropdownListOnClick_False_ReadOnly_True_OpenSelectedItem_With_Mo ReadOnly = true }; cb.SetSource (new List { "One", "Two", "Three" }); - cb.OpenSelectedItem += (e) => selected = e.Value.ToString (); + cb.OpenSelectedItem += (s,e) => selected = e.Value.ToString (); Application.Top.Add (cb); Application.Begin (Application.Top); @@ -611,7 +611,7 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_F4 HideDropdownListOnClick = true }; cb.SetSource (new List { "One", "Two", "Three" }); - cb.OpenSelectedItem += (e) => selected = e.Value.ToString (); + cb.OpenSelectedItem += (s,e) => selected = e.Value.ToString (); Application.Top.Add (cb); Application.Begin (Application.Top); @@ -648,7 +648,7 @@ public void HideDropdownListOnClick_False_OpenSelectedItem_With_Mouse_And_Key_F4 HideDropdownListOnClick = false }; cb.SetSource (new List { "One", "Two", "Three" }); - cb.OpenSelectedItem += (e) => selected = e.Value.ToString (); + cb.OpenSelectedItem += (s,e) => selected = e.Value.ToString (); Application.Top.Add (cb); Application.Begin (Application.Top); @@ -685,7 +685,7 @@ public void HideDropdownListOnClick_True_Colapse_On_Click_Outside_Frame () HideDropdownListOnClick = true }; cb.SetSource (new List { "One", "Two", "Three" }); - cb.OpenSelectedItem += (e) => selected = e.Value.ToString (); + cb.OpenSelectedItem += (s,e) => selected = e.Value.ToString (); Application.Top.Add (cb); Application.Begin (Application.Top); @@ -790,7 +790,7 @@ public void HideDropdownListOnClick_True_Highlight_Current_Item () HideDropdownListOnClick = true, }; cb.SetSource (new List { "One", "Two", "Three" }); - cb.OpenSelectedItem += (e) => selected = e.Value.ToString (); + cb.OpenSelectedItem += (s,e) => selected = e.Value.ToString (); Application.Top.Add (cb); Application.Begin (Application.Top); @@ -912,8 +912,8 @@ public void Expanded_Collapsed_Events () }; var list = new List { "One", "Two", "Three" }; - cb.Expanded += () => cb.SetSource (list); - cb.Collapsed += () => cb.Source = null; + cb.Expanded += (s,e) => cb.SetSource (list); + cb.Collapsed += (s,e) => cb.Source = null; Application.Top.Add (cb); Application.Begin (Application.Top); diff --git a/UnitTests/Views/ListViewTests.cs b/UnitTests/Views/ListViewTests.cs index 01e7848101..82a648cc3e 100644 --- a/UnitTests/Views/ListViewTests.cs +++ b/UnitTests/Views/ListViewTests.cs @@ -175,7 +175,7 @@ public void KeyBindings_Command () Assert.True (lv.ProcessKey (new KeyEvent (Key.Space, new KeyModifiers ()))); Assert.True (lv.Source.IsMarked (lv.SelectedItem)); var opened = false; - lv.OpenSelectedItem += (_) => opened = true; + lv.OpenSelectedItem += (s,_) => opened = true; Assert.True (lv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); Assert.True (opened); Assert.True (lv.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()))); @@ -191,7 +191,7 @@ public void RowRender_Event () var rendered = false; var source = new List () { "one", "two", "three" }; var lv = new ListView () { Width = Dim.Fill (), Height = Dim.Fill () }; - lv.RowRender += _ => rendered = true; + lv.RowRender += (s,_) => rendered = true; Application.Top.Add (lv); Application.Begin (Application.Top); Assert.False (rendered); diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index d5526c1a69..e421b79717 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -909,7 +909,7 @@ public void ShowScrollIndicator_False_Must_Also_Set_Visible_To_False_To_Not_Resp var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test"; var label = new Label (text) { Width = 14, Height = 5 }; var btn = new Button (14, 0, "Click Me!"); - btn.Clicked += () => clicked = true; + btn.Clicked += (s,e) => clicked = true; Application.Top.Add (label, btn); var sbv = new ScrollBarView (label, true, false) { From 09683a2cd570944bfc5d230c8f986b7a1febe3a9 Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 12 Mar 2023 02:31:22 +0000 Subject: [PATCH 16/46] Refactor more `event Action` to `event EventHandler` --- Terminal.Gui/Views/DateField.cs | 4 +- Terminal.Gui/Views/RadioGroup.cs | 4 +- Terminal.Gui/Views/ScrollBarView.cs | 4 +- Terminal.Gui/Views/TableView.cs | 8 ++-- Terminal.Gui/Views/TextField.cs | 4 +- Terminal.Gui/Views/TextView.cs | 8 ++-- Terminal.Gui/Views/TileView.cs | 10 ++--- Terminal.Gui/Views/TimeField.cs | 4 +- Terminal.Gui/Views/TreeView.cs | 4 +- Terminal.Gui/Windows/Wizard.cs | 40 +++++++++---------- UICatalog/Scenarios/AllViewsTester.cs | 8 ++-- UICatalog/Scenarios/Borders.cs | 26 ++++++------ UICatalog/Scenarios/BordersOnContainers.cs | 26 ++++++------ UICatalog/Scenarios/Buttons.cs | 2 +- UICatalog/Scenarios/ConfigurationEditor.cs | 2 +- UICatalog/Scenarios/CsvEditor.cs | 8 ++-- UICatalog/Scenarios/Editor.cs | 4 +- UICatalog/Scenarios/LabelsAsButtons.cs | 2 +- UICatalog/Scenarios/ListViewWithSelection.cs | 4 +- UICatalog/Scenarios/ListsAndCombos.cs | 8 ++-- UICatalog/Scenarios/MultiColouredTable.cs | 2 +- UICatalog/Scenarios/ProgressBarStyles.cs | 2 +- UICatalog/Scenarios/TableEditor.cs | 8 ++-- UICatalog/Scenarios/Text.cs | 6 +-- UICatalog/Scenarios/TextAlignments.cs | 2 +- .../Scenarios/TextAlignmentsAndDirection.cs | 2 +- UICatalog/Scenarios/TimeAndDate.cs | 4 +- UICatalog/Scenarios/TreeViewFileSystem.cs | 4 +- UICatalog/Scenarios/WizardAsView.cs | 8 ++-- UICatalog/Scenarios/Wizards.cs | 12 +++--- UnitTests/TopLevels/WizardTests.cs | 6 +-- UnitTests/UICatalog/ScenarioTests.cs | 8 ++-- UnitTests/Views/RadioGroupTests.cs | 2 +- UnitTests/Views/ScrollBarViewTests.cs | 12 +++--- UnitTests/Views/TableViewTests.cs | 8 ++-- UnitTests/Views/TextFieldTests.cs | 6 +-- UnitTests/Views/TextViewTests.cs | 26 ++++++------ UnitTests/Views/TreeViewTests.cs | 20 +++++----- 38 files changed, 159 insertions(+), 159 deletions(-) diff --git a/Terminal.Gui/Views/DateField.cs b/Terminal.Gui/Views/DateField.cs index 3093eb59fa..d88648a41a 100644 --- a/Terminal.Gui/Views/DateField.cs +++ b/Terminal.Gui/Views/DateField.cs @@ -38,7 +38,7 @@ public class DateField : TextField { /// /// The passed event arguments containing the old value, new value, and format string. /// - public event Action> DateChanged; + public event EventHandler> DateChanged; /// /// Initializes a new instance of using layout. @@ -418,7 +418,7 @@ public override bool MouseEvent (MouseEvent ev) /// Event arguments public virtual void OnDateChanged (DateTimeEventArgs args) { - DateChanged?.Invoke (args); + DateChanged?.Invoke (this,args); } } diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index aaa510abf5..474baebc12 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -265,7 +265,7 @@ public override void PositionCursor () /// /// Invoked when the selected radio label has changed. /// - public event Action SelectedItemChanged; + public event EventHandler SelectedItemChanged; /// /// The currently selected item from the list of radio labels @@ -296,7 +296,7 @@ public void Refresh () public virtual void OnSelectedItemChanged (int selectedItem, int previousSelectedItem) { selected = selectedItem; - SelectedItemChanged?.Invoke (new SelectedItemChangedArgs (selectedItem, previousSelectedItem)); + SelectedItemChanged?.Invoke (this, new SelectedItemChangedArgs (selectedItem, previousSelectedItem)); } /// diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index 6870e08486..991a3675d4 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -199,7 +199,7 @@ public int Size { /// /// This event is raised when the position on the scrollbar has changed. /// - public event Action ChangedPosition; + public event EventHandler ChangedPosition; /// /// The position, relative to , to set the scrollbar at. @@ -312,7 +312,7 @@ public bool AutoHideScrollBars { /// public virtual void OnChangedPosition () { - ChangedPosition?.Invoke (); + ChangedPosition?.Invoke (this, EventArgs.Empty); } /// diff --git a/Terminal.Gui/Views/TableView.cs b/Terminal.Gui/Views/TableView.cs index c1647437bd..6ea1925310 100644 --- a/Terminal.Gui/Views/TableView.cs +++ b/Terminal.Gui/Views/TableView.cs @@ -171,12 +171,12 @@ public int SelectedRow { /// /// This event is raised when the selected cell in the table changes. /// - public event Action SelectedCellChanged; + public event EventHandler SelectedCellChanged; /// /// This event is raised when a cell is activated e.g. by double clicking or pressing /// - public event Action CellActivated; + public event EventHandler CellActivated; /// /// The key which when pressed should trigger event. Defaults to Enter. @@ -1510,7 +1510,7 @@ public void EnsureSelectedCellIsVisible () /// protected virtual void OnSelectedCellChanged (SelectedCellChangedEventArgs args) { - SelectedCellChanged?.Invoke (args); + SelectedCellChanged?.Invoke (this,args); } /// @@ -1519,7 +1519,7 @@ protected virtual void OnSelectedCellChanged (SelectedCellChangedEventArgs args) /// protected virtual void OnCellActivated (CellActivatedEventArgs args) { - CellActivated?.Invoke (args); + CellActivated?.Invoke (this, args); } /// diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index 7b0f88e335..18b3a9a95b 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -42,7 +42,7 @@ public class TextField : View { /// /// Changing event, raised before the changes and can be canceled or changing the new text. /// - public event Action TextChanging; + public event EventHandler TextChanging; /// /// Changed event, raised when the text has changed. @@ -1249,7 +1249,7 @@ public virtual void Paste () public virtual TextChangingEventArgs OnTextChanging (ustring newText) { var ev = new TextChangingEventArgs (newText); - TextChanging?.Invoke (ev); + TextChanging?.Invoke (this, ev); return ev; } diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 8556b6cfb6..cca45f7ea9 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -1156,7 +1156,7 @@ public class TextView : View { /// set, not as the user types. To be notified as the user changes the contents of the TextView /// see . /// - public event Action TextChanged; + public event EventHandler TextChanged; /// /// Raised when the contents of the are changed. @@ -1165,7 +1165,7 @@ public class TextView : View { /// Unlike the event, this event is raised whenever the user types or /// otherwise changes the contents of the . /// - public event Action ContentsChanged; + public event EventHandler ContentsChanged; /// /// Invoked with the unwrapped . @@ -1492,7 +1492,7 @@ public override ustring Text { wrapManager = new WordWrapManager (model); model = wrapManager.WrapModel (frameWidth, out _, out _, out _, out _); } - TextChanged?.Invoke (); + TextChanged?.Invoke (this, EventArgs.Empty); SetNeedsDisplay (); historyText.Clear (Text); @@ -2742,7 +2742,7 @@ public ContentsChangedEventArgs (int currentRow, int currentColumn) /// public virtual void OnContentsChanged () { - ContentsChanged?.Invoke (new ContentsChangedEventArgs (CurrentRow, CurrentColumn)); + ContentsChanged?.Invoke (this, new ContentsChangedEventArgs (CurrentRow, CurrentColumn)); } (int width, int height) OffSetBackground () diff --git a/Terminal.Gui/Views/TileView.cs b/Terminal.Gui/Views/TileView.cs index d5a431721f..5c0a09c6cd 100644 --- a/Terminal.Gui/Views/TileView.cs +++ b/Terminal.Gui/Views/TileView.cs @@ -101,7 +101,7 @@ public TitleEventArgs (ustring oldTitle, ustring newTitle) public virtual bool OnTitleChanging (ustring oldTitle, ustring newTitle) { var args = new TitleEventArgs (oldTitle, newTitle); - TitleChanging?.Invoke (args); + TitleChanging?.Invoke (this, args); return args.Cancel; } @@ -109,7 +109,7 @@ public virtual bool OnTitleChanging (ustring oldTitle, ustring newTitle) /// Event fired when the is changing. Set to /// true to cancel the Title change. /// - public event Action TitleChanging; + public event EventHandler TitleChanging; /// /// Called when the has been changed. Invokes the event. @@ -119,13 +119,13 @@ public virtual bool OnTitleChanging (ustring oldTitle, ustring newTitle) public virtual void OnTitleChanged (ustring oldTitle, ustring newTitle) { var args = new TitleEventArgs (oldTitle, newTitle); - TitleChanged?.Invoke (args); + TitleChanged?.Invoke (this, args); } /// /// Event fired after the has been changed. /// - public event Action TitleChanged; + public event EventHandler TitleChanged; /// /// Creates a new instance of the class. @@ -233,7 +233,7 @@ public void RebuildForTileCount (int count) var tile = new Tile (); tiles.Add (tile); Add (tile.ContentView); - tile.TitleChanged += (e) => SetNeedsDisplay (); + tile.TitleChanged += (s,e) => SetNeedsDisplay (); } LayoutSubviews (); diff --git a/Terminal.Gui/Views/TimeField.cs b/Terminal.Gui/Views/TimeField.cs index 1675a295a9..132803dbc0 100644 --- a/Terminal.Gui/Views/TimeField.cs +++ b/Terminal.Gui/Views/TimeField.cs @@ -38,7 +38,7 @@ public class TimeField : TextField { /// /// The passed is a containing the old value, new value, and format string. /// - public event Action> TimeChanged; + public event EventHandler> TimeChanged; /// /// Initializes a new instance of using positioning. @@ -336,7 +336,7 @@ public override bool MouseEvent (MouseEvent ev) /// The event arguments public virtual void OnTimeChanged (DateTimeEventArgs args) { - TimeChanged?.Invoke (args); + TimeChanged?.Invoke (this,args); } } } \ No newline at end of file diff --git a/Terminal.Gui/Views/TreeView.cs b/Terminal.Gui/Views/TreeView.cs index 7b8942c398..0b619e8938 100644 --- a/Terminal.Gui/Views/TreeView.cs +++ b/Terminal.Gui/Views/TreeView.cs @@ -112,7 +112,7 @@ public T SelectedObject { /// This event is raised when an object is activated e.g. by double clicking or /// pressing . /// - public event Action> ObjectActivated; + public event EventHandler> ObjectActivated; /// /// Key which when pressed triggers . @@ -712,7 +712,7 @@ public void ScrollUp () /// protected virtual void OnObjectActivated (ObjectActivatedEventArgs e) { - ObjectActivated?.Invoke (e); + ObjectActivated?.Invoke (this,e); } /// diff --git a/Terminal.Gui/Windows/Wizard.cs b/Terminal.Gui/Windows/Wizard.cs index 846cb440d8..f3fff9c03d 100644 --- a/Terminal.Gui/Windows/Wizard.cs +++ b/Terminal.Gui/Windows/Wizard.cs @@ -132,7 +132,7 @@ public TitleEventArgs (ustring oldTitle, ustring newTitle) public virtual bool OnTitleChanging (ustring oldTitle, ustring newTitle) { var args = new TitleEventArgs (oldTitle, newTitle); - TitleChanging?.Invoke (args); + TitleChanging?.Invoke (this, args); return args.Cancel; } @@ -140,7 +140,7 @@ public virtual bool OnTitleChanging (ustring oldTitle, ustring newTitle) /// Event fired when the is changing. Set to /// true to cancel the Title change. /// - public event Action TitleChanging; + public event EventHandler TitleChanging; /// /// Called when the has been changed. Invokes the event. @@ -150,13 +150,13 @@ public virtual bool OnTitleChanging (ustring oldTitle, ustring newTitle) public virtual void OnTitleChanged (ustring oldTitle, ustring newTitle) { var args = new TitleEventArgs (oldTitle, newTitle); - TitleChanged?.Invoke (args); + TitleChanged?.Invoke (this, args); } /// /// Event fired after the has been changed. /// - public event Action TitleChanged; + public event EventHandler TitleChanged; // The contentView works like the ContentView in FrameView. private View contentView = new View () { Data = "WizardContentView" }; @@ -211,7 +211,7 @@ public WizardStep (ustring title) var scrollBar = new ScrollBarView (helpTextView, true); - scrollBar.ChangedPosition += () => { + scrollBar.ChangedPosition += (s,e) => { helpTextView.TopRow = scrollBar.Position; if (helpTextView.TopRow != scrollBar.Position) { scrollBar.Position = helpTextView.TopRow; @@ -219,7 +219,7 @@ public WizardStep (ustring title) helpTextView.SetNeedsDisplay (); }; - scrollBar.OtherScrollBarView.ChangedPosition += () => { + scrollBar.OtherScrollBarView.ChangedPosition += (s,e) => { helpTextView.LeftColumn = scrollBar.OtherScrollBarView.Position; if (helpTextView.LeftColumn != scrollBar.OtherScrollBarView.Position) { scrollBar.OtherScrollBarView.Position = helpTextView.LeftColumn; @@ -396,7 +396,7 @@ private void Wizard_Closing (object sender, ToplevelClosingEventArgs obj) { if (!finishedPressed) { var args = new WizardButtonEventArgs (); - Cancelled?.Invoke (args); + Cancelled?.Invoke (this, args); } } @@ -404,7 +404,7 @@ private void NextfinishBtn_Clicked (object sender, EventArgs e) { if (CurrentStep == GetLastStep ()) { var args = new WizardButtonEventArgs (); - Finished?.Invoke (args); + Finished?.Invoke (this, args); if (!args.Cancel) { finishedPressed = true; if (IsCurrentTop) { @@ -416,7 +416,7 @@ private void NextfinishBtn_Clicked (object sender, EventArgs e) } } else { var args = new WizardButtonEventArgs (); - MovingNext?.Invoke (args); + MovingNext?.Invoke (this, args); if (!args.Cancel) { GoNext (); } @@ -437,7 +437,7 @@ public override bool ProcessKey (KeyEvent kb) switch (kb.Key) { case Key.Esc: var args = new WizardButtonEventArgs (); - Cancelled?.Invoke (args); + Cancelled?.Invoke (this, args); return false; } } @@ -489,7 +489,7 @@ public WizardStep GetNextStep () private void BackBtn_Clicked (object sender, EventArgs e) { var args = new WizardButtonEventArgs (); - MovingBack?.Invoke (args); + MovingBack?.Invoke (this, args); if (!args.Cancel) { GoBack (); } @@ -591,7 +591,7 @@ public void AddStep (WizardStep newStep) SizeStep (newStep); newStep.EnabledChanged += (s,e)=> UpdateButtonsAndTitle(); - newStep.TitleChanged += (args) => UpdateButtonsAndTitle (); + newStep.TitleChanged += (s,e) => UpdateButtonsAndTitle (); steps.AddLast (newStep); this.Add (newStep); UpdateButtonsAndTitle (); @@ -637,7 +637,7 @@ public WizardButtonEventArgs () /// Raised when the Back button in the is clicked. The Back button is always /// the first button in the array of Buttons passed to the constructor, if any. /// - public event Action MovingBack; + public event EventHandler MovingBack; /// /// Raised when the Next/Finish button in the is clicked (or the user presses Enter). @@ -645,7 +645,7 @@ public WizardButtonEventArgs () /// if any. This event is only raised if the is the last Step in the Wizard flow /// (otherwise the event is raised). /// - public event Action MovingNext; + public event EventHandler MovingNext; /// /// Raised when the Next/Finish button in the is clicked. The Next/Finish button is always @@ -653,7 +653,7 @@ public WizardButtonEventArgs () /// raised if the is the last Step in the Wizard flow /// (otherwise the event is raised). /// - public event Action Finished; + public event EventHandler Finished; /// /// Raised when the user has cancelled the by pressin the Esc key. @@ -661,7 +661,7 @@ public WizardButtonEventArgs () /// closing, cancel the event by setting to /// true before returning from the event handler. /// - public event Action Cancelled; + public event EventHandler Cancelled; /// /// for events. @@ -699,12 +699,12 @@ public StepChangeEventArgs (WizardStep oldStep, WizardStep newStep) /// This event is raised when the current ) is about to change. Use /// to abort the transition. /// - public event Action StepChanging; + public event EventHandler StepChanging; /// /// This event is raised after the has changed the . /// - public event Action StepChanged; + public event EventHandler StepChanged; /// /// Gets or sets the currently active . @@ -725,7 +725,7 @@ public WizardStep CurrentStep { public virtual bool OnStepChanging (WizardStep oldStep, WizardStep newStep) { var args = new StepChangeEventArgs (oldStep, newStep); - StepChanging?.Invoke (args); + StepChanging?.Invoke (this, args); return args.Cancel; } @@ -738,7 +738,7 @@ public virtual bool OnStepChanging (WizardStep oldStep, WizardStep newStep) public virtual bool OnStepChanged (WizardStep oldStep, WizardStep newStep) { var args = new StepChangeEventArgs (oldStep, newStep); - StepChanged?.Invoke (args); + StepChanged?.Invoke (this, args); return args.Cancel; } diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index 7ef9ff4d6f..2c52dc7d5b 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -124,7 +124,7 @@ public override void Setup () X = 0, Y = Pos.Bottom (label), }; - _xRadioGroup.SelectedItemChanged += (selected) => DimPosChanged (_curView); + _xRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); _xText = new TextField ($"{_xVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; _xText.TextChanged += (args) => { try { @@ -155,7 +155,7 @@ public override void Setup () X = Pos.X (label), Y = Pos.Bottom (label), }; - _yRadioGroup.SelectedItemChanged += (selected) => DimPosChanged (_curView); + _yRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); _locationFrame.Add (_yRadioGroup); _sizeFrame = new FrameView ("Size (Dim)") { @@ -172,7 +172,7 @@ public override void Setup () X = 0, Y = Pos.Bottom (label), }; - _wRadioGroup.SelectedItemChanged += (selected) => DimPosChanged (_curView); + _wRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); _wText = new TextField ($"{_wVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; _wText.TextChanged += (args) => { try { @@ -219,7 +219,7 @@ public override void Setup () X = Pos.X (label), Y = Pos.Bottom (label), }; - _hRadioGroup.SelectedItemChanged += (selected) => DimPosChanged (_curView); + _hRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); _sizeFrame.Add (_hRadioGroup); _settingsPane.Add (_sizeFrame); diff --git a/UICatalog/Scenarios/Borders.cs b/UICatalog/Scenarios/Borders.cs index f1ed391af6..60b0bd571d 100644 --- a/UICatalog/Scenarios/Borders.cs +++ b/UICatalog/Scenarios/Borders.cs @@ -99,7 +99,7 @@ public override void Setup () Y = 1, Width = 5 }; - paddingTopEdit.TextChanging += (e) => { + paddingTopEdit.TextChanging += (s, e) => { try { smartPanel.Child.Border.Padding = new Thickness (smartPanel.Child.Border.Padding.Left, int.Parse (e.NewText.ToString ()), smartPanel.Child.Border.Padding.Right, @@ -123,7 +123,7 @@ public override void Setup () Y = 2, Width = 5 }; - paddingLeftEdit.TextChanging += (e) => { + paddingLeftEdit.TextChanging += (s, e) => { try { smartPanel.Child.Border.Padding = new Thickness (int.Parse (e.NewText.ToString ()), smartPanel.Child.Border.Padding.Top, smartPanel.Child.Border.Padding.Right, @@ -146,7 +146,7 @@ public override void Setup () Y = 2, Width = 5 }; - paddingRightEdit.TextChanging += (e) => { + paddingRightEdit.TextChanging += (s, e) => { try { smartPanel.Child.Border.Padding = new Thickness (smartPanel.Child.Border.Padding.Left, smartPanel.Child.Border.Padding.Top, int.Parse (e.NewText.ToString ()), @@ -169,7 +169,7 @@ public override void Setup () Y = 3, Width = 5 }; - paddingBottomEdit.TextChanging += (e) => { + paddingBottomEdit.TextChanging += (s, e) => { try { smartPanel.Child.Border.Padding = new Thickness (smartPanel.Child.Border.Padding.Left, smartPanel.Child.Border.Padding.Top, smartPanel.Child.Border.Padding.Right, @@ -218,7 +218,7 @@ public override void Setup () Y = 1, Width = 5 }; - borderTopEdit.TextChanging += (e) => { + borderTopEdit.TextChanging += (s, e) => { try { smartPanel.Child.Border.BorderThickness = new Thickness (smartPanel.Child.Border.BorderThickness.Left, int.Parse (e.NewText.ToString ()), smartPanel.Child.Border.BorderThickness.Right, @@ -242,7 +242,7 @@ public override void Setup () Y = 2, Width = 5 }; - borderLeftEdit.TextChanging += (e) => { + borderLeftEdit.TextChanging += (s, e) => { try { smartPanel.Child.Border.BorderThickness = new Thickness (int.Parse (e.NewText.ToString ()), smartPanel.Child.Border.BorderThickness.Top, smartPanel.Child.Border.BorderThickness.Right, @@ -265,7 +265,7 @@ public override void Setup () Y = 2, Width = 5 }; - borderRightEdit.TextChanging += (e) => { + borderRightEdit.TextChanging += (s, e) => { try { smartPanel.Child.Border.BorderThickness = new Thickness (smartPanel.Child.Border.BorderThickness.Left, smartPanel.Child.Border.BorderThickness.Top, int.Parse (e.NewText.ToString ()), @@ -288,7 +288,7 @@ public override void Setup () Y = 3, Width = 5 }; - borderBottomEdit.TextChanging += (e) => { + borderBottomEdit.TextChanging += (s, e) => { try { smartPanel.Child.Border.BorderThickness = new Thickness (smartPanel.Child.Border.BorderThickness.Left, smartPanel.Child.Border.BorderThickness.Top, smartPanel.Child.Border.BorderThickness.Right, @@ -348,7 +348,7 @@ public override void Setup () }; Win.Add (cbDrawMarginFrame); - rbBorderStyle.SelectedItemChanged += (e) => { + rbBorderStyle.SelectedItemChanged += (s,e) => { smartPanel.Child.Border.BorderStyle = (BorderStyle)e.SelectedItem; smartLabel.Border.BorderStyle = (BorderStyle)e.SelectedItem; smartLabel.SetNeedsDisplay (); @@ -378,7 +378,7 @@ public override void Setup () Y = 3, Width = 5 }; - effect3DOffsetX.TextChanging += (e) => { + effect3DOffsetX.TextChanging += (s, e) => { try { smartPanel.Child.Border.Effect3DOffset = new Point (int.Parse (e.NewText.ToString ()), smartPanel.Child.Border.Effect3DOffset.Y); @@ -404,7 +404,7 @@ public override void Setup () Y = 3, Width = 5 }; - effect3DOffsetY.TextChanging += (e) => { + effect3DOffsetY.TextChanging += (s, e) => { try { smartPanel.Child.Border.Effect3DOffset = new Point (smartPanel.Child.Border.Effect3DOffset.X, int.Parse (e.NewText.ToString ())); @@ -439,7 +439,7 @@ public override void Setup () Y = 6, SelectedItem = (int)smartLabel.Border.Background }; - rbBackground.SelectedItemChanged += (e) => { + rbBackground.SelectedItemChanged += (s,e) => { smartPanel.Child.Border.Background = smartLabel.Border.Background = (Color)e.SelectedItem; }; Win.Add (rbBackground); @@ -456,7 +456,7 @@ public override void Setup () Y = 6, SelectedItem = (int)smartLabel.Border.BorderBrush }; - rbBorderBrush.SelectedItemChanged += (e) => { + rbBorderBrush.SelectedItemChanged += (s,e) => { smartPanel.Child.Border.BorderBrush = smartLabel.Border.BorderBrush = (Color)e.SelectedItem; }; Win.Add (rbBorderBrush); diff --git a/UICatalog/Scenarios/BordersOnContainers.cs b/UICatalog/Scenarios/BordersOnContainers.cs index 2b17284ae4..f330d317ed 100644 --- a/UICatalog/Scenarios/BordersOnContainers.cs +++ b/UICatalog/Scenarios/BordersOnContainers.cs @@ -64,7 +64,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie Y = 1, Width = 5 }; - paddingTopEdit.TextChanging += (e) => { + paddingTopEdit.TextChanging += (s,e) => { try { smartView.Border.Padding = new Thickness (smartView.Border.Padding.Left, int.Parse (e.NewText.ToString ()), smartView.Border.Padding.Right, @@ -84,7 +84,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie Y = 2, Width = 5 }; - paddingLeftEdit.TextChanging += (e) => { + paddingLeftEdit.TextChanging += (s,e) => { try { smartView.Border.Padding = new Thickness (int.Parse (e.NewText.ToString ()), smartView.Border.Padding.Top, smartView.Border.Padding.Right, @@ -103,7 +103,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie Y = 2, Width = 5 }; - paddingRightEdit.TextChanging += (e) => { + paddingRightEdit.TextChanging += (s,e) => { try { smartView.Border.Padding = new Thickness (smartView.Border.Padding.Left, smartView.Border.Padding.Top, int.Parse (e.NewText.ToString ()), @@ -122,7 +122,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie Y = 3, Width = 5 }; - paddingBottomEdit.TextChanging += (e) => { + paddingBottomEdit.TextChanging += (s,e) => { try { smartView.Border.Padding = new Thickness (smartView.Border.Padding.Left, smartView.Border.Padding.Top, smartView.Border.Padding.Right, @@ -158,7 +158,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie Y = 1, Width = 5 }; - borderTopEdit.TextChanging += (e) => { + borderTopEdit.TextChanging += (s,e) => { try { smartView.Border.BorderThickness = new Thickness (smartView.Border.BorderThickness.Left, int.Parse (e.NewText.ToString ()), smartView.Border.BorderThickness.Right, @@ -178,7 +178,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie Y = 2, Width = 5 }; - borderLeftEdit.TextChanging += (e) => { + borderLeftEdit.TextChanging += (s,e) => { try { smartView.Border.BorderThickness = new Thickness (int.Parse (e.NewText.ToString ()), smartView.Border.BorderThickness.Top, smartView.Border.BorderThickness.Right, @@ -197,7 +197,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie Y = 2, Width = 5 }; - borderRightEdit.TextChanging += (e) => { + borderRightEdit.TextChanging += (s,e) => { try { smartView.Border.BorderThickness = new Thickness (smartView.Border.BorderThickness.Left, smartView.Border.BorderThickness.Top, int.Parse (e.NewText.ToString ()), @@ -216,7 +216,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie Y = 3, Width = 5 }; - borderBottomEdit.TextChanging += (e) => { + borderBottomEdit.TextChanging += (s,e) => { try { smartView.Border.BorderThickness = new Thickness (smartView.Border.BorderThickness.Left, smartView.Border.BorderThickness.Top, smartView.Border.BorderThickness.Right, @@ -272,7 +272,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie }; Add (cbDrawMarginFrame); - rbBorderStyle.SelectedItemChanged += (e) => { + rbBorderStyle.SelectedItemChanged += (s,e) => { smartView.Border.BorderStyle = (BorderStyle)e.SelectedItem; smartView.SetNeedsDisplay (); if (cbDrawMarginFrame.Checked != smartView.Border.DrawMarginFrame) { @@ -301,7 +301,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie Y = 3, Width = 5 }; - effect3DOffsetX.TextChanging += (e) => { + effect3DOffsetX.TextChanging += (s,e) => { try { smartView.Border.Effect3DOffset = new Point (int.Parse (e.NewText.ToString ()), smartView.Border.Effect3DOffset.Y); @@ -324,7 +324,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie Y = 3, Width = 5 }; - effect3DOffsetY.TextChanging += (e) => { + effect3DOffsetY.TextChanging += (s,e) => { try { smartView.Border.Effect3DOffset = new Point (smartView.Border.Effect3DOffset.X, int.Parse (e.NewText.ToString ())); @@ -356,7 +356,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie Y = 6, SelectedItem = (int)smartView.Border.Background }; - rbBackground.SelectedItemChanged += (e) => { + rbBackground.SelectedItemChanged += (s,e) => { smartView.Border.Background = (Color)e.SelectedItem; }; Add (rbBackground); @@ -373,7 +373,7 @@ public BordersOnContainers (NStack.ustring title, string typeName, View smartVie Y = 6, SelectedItem = (int)smartView.Border.BorderBrush }; - rbBorderBrush.SelectedItemChanged += (e) => { + rbBorderBrush.SelectedItemChanged += (s,e) => { smartView.Border.BorderBrush = (Color)e.SelectedItem; }; Add (rbBorderBrush); diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs index 6789141702..313f154772 100644 --- a/UICatalog/Scenarios/Buttons.cs +++ b/UICatalog/Scenarios/Buttons.cs @@ -235,7 +235,7 @@ ustring MoveHotkey (ustring txt) }; Win.Add (moveUnicodeHotKeyBtn); - radioGroup.SelectedItemChanged += (args) => { + radioGroup.SelectedItemChanged += (s, args) => { switch (args.SelectedItem) { case 0: moveBtn.TextAlignment = TextAlignment.Left; diff --git a/UICatalog/Scenarios/ConfigurationEditor.cs b/UICatalog/Scenarios/ConfigurationEditor.cs index 6b29ebd944..258cccf138 100644 --- a/UICatalog/Scenarios/ConfigurationEditor.cs +++ b/UICatalog/Scenarios/ConfigurationEditor.cs @@ -82,7 +82,7 @@ private class ConfigTextView : TextView { internal ConfigTextView () { - ContentsChanged += (obj) => { + ContentsChanged += (s,obj) => { if (IsDirty) { if (!Tile.Title.EndsWith ('*')) { Tile.Title += '*'; diff --git a/UICatalog/Scenarios/CsvEditor.cs b/UICatalog/Scenarios/CsvEditor.cs index 89062a7e6b..0ae0ccb63d 100644 --- a/UICatalog/Scenarios/CsvEditor.cs +++ b/UICatalog/Scenarios/CsvEditor.cs @@ -114,7 +114,7 @@ private void SelectedCellLabel_TextChanged (ustring last) } } - private void OnSelectedCellChanged (TableView.SelectedCellChangedEventArgs e) + private void OnSelectedCellChanged (object sender, TableView.SelectedCellChangedEventArgs e) { // only update the text box if the user is not manually editing it if (!selectedCellLabel.HasFocus) @@ -446,7 +446,7 @@ private void SetupScrollBar () { var _scrollBar = new ScrollBarView (tableView, true); - _scrollBar.ChangedPosition += () => { + _scrollBar.ChangedPosition += (s,e) => { tableView.RowOffset = _scrollBar.Position; if (tableView.RowOffset != _scrollBar.Position) { _scrollBar.Position = tableView.RowOffset; @@ -454,7 +454,7 @@ private void SetupScrollBar () tableView.SetNeedsDisplay (); }; /* - _scrollBar.OtherScrollBarView.ChangedPosition += () => { + _scrollBar.OtherScrollBarView.ChangedPosition += (s,e) => { _listView.LeftItem = _scrollBar.OtherScrollBarView.Position; if (_listView.LeftItem != _scrollBar.OtherScrollBarView.Position) { _scrollBar.OtherScrollBarView.Position = _listView.LeftItem; @@ -540,7 +540,7 @@ private bool GetText (string title, string label, string initialText, out string enteredText = okPressed ? tf.Text.ToString () : null; return okPressed; } - private void EditCurrentCell (TableView.CellActivatedEventArgs e) + private void EditCurrentCell (object sender, TableView.CellActivatedEventArgs e) { if (e.Table == null) return; diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index a39b420cc2..1a98fea9f8 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -128,7 +128,7 @@ public override void Init (ColorScheme colorScheme) _scrollBar = new ScrollBarView (_textView, true); - _scrollBar.ChangedPosition += () => { + _scrollBar.ChangedPosition += (s,e) => { _textView.TopRow = _scrollBar.Position; if (_textView.TopRow != _scrollBar.Position) { _scrollBar.Position = _textView.TopRow; @@ -136,7 +136,7 @@ public override void Init (ColorScheme colorScheme) _textView.SetNeedsDisplay (); }; - _scrollBar.OtherScrollBarView.ChangedPosition += () => { + _scrollBar.OtherScrollBarView.ChangedPosition += (s,e) => { _textView.LeftColumn = _scrollBar.OtherScrollBarView.Position; if (_textView.LeftColumn != _scrollBar.OtherScrollBarView.Position) { _scrollBar.OtherScrollBarView.Position = _textView.LeftColumn; diff --git a/UICatalog/Scenarios/LabelsAsButtons.cs b/UICatalog/Scenarios/LabelsAsButtons.cs index 0c58c82a3e..bfdaf81529 100644 --- a/UICatalog/Scenarios/LabelsAsButtons.cs +++ b/UICatalog/Scenarios/LabelsAsButtons.cs @@ -269,7 +269,7 @@ ustring MoveHotkey (ustring txt) }; Win.Add (moveUnicodeHotKeyBtn); - radioGroup.SelectedItemChanged += (args) => { + radioGroup.SelectedItemChanged += (s,args) => { switch (args.SelectedItem) { case 0: moveBtn.TextAlignment = TextAlignment.Left; diff --git a/UICatalog/Scenarios/ListViewWithSelection.cs b/UICatalog/Scenarios/ListViewWithSelection.cs index c1d333290b..b05dfea278 100644 --- a/UICatalog/Scenarios/ListViewWithSelection.cs +++ b/UICatalog/Scenarios/ListViewWithSelection.cs @@ -62,7 +62,7 @@ public override void Setup () var _scrollBar = new ScrollBarView (_listView, true); - _scrollBar.ChangedPosition += () => { + _scrollBar.ChangedPosition += (s,e) => { _listView.TopItem = _scrollBar.Position; if (_listView.TopItem != _scrollBar.Position) { _scrollBar.Position = _listView.TopItem; @@ -70,7 +70,7 @@ public override void Setup () _listView.SetNeedsDisplay (); }; - _scrollBar.OtherScrollBarView.ChangedPosition += () => { + _scrollBar.OtherScrollBarView.ChangedPosition += (s,e) => { _listView.LeftItem = _scrollBar.OtherScrollBarView.Position; if (_listView.LeftItem != _scrollBar.OtherScrollBarView.Position) { _scrollBar.OtherScrollBarView.Position = _listView.LeftItem; diff --git a/UICatalog/Scenarios/ListsAndCombos.cs b/UICatalog/Scenarios/ListsAndCombos.cs index bd1881955c..80ebac6235 100644 --- a/UICatalog/Scenarios/ListsAndCombos.cs +++ b/UICatalog/Scenarios/ListsAndCombos.cs @@ -41,7 +41,7 @@ public override void Setup () var _scrollBar = new ScrollBarView (listview, true); - _scrollBar.ChangedPosition += () => { + _scrollBar.ChangedPosition += (s,e) => { listview.TopItem = _scrollBar.Position; if (listview.TopItem != _scrollBar.Position) { _scrollBar.Position = listview.TopItem; @@ -49,7 +49,7 @@ public override void Setup () listview.SetNeedsDisplay (); }; - _scrollBar.OtherScrollBarView.ChangedPosition += () => { + _scrollBar.OtherScrollBarView.ChangedPosition += (s,e) => { listview.LeftItem = _scrollBar.OtherScrollBarView.Position; if (listview.LeftItem != _scrollBar.OtherScrollBarView.Position) { _scrollBar.OtherScrollBarView.Position = listview.LeftItem; @@ -85,7 +85,7 @@ public override void Setup () var scrollBarCbx = new ScrollBarView (comboBox.Subviews [1], true); - scrollBarCbx.ChangedPosition += () => { + scrollBarCbx.ChangedPosition += (s,e) => { ((ListView)comboBox.Subviews [1]).TopItem = scrollBarCbx.Position; if (((ListView)comboBox.Subviews [1]).TopItem != scrollBarCbx.Position) { scrollBarCbx.Position = ((ListView)comboBox.Subviews [1]).TopItem; @@ -93,7 +93,7 @@ public override void Setup () comboBox.SetNeedsDisplay (); }; - scrollBarCbx.OtherScrollBarView.ChangedPosition += () => { + scrollBarCbx.OtherScrollBarView.ChangedPosition += (s,e) => { ((ListView)comboBox.Subviews [1]).LeftItem = scrollBarCbx.OtherScrollBarView.Position; if (((ListView)comboBox.Subviews [1]).LeftItem != scrollBarCbx.OtherScrollBarView.Position) { scrollBarCbx.OtherScrollBarView.Position = ((ListView)comboBox.Subviews [1]).LeftItem; diff --git a/UICatalog/Scenarios/MultiColouredTable.cs b/UICatalog/Scenarios/MultiColouredTable.cs index 6bce14ff65..75b67a0f62 100644 --- a/UICatalog/Scenarios/MultiColouredTable.cs +++ b/UICatalog/Scenarios/MultiColouredTable.cs @@ -98,7 +98,7 @@ private bool GetText (string title, string label, string initialText, out string enteredText = okPressed ? tf.Text.ToString () : null; return okPressed; } - private void EditCurrentCell (TableView.CellActivatedEventArgs e) + private void EditCurrentCell (object sender, TableView.CellActivatedEventArgs e) { if (e.Table == null) return; diff --git a/UICatalog/Scenarios/ProgressBarStyles.cs b/UICatalog/Scenarios/ProgressBarStyles.cs index bad40aae75..bc8ba33e0d 100644 --- a/UICatalog/Scenarios/ProgressBarStyles.cs +++ b/UICatalog/Scenarios/ProgressBarStyles.cs @@ -113,7 +113,7 @@ public override void Setup () }; Win.Add (marqueesContinuousPB); - rbPBFormat.SelectedItemChanged += (e) => { + rbPBFormat.SelectedItemChanged += (s,e) => { blocksPB.ProgressBarFormat = (ProgressBarFormat)e.SelectedItem; continuousPB.ProgressBarFormat = (ProgressBarFormat)e.SelectedItem; marqueesBlocksPB.ProgressBarFormat = (ProgressBarFormat)e.SelectedItem; diff --git a/UICatalog/Scenarios/TableEditor.cs b/UICatalog/Scenarios/TableEditor.cs index a11fddd25d..e5bcb40f44 100644 --- a/UICatalog/Scenarios/TableEditor.cs +++ b/UICatalog/Scenarios/TableEditor.cs @@ -103,7 +103,7 @@ public override void Setup () Win.Add (selectedCellLabel); - tableView.SelectedCellChanged += (e) => { selectedCellLabel.Text = $"{tableView.SelectedRow},{tableView.SelectedColumn}"; }; + tableView.SelectedCellChanged += (s, e) => { selectedCellLabel.Text = $"{tableView.SelectedRow},{tableView.SelectedColumn}"; }; tableView.CellActivated += EditCurrentCell; tableView.KeyPress += TableViewKeyPress; @@ -319,7 +319,7 @@ private void SetupScrollBar () { var _scrollBar = new ScrollBarView (tableView, true); - _scrollBar.ChangedPosition += () => { + _scrollBar.ChangedPosition += (s,e) => { tableView.RowOffset = _scrollBar.Position; if (tableView.RowOffset != _scrollBar.Position) { _scrollBar.Position = tableView.RowOffset; @@ -327,7 +327,7 @@ private void SetupScrollBar () tableView.SetNeedsDisplay (); }; /* - _scrollBar.OtherScrollBarView.ChangedPosition += () => { + _scrollBar.OtherScrollBarView.ChangedPosition += (s,e) => { _listView.LeftItem = _scrollBar.OtherScrollBarView.Position; if (_listView.LeftItem != _scrollBar.OtherScrollBarView.Position) { _scrollBar.OtherScrollBarView.Position = _listView.LeftItem; @@ -748,7 +748,7 @@ private void OpenSimple (bool big) tableView.Table = BuildSimpleDataTable (big ? 30 : 5, big ? 1000 : 5); } - private void EditCurrentCell (TableView.CellActivatedEventArgs e) + private void EditCurrentCell (object sender, TableView.CellActivatedEventArgs e) { if (e.Table == null) return; diff --git a/UICatalog/Scenarios/Text.cs b/UICatalog/Scenarios/Text.cs index 00ddf3af07..7521e6c3d5 100644 --- a/UICatalog/Scenarios/Text.cs +++ b/UICatalog/Scenarios/Text.cs @@ -26,7 +26,7 @@ public override void Setup () }; textField.TextChanging += TextField_TextChanging; - void TextField_TextChanging (TextChangingEventArgs e) + void TextField_TextChanging (object sender, TextChangingEventArgs e) { textField.Autocomplete.AllSuggestions = Regex.Matches (e.NewText.ToString (), "\\w+") .Select (s => s.Value) @@ -75,7 +75,7 @@ void TextView_DrawContent (Rect e) // Use ContentChanged to detect if the user has typed something in a TextView. // The TextChanged property is only fired if the TextView.Text property is // explicitly set - textView.ContentsChanged += (a) => { + textView.ContentsChanged += (s,a) => { labelMirroringTextView.Enabled = !labelMirroringTextView.Enabled; labelMirroringTextView.Text = textView.Text; }; @@ -218,7 +218,7 @@ void TextView_DrawContent (Rect e) TimeField _timeField; Label _labelMirroringTimeField; - private void TimeChanged (DateTimeEventArgs e) + private void TimeChanged (object sender, DateTimeEventArgs e) { _labelMirroringTimeField.Text = _timeField.Text; } diff --git a/UICatalog/Scenarios/TextAlignments.cs b/UICatalog/Scenarios/TextAlignments.cs index defc68eb4d..8d10bdacc8 100644 --- a/UICatalog/Scenarios/TextAlignments.cs +++ b/UICatalog/Scenarios/TextAlignments.cs @@ -40,7 +40,7 @@ public override void Setup () ColorScheme = Colors.TopLevel, Text = txt, }; - edit.TextChanged += () => { + edit.TextChanged += (s,e) => { foreach (var alignment in alignments) { singleLines [(int)alignment].Text = edit.Text; multipleLines [(int)alignment].Text = edit.Text; diff --git a/UICatalog/Scenarios/TextAlignmentsAndDirection.cs b/UICatalog/Scenarios/TextAlignmentsAndDirection.cs index a78a4e9b8b..9d8886b580 100644 --- a/UICatalog/Scenarios/TextAlignmentsAndDirection.cs +++ b/UICatalog/Scenarios/TextAlignmentsAndDirection.cs @@ -175,7 +175,7 @@ public override void Setup () HotKeySpecifier = '\xffff' }; - directionOptions.SelectedItemChanged += (ev) => { + directionOptions.SelectedItemChanged += (s, ev) => { foreach (var v in mtxts) { v.TextDirection = (TextDirection)ev.SelectedItem; } diff --git a/UICatalog/Scenarios/TimeAndDate.cs b/UICatalog/Scenarios/TimeAndDate.cs index 7885c3dd28..87983eddbe 100644 --- a/UICatalog/Scenarios/TimeAndDate.cs +++ b/UICatalog/Scenarios/TimeAndDate.cs @@ -118,14 +118,14 @@ public override void Setup () Win.Add (swapButton); } - private void TimeChanged (DateTimeEventArgs e) + private void TimeChanged (object sender, DateTimeEventArgs e) { lblOldTime.Text = $"Old Time: {e.OldValue}"; lblNewTime.Text = $"New Time: {e.NewValue}"; lblTimeFmt.Text = $"Time Format: {e.Format}"; } - private void DateChanged (DateTimeEventArgs e) + private void DateChanged (object sender, DateTimeEventArgs e) { lblOldDate.Text = $"Old Date: {e.OldValue}"; lblNewDate.Text = $"New Date: {e.NewValue}"; diff --git a/UICatalog/Scenarios/TreeViewFileSystem.cs b/UICatalog/Scenarios/TreeViewFileSystem.cs index 56fcc7d4dc..d015e33e0a 100644 --- a/UICatalog/Scenarios/TreeViewFileSystem.cs +++ b/UICatalog/Scenarios/TreeViewFileSystem.cs @@ -204,7 +204,7 @@ private void SetupScrollBar () var _scrollBar = new ScrollBarView (treeViewFiles, true); - _scrollBar.ChangedPosition += () => { + _scrollBar.ChangedPosition += (s,e) => { treeViewFiles.ScrollOffsetVertical = _scrollBar.Position; if (treeViewFiles.ScrollOffsetVertical != _scrollBar.Position) { _scrollBar.Position = treeViewFiles.ScrollOffsetVertical; @@ -212,7 +212,7 @@ private void SetupScrollBar () treeViewFiles.SetNeedsDisplay (); }; - _scrollBar.OtherScrollBarView.ChangedPosition += () => { + _scrollBar.OtherScrollBarView.ChangedPosition += (s,e) => { treeViewFiles.ScrollOffsetHorizontal = _scrollBar.OtherScrollBarView.Position; if (treeViewFiles.ScrollOffsetHorizontal != _scrollBar.OtherScrollBarView.Position) { _scrollBar.OtherScrollBarView.Position = treeViewFiles.ScrollOffsetHorizontal; diff --git a/UICatalog/Scenarios/WizardAsView.cs b/UICatalog/Scenarios/WizardAsView.cs index e4ed7f4e52..9727b8d512 100644 --- a/UICatalog/Scenarios/WizardAsView.cs +++ b/UICatalog/Scenarios/WizardAsView.cs @@ -35,23 +35,23 @@ public override void Init (ColorScheme colorScheme) // behave like an non-modal View (vs. a modal/pop-up Window). wizard.Modal = false; - wizard.MovingBack += (args) => { + wizard.MovingBack += (s,args) => { //args.Cancel = true; //actionLabel.Text = "Moving Back"; }; - wizard.MovingNext += (args) => { + wizard.MovingNext += (s,args) => { //args.Cancel = true; //actionLabel.Text = "Moving Next"; }; - wizard.Finished += (args) => { + wizard.Finished += (s,args) => { //args.Cancel = true; MessageBox.Query ("Setup Wizard", "Finished", "Ok"); Application.RequestStop (); }; - wizard.Cancelled += (args) => { + wizard.Cancelled += (s,args) => { var btn = MessageBox.Query ("Setup Wizard", "Are you sure you want to cancel?", "Yes", "No"); args.Cancel = btn == 1; if (btn == 0) { diff --git a/UICatalog/Scenarios/Wizards.cs b/UICatalog/Scenarios/Wizards.cs index b358aada0c..a6a94e3fad 100644 --- a/UICatalog/Scenarios/Wizards.cs +++ b/UICatalog/Scenarios/Wizards.cs @@ -116,22 +116,22 @@ void Top_Loaded (object sender, EventArgs args) Height = height }; - wizard.MovingBack += (args) => { + wizard.MovingBack += (s, args) => { //args.Cancel = true; actionLabel.Text = "Moving Back"; }; - wizard.MovingNext += (args) => { + wizard.MovingNext += (s, args) => { //args.Cancel = true; actionLabel.Text = "Moving Next"; }; - wizard.Finished += (args) => { + wizard.Finished += (s, args) => { //args.Cancel = true; actionLabel.Text = "Finished"; }; - wizard.Cancelled += (args) => { + wizard.Cancelled += (s, args) => { //args.Cancel = true; actionLabel.Text = "Cancelled"; }; @@ -176,7 +176,7 @@ void Top_Loaded (object sender, EventArgs args) }; frame.Add (new TextField ("This is a TextField inside of the frame.")); secondStep.Add (frame); - wizard.StepChanging += (args) => { + wizard.StepChanging += (s, args) => { if (args.OldStep == secondStep && firstNameField.Text.IsEmpty) { args.Cancel = true; var btn = MessageBox.ErrorQuery ("Second Step", "You must enter a First Name to continue", "Ok"); @@ -237,7 +237,7 @@ void Top_Loaded (object sender, EventArgs args) fourthStep.NextButtonText = "Go To Last Step"; var scrollBar = new ScrollBarView (someText, true); - scrollBar.ChangedPosition += () => { + scrollBar.ChangedPosition += (s,e) => { someText.TopRow = scrollBar.Position; if (someText.TopRow != scrollBar.Position) { scrollBar.Position = someText.TopRow; diff --git a/UnitTests/TopLevels/WizardTests.cs b/UnitTests/TopLevels/WizardTests.cs index 1502e2eb8d..ea6d8f6b0b 100644 --- a/UnitTests/TopLevels/WizardTests.cs +++ b/UnitTests/TopLevels/WizardTests.cs @@ -518,7 +518,7 @@ public void Finish_Button_Closes () wizard.AddStep (step1); var finishedFired = false; - wizard.Finished += (args) => { + wizard.Finished += (s, args) => { finishedFired = true; }; @@ -548,7 +548,7 @@ public void Finish_Button_Closes () wizard.AddStep (step2); finishedFired = false; - wizard.Finished += (args) => { + wizard.Finished += (s, args) => { finishedFired = true; }; @@ -586,7 +586,7 @@ public void Finish_Button_Closes () step1.Enabled = false; finishedFired = false; - wizard.Finished += (args) => { + wizard.Finished += (s, args) => { finishedFired = true; }; diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index a1ea6e14e1..1104154b3d 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -310,7 +310,7 @@ public void Run_All_Views_Tester_Scenario () } }; - _xRadioGroup.SelectedItemChanged += (selected) => DimPosChanged (_curView); + _xRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); _xText.TextChanged += (args) => { try { @@ -330,9 +330,9 @@ public void Run_All_Views_Tester_Scenario () } }; - _yRadioGroup.SelectedItemChanged += (selected) => DimPosChanged (_curView); + _yRadioGroup.SelectedItemChanged += (s,selected) => DimPosChanged (_curView); - _wRadioGroup.SelectedItemChanged += (selected) => DimPosChanged (_curView); + _wRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); _wText.TextChanged += (args) => { try { @@ -352,7 +352,7 @@ public void Run_All_Views_Tester_Scenario () } }; - _hRadioGroup.SelectedItemChanged += (selected) => DimPosChanged (_curView); + _hRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); Top.Add (_leftPane, _settingsPane, _hostPane); diff --git a/UnitTests/Views/RadioGroupTests.cs b/UnitTests/Views/RadioGroupTests.cs index ec2e76a18b..2c1e8a93cb 100644 --- a/UnitTests/Views/RadioGroupTests.cs +++ b/UnitTests/Views/RadioGroupTests.cs @@ -150,7 +150,7 @@ public void SelectedItemChanged_Event () var previousSelectedItem = -1; var selectedItem = -1; var rg = new RadioGroup (new NStack.ustring [] { "Test", "New Test" }); - rg.SelectedItemChanged += (e) => { + rg.SelectedItemChanged += (s,e) => { previousSelectedItem = e.PreviousSelectedItem; selectedItem = e.SelectedItem; }; diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index e421b79717..30f1a134c6 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -85,7 +85,7 @@ private void _hostView_DrawContent (Rect obj) _scrollBar.Refresh (); } - private void _scrollBar_ChangedPosition () + private void _scrollBar_ChangedPosition (object sender, EventArgs e) { _hostView.Top = _scrollBar.Position; if (_hostView.Top != _scrollBar.Position) { @@ -94,7 +94,7 @@ private void _scrollBar_ChangedPosition () _hostView.SetNeedsDisplay (); } - private void _scrollBar_OtherScrollBarView_ChangedPosition () + private void _scrollBar_OtherScrollBarView_ChangedPosition (object sender, EventArgs e) { _hostView.Left = _scrollBar.OtherScrollBarView.Position; if (_hostView.Left != _scrollBar.OtherScrollBarView.Position) { @@ -478,7 +478,7 @@ public void Constructor_ShowBothScrollIndicator_False_And_IsVertical_True_Refres }; win.Add (newScrollBarView); - newScrollBarView.ChangedPosition += () => { + newScrollBarView.ChangedPosition += (s,e) => { listView.TopItem = newScrollBarView.Position; if (listView.TopItem != newScrollBarView.Position) { newScrollBarView.Position = listView.TopItem; @@ -553,7 +553,7 @@ public void Constructor_ShowBothScrollIndicator_False_And_IsVertical_False_Refre }; win.Add (newScrollBarView); - newScrollBarView.ChangedPosition += () => { + newScrollBarView.ChangedPosition += (s,e) => { listView.LeftItem = newScrollBarView.Position; if (listView.LeftItem != newScrollBarView.Position) { newScrollBarView.Position = listView.LeftItem; @@ -652,7 +652,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible () var scrollBar = new ScrollBarView (textView, true); - scrollBar.ChangedPosition += () => { + scrollBar.ChangedPosition += (s,e) => { textView.TopRow = scrollBar.Position; if (textView.TopRow != scrollBar.Position) { scrollBar.Position = textView.TopRow; @@ -660,7 +660,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible () textView.SetNeedsDisplay (); }; - scrollBar.OtherScrollBarView.ChangedPosition += () => { + scrollBar.OtherScrollBarView.ChangedPosition += (s,e) => { textView.LeftColumn = scrollBar.OtherScrollBarView.Position; if (textView.LeftColumn != scrollBar.OtherScrollBarView.Position) { scrollBar.OtherScrollBarView.Position = textView.LeftColumn; diff --git a/UnitTests/Views/TableViewTests.cs b/UnitTests/Views/TableViewTests.cs index e4c46aa7bf..b79e10f116 100644 --- a/UnitTests/Views/TableViewTests.cs +++ b/UnitTests/Views/TableViewTests.cs @@ -100,7 +100,7 @@ public void SelectedCellChanged_NotFiredForSameValue () }; bool called = false; - tableView.SelectedCellChanged += (e) => { called = true; }; + tableView.SelectedCellChanged += (s,e) => { called = true; }; Assert.Equal (0, tableView.SelectedColumn); Assert.False (called); @@ -124,7 +124,7 @@ public void SelectedCellChanged_SelectedColumnIndexesCorrect () }; bool called = false; - tableView.SelectedCellChanged += (e) => { + tableView.SelectedCellChanged += (s,e) => { called = true; Assert.Equal (0, e.OldCol); Assert.Equal (10, e.NewCol); @@ -142,7 +142,7 @@ public void SelectedCellChanged_SelectedRowIndexesCorrect () }; bool called = false; - tableView.SelectedCellChanged += (e) => { + tableView.SelectedCellChanged += (s,e) => { called = true; Assert.Equal (0, e.OldRow); Assert.Equal (10, e.NewRow); @@ -520,7 +520,7 @@ public void TableView_Activate() { string activatedValue = null; var tv = new TableView (BuildTable(1,1)); - tv.CellActivated += (c) => activatedValue = c.Table.Rows[c.Row][c.Col].ToString(); + tv.CellActivated += (s,c) => activatedValue = c.Table.Rows[c.Row][c.Col].ToString(); Application.Top.Add (tv); Application.Begin (Application.Top); diff --git a/UnitTests/Views/TextFieldTests.cs b/UnitTests/Views/TextFieldTests.cs index 531b35120b..4eaa588ca8 100644 --- a/UnitTests/Views/TextFieldTests.cs +++ b/UnitTests/Views/TextFieldTests.cs @@ -663,7 +663,7 @@ public void TextChanging_Event () { bool cancel = true; - _textField.TextChanging += (e) => { + _textField.TextChanging += (s,e) => { Assert.Equal ("changing", e.NewText); if (cancel) { e.Cancel = true; @@ -781,7 +781,7 @@ public void Cancel_TextChanging_ThenBackspace () Assert.Equal ("A", tf.Text.ToString ()); // cancel the next keystroke - tf.TextChanging += (e) => e.Cancel = e.NewText == "AB"; + tf.TextChanging += (s,e) => e.Cancel = e.NewText == "AB"; tf.ProcessKey (new KeyEvent (Key.B, new KeyModifiers ())); // B was canceled so should just be A @@ -1137,7 +1137,7 @@ public void DeleteSelectedText_InsertText_DeleteCharLeft_DeleteCharRight_Cut () var oldText = ""; var tf = new TextField () { Width = 10, Text = "-1" }; - tf.TextChanging += (e) => newText = e.NewText.ToString (); + tf.TextChanging += (s,e) => newText = e.NewText.ToString (); tf.TextChanged += (e) => oldText = e.ToString (); Application.Top.Add (tf); diff --git a/UnitTests/Views/TextViewTests.cs b/UnitTests/Views/TextViewTests.cs index 981ff2d148..372843a49e 100644 --- a/UnitTests/Views/TextViewTests.cs +++ b/UnitTests/Views/TextViewTests.cs @@ -1380,7 +1380,7 @@ public void Paste_Always_Clear_The_SelectedText () [TextViewTestsAutoInitShutdown] public void TextChanged_Event () { - _textView.TextChanged += () => { + _textView.TextChanged += (s,e) => { if (_textView.Text == "changing") { Assert.Equal ("changing", _textView.Text); _textView.Text = "changed"; @@ -1396,7 +1396,7 @@ public void TextChanged_Event () public void TextChanged_Event_NoFires_OnTyping () { var eventcount = 0; - _textView.TextChanged += () => { + _textView.TextChanged += (s,e) => { eventcount++; }; @@ -6477,7 +6477,7 @@ public void ContentsChanged_Event_NoFires_On_CursorPosition () Height = 10, }; - tv.ContentsChanged += (e) => { + tv.ContentsChanged += (s,e) => { eventcount++; }; Assert.Equal (0, eventcount); @@ -6498,7 +6498,7 @@ public void ContentsChanged_Event_Fires_On_InsertText () }; tv.CursorPosition = new Point (0, 0); - tv.ContentsChanged += (e) => { + tv.ContentsChanged += (s,e) => { eventcount++; }; @@ -6536,7 +6536,7 @@ public void ContentsChanged_Event_Fires_On_Init () Width = 50, Height = 10, }; - tv.ContentsChanged += (e) => { + tv.ContentsChanged += (s,e) => { eventcount++; Assert.Equal (expectedRow, e.Row); Assert.Equal (expectedCol, e.Col); @@ -6565,7 +6565,7 @@ public void ContentsChanged_Event_Fires_On_Set_Text () // row/col = 0 when you set Text Text = "abc", }; - tv.ContentsChanged += (e) => { + tv.ContentsChanged += (s,e) => { eventcount++; Assert.Equal (expectedRow, e.Row); Assert.Equal (expectedCol, e.Col); @@ -6597,7 +6597,7 @@ public void ContentsChanged_Event_Fires_On_Typing () Width = 50, Height = 10, }; - tv.ContentsChanged += (e) => { + tv.ContentsChanged += (s,e) => { eventcount++; Assert.Equal (expectedRow, e.Row); Assert.Equal (expectedCol, e.Col); @@ -6622,7 +6622,7 @@ public void ContentsChanged_Event_Fires_Using_Kill_Delete_Tests () { var eventcount = 0; - _textView.ContentsChanged += (e) => { + _textView.ContentsChanged += (s,e) => { eventcount++; }; @@ -6649,7 +6649,7 @@ public void ContentsChanged_Event_Fires_Using_Copy_Or_Cut_Tests () { var eventcount = 0; - _textView.ContentsChanged += (e) => { + _textView.ContentsChanged += (s,e) => { eventcount++; }; @@ -6715,7 +6715,7 @@ public void ContentsChanged_Event_Fires_On_Undo_Redo () var eventcount = 0; var expectedEventCount = 0; - _textView.ContentsChanged += (e) => { + _textView.ContentsChanged += (s,e) => { eventcount++; }; @@ -6759,7 +6759,7 @@ public void ContentsChanged_Event_Fires_ClearHistoryChanges () Height = 10, Text = text, }; - tv.ContentsChanged += (e) => { + tv.ContentsChanged += (s,e) => { eventcount++; }; @@ -6784,7 +6784,7 @@ public void ContentsChanged_Event_Fires_LoadStream_By_Calling_HistoryText_Clear Width = 50, Height = 10, }; - tv.ContentsChanged += (e) => { + tv.ContentsChanged += (s,e) => { eventcount++; }; @@ -6804,7 +6804,7 @@ public void ContentsChanged_Event_Fires_On_LoadFile_By_Calling_HistoryText_Clear Width = 50, Height = 10, }; - tv.ContentsChanged += (e) => { + tv.ContentsChanged += (s,e) => { eventcount++; }; diff --git a/UnitTests/Views/TreeViewTests.cs b/UnitTests/Views/TreeViewTests.cs index 3390339235..0fc4ca843f 100644 --- a/UnitTests/Views/TreeViewTests.cs +++ b/UnitTests/Views/TreeViewTests.cs @@ -492,8 +492,8 @@ public void ObjectActivated_Called () bool called = false; // register for the event - tree.ObjectActivated += (s) => { - activated = s.ActivatedObject; + tree.ObjectActivated += (s,e) => { + activated = e.ActivatedObject; called = true; }; @@ -565,8 +565,8 @@ public void ObjectActivated_CustomKey () bool called = false; // register for the event - tree.ObjectActivated += (s) => { - activated = s.ActivatedObject; + tree.ObjectActivated += (s,e) => { + activated = e.ActivatedObject; called = true; }; @@ -607,8 +607,8 @@ public void ObjectActivationButton_DoubleClick () bool called = false; // register for the event - tree.ObjectActivated += (s) => { - activated = s.ActivatedObject; + tree.ObjectActivated += (s, e) => { + activated = e.ActivatedObject; called = true; }; @@ -638,8 +638,8 @@ public void ObjectActivationButton_SetToNull () bool called = false; // register for the event - tree.ObjectActivated += (s) => { - activated = s.ActivatedObject; + tree.ObjectActivated += (s,e) => { + activated = e.ActivatedObject; called = true; }; @@ -670,8 +670,8 @@ public void ObjectActivationButton_RightClick () bool called = false; // register for the event - tree.ObjectActivated += (s) => { - activated = s.ActivatedObject; + tree.ObjectActivated += (s,e) => { + activated = e.ActivatedObject; called = true; }; From 796e15a64dd7cdd8323c0d5f0bb2506d2940b3e1 Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 12 Mar 2023 02:39:32 +0000 Subject: [PATCH 17/46] Added DrawEventArgs --- .../Core/Autocomplete/Autocomplete.cs | 4 +-- Terminal.Gui/Core/EventArgs/DrawEventArgs.cs | 28 +++++++++++++++++++ Terminal.Gui/Core/View.cs | 8 +++--- Terminal.Gui/Windows/Wizard.cs | 2 +- UICatalog/Scenarios/CharacterMap.cs | 4 ++- UICatalog/Scenarios/CsvEditor.cs | 2 +- UICatalog/Scenarios/Editor.cs | 6 ++-- UICatalog/Scenarios/ListViewWithSelection.cs | 2 +- UICatalog/Scenarios/ListsAndCombos.cs | 4 +-- UICatalog/Scenarios/Scrolling.cs | 2 +- UICatalog/Scenarios/TableEditor.cs | 2 +- UICatalog/Scenarios/Text.cs | 2 +- .../Scenarios/TextViewAutocompletePopup.cs | 10 +++---- UICatalog/Scenarios/TreeViewFileSystem.cs | 2 +- UICatalog/Scenarios/Wizards.cs | 2 +- UnitTests/Core/LineCanvasTests.cs | 2 +- UnitTests/Core/ViewTests.cs | 14 +++++----- UnitTests/Views/ScrollBarViewTests.cs | 8 +++--- 18 files changed, 67 insertions(+), 37 deletions(-) create mode 100644 Terminal.Gui/Core/EventArgs/DrawEventArgs.cs diff --git a/Terminal.Gui/Core/Autocomplete/Autocomplete.cs b/Terminal.Gui/Core/Autocomplete/Autocomplete.cs index ea987c16b8..9b225e5b8a 100644 --- a/Terminal.Gui/Core/Autocomplete/Autocomplete.cs +++ b/Terminal.Gui/Core/Autocomplete/Autocomplete.cs @@ -80,12 +80,12 @@ private void Top_Removed (object sender, SuperViewChangedEventArgs e) ManipulatePopup (); } - private void Top_DrawContentComplete (Rect obj) + private void Top_DrawContentComplete (object sender, DrawEventArgs e) { ManipulatePopup (); } - private void Top_DrawContent (Rect obj) + private void Top_DrawContent (object sender, DrawEventArgs e) { if (!closed) { ReopenSuggestions (); diff --git a/Terminal.Gui/Core/EventArgs/DrawEventArgs.cs b/Terminal.Gui/Core/EventArgs/DrawEventArgs.cs new file mode 100644 index 0000000000..65aee24388 --- /dev/null +++ b/Terminal.Gui/Core/EventArgs/DrawEventArgs.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Terminal.Gui { + + /// + /// Event args for draw events + /// + public class DrawEventArgs : EventArgs{ + + /// + /// Creates a new instance of the class. + /// + /// Gets the view-relative rectangle describing the currently visible viewport into the . + public DrawEventArgs (Rect rect) + { + Rect = rect; + } + + /// + /// Gets the view-relative rectangle describing the currently visible viewport into the . + /// + public Rect Rect { get; } + } +} diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index fa67b1c52d..95dde58a5f 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -1602,7 +1602,7 @@ Rect GetContainerBounds () /// Rect provides the view-relative rectangle describing the currently visible viewport into the . /// /// - public event Action DrawContent; + public event EventHandler DrawContent; /// /// Enables overrides to draw infinitely scrolled content and/or a background behind added controls. @@ -1613,7 +1613,7 @@ Rect GetContainerBounds () /// public virtual void OnDrawContent (Rect viewport) { - DrawContent?.Invoke (viewport); + DrawContent?.Invoke (this, new DrawEventArgs(viewport)); } /// @@ -1627,7 +1627,7 @@ public virtual void OnDrawContent (Rect viewport) /// Rect provides the view-relative rectangle describing the currently visible viewport into the . /// /// - public event Action DrawContentComplete; + public event EventHandler DrawContentComplete; /// /// Enables overrides after completed drawing infinitely scrolled content and/or a background behind removed controls. @@ -1638,7 +1638,7 @@ public virtual void OnDrawContent (Rect viewport) /// public virtual void OnDrawContentComplete (Rect viewport) { - DrawContentComplete?.Invoke (viewport); + DrawContentComplete?.Invoke (this, new DrawEventArgs (viewport)); } /// diff --git a/Terminal.Gui/Windows/Wizard.cs b/Terminal.Gui/Windows/Wizard.cs index f3fff9c03d..ea774ca963 100644 --- a/Terminal.Gui/Windows/Wizard.cs +++ b/Terminal.Gui/Windows/Wizard.cs @@ -243,7 +243,7 @@ public WizardStep (ustring title) } }; - helpTextView.DrawContent += (e) => { + helpTextView.DrawContent += (s,e) => { scrollBar.Size = helpTextView.Lines; scrollBar.Position = helpTextView.TopRow; if (scrollBar.OtherScrollBarView != null) { diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index b89d2fa5a9..6728d09e43 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -226,8 +226,10 @@ private void CopyGlyph () Clipboard.Contents = $"{new Rune (SelectedGlyph)}"; } - private void CharMap_DrawContent (Rect viewport) + private void CharMap_DrawContent (object sender, DrawEventArgs e) { + Rect viewport = e.Rect; + var oldClip = Driver.Clip; Driver.Clip = Frame; // Redraw doesn't know about the scroll indicators, so if off, add one to height diff --git a/UICatalog/Scenarios/CsvEditor.cs b/UICatalog/Scenarios/CsvEditor.cs index 0ae0ccb63d..04d49b6f2c 100644 --- a/UICatalog/Scenarios/CsvEditor.cs +++ b/UICatalog/Scenarios/CsvEditor.cs @@ -462,7 +462,7 @@ private void SetupScrollBar () _listView.SetNeedsDisplay (); };*/ - tableView.DrawContent += (e) => { + tableView.DrawContent += (s,e) => { _scrollBar.Size = tableView.Table?.Rows?.Count ?? 0; _scrollBar.Position = tableView.RowOffset; // _scrollBar.OtherScrollBarView.Size = _listView.Maxlength - 1; diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index 1a98fea9f8..60029e0491 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -160,7 +160,7 @@ public override void Init (ColorScheme colorScheme) } }; - _textView.DrawContent += (e) => { + _textView.DrawContent += (s,e) => { _scrollBar.Size = _textView.Lines; _scrollBar.Position = _textView.TopRow; if (_scrollBar.OtherScrollBarView != null) { @@ -765,7 +765,7 @@ private void SetFindText () private View FindTab () { var d = new View (); - d.DrawContent += (e) => { + d.DrawContent += (s,e) => { foreach (var v in d.Subviews) { v.SetNeedsDisplay (); } @@ -857,7 +857,7 @@ private View FindTab () private View ReplaceTab () { var d = new View (); - d.DrawContent += (e) => { + d.DrawContent += (s,e) => { foreach (var v in d.Subviews) { v.SetNeedsDisplay (); } diff --git a/UICatalog/Scenarios/ListViewWithSelection.cs b/UICatalog/Scenarios/ListViewWithSelection.cs index b05dfea278..42a18f6a0c 100644 --- a/UICatalog/Scenarios/ListViewWithSelection.cs +++ b/UICatalog/Scenarios/ListViewWithSelection.cs @@ -78,7 +78,7 @@ public override void Setup () _listView.SetNeedsDisplay (); }; - _listView.DrawContent += (e) => { + _listView.DrawContent += (s,e) => { _scrollBar.Size = _listView.Source.Count - 1; _scrollBar.Position = _listView.TopItem; _scrollBar.OtherScrollBarView.Size = _listView.Maxlength - 1; diff --git a/UICatalog/Scenarios/ListsAndCombos.cs b/UICatalog/Scenarios/ListsAndCombos.cs index 80ebac6235..848083793f 100644 --- a/UICatalog/Scenarios/ListsAndCombos.cs +++ b/UICatalog/Scenarios/ListsAndCombos.cs @@ -57,7 +57,7 @@ public override void Setup () listview.SetNeedsDisplay (); }; - listview.DrawContent += (e) => { + listview.DrawContent += (s,e) => { _scrollBar.Size = listview.Source.Count - 1; _scrollBar.Position = listview.TopItem; _scrollBar.OtherScrollBarView.Size = listview.Maxlength - 1; @@ -101,7 +101,7 @@ public override void Setup () comboBox.SetNeedsDisplay (); }; - comboBox.DrawContent += (e) => { + comboBox.DrawContent += (s,e) => { scrollBarCbx.Size = comboBox.Source.Count; scrollBarCbx.Position = ((ListView)comboBox.Subviews [1]).TopItem; scrollBarCbx.OtherScrollBarView.Size = ((ListView)comboBox.Subviews [1]).Maxlength - 1; diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index a6ca4ff19c..ddc872383f 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -270,7 +270,7 @@ void Top_Loaded (object sender, EventArgs args) }; var filler = new Filler (new Rect (0, 0, 60, 40)); scrollView2.Add (filler); - scrollView2.DrawContent += (r) => { + scrollView2.DrawContent += (s,e) => { scrollView2.ContentSize = filler.GetContentSize (); }; Win.Add (scrollView2); diff --git a/UICatalog/Scenarios/TableEditor.cs b/UICatalog/Scenarios/TableEditor.cs index e5bcb40f44..6a0c9cd179 100644 --- a/UICatalog/Scenarios/TableEditor.cs +++ b/UICatalog/Scenarios/TableEditor.cs @@ -335,7 +335,7 @@ private void SetupScrollBar () _listView.SetNeedsDisplay (); };*/ - tableView.DrawContent += (e) => { + tableView.DrawContent += (s,e) => { _scrollBar.Size = tableView.Table?.Rows?.Count ?? 0; _scrollBar.Position = tableView.RowOffset; // _scrollBar.OtherScrollBarView.Size = _listView.Maxlength - 1; diff --git a/UICatalog/Scenarios/Text.cs b/UICatalog/Scenarios/Text.cs index 7521e6c3d5..202e81ee0b 100644 --- a/UICatalog/Scenarios/Text.cs +++ b/UICatalog/Scenarios/Text.cs @@ -56,7 +56,7 @@ void TextField_TextChanging (object sender, TextChangingEventArgs e) textView.DrawContent += TextView_DrawContent; // This shows how to enable autocomplete in TextView. - void TextView_DrawContent (Rect e) + void TextView_DrawContent (object sender, DrawEventArgs e) { textView.Autocomplete.AllSuggestions = Regex.Matches (textView.Text.ToString (), "\\w+") .Select (s => s.Value) diff --git a/UICatalog/Scenarios/TextViewAutocompletePopup.cs b/UICatalog/Scenarios/TextViewAutocompletePopup.cs index e37019cd9c..a01ea2c0bc 100644 --- a/UICatalog/Scenarios/TextViewAutocompletePopup.cs +++ b/UICatalog/Scenarios/TextViewAutocompletePopup.cs @@ -126,27 +126,27 @@ private void SetAllSuggestions (TextView view) .Distinct ().ToList (); } - private void TextViewCentered_DrawContent (Rect obj) + private void TextViewCentered_DrawContent (object sender, DrawEventArgs e) { SetAllSuggestions (textViewCentered); } - private void TextViewBottomRight_DrawContent (Rect obj) + private void TextViewBottomRight_DrawContent (object sender, DrawEventArgs e) { SetAllSuggestions (textViewBottomRight); } - private void TextViewBottomLeft_DrawContent (Rect obj) + private void TextViewBottomLeft_DrawContent (object sender, DrawEventArgs e) { SetAllSuggestions (textViewBottomLeft); } - private void TextViewTopRight_DrawContent (Rect obj) + private void TextViewTopRight_DrawContent (object sender, DrawEventArgs e) { SetAllSuggestions (textViewTopRight); } - private void TextViewTopLeft_DrawContent (Rect obj) + private void TextViewTopLeft_DrawContent (object sender, DrawEventArgs e) { SetAllSuggestions (textViewTopLeft); } diff --git a/UICatalog/Scenarios/TreeViewFileSystem.cs b/UICatalog/Scenarios/TreeViewFileSystem.cs index d015e33e0a..b895e48410 100644 --- a/UICatalog/Scenarios/TreeViewFileSystem.cs +++ b/UICatalog/Scenarios/TreeViewFileSystem.cs @@ -220,7 +220,7 @@ private void SetupScrollBar () treeViewFiles.SetNeedsDisplay (); }; - treeViewFiles.DrawContent += (e) => { + treeViewFiles.DrawContent += (s,e) => { _scrollBar.Size = treeViewFiles.ContentHeight; _scrollBar.Position = treeViewFiles.ScrollOffsetVertical; _scrollBar.OtherScrollBarView.Size = treeViewFiles.GetContentWidth (true); diff --git a/UICatalog/Scenarios/Wizards.cs b/UICatalog/Scenarios/Wizards.cs index a6a94e3fad..29e5a3e486 100644 --- a/UICatalog/Scenarios/Wizards.cs +++ b/UICatalog/Scenarios/Wizards.cs @@ -253,7 +253,7 @@ void Top_Loaded (object sender, EventArgs args) } }; - someText.DrawContent += (e) => { + someText.DrawContent += (s,e) => { scrollBar.Size = someText.Lines; scrollBar.Position = someText.TopRow; if (scrollBar.OtherScrollBarView != null) { diff --git a/UnitTests/Core/LineCanvasTests.cs b/UnitTests/Core/LineCanvasTests.cs index 65bc1f3a25..1d347708fa 100644 --- a/UnitTests/Core/LineCanvasTests.cs +++ b/UnitTests/Core/LineCanvasTests.cs @@ -330,7 +330,7 @@ private View GetCanvas (out LineCanvas canvas, int offsetX = 0, int offsetY = 0) }; var canvasCopy = canvas = new LineCanvas (); - v.DrawContentComplete += (r) => { + v.DrawContentComplete += (s, e) => { foreach(var p in canvasCopy.GenerateImage(v.Bounds)) { v.AddRune( diff --git a/UnitTests/Core/ViewTests.cs b/UnitTests/Core/ViewTests.cs index bd45d853c3..343768c212 100644 --- a/UnitTests/Core/ViewTests.cs +++ b/UnitTests/Core/ViewTests.cs @@ -1655,7 +1655,7 @@ public void DrawFrame_With_Positive_Positions () { var view = new View (new Rect (0, 0, 8, 4)); - view.DrawContent += (_) => view.DrawFrame (view.Bounds, 0, true); + view.DrawContent += (s, e) => view.DrawFrame (view.Bounds, 0, true); Assert.Equal (Point.Empty, new Point (view.Frame.X, view.Frame.Y)); Assert.Equal (new Size (8, 4), new Size (view.Frame.Width, view.Frame.Height)); @@ -1679,7 +1679,7 @@ public void DrawFrame_With_Minimum_Size () { var view = new View (new Rect (0, 0, 2, 2)); - view.DrawContent += (_) => view.DrawFrame (view.Bounds, 0, true); + view.DrawContent += (s, e) => view.DrawFrame (view.Bounds, 0, true); Assert.Equal (Point.Empty, new Point (view.Frame.X, view.Frame.Y)); Assert.Equal (new Size (2, 2), new Size (view.Frame.Width, view.Frame.Height)); @@ -1701,7 +1701,7 @@ public void DrawFrame_With_Negative_Positions () { var view = new View (new Rect (-1, 0, 8, 4)); - view.DrawContent += (_) => view.DrawFrame (view.Bounds, 0, true); + view.DrawContent += (s, e) => view.DrawFrame (view.Bounds, 0, true); Assert.Equal (new Point (-1, 0), new Point (view.Frame.X, view.Frame.Y)); Assert.Equal (new Size (8, 4), new Size (view.Frame.Width, view.Frame.Height)); @@ -2025,7 +2025,7 @@ public void Clear_Can_Use_Driver_AddRune_Or_AddStr_Methods () Width = Dim.Fill (), Height = Dim.Fill () }; - view.DrawContent += e => { + view.DrawContent += (s,e) => { view.DrawFrame (view.Bounds); var savedClip = Application.Driver.Clip; Application.Driver.Clip = new Rect (1, 1, view.Bounds.Width - 2, view.Bounds.Height - 2); @@ -2073,7 +2073,7 @@ public void Clear_Bounds_Can_Use_Driver_AddRune_Or_AddStr_Methods () Width = Dim.Fill (), Height = Dim.Fill () }; - view.DrawContent += e => { + view.DrawContent += (s,e) => { view.DrawFrame (view.Bounds); var savedClip = Application.Driver.Clip; Application.Driver.Clip = new Rect (1, 1, view.Bounds.Width - 2, view.Bounds.Height - 2); @@ -2268,9 +2268,9 @@ public void DrawContentComplete_Event_Is_Always_Called () var tvCalled = false; var view = new View ("View") { Width = 10, Height = 10 }; - view.DrawContentComplete += (e) => viewCalled = true; + view.DrawContentComplete += (s,e) => viewCalled = true; var tv = new TextView () { Y = 11, Width = 10, Height = 10 }; - tv.DrawContentComplete += (e) => tvCalled = true; + tv.DrawContentComplete += (s, e) => tvCalled = true; Application.Top.Add (view, tv); Application.Begin (Application.Top); diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 30f1a134c6..11e7a030a4 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -76,7 +76,7 @@ private void RemoveHandlers () _added = false; } - private void _hostView_DrawContent (Rect obj) + private void _hostView_DrawContent (object sender, DrawEventArgs e) { _scrollBar.Size = _hostView.Lines; _scrollBar.Position = _hostView.Top; @@ -487,7 +487,7 @@ public void Constructor_ShowBothScrollIndicator_False_And_IsVertical_True_Refres listView.SetNeedsDisplay (); }; - listView.DrawContent += (e) => { + listView.DrawContent += (s,e) => { newScrollBarView.Size = listView.Source.Count; Assert.Equal (newScrollBarView.Size, listView.Source.Count); newScrollBarView.Position = listView.TopItem; @@ -562,7 +562,7 @@ public void Constructor_ShowBothScrollIndicator_False_And_IsVertical_False_Refre listView.SetNeedsDisplay (); }; - listView.DrawContent += (e) => { + listView.DrawContent += (s,e) => { newScrollBarView.Size = listView.Maxlength; Assert.Equal (newScrollBarView.Size, listView.Maxlength); newScrollBarView.Position = listView.LeftItem; @@ -684,7 +684,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible () } }; - textView.DrawContent += (e) => { + textView.DrawContent += (s,e) => { scrollBar.Size = textView.Lines; scrollBar.Position = textView.TopRow; if (scrollBar.OtherScrollBarView != null) { From 997bfe63a927ff047115330e9ac4bbc8e8b94795 Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 12 Mar 2023 02:44:39 +0000 Subject: [PATCH 18/46] Added MouseFlagsChangedEventArgs --- .../EventArgs/MouseFlagsChangedEventArgs.cs | 34 +++++++++++++++++++ Terminal.Gui/Views/ContextMenu.cs | 4 +-- UnitTests/Menus/ContextMenuTests.cs | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 Terminal.Gui/Core/EventArgs/MouseFlagsChangedEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/MouseFlagsChangedEventArgs.cs b/Terminal.Gui/Core/EventArgs/MouseFlagsChangedEventArgs.cs new file mode 100644 index 0000000000..36bf7390f9 --- /dev/null +++ b/Terminal.Gui/Core/EventArgs/MouseFlagsChangedEventArgs.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Terminal.Gui { + /// + /// Args for events that describe a change in + /// + public class MouseFlagsChangedEventArgs : EventArgs{ + + /// + /// Creates a new instance of the class. + /// + /// + /// + public MouseFlagsChangedEventArgs (MouseFlags oldValue, MouseFlags newValue) + { + OldValue = oldValue; + NewValue = newValue; + } + + /// + /// The old value before event + /// + public MouseFlags OldValue { get; } + + /// + /// The new value + /// + public MouseFlags NewValue { get; } + } +} diff --git a/Terminal.Gui/Views/ContextMenu.cs b/Terminal.Gui/Views/ContextMenu.cs index e4cd03d06f..a2321c9f6d 100644 --- a/Terminal.Gui/Views/ContextMenu.cs +++ b/Terminal.Gui/Views/ContextMenu.cs @@ -174,7 +174,7 @@ public void Hide () /// /// Event invoked when the is changed. /// - public event Action MouseFlagsChanged; + public event EventHandler MouseFlagsChanged; /// /// Gets or sets the menu position. @@ -206,7 +206,7 @@ public MouseFlags MouseFlags { set { var oldFlags = mouseFlags; mouseFlags = value; - MouseFlagsChanged?.Invoke (oldFlags); + MouseFlagsChanged?.Invoke (this, new MouseFlagsChangedEventArgs(oldFlags,value)); } } diff --git a/UnitTests/Menus/ContextMenuTests.cs b/UnitTests/Menus/ContextMenuTests.cs index 9062e05aa0..419aaa9e1f 100644 --- a/UnitTests/Menus/ContextMenuTests.cs +++ b/UnitTests/Menus/ContextMenuTests.cs @@ -241,7 +241,7 @@ public void MouseFlagsChanged_Event () var oldMouseFlags = new MouseFlags (); var cm = new ContextMenu (); - cm.MouseFlagsChanged += (e) => oldMouseFlags = e; + cm.MouseFlagsChanged += (s,e) => oldMouseFlags = e.OldValue; cm.MouseFlags = MouseFlags.Button2Clicked; Assert.Equal (MouseFlags.Button2Clicked, cm.MouseFlags); From 6f5ef32fb70bce6b6540de3a43801407adc0c47f Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 12 Mar 2023 02:47:18 +0000 Subject: [PATCH 19/46] Switch `event Action` to `event EventHandler` --- Terminal.Gui/Views/ContextMenu.cs | 2 +- Terminal.Gui/Views/HexView.cs | 4 ++-- Terminal.Gui/Views/Menu.cs | 8 ++++---- Terminal.Gui/Views/TextView.cs | 6 +++--- UICatalog/Scenarios/HexEditor.cs | 2 +- UnitTests/Menus/MenuTests.cs | 4 ++-- UnitTests/Views/HexViewTests.cs | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Terminal.Gui/Views/ContextMenu.cs b/Terminal.Gui/Views/ContextMenu.cs index a2321c9f6d..df6da1de98 100644 --- a/Terminal.Gui/Views/ContextMenu.cs +++ b/Terminal.Gui/Views/ContextMenu.cs @@ -61,7 +61,7 @@ public ContextMenu (int x, int y, MenuBarItem menuItems) Position = new Point (x, y); } - private void MenuBar_MenuAllClosed () + private void MenuBar_MenuAllClosed (object sender, EventArgs e) { Dispose (); } diff --git a/Terminal.Gui/Views/HexView.cs b/Terminal.Gui/Views/HexView.cs index e92a17041d..68f7245440 100644 --- a/Terminal.Gui/Views/HexView.cs +++ b/Terminal.Gui/Views/HexView.cs @@ -108,7 +108,7 @@ public HexView (Stream source) : base () /// /// Event to be invoked when the position and cursor position changes. /// - public event Action PositionChanged; + public event EventHandler PositionChanged; /// /// Sets or gets the the is operating on; the stream must support seeking ( == true). @@ -484,7 +484,7 @@ public virtual void OnEdited (KeyValuePair keyValuePair) /// public virtual void OnPositionChanged () { - PositionChanged?.Invoke (new HexViewEventArgs (Position, CursorPosition, BytesPerLine)); + PositionChanged?.Invoke (this, new HexViewEventArgs (Position, CursorPosition, BytesPerLine)); } /// diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs index 3eaed4c9d3..585cc11e1b 100644 --- a/Terminal.Gui/Views/Menu.cs +++ b/Terminal.Gui/Views/Menu.cs @@ -1206,12 +1206,12 @@ void Selected (MenuItem item) /// /// Raised when a menu is closing passing . /// - public event Action MenuClosing; + public event EventHandler MenuClosing; /// /// Raised when all the menu is closed. /// - public event Action MenuAllClosed; + public event EventHandler MenuAllClosed; internal Menu openMenu; Menu ocm; @@ -1275,7 +1275,7 @@ public virtual void OnMenuOpened () public virtual MenuClosingEventArgs OnMenuClosing (MenuBarItem currentMenu, bool reopen, bool isSubMenu) { var ev = new MenuClosingEventArgs (currentMenu, reopen, isSubMenu); - MenuClosing?.Invoke (ev); + MenuClosing?.Invoke (this, ev); return ev; } @@ -1284,7 +1284,7 @@ public virtual MenuClosingEventArgs OnMenuClosing (MenuBarItem currentMenu, bool /// public virtual void OnMenuAllClosed () { - MenuAllClosed?.Invoke (); + MenuAllClosed?.Invoke (this, EventArgs.Empty); } View lastFocused; diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index cca45f7ea9..b7a59371cd 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -16,7 +16,7 @@ namespace Terminal.Gui { class TextModel { List> lines = new List> (); - public event Action LinesLoaded; + public event EventHandler LinesLoaded; public bool LoadFile (string file) { @@ -120,7 +120,7 @@ public void LoadString (ustring content) void OnLinesLoaded () { - LinesLoaded?.Invoke (); + LinesLoaded?.Invoke (this, EventArgs.Empty); } public override string ToString () @@ -1383,7 +1383,7 @@ private void ContextMenu_KeyChanged (object sender, KeyChangedEventArgs e) ReplaceKeyBinding (e.OldKey, e.NewKey); } - private void Model_LinesLoaded () + private void Model_LinesLoaded (object sender, EventArgs e) { // This call is not needed. Model_LinesLoaded gets invoked when // model.LoadString (value) is called. LoadString is called from one place diff --git a/UICatalog/Scenarios/HexEditor.cs b/UICatalog/Scenarios/HexEditor.cs index 121a164ae4..6784181ee2 100644 --- a/UICatalog/Scenarios/HexEditor.cs +++ b/UICatalog/Scenarios/HexEditor.cs @@ -64,7 +64,7 @@ public override void Setup () Application.Top.Add (statusBar); } - private void _hexView_PositionChanged (HexView.HexViewEventArgs obj) + private void _hexView_PositionChanged (object sender, HexView.HexViewEventArgs obj) { siPositionChanged.Title = $"Position: {obj.Position} Line: {obj.CursorPosition.Y} Col: {obj.CursorPosition.X} Line length: {obj.BytesPerLine}"; statusBar.SetNeedsDisplay (); diff --git a/UnitTests/Menus/MenuTests.cs b/UnitTests/Menus/MenuTests.cs index 972e0e84bb..aeb37e46b9 100644 --- a/UnitTests/Menus/MenuTests.cs +++ b/UnitTests/Menus/MenuTests.cs @@ -128,7 +128,7 @@ public void MenuOpening_MenuOpened_MenuClosing_Events () e.Action (); Assert.Equal ("Copy", miAction); }; - menu.MenuClosing += (e) => { + menu.MenuClosing += (s,e) => { Assert.False (isMenuClosed); if (cancelClosing) { e.Cancel = true; @@ -383,7 +383,7 @@ public void KeyBindings_Command () miCurrent = e; mCurrent = menu.openCurrentMenu; }; - menu.MenuClosing += (_) => { + menu.MenuClosing += (s,e) => { mbiCurrent = null; miCurrent = null; mCurrent = null; diff --git a/UnitTests/Views/HexViewTests.cs b/UnitTests/Views/HexViewTests.cs index 7e8cc02f26..ffa3cfcd9f 100644 --- a/UnitTests/Views/HexViewTests.cs +++ b/UnitTests/Views/HexViewTests.cs @@ -255,7 +255,7 @@ public void PositionChanged_Event () { var hv = new HexView (LoadStream ()) { Width = Dim.Fill (), Height = Dim.Fill () }; HexView.HexViewEventArgs hexViewEventArgs = null; - hv.PositionChanged += (e) => hexViewEventArgs = e; + hv.PositionChanged += (s, e) => hexViewEventArgs = e; Application.Top.Add (hv); Application.Begin (Application.Top); From e347a255b7c3e6fa8c1930d2e0f6dc4d069124d1 Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 12 Mar 2023 02:54:46 +0000 Subject: [PATCH 20/46] Add HexViewEditEventArgs --- Terminal.Gui/Views/HexView.cs | 38 +++++++++++++++++++++++++++----- UICatalog/Scenarios/HexEditor.cs | 2 +- UICatalog/Scenarios/Text.cs | 2 +- UnitTests/Views/HexViewTests.cs | 2 +- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/Terminal.Gui/Views/HexView.cs b/Terminal.Gui/Views/HexView.cs index 68f7245440..910e9e1050 100644 --- a/Terminal.Gui/Views/HexView.cs +++ b/Terminal.Gui/Views/HexView.cs @@ -103,7 +103,7 @@ public HexView (Stream source) : base () /// /// Event to be invoked when an edit is made on the . /// - public event Action> Edited; + public event EventHandler Edited; /// /// Event to be invoked when the position and cursor position changes. @@ -458,11 +458,11 @@ public override bool ProcessKey (KeyEvent keyEvent) firstNibble = false; b = (byte)(b & 0xf | (value << bsize)); edits [position] = b; - OnEdited (new KeyValuePair (position, edits [position])); + OnEdited (new HexViewEditEventArgs (position, edits [position])); } else { b = (byte)(b & 0xf0 | value); edits [position] = b; - OnEdited (new KeyValuePair (position, edits [position])); + OnEdited (new HexViewEditEventArgs (position, edits [position])); MoveRight (); } return true; @@ -473,10 +473,10 @@ public override bool ProcessKey (KeyEvent keyEvent) /// /// Method used to invoke the event passing the . /// - /// The key value pair. - public virtual void OnEdited (KeyValuePair keyValuePair) + /// The key value pair. + public virtual void OnEdited (HexViewEditEventArgs e) { - Edited?.Invoke (keyValuePair); + Edited?.Invoke (this, e); } /// @@ -632,6 +632,32 @@ public override bool OnEnter (View view) return base.OnEnter (view); } + /// + /// Defines the event arguments for event. + /// + public class HexViewEditEventArgs : EventArgs { + + /// + /// Creates a new instance of the class. + /// + /// + /// + public HexViewEditEventArgs (long position, byte newValue) + { + Position = position; + NewValue = newValue; + } + + /// + /// Gets the location of the edit. + /// + public long Position { get; } + + /// + /// Gets the new value for that . + /// + public byte NewValue { get; } + } /// /// Defines the event arguments for event. /// diff --git a/UICatalog/Scenarios/HexEditor.cs b/UICatalog/Scenarios/HexEditor.cs index 6784181ee2..cce25fd92d 100644 --- a/UICatalog/Scenarios/HexEditor.cs +++ b/UICatalog/Scenarios/HexEditor.cs @@ -75,7 +75,7 @@ private void ToggleAllowEdits () _hexView.AllowEdits = (bool)(miAllowEdits.Checked = !miAllowEdits.Checked); } - private void _hexView_Edited (System.Collections.Generic.KeyValuePair obj) + private void _hexView_Edited (object sender, HexView.HexViewEditEventArgs e) { _saved = false; } diff --git a/UICatalog/Scenarios/Text.cs b/UICatalog/Scenarios/Text.cs index 202e81ee0b..7ed9835282 100644 --- a/UICatalog/Scenarios/Text.cs +++ b/UICatalog/Scenarios/Text.cs @@ -136,7 +136,7 @@ void TextView_DrawContent (object sender, DrawEventArgs e) }; var array = ((MemoryStream)hexEditor.Source).ToArray (); labelMirroringHexEditor.Text = Encoding.UTF8.GetString (array, 0, array.Length); - hexEditor.Edited += (kv) => { + hexEditor.Edited += (s,kv) => { hexEditor.ApplyEdits (); var array = ((MemoryStream)hexEditor.Source).ToArray (); labelMirroringHexEditor.Text = Encoding.UTF8.GetString (array, 0, array.Length); diff --git a/UnitTests/Views/HexViewTests.cs b/UnitTests/Views/HexViewTests.cs index ffa3cfcd9f..41f45f8456 100644 --- a/UnitTests/Views/HexViewTests.cs +++ b/UnitTests/Views/HexViewTests.cs @@ -106,7 +106,7 @@ public void Edited_Event () { var hv = new HexView (LoadStream (true)) { Width = 20, Height = 20 }; KeyValuePair keyValuePair = default; - hv.Edited += (e) => keyValuePair = e; + hv.Edited += (s,e) => keyValuePair = new KeyValuePair(e.Position,e.NewValue); Assert.True (hv.ProcessKey (new KeyEvent (Key.D4, new KeyModifiers ()))); Assert.True (hv.ProcessKey (new KeyEvent (Key.D6, new KeyModifiers ()))); From 6a33f142e01f1c4b002339449c379aab1f046d1b Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 12 Mar 2023 03:06:12 +0000 Subject: [PATCH 21/46] Added MenuOpenedEventArgs class --- .../Core/EventArgs/MenuOpenedEventArgs.cs | 36 +++++++++++++++++++ Terminal.Gui/Views/Menu.cs | 14 +++++--- UnitTests/Menus/MenuTests.cs | 26 +++++++------- 3 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 Terminal.Gui/Core/EventArgs/MenuOpenedEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/MenuOpenedEventArgs.cs b/Terminal.Gui/Core/EventArgs/MenuOpenedEventArgs.cs new file mode 100644 index 0000000000..dec4324495 --- /dev/null +++ b/Terminal.Gui/Core/EventArgs/MenuOpenedEventArgs.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Terminal.Gui { + + /// + /// Defines arguments for the event + /// + public class MenuOpenedEventArgs : EventArgs{ + + /// + /// Creates a new instance of the class + /// + /// + /// + public MenuOpenedEventArgs (MenuBarItem parent, MenuItem menuItem) + { + Parent = parent; + MenuItem = menuItem; + } + + /// + /// The parent of . Will be null if menu opening + /// is the root (see ). + /// + public MenuBarItem Parent { get; } + + /// + /// Gets the being opened. + /// + public MenuItem MenuItem { get; } + } +} diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs index 585cc11e1b..a8e0cf34ea 100644 --- a/Terminal.Gui/Views/Menu.cs +++ b/Terminal.Gui/Views/Menu.cs @@ -1201,7 +1201,7 @@ void Selected (MenuItem item) /// /// Raised when a menu is opened. /// - public event Action MenuOpened; + public event EventHandler MenuOpened; /// /// Raised when a menu is closing passing . @@ -1254,16 +1254,20 @@ public virtual MenuOpeningEventArgs OnMenuOpening (MenuBarItem currentMenu) public virtual void OnMenuOpened () { MenuItem mi = null; + MenuBarItem parent; + if (openCurrentMenu.barItems.Children != null && openCurrentMenu.barItems.Children.Length > 0 && openCurrentMenu?.current > -1) { - - mi = openCurrentMenu.barItems.Children [openCurrentMenu.current]; + parent = openCurrentMenu.barItems; + mi = parent.Children [openCurrentMenu.current]; } else if (openCurrentMenu.barItems.IsTopLevel) { + parent = null; mi = openCurrentMenu.barItems; } else { - mi = openMenu.barItems.Children [openMenu.current]; + parent = openMenu.barItems; + mi = parent.Children [openMenu.current]; } - MenuOpened?.Invoke (mi); + MenuOpened?.Invoke (this, new MenuOpenedEventArgs(parent, mi)); } /// diff --git a/UnitTests/Menus/MenuTests.cs b/UnitTests/Menus/MenuTests.cs index aeb37e46b9..cf8bd0b996 100644 --- a/UnitTests/Menus/MenuTests.cs +++ b/UnitTests/Menus/MenuTests.cs @@ -120,12 +120,14 @@ public void MenuOpening_MenuOpened_MenuClosing_Events () new MenuItem ("_Copy", "Copies the selection.", Copy) }); }; - menu.MenuOpened += (e) => { - Assert.Equal ("_Edit", e.Parent.Title); - Assert.Equal ("_Copy", e.Title); - Assert.Equal ("Copies the selection.", e.Help); - Assert.Equal (Copy, e.Action); - e.Action (); + menu.MenuOpened += (s, e) => { + var mi = e.MenuItem; + + Assert.Equal ("_Edit", mi.Parent.Title); + Assert.Equal ("_Copy", mi.Title); + Assert.Equal ("Copies the selection.", mi.Help); + Assert.Equal (Copy, mi.Action); + mi.Action (); Assert.Equal ("Copy", miAction); }; menu.MenuClosing += (s,e) => { @@ -194,8 +196,8 @@ public void MenuOpened_On_Disabled_MenuItem () new MenuItem ("_Save", "Saves the file.", null, null) }) }); - menu.MenuOpened += (e) => { - miCurrent = e; + menu.MenuOpened += (s,e) => { + miCurrent = e.MenuItem; mCurrent = menu.openMenu; }; menu.UseKeysUpDownAsKeysLeftRight = true; @@ -290,8 +292,8 @@ public void MouseEvent_Test () new MenuItem ("_Paste", "", null) }) }); - menu.MenuOpened += (e) => { - miCurrent = e; + menu.MenuOpened += (s, e) => { + miCurrent = e.MenuItem; mCurrent = menu.openCurrentMenu; }; Application.Top.Add (menu); @@ -379,8 +381,8 @@ public void KeyBindings_Command () new MenuBarItem ("_About", "Top-Level", () => miAction ="About") }); menu.MenuOpening += (s,e) => mbiCurrent = e.CurrentMenu; - menu.MenuOpened += (e) => { - miCurrent = e; + menu.MenuOpened += (s, e) => { + miCurrent = e.MenuItem; mCurrent = menu.openCurrentMenu; }; menu.MenuClosing += (s,e) => { From fe2710ad2d8338f1a28228274a3eed95f8970f73 Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 12 Mar 2023 09:08:58 +0000 Subject: [PATCH 22/46] Added TextChangedEventArgs --- .../Core/EventArgs/TextChangedEventArgs.cs | 36 +++++++++++++++++++ Terminal.Gui/Views/ComboBox.cs | 5 ++- Terminal.Gui/Views/DateField.cs | 8 ++--- Terminal.Gui/Views/TextField.cs | 4 +-- Terminal.Gui/Views/TimeField.cs | 8 ++--- Terminal.Gui/Windows/FileDialog.cs | 4 +-- UICatalog/Scenarios/AllViewsTester.cs | 8 ++--- UICatalog/Scenarios/CharacterMap.cs | 2 +- UICatalog/Scenarios/CsvEditor.cs | 2 +- UICatalog/Scenarios/DynamicMenuBar.cs | 2 +- UICatalog/Scenarios/DynamicStatusBar.cs | 2 +- UICatalog/Scenarios/Editor.cs | 6 ++-- UICatalog/Scenarios/Progress.cs | 4 +-- UICatalog/Scenarios/Text.cs | 4 +-- UICatalog/Scenarios/TileViewNesting.cs | 2 +- UnitTests/UICatalog/ScenarioTests.cs | 8 ++--- UnitTests/Views/TextFieldTests.cs | 7 ++-- 17 files changed, 76 insertions(+), 36 deletions(-) create mode 100644 Terminal.Gui/Core/EventArgs/TextChangedEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/TextChangedEventArgs.cs b/Terminal.Gui/Core/EventArgs/TextChangedEventArgs.cs new file mode 100644 index 0000000000..778448b158 --- /dev/null +++ b/Terminal.Gui/Core/EventArgs/TextChangedEventArgs.cs @@ -0,0 +1,36 @@ +using NStack; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Terminal.Gui { + + /// + /// Event args for events where text is changed + /// + public class TextChangedEventArgs : EventArgs { + + /// + /// Creates a new instance of the class + /// + /// + /// + public TextChangedEventArgs (ustring oldValue, ustring newValue) + { + OldValue = oldValue; + NewValue = newValue; + } + + /// + /// The old value before the text changed + /// + public ustring OldValue { get; } + + /// + /// The new value + /// + public ustring NewValue { get; } + } +} diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index b204d33b80..2ae0729860 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -805,8 +805,11 @@ private void SetSearchSet () searchset.Add (item); } } - private void Search_Changed (ustring text) + { + Search_Changed (this, new TextChangedEventArgs (text, text)); + } + private void Search_Changed (object sender, TextChangedEventArgs args) { if (source == null) { // Object initialization return; diff --git a/Terminal.Gui/Views/DateField.cs b/Terminal.Gui/Views/DateField.cs index d88648a41a..cf3375356d 100644 --- a/Terminal.Gui/Views/DateField.cs +++ b/Terminal.Gui/Views/DateField.cs @@ -106,13 +106,13 @@ void Initialize (DateTime date, bool isShort = false) AddKeyBinding (Key.F | Key.CtrlMask, Command.Right); } - void DateField_Changed (ustring e) + void DateField_Changed (object sender, TextChangedEventArgs e) { try { - if (!DateTime.TryParseExact (GetDate (Text).ToString (), GetInvarianteFormat (), CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime result)) - Text = e; + if (!DateTime.TryParseExact (GetDate (e.NewValue).ToString (), GetInvarianteFormat (), CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime result)) + Text = e.OldValue; } catch (Exception) { - Text = e; + Text = e.OldValue; } } diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index 18b3a9a95b..4fd8233e0a 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -53,7 +53,7 @@ public class TextField : View { /// /// The passed is a containing the old value. /// - public event Action TextChanged; + public event EventHandler TextChanged; /// /// Initializes a new instance of the class using positioning. @@ -308,7 +308,7 @@ public override Rect Frame { , HistoryText.LineStatus.Replaced); } - TextChanged?.Invoke (oldText); + TextChanged?.Invoke (this, new TextChangedEventArgs(oldText, newText.NewText)); if (point > text.Count) { point = Math.Max (TextModel.DisplaySize (text, 0).size - 1, 0); diff --git a/Terminal.Gui/Views/TimeField.cs b/Terminal.Gui/Views/TimeField.cs index 132803dbc0..8e195e4273 100644 --- a/Terminal.Gui/Views/TimeField.cs +++ b/Terminal.Gui/Views/TimeField.cs @@ -106,13 +106,13 @@ void Initialize (TimeSpan time, bool isShort = false) AddKeyBinding (Key.F | Key.CtrlMask, Command.Right); } - void TextField_TextChanged (ustring e) + void TextField_TextChanged (object sender, TextChangedEventArgs e) { try { - if (!TimeSpan.TryParseExact (Text.ToString ().Trim (), format.Trim (), CultureInfo.CurrentCulture, TimeSpanStyles.None, out TimeSpan result)) - Text = e; + if (!TimeSpan.TryParseExact (e.NewValue.ToString ().Trim (), format.Trim (), CultureInfo.CurrentCulture, TimeSpanStyles.None, out TimeSpan result)) + Text = e.OldValue; } catch (Exception) { - Text = e; + Text = e.OldValue; } } diff --git a/Terminal.Gui/Windows/FileDialog.cs b/Terminal.Gui/Windows/FileDialog.cs index 2d23079673..b78d106bc2 100644 --- a/Terminal.Gui/Windows/FileDialog.cs +++ b/Terminal.Gui/Windows/FileDialog.cs @@ -649,7 +649,7 @@ public FileDialog (ustring title, ustring prompt, ustring nameDirLabel, ustring Y = 1 + msgLines, Width = Dim.Fill () - 1, }; - dirEntry.TextChanged += (e) => { + dirEntry.TextChanged += (s,e) => { DirectoryPath = dirEntry.Text; nameEntry.Text = ustring.Empty; }; @@ -731,7 +731,7 @@ public FileDialog (ustring title, ustring prompt, ustring nameDirLabel, ustring }; AddButton (this.prompt); - nameEntry.TextChanged += (e) => { + nameEntry.TextChanged += (s, e) => { if (nameEntry.Text.IsEmpty) { this.prompt.Enabled = false; } else { diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index 2c52dc7d5b..733c8690c9 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -126,7 +126,7 @@ public override void Setup () }; _xRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); _xText = new TextField ($"{_xVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; - _xText.TextChanged += (args) => { + _xText.TextChanged += (s,args) => { try { _xVal = int.Parse (_xText.Text.ToString ()); DimPosChanged (_curView); @@ -142,7 +142,7 @@ public override void Setup () label = new Label ("y:") { X = Pos.Right (_xRadioGroup) + 1, Y = 0 }; _locationFrame.Add (label); _yText = new TextField ($"{_yVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; - _yText.TextChanged += (args) => { + _yText.TextChanged += (s, args) => { try { _yVal = int.Parse (_yText.Text.ToString ()); DimPosChanged (_curView); @@ -174,7 +174,7 @@ public override void Setup () }; _wRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); _wText = new TextField ($"{_wVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; - _wText.TextChanged += (args) => { + _wText.TextChanged += (s,args) => { try { switch (_wRadioGroup.SelectedItem) { case 0: @@ -197,7 +197,7 @@ public override void Setup () label = new Label ("height:") { X = Pos.Right (_wRadioGroup) + 1, Y = 0 }; _sizeFrame.Add (label); _hText = new TextField ($"{_hVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; - _hText.TextChanged += (args) => { + _hText.TextChanged += (s, args) => { try { switch (_hRadioGroup.SelectedItem) { case 0: diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index 6728d09e43..40551691c9 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -39,7 +39,7 @@ public override void Setup () Win.Add (jumpEdit); var unicodeLabel = new Label ("") { X = Pos.Right (jumpEdit) + 1, Y = Pos.Y (_charMap) }; Win.Add (unicodeLabel); - jumpEdit.TextChanged += (s) => { + jumpEdit.TextChanged += (s,e) => { uint result = 0; if (jumpEdit.Text.Length == 0) return; try { diff --git a/UICatalog/Scenarios/CsvEditor.cs b/UICatalog/Scenarios/CsvEditor.cs index 04d49b6f2c..62e550efdd 100644 --- a/UICatalog/Scenarios/CsvEditor.cs +++ b/UICatalog/Scenarios/CsvEditor.cs @@ -99,7 +99,7 @@ public override void Setup () SetupScrollBar (); } - private void SelectedCellLabel_TextChanged (ustring last) + private void SelectedCellLabel_TextChanged (object sender, TextChangedEventArgs args) { // if user is in the text control and editing the selected cell if (!selectedCellLabel.HasFocus) diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs index 542c6897a1..e1cfbca413 100644 --- a/UICatalog/Scenarios/DynamicMenuBar.cs +++ b/UICatalog/Scenarios/DynamicMenuBar.cs @@ -89,7 +89,7 @@ public DynamicMenuBarSample (ustring title) : base (title) X = Pos.Center (), Width = 2, }; - _txtDelimiter.TextChanged += (_) => MenuBar.ShortcutDelimiter = _txtDelimiter.Text; + _txtDelimiter.TextChanged += (s,e) => MenuBar.ShortcutDelimiter = _txtDelimiter.Text; _frmDelimiter.Add (_txtDelimiter); Add (_frmDelimiter); diff --git a/UICatalog/Scenarios/DynamicStatusBar.cs b/UICatalog/Scenarios/DynamicStatusBar.cs index d78327a63e..082d4e007d 100644 --- a/UICatalog/Scenarios/DynamicStatusBar.cs +++ b/UICatalog/Scenarios/DynamicStatusBar.cs @@ -77,7 +77,7 @@ public DynamicStatusBarSample (ustring title) : base (title) X = Pos.Center (), Width = 2, }; - _txtDelimiter.TextChanged += (_) => StatusBar.ShortcutDelimiter = _txtDelimiter.Text; + _txtDelimiter.TextChanged += (s,e) => StatusBar.ShortcutDelimiter = _txtDelimiter.Text; _frmDelimiter.Add (_txtDelimiter); Add (_frmDelimiter); diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index 60029e0491..482d407b59 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -813,7 +813,7 @@ private View FindTab () btnFindPrevious.Clicked += (s,e) => FindPrevious (); d.Add (btnFindPrevious); - txtToFind.TextChanged += (e) => { + txtToFind.TextChanged += (s,e) => { _textToFind = txtToFind.Text.ToString (); _textView.FindTextChanged (); btnFindNext.Enabled = !txtToFind.Text.IsEmpty; @@ -908,7 +908,7 @@ private View ReplaceTab () Y = Pos.Top (label), Width = 20 }; - txtToReplace.TextChanged += (e) => _textToReplace = txtToReplace.Text.ToString (); + txtToReplace.TextChanged += (s,e) => _textToReplace = txtToReplace.Text.ToString (); d.Add (txtToReplace); var btnFindPrevious = new Button ("Replace _Previous") { @@ -933,7 +933,7 @@ private View ReplaceTab () btnReplaceAll.Clicked += (s,e) => ReplaceAll (); d.Add (btnReplaceAll); - txtToFind.TextChanged += (e) => { + txtToFind.TextChanged += (s, e) => { _textToFind = txtToFind.Text.ToString (); _textView.FindTextChanged (); btnFindNext.Enabled = !txtToFind.Text.IsEmpty; diff --git a/UICatalog/Scenarios/Progress.cs b/UICatalog/Scenarios/Progress.cs index a6869607dc..40cbb5aa98 100644 --- a/UICatalog/Scenarios/Progress.cs +++ b/UICatalog/Scenarios/Progress.cs @@ -167,7 +167,7 @@ public override void Setup () systemTimerDemo.PulseProgressBar.Fraction = 1F; }; systemTimerDemo.Speed.Text = $"{_systemTimerTick}"; - systemTimerDemo.Speed.TextChanged += (a) => { + systemTimerDemo.Speed.TextChanged += (s, a) => { uint result; if (uint.TryParse (systemTimerDemo.Speed.Text.ToString(), out result)) { _systemTimerTick = result; @@ -210,7 +210,7 @@ public override void Setup () }; mainLoopTimeoutDemo.Speed.Text = $"{_mainLooopTimeoutTick}"; - mainLoopTimeoutDemo.Speed.TextChanged += (a) => { + mainLoopTimeoutDemo.Speed.TextChanged += (s, a) => { uint result; if (uint.TryParse (mainLoopTimeoutDemo.Speed.Text.ToString (), out result)) { _mainLooopTimeoutTick = result; diff --git a/UICatalog/Scenarios/Text.cs b/UICatalog/Scenarios/Text.cs index 7ed9835282..8c37b828e6 100644 --- a/UICatalog/Scenarios/Text.cs +++ b/UICatalog/Scenarios/Text.cs @@ -41,7 +41,7 @@ void TextField_TextChanging (object sender, TextChangingEventArgs e) }; Win.Add (labelMirroringTextField); - textField.TextChanged += (prev) => { + textField.TextChanged += (s, prev) => { labelMirroringTextField.Text = textField.Text; }; @@ -159,7 +159,7 @@ void TextView_DrawContent (object sender, DrawEventArgs e) }; Win.Add (labelMirroringDateField); - dateField.TextChanged += (prev) => { + dateField.TextChanged += (s, prev) => { labelMirroringDateField.Text = dateField.Text; }; diff --git a/UICatalog/Scenarios/TileViewNesting.cs b/UICatalog/Scenarios/TileViewNesting.cs index 3cee1b1954..8d7fd551cc 100644 --- a/UICatalog/Scenarios/TileViewNesting.cs +++ b/UICatalog/Scenarios/TileViewNesting.cs @@ -36,7 +36,7 @@ public override void Setup () Text = "2", }; - textField.TextChanged += (s) => SetupTileView (); + textField.TextChanged += (s, e) => SetupTileView (); cbHorizontal = new CheckBox ("Horizontal") { diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index 1104154b3d..a2f0518878 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -312,7 +312,7 @@ public void Run_All_Views_Tester_Scenario () _xRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); - _xText.TextChanged += (args) => { + _xText.TextChanged += (s,args) => { try { _xVal = int.Parse (_xText.Text.ToString ()); DimPosChanged (_curView); @@ -321,7 +321,7 @@ public void Run_All_Views_Tester_Scenario () } }; - _yText.TextChanged += (args) => { + _yText.TextChanged += (s, args) => { try { _yVal = int.Parse (_yText.Text.ToString ()); DimPosChanged (_curView); @@ -334,7 +334,7 @@ public void Run_All_Views_Tester_Scenario () _wRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); - _wText.TextChanged += (args) => { + _wText.TextChanged += (s, args) => { try { _wVal = int.Parse (_wText.Text.ToString ()); DimPosChanged (_curView); @@ -343,7 +343,7 @@ public void Run_All_Views_Tester_Scenario () } }; - _hText.TextChanged += (args) => { + _hText.TextChanged += (s, args) => { try { _hVal = int.Parse (_hText.Text.ToString ()); DimPosChanged (_curView); diff --git a/UnitTests/Views/TextFieldTests.cs b/UnitTests/Views/TextFieldTests.cs index 4eaa588ca8..ed68e74935 100644 --- a/UnitTests/Views/TextFieldTests.cs +++ b/UnitTests/Views/TextFieldTests.cs @@ -681,8 +681,9 @@ public void TextChanging_Event () [TextFieldTestsAutoInitShutdown] public void TextChanged_Event () { - _textField.TextChanged += (e) => { - Assert.Equal ("TAB to jump between text fields.", e); + _textField.TextChanged += (s,e) => { + Assert.Equal ("TAB to jump between text fields.", e.OldValue); + Assert.Equal ("changed", e.NewValue); }; _textField.Text = "changed"; @@ -1138,7 +1139,7 @@ public void DeleteSelectedText_InsertText_DeleteCharLeft_DeleteCharRight_Cut () var tf = new TextField () { Width = 10, Text = "-1" }; tf.TextChanging += (s,e) => newText = e.NewText.ToString (); - tf.TextChanged += (e) => oldText = e.ToString (); + tf.TextChanged += (s,e) => oldText = e.ToString (); Application.Top.Add (tf); Application.Begin (Application.Top); From 50a299adea57b04331d8caa15245663f889489f1 Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 12 Mar 2023 09:14:15 +0000 Subject: [PATCH 23/46] Made HistoryTextItem inherit from EventArgs --- Terminal.Gui/Views/TextField.cs | 2 +- Terminal.Gui/Views/TextView.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index 4fd8233e0a..a208da3a8d 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -233,7 +233,7 @@ private void ContextMenu_KeyChanged (object sender, KeyChangedEventArgs e) ReplaceKeyBinding (e.OldKey, e.NewKey); } - private void HistoryText_ChangeText (HistoryText.HistoryTextItem obj) + private void HistoryText_ChangeText (object sender, HistoryText.HistoryTextItem obj) { if (obj == null) return; diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index b7a59371cd..7e91c3b06e 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -523,7 +523,7 @@ public enum LineStatus { Added } - public class HistoryTextItem { + public class HistoryTextItem : EventArgs{ public List> Lines; public Point CursorPosition; public LineStatus LineStatus; @@ -559,7 +559,7 @@ public override string ToString () public bool HasHistoryChanges => idxHistoryText > -1; - public event Action ChangeText; + public event EventHandler ChangeText; public void Add (List> lines, Point curPos, LineStatus lineStatus = LineStatus.Original) { @@ -711,7 +711,7 @@ void ProcessChanges (ref HistoryTextItem historyTextItem) void OnChangeText (HistoryTextItem lines) { - ChangeText?.Invoke (lines); + ChangeText?.Invoke (this, lines); } public void Clear (ustring text) @@ -1393,7 +1393,7 @@ private void Model_LinesLoaded (object sender, EventArgs e) //historyText.Clear (Text); } - private void HistoryText_ChangeText (HistoryText.HistoryTextItem obj) + private void HistoryText_ChangeText (object sender, HistoryText.HistoryTextItem obj) { SetWrapModel (); From 7a52f45a1016bcec5282ee7e5fd999a1d4d1d51f Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 12 Mar 2023 09:18:06 +0000 Subject: [PATCH 24/46] Add PointEventArgs --- Terminal.Gui/Core/EventArgs/PointEventArgs.cs | 27 +++++++++++++++++++ Terminal.Gui/Views/TextView.cs | 4 +-- UICatalog/Scenarios/Editor.cs | 4 +-- UnitTests/Views/TextViewTests.cs | 4 +-- 4 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 Terminal.Gui/Core/EventArgs/PointEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/PointEventArgs.cs b/Terminal.Gui/Core/EventArgs/PointEventArgs.cs new file mode 100644 index 0000000000..e8a249496a --- /dev/null +++ b/Terminal.Gui/Core/EventArgs/PointEventArgs.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Terminal.Gui { + /// + /// Event args for events which relate to a single + /// + public class PointEventArgs : EventArgs{ + + /// + /// Creates a new instance of the class + /// + /// + public PointEventArgs (Point p) + { + this.Point = p; + } + + /// + /// The point the event happened at + /// + public Point Point { get; } + } +} diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 7e91c3b06e..424727affd 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -1170,7 +1170,7 @@ public class TextView : View { /// /// Invoked with the unwrapped . /// - public event Action UnwrappedCursorPosition; + public event EventHandler UnwrappedCursorPosition; /// /// Provides autocomplete context menu based on suggestions at the current cursor @@ -2364,7 +2364,7 @@ public virtual void OnUnwrappedCursorPosition (int? cRow = null, int? cCol = nul row = wrapManager.GetModelLineFromWrappedLines (currentRow); col = wrapManager.GetModelColFromWrappedLines (currentRow, currentColumn); } - UnwrappedCursorPosition?.Invoke (new Point ((int)col, (int)row)); + UnwrappedCursorPosition?.Invoke (this, new PointEventArgs(new Point ((int)col, (int)row))); } ustring GetSelectedRegion () diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index 482d407b59..5ef47b731b 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -59,8 +59,8 @@ public override void Init (ColorScheme colorScheme) var siCursorPosition = new StatusItem (Key.Null, "", null); - _textView.UnwrappedCursorPosition += (e) => { - siCursorPosition.Title = $"Ln {e.Y + 1}, Col {e.X + 1}"; + _textView.UnwrappedCursorPosition += (s,e) => { + siCursorPosition.Title = $"Ln {e.Point.Y + 1}, Col {e.Point.X + 1}"; }; LoadFile (); diff --git a/UnitTests/Views/TextViewTests.cs b/UnitTests/Views/TextViewTests.cs index 372843a49e..145b7f0885 100644 --- a/UnitTests/Views/TextViewTests.cs +++ b/UnitTests/Views/TextViewTests.cs @@ -6001,8 +6001,8 @@ public void UnwrappedCursorPosition_Event () Height = Dim.Fill (), Text = "This is the first line.\nThis is the second line.\n" }; - tv.UnwrappedCursorPosition += (e) => { - cp = e; + tv.UnwrappedCursorPosition += (s,e) => { + cp = e.Point; }; Application.Top.Add (tv); Application.Begin (Application.Top); From 4b5fbfb89cdfa01a2f170766a85ab342ba9dd59f Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 12 Mar 2023 09:24:18 +0000 Subject: [PATCH 25/46] Revert "Added TextChangedEventArgs" This reverts commit fe2710ad2d8338f1a28228274a3eed95f8970f73. --- .../Core/EventArgs/TextChangedEventArgs.cs | 36 ------------------- Terminal.Gui/Views/ComboBox.cs | 5 +-- Terminal.Gui/Views/DateField.cs | 8 ++--- Terminal.Gui/Views/TextField.cs | 4 +-- Terminal.Gui/Views/TimeField.cs | 8 ++--- Terminal.Gui/Windows/FileDialog.cs | 4 +-- UICatalog/Scenarios/AllViewsTester.cs | 8 ++--- UICatalog/Scenarios/CharacterMap.cs | 2 +- UICatalog/Scenarios/CsvEditor.cs | 2 +- UICatalog/Scenarios/DynamicMenuBar.cs | 2 +- UICatalog/Scenarios/DynamicStatusBar.cs | 2 +- UICatalog/Scenarios/Editor.cs | 6 ++-- UICatalog/Scenarios/Progress.cs | 4 +-- UICatalog/Scenarios/Text.cs | 4 +-- UICatalog/Scenarios/TileViewNesting.cs | 2 +- UnitTests/UICatalog/ScenarioTests.cs | 8 ++--- UnitTests/Views/TextFieldTests.cs | 7 ++-- 17 files changed, 36 insertions(+), 76 deletions(-) delete mode 100644 Terminal.Gui/Core/EventArgs/TextChangedEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/TextChangedEventArgs.cs b/Terminal.Gui/Core/EventArgs/TextChangedEventArgs.cs deleted file mode 100644 index 778448b158..0000000000 --- a/Terminal.Gui/Core/EventArgs/TextChangedEventArgs.cs +++ /dev/null @@ -1,36 +0,0 @@ -using NStack; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Terminal.Gui { - - /// - /// Event args for events where text is changed - /// - public class TextChangedEventArgs : EventArgs { - - /// - /// Creates a new instance of the class - /// - /// - /// - public TextChangedEventArgs (ustring oldValue, ustring newValue) - { - OldValue = oldValue; - NewValue = newValue; - } - - /// - /// The old value before the text changed - /// - public ustring OldValue { get; } - - /// - /// The new value - /// - public ustring NewValue { get; } - } -} diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 2ae0729860..b204d33b80 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -805,11 +805,8 @@ private void SetSearchSet () searchset.Add (item); } } + private void Search_Changed (ustring text) - { - Search_Changed (this, new TextChangedEventArgs (text, text)); - } - private void Search_Changed (object sender, TextChangedEventArgs args) { if (source == null) { // Object initialization return; diff --git a/Terminal.Gui/Views/DateField.cs b/Terminal.Gui/Views/DateField.cs index cf3375356d..d88648a41a 100644 --- a/Terminal.Gui/Views/DateField.cs +++ b/Terminal.Gui/Views/DateField.cs @@ -106,13 +106,13 @@ void Initialize (DateTime date, bool isShort = false) AddKeyBinding (Key.F | Key.CtrlMask, Command.Right); } - void DateField_Changed (object sender, TextChangedEventArgs e) + void DateField_Changed (ustring e) { try { - if (!DateTime.TryParseExact (GetDate (e.NewValue).ToString (), GetInvarianteFormat (), CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime result)) - Text = e.OldValue; + if (!DateTime.TryParseExact (GetDate (Text).ToString (), GetInvarianteFormat (), CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime result)) + Text = e; } catch (Exception) { - Text = e.OldValue; + Text = e; } } diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index a208da3a8d..f37e5da9dc 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -53,7 +53,7 @@ public class TextField : View { /// /// The passed is a containing the old value. /// - public event EventHandler TextChanged; + public event Action TextChanged; /// /// Initializes a new instance of the class using positioning. @@ -308,7 +308,7 @@ public override Rect Frame { , HistoryText.LineStatus.Replaced); } - TextChanged?.Invoke (this, new TextChangedEventArgs(oldText, newText.NewText)); + TextChanged?.Invoke (oldText); if (point > text.Count) { point = Math.Max (TextModel.DisplaySize (text, 0).size - 1, 0); diff --git a/Terminal.Gui/Views/TimeField.cs b/Terminal.Gui/Views/TimeField.cs index 8e195e4273..132803dbc0 100644 --- a/Terminal.Gui/Views/TimeField.cs +++ b/Terminal.Gui/Views/TimeField.cs @@ -106,13 +106,13 @@ void Initialize (TimeSpan time, bool isShort = false) AddKeyBinding (Key.F | Key.CtrlMask, Command.Right); } - void TextField_TextChanged (object sender, TextChangedEventArgs e) + void TextField_TextChanged (ustring e) { try { - if (!TimeSpan.TryParseExact (e.NewValue.ToString ().Trim (), format.Trim (), CultureInfo.CurrentCulture, TimeSpanStyles.None, out TimeSpan result)) - Text = e.OldValue; + if (!TimeSpan.TryParseExact (Text.ToString ().Trim (), format.Trim (), CultureInfo.CurrentCulture, TimeSpanStyles.None, out TimeSpan result)) + Text = e; } catch (Exception) { - Text = e.OldValue; + Text = e; } } diff --git a/Terminal.Gui/Windows/FileDialog.cs b/Terminal.Gui/Windows/FileDialog.cs index b78d106bc2..2d23079673 100644 --- a/Terminal.Gui/Windows/FileDialog.cs +++ b/Terminal.Gui/Windows/FileDialog.cs @@ -649,7 +649,7 @@ public FileDialog (ustring title, ustring prompt, ustring nameDirLabel, ustring Y = 1 + msgLines, Width = Dim.Fill () - 1, }; - dirEntry.TextChanged += (s,e) => { + dirEntry.TextChanged += (e) => { DirectoryPath = dirEntry.Text; nameEntry.Text = ustring.Empty; }; @@ -731,7 +731,7 @@ public FileDialog (ustring title, ustring prompt, ustring nameDirLabel, ustring }; AddButton (this.prompt); - nameEntry.TextChanged += (s, e) => { + nameEntry.TextChanged += (e) => { if (nameEntry.Text.IsEmpty) { this.prompt.Enabled = false; } else { diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index 733c8690c9..2c52dc7d5b 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -126,7 +126,7 @@ public override void Setup () }; _xRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); _xText = new TextField ($"{_xVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; - _xText.TextChanged += (s,args) => { + _xText.TextChanged += (args) => { try { _xVal = int.Parse (_xText.Text.ToString ()); DimPosChanged (_curView); @@ -142,7 +142,7 @@ public override void Setup () label = new Label ("y:") { X = Pos.Right (_xRadioGroup) + 1, Y = 0 }; _locationFrame.Add (label); _yText = new TextField ($"{_yVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; - _yText.TextChanged += (s, args) => { + _yText.TextChanged += (args) => { try { _yVal = int.Parse (_yText.Text.ToString ()); DimPosChanged (_curView); @@ -174,7 +174,7 @@ public override void Setup () }; _wRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); _wText = new TextField ($"{_wVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; - _wText.TextChanged += (s,args) => { + _wText.TextChanged += (args) => { try { switch (_wRadioGroup.SelectedItem) { case 0: @@ -197,7 +197,7 @@ public override void Setup () label = new Label ("height:") { X = Pos.Right (_wRadioGroup) + 1, Y = 0 }; _sizeFrame.Add (label); _hText = new TextField ($"{_hVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; - _hText.TextChanged += (s, args) => { + _hText.TextChanged += (args) => { try { switch (_hRadioGroup.SelectedItem) { case 0: diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index 40551691c9..6728d09e43 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -39,7 +39,7 @@ public override void Setup () Win.Add (jumpEdit); var unicodeLabel = new Label ("") { X = Pos.Right (jumpEdit) + 1, Y = Pos.Y (_charMap) }; Win.Add (unicodeLabel); - jumpEdit.TextChanged += (s,e) => { + jumpEdit.TextChanged += (s) => { uint result = 0; if (jumpEdit.Text.Length == 0) return; try { diff --git a/UICatalog/Scenarios/CsvEditor.cs b/UICatalog/Scenarios/CsvEditor.cs index 62e550efdd..04d49b6f2c 100644 --- a/UICatalog/Scenarios/CsvEditor.cs +++ b/UICatalog/Scenarios/CsvEditor.cs @@ -99,7 +99,7 @@ public override void Setup () SetupScrollBar (); } - private void SelectedCellLabel_TextChanged (object sender, TextChangedEventArgs args) + private void SelectedCellLabel_TextChanged (ustring last) { // if user is in the text control and editing the selected cell if (!selectedCellLabel.HasFocus) diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs index e1cfbca413..542c6897a1 100644 --- a/UICatalog/Scenarios/DynamicMenuBar.cs +++ b/UICatalog/Scenarios/DynamicMenuBar.cs @@ -89,7 +89,7 @@ public DynamicMenuBarSample (ustring title) : base (title) X = Pos.Center (), Width = 2, }; - _txtDelimiter.TextChanged += (s,e) => MenuBar.ShortcutDelimiter = _txtDelimiter.Text; + _txtDelimiter.TextChanged += (_) => MenuBar.ShortcutDelimiter = _txtDelimiter.Text; _frmDelimiter.Add (_txtDelimiter); Add (_frmDelimiter); diff --git a/UICatalog/Scenarios/DynamicStatusBar.cs b/UICatalog/Scenarios/DynamicStatusBar.cs index 082d4e007d..d78327a63e 100644 --- a/UICatalog/Scenarios/DynamicStatusBar.cs +++ b/UICatalog/Scenarios/DynamicStatusBar.cs @@ -77,7 +77,7 @@ public DynamicStatusBarSample (ustring title) : base (title) X = Pos.Center (), Width = 2, }; - _txtDelimiter.TextChanged += (s,e) => StatusBar.ShortcutDelimiter = _txtDelimiter.Text; + _txtDelimiter.TextChanged += (_) => StatusBar.ShortcutDelimiter = _txtDelimiter.Text; _frmDelimiter.Add (_txtDelimiter); Add (_frmDelimiter); diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index 5ef47b731b..b17f5e0da3 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -813,7 +813,7 @@ private View FindTab () btnFindPrevious.Clicked += (s,e) => FindPrevious (); d.Add (btnFindPrevious); - txtToFind.TextChanged += (s,e) => { + txtToFind.TextChanged += (e) => { _textToFind = txtToFind.Text.ToString (); _textView.FindTextChanged (); btnFindNext.Enabled = !txtToFind.Text.IsEmpty; @@ -908,7 +908,7 @@ private View ReplaceTab () Y = Pos.Top (label), Width = 20 }; - txtToReplace.TextChanged += (s,e) => _textToReplace = txtToReplace.Text.ToString (); + txtToReplace.TextChanged += (e) => _textToReplace = txtToReplace.Text.ToString (); d.Add (txtToReplace); var btnFindPrevious = new Button ("Replace _Previous") { @@ -933,7 +933,7 @@ private View ReplaceTab () btnReplaceAll.Clicked += (s,e) => ReplaceAll (); d.Add (btnReplaceAll); - txtToFind.TextChanged += (s, e) => { + txtToFind.TextChanged += (e) => { _textToFind = txtToFind.Text.ToString (); _textView.FindTextChanged (); btnFindNext.Enabled = !txtToFind.Text.IsEmpty; diff --git a/UICatalog/Scenarios/Progress.cs b/UICatalog/Scenarios/Progress.cs index 40cbb5aa98..a6869607dc 100644 --- a/UICatalog/Scenarios/Progress.cs +++ b/UICatalog/Scenarios/Progress.cs @@ -167,7 +167,7 @@ public override void Setup () systemTimerDemo.PulseProgressBar.Fraction = 1F; }; systemTimerDemo.Speed.Text = $"{_systemTimerTick}"; - systemTimerDemo.Speed.TextChanged += (s, a) => { + systemTimerDemo.Speed.TextChanged += (a) => { uint result; if (uint.TryParse (systemTimerDemo.Speed.Text.ToString(), out result)) { _systemTimerTick = result; @@ -210,7 +210,7 @@ public override void Setup () }; mainLoopTimeoutDemo.Speed.Text = $"{_mainLooopTimeoutTick}"; - mainLoopTimeoutDemo.Speed.TextChanged += (s, a) => { + mainLoopTimeoutDemo.Speed.TextChanged += (a) => { uint result; if (uint.TryParse (mainLoopTimeoutDemo.Speed.Text.ToString (), out result)) { _mainLooopTimeoutTick = result; diff --git a/UICatalog/Scenarios/Text.cs b/UICatalog/Scenarios/Text.cs index 8c37b828e6..7ed9835282 100644 --- a/UICatalog/Scenarios/Text.cs +++ b/UICatalog/Scenarios/Text.cs @@ -41,7 +41,7 @@ void TextField_TextChanging (object sender, TextChangingEventArgs e) }; Win.Add (labelMirroringTextField); - textField.TextChanged += (s, prev) => { + textField.TextChanged += (prev) => { labelMirroringTextField.Text = textField.Text; }; @@ -159,7 +159,7 @@ void TextView_DrawContent (object sender, DrawEventArgs e) }; Win.Add (labelMirroringDateField); - dateField.TextChanged += (s, prev) => { + dateField.TextChanged += (prev) => { labelMirroringDateField.Text = dateField.Text; }; diff --git a/UICatalog/Scenarios/TileViewNesting.cs b/UICatalog/Scenarios/TileViewNesting.cs index 8d7fd551cc..3cee1b1954 100644 --- a/UICatalog/Scenarios/TileViewNesting.cs +++ b/UICatalog/Scenarios/TileViewNesting.cs @@ -36,7 +36,7 @@ public override void Setup () Text = "2", }; - textField.TextChanged += (s, e) => SetupTileView (); + textField.TextChanged += (s) => SetupTileView (); cbHorizontal = new CheckBox ("Horizontal") { diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index a2f0518878..1104154b3d 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -312,7 +312,7 @@ public void Run_All_Views_Tester_Scenario () _xRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); - _xText.TextChanged += (s,args) => { + _xText.TextChanged += (args) => { try { _xVal = int.Parse (_xText.Text.ToString ()); DimPosChanged (_curView); @@ -321,7 +321,7 @@ public void Run_All_Views_Tester_Scenario () } }; - _yText.TextChanged += (s, args) => { + _yText.TextChanged += (args) => { try { _yVal = int.Parse (_yText.Text.ToString ()); DimPosChanged (_curView); @@ -334,7 +334,7 @@ public void Run_All_Views_Tester_Scenario () _wRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); - _wText.TextChanged += (s, args) => { + _wText.TextChanged += (args) => { try { _wVal = int.Parse (_wText.Text.ToString ()); DimPosChanged (_curView); @@ -343,7 +343,7 @@ public void Run_All_Views_Tester_Scenario () } }; - _hText.TextChanged += (s, args) => { + _hText.TextChanged += (args) => { try { _hVal = int.Parse (_hText.Text.ToString ()); DimPosChanged (_curView); diff --git a/UnitTests/Views/TextFieldTests.cs b/UnitTests/Views/TextFieldTests.cs index ed68e74935..4eaa588ca8 100644 --- a/UnitTests/Views/TextFieldTests.cs +++ b/UnitTests/Views/TextFieldTests.cs @@ -681,9 +681,8 @@ public void TextChanging_Event () [TextFieldTestsAutoInitShutdown] public void TextChanged_Event () { - _textField.TextChanged += (s,e) => { - Assert.Equal ("TAB to jump between text fields.", e.OldValue); - Assert.Equal ("changed", e.NewValue); + _textField.TextChanged += (e) => { + Assert.Equal ("TAB to jump between text fields.", e); }; _textField.Text = "changed"; @@ -1139,7 +1138,7 @@ public void DeleteSelectedText_InsertText_DeleteCharLeft_DeleteCharRight_Cut () var tf = new TextField () { Width = 10, Text = "-1" }; tf.TextChanging += (s,e) => newText = e.NewText.ToString (); - tf.TextChanged += (s,e) => oldText = e.ToString (); + tf.TextChanged += (e) => oldText = e.ToString (); Application.Top.Add (tf); Application.Begin (Application.Top); From 53597b7cecf131a055bfa3c9f0d5ab5c4c91a892 Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 12 Mar 2023 19:20:14 +0000 Subject: [PATCH 26/46] Add TextChangedEventArgs (correctly this time) --- Terminal.Gui/Views/ComboBox.cs | 12 ++++++------ Terminal.Gui/Views/DateField.cs | 6 +++--- Terminal.Gui/Views/TextField.cs | 22 ++++++++++++++++++++-- Terminal.Gui/Views/TimeField.cs | 6 +++--- Terminal.Gui/Windows/FileDialog.cs | 4 ++-- UICatalog/Scenarios/AllViewsTester.cs | 8 ++++---- UICatalog/Scenarios/CharacterMap.cs | 2 +- UICatalog/Scenarios/CsvEditor.cs | 2 +- UICatalog/Scenarios/DynamicMenuBar.cs | 2 +- UICatalog/Scenarios/DynamicStatusBar.cs | 2 +- UICatalog/Scenarios/Editor.cs | 6 +++--- UICatalog/Scenarios/Progress.cs | 4 ++-- UICatalog/Scenarios/Text.cs | 4 ++-- UICatalog/Scenarios/TileViewNesting.cs | 2 +- UnitTests/UICatalog/ScenarioTests.cs | 8 ++++---- UnitTests/Views/TextFieldTests.cs | 6 +++--- 16 files changed, 57 insertions(+), 39 deletions(-) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index b204d33b80..4bae179bf5 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -188,7 +188,7 @@ public IListDataSource Source { if (SuperView != null && SuperView.Subviews.Contains (this)) { SelectedItem = -1; search.Text = ""; - Search_Changed (""); + Search_Changed (this, new TextChangedEventArgs("")); SetNeedsDisplay (); } } @@ -328,7 +328,7 @@ private void Initialize () SetNeedsLayout (); SetNeedsDisplay (); - Search_Changed (Text); + Search_Changed (this, new TextChangedEventArgs( Text)); }; // Things this view knows how to do @@ -750,7 +750,7 @@ private void Selected () SetValue (searchset [listview.SelectedItem]); search.CursorPosition = search.Text.ConsoleWidth; - Search_Changed (search.Text); + Search_Changed (this, new TextChangedEventArgs(search.Text)); OnOpenSelectedItem (); Reset (keepSearchText: true); HideList (); @@ -806,15 +806,15 @@ private void SetSearchSet () } } - private void Search_Changed (ustring text) + private void Search_Changed (object sender, TextChangedEventArgs e) { if (source == null) { // Object initialization return; } - if (ustring.IsNullOrEmpty (search.Text) && ustring.IsNullOrEmpty (text)) { + if (ustring.IsNullOrEmpty (search.Text) && ustring.IsNullOrEmpty (e.OldValue)) { ResetSearchSet (); - } else if (search.Text != text) { + } else if (search.Text != e.OldValue) { isShow = true; ResetSearchSet (noCopy: true); diff --git a/Terminal.Gui/Views/DateField.cs b/Terminal.Gui/Views/DateField.cs index d88648a41a..98c1ae095d 100644 --- a/Terminal.Gui/Views/DateField.cs +++ b/Terminal.Gui/Views/DateField.cs @@ -106,13 +106,13 @@ void Initialize (DateTime date, bool isShort = false) AddKeyBinding (Key.F | Key.CtrlMask, Command.Right); } - void DateField_Changed (ustring e) + void DateField_Changed (object sender, TextChangedEventArgs e) { try { if (!DateTime.TryParseExact (GetDate (Text).ToString (), GetInvarianteFormat (), CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime result)) - Text = e; + Text = e.OldValue; } catch (Exception) { - Text = e; + Text = e.OldValue; } } diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index f37e5da9dc..f907ad5294 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -53,7 +53,7 @@ public class TextField : View { /// /// The passed is a containing the old value. /// - public event Action TextChanged; + public event EventHandler TextChanged; /// /// Initializes a new instance of the class using positioning. @@ -308,7 +308,7 @@ public override Rect Frame { , HistoryText.LineStatus.Replaced); } - TextChanged?.Invoke (oldText); + TextChanged?.Invoke (this, new TextChangedEventArgs(oldText)); if (point > text.Count) { point = Math.Max (TextModel.DisplaySize (text, 0).size - 1, 0); @@ -1331,7 +1331,25 @@ public TextChangingEventArgs (ustring newText) NewText = newText; } } + /// + /// Event args for the event + /// + public class TextChangedEventArgs : EventArgs { + + /// + /// Creates a new instance of the class + /// + /// + public TextChangedEventArgs (ustring oldValue) + { + OldValue = oldValue; + } + /// + /// The old value before the text changed + /// + public ustring OldValue { get; } + } /// /// Renders an overlay on another view at a given point that allows selecting /// from a range of 'autocomplete' options. diff --git a/Terminal.Gui/Views/TimeField.cs b/Terminal.Gui/Views/TimeField.cs index 132803dbc0..b2f9ba0181 100644 --- a/Terminal.Gui/Views/TimeField.cs +++ b/Terminal.Gui/Views/TimeField.cs @@ -106,13 +106,13 @@ void Initialize (TimeSpan time, bool isShort = false) AddKeyBinding (Key.F | Key.CtrlMask, Command.Right); } - void TextField_TextChanged (ustring e) + void TextField_TextChanged (object sender, TextChangedEventArgs e) { try { if (!TimeSpan.TryParseExact (Text.ToString ().Trim (), format.Trim (), CultureInfo.CurrentCulture, TimeSpanStyles.None, out TimeSpan result)) - Text = e; + Text = e.OldValue; } catch (Exception) { - Text = e; + Text = e.OldValue; } } diff --git a/Terminal.Gui/Windows/FileDialog.cs b/Terminal.Gui/Windows/FileDialog.cs index 2d23079673..eb8df038f8 100644 --- a/Terminal.Gui/Windows/FileDialog.cs +++ b/Terminal.Gui/Windows/FileDialog.cs @@ -649,7 +649,7 @@ public FileDialog (ustring title, ustring prompt, ustring nameDirLabel, ustring Y = 1 + msgLines, Width = Dim.Fill () - 1, }; - dirEntry.TextChanged += (e) => { + dirEntry.TextChanged += (s, e) => { DirectoryPath = dirEntry.Text; nameEntry.Text = ustring.Empty; }; @@ -731,7 +731,7 @@ public FileDialog (ustring title, ustring prompt, ustring nameDirLabel, ustring }; AddButton (this.prompt); - nameEntry.TextChanged += (e) => { + nameEntry.TextChanged += (s,e) => { if (nameEntry.Text.IsEmpty) { this.prompt.Enabled = false; } else { diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index 2c52dc7d5b..45cffdbfdf 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -126,7 +126,7 @@ public override void Setup () }; _xRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); _xText = new TextField ($"{_xVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; - _xText.TextChanged += (args) => { + _xText.TextChanged += (s, args) => { try { _xVal = int.Parse (_xText.Text.ToString ()); DimPosChanged (_curView); @@ -142,7 +142,7 @@ public override void Setup () label = new Label ("y:") { X = Pos.Right (_xRadioGroup) + 1, Y = 0 }; _locationFrame.Add (label); _yText = new TextField ($"{_yVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; - _yText.TextChanged += (args) => { + _yText.TextChanged += (s,args) => { try { _yVal = int.Parse (_yText.Text.ToString ()); DimPosChanged (_curView); @@ -174,7 +174,7 @@ public override void Setup () }; _wRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); _wText = new TextField ($"{_wVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; - _wText.TextChanged += (args) => { + _wText.TextChanged += (s,args) => { try { switch (_wRadioGroup.SelectedItem) { case 0: @@ -197,7 +197,7 @@ public override void Setup () label = new Label ("height:") { X = Pos.Right (_wRadioGroup) + 1, Y = 0 }; _sizeFrame.Add (label); _hText = new TextField ($"{_hVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 }; - _hText.TextChanged += (args) => { + _hText.TextChanged += (s, args) => { try { switch (_hRadioGroup.SelectedItem) { case 0: diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index 6728d09e43..c9a7a07112 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -39,7 +39,7 @@ public override void Setup () Win.Add (jumpEdit); var unicodeLabel = new Label ("") { X = Pos.Right (jumpEdit) + 1, Y = Pos.Y (_charMap) }; Win.Add (unicodeLabel); - jumpEdit.TextChanged += (s) => { + jumpEdit.TextChanged += (s, e) => { uint result = 0; if (jumpEdit.Text.Length == 0) return; try { diff --git a/UICatalog/Scenarios/CsvEditor.cs b/UICatalog/Scenarios/CsvEditor.cs index 04d49b6f2c..14ee9fadeb 100644 --- a/UICatalog/Scenarios/CsvEditor.cs +++ b/UICatalog/Scenarios/CsvEditor.cs @@ -99,7 +99,7 @@ public override void Setup () SetupScrollBar (); } - private void SelectedCellLabel_TextChanged (ustring last) + private void SelectedCellLabel_TextChanged (object sender, TextChangedEventArgs e) { // if user is in the text control and editing the selected cell if (!selectedCellLabel.HasFocus) diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs index 542c6897a1..ebf710d558 100644 --- a/UICatalog/Scenarios/DynamicMenuBar.cs +++ b/UICatalog/Scenarios/DynamicMenuBar.cs @@ -89,7 +89,7 @@ public DynamicMenuBarSample (ustring title) : base (title) X = Pos.Center (), Width = 2, }; - _txtDelimiter.TextChanged += (_) => MenuBar.ShortcutDelimiter = _txtDelimiter.Text; + _txtDelimiter.TextChanged += (s, _) => MenuBar.ShortcutDelimiter = _txtDelimiter.Text; _frmDelimiter.Add (_txtDelimiter); Add (_frmDelimiter); diff --git a/UICatalog/Scenarios/DynamicStatusBar.cs b/UICatalog/Scenarios/DynamicStatusBar.cs index d78327a63e..6d5d1d73e5 100644 --- a/UICatalog/Scenarios/DynamicStatusBar.cs +++ b/UICatalog/Scenarios/DynamicStatusBar.cs @@ -77,7 +77,7 @@ public DynamicStatusBarSample (ustring title) : base (title) X = Pos.Center (), Width = 2, }; - _txtDelimiter.TextChanged += (_) => StatusBar.ShortcutDelimiter = _txtDelimiter.Text; + _txtDelimiter.TextChanged += (s, _) => StatusBar.ShortcutDelimiter = _txtDelimiter.Text; _frmDelimiter.Add (_txtDelimiter); Add (_frmDelimiter); diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index b17f5e0da3..22b5ce678d 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -813,7 +813,7 @@ private View FindTab () btnFindPrevious.Clicked += (s,e) => FindPrevious (); d.Add (btnFindPrevious); - txtToFind.TextChanged += (e) => { + txtToFind.TextChanged += (s, e) => { _textToFind = txtToFind.Text.ToString (); _textView.FindTextChanged (); btnFindNext.Enabled = !txtToFind.Text.IsEmpty; @@ -908,7 +908,7 @@ private View ReplaceTab () Y = Pos.Top (label), Width = 20 }; - txtToReplace.TextChanged += (e) => _textToReplace = txtToReplace.Text.ToString (); + txtToReplace.TextChanged += (s, e) => _textToReplace = txtToReplace.Text.ToString (); d.Add (txtToReplace); var btnFindPrevious = new Button ("Replace _Previous") { @@ -933,7 +933,7 @@ private View ReplaceTab () btnReplaceAll.Clicked += (s,e) => ReplaceAll (); d.Add (btnReplaceAll); - txtToFind.TextChanged += (e) => { + txtToFind.TextChanged += (s, e) => { _textToFind = txtToFind.Text.ToString (); _textView.FindTextChanged (); btnFindNext.Enabled = !txtToFind.Text.IsEmpty; diff --git a/UICatalog/Scenarios/Progress.cs b/UICatalog/Scenarios/Progress.cs index a6869607dc..40cbb5aa98 100644 --- a/UICatalog/Scenarios/Progress.cs +++ b/UICatalog/Scenarios/Progress.cs @@ -167,7 +167,7 @@ public override void Setup () systemTimerDemo.PulseProgressBar.Fraction = 1F; }; systemTimerDemo.Speed.Text = $"{_systemTimerTick}"; - systemTimerDemo.Speed.TextChanged += (a) => { + systemTimerDemo.Speed.TextChanged += (s, a) => { uint result; if (uint.TryParse (systemTimerDemo.Speed.Text.ToString(), out result)) { _systemTimerTick = result; @@ -210,7 +210,7 @@ public override void Setup () }; mainLoopTimeoutDemo.Speed.Text = $"{_mainLooopTimeoutTick}"; - mainLoopTimeoutDemo.Speed.TextChanged += (a) => { + mainLoopTimeoutDemo.Speed.TextChanged += (s, a) => { uint result; if (uint.TryParse (mainLoopTimeoutDemo.Speed.Text.ToString (), out result)) { _mainLooopTimeoutTick = result; diff --git a/UICatalog/Scenarios/Text.cs b/UICatalog/Scenarios/Text.cs index 7ed9835282..8c37b828e6 100644 --- a/UICatalog/Scenarios/Text.cs +++ b/UICatalog/Scenarios/Text.cs @@ -41,7 +41,7 @@ void TextField_TextChanging (object sender, TextChangingEventArgs e) }; Win.Add (labelMirroringTextField); - textField.TextChanged += (prev) => { + textField.TextChanged += (s, prev) => { labelMirroringTextField.Text = textField.Text; }; @@ -159,7 +159,7 @@ void TextView_DrawContent (object sender, DrawEventArgs e) }; Win.Add (labelMirroringDateField); - dateField.TextChanged += (prev) => { + dateField.TextChanged += (s, prev) => { labelMirroringDateField.Text = dateField.Text; }; diff --git a/UICatalog/Scenarios/TileViewNesting.cs b/UICatalog/Scenarios/TileViewNesting.cs index 3cee1b1954..983849c6c3 100644 --- a/UICatalog/Scenarios/TileViewNesting.cs +++ b/UICatalog/Scenarios/TileViewNesting.cs @@ -36,7 +36,7 @@ public override void Setup () Text = "2", }; - textField.TextChanged += (s) => SetupTileView (); + textField.TextChanged += (s,e) => SetupTileView (); cbHorizontal = new CheckBox ("Horizontal") { diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index 1104154b3d..b530d1d696 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -312,7 +312,7 @@ public void Run_All_Views_Tester_Scenario () _xRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); - _xText.TextChanged += (args) => { + _xText.TextChanged += (s, args) => { try { _xVal = int.Parse (_xText.Text.ToString ()); DimPosChanged (_curView); @@ -321,7 +321,7 @@ public void Run_All_Views_Tester_Scenario () } }; - _yText.TextChanged += (args) => { + _yText.TextChanged += (s,e) => { try { _yVal = int.Parse (_yText.Text.ToString ()); DimPosChanged (_curView); @@ -334,7 +334,7 @@ public void Run_All_Views_Tester_Scenario () _wRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); - _wText.TextChanged += (args) => { + _wText.TextChanged += (s, args) => { try { _wVal = int.Parse (_wText.Text.ToString ()); DimPosChanged (_curView); @@ -343,7 +343,7 @@ public void Run_All_Views_Tester_Scenario () } }; - _hText.TextChanged += (args) => { + _hText.TextChanged += (s, args) => { try { _hVal = int.Parse (_hText.Text.ToString ()); DimPosChanged (_curView); diff --git a/UnitTests/Views/TextFieldTests.cs b/UnitTests/Views/TextFieldTests.cs index 4eaa588ca8..c448848189 100644 --- a/UnitTests/Views/TextFieldTests.cs +++ b/UnitTests/Views/TextFieldTests.cs @@ -681,8 +681,8 @@ public void TextChanging_Event () [TextFieldTestsAutoInitShutdown] public void TextChanged_Event () { - _textField.TextChanged += (e) => { - Assert.Equal ("TAB to jump between text fields.", e); + _textField.TextChanged += (s,e) => { + Assert.Equal ("TAB to jump between text fields.", e.OldValue); }; _textField.Text = "changed"; @@ -1138,7 +1138,7 @@ public void DeleteSelectedText_InsertText_DeleteCharLeft_DeleteCharRight_Cut () var tf = new TextField () { Width = 10, Text = "-1" }; tf.TextChanging += (s,e) => newText = e.NewText.ToString (); - tf.TextChanged += (e) => oldText = e.ToString (); + tf.TextChanged += (s, e) => oldText = e.OldValue.ToString (); Application.Top.Add (tf); Application.Begin (Application.Top); From 82bf8f05468bc16cb7634af18a4bd15f102b532e Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 13 Mar 2023 21:41:33 +0000 Subject: [PATCH 27/46] Fixes https://github.com/gui-cs/Terminal.Gui/issues/2413. GrabMouse ungrab other view that was grabbed and still need it. --- Terminal.Gui/Core/Application.cs | 58 +++++-- .../Core/EventArgs/GrabMouseEventArgs.cs | 29 ++++ Terminal.Gui/Core/Toplevel.cs | 23 ++- UICatalog/Scenarios/Clipping.cs | 9 +- UnitTests/TopLevels/ToplevelTests.cs | 154 ++++++++++++++++-- 5 files changed, 243 insertions(+), 30 deletions(-) create mode 100644 Terminal.Gui/Core/EventArgs/GrabMouseEventArgs.cs diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index f38e31b210..0f847c97f2 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -162,7 +162,7 @@ public static Key AlternateForwardKey { if (alternateForwardKey != value) { var oldKey = alternateForwardKey; alternateForwardKey = value; - OnAlternateForwardKeyChanged (new KeyChangedEventArgs(oldKey,value)); + OnAlternateForwardKeyChanged (new KeyChangedEventArgs (oldKey, value)); } } } @@ -186,7 +186,7 @@ public static Key AlternateBackwardKey { if (alternateBackwardKey != value) { var oldKey = alternateBackwardKey; alternateBackwardKey = value; - OnAlternateBackwardKeyChanged (new KeyChangedEventArgs(oldKey,value)); + OnAlternateBackwardKeyChanged (new KeyChangedEventArgs (oldKey, value)); } } } @@ -210,7 +210,7 @@ public static Key QuitKey { if (quitKey != value) { var oldKey = quitKey; quitKey = value; - OnQuitKeyChanged (new KeyChangedEventArgs(oldKey,value)); + OnQuitKeyChanged (new KeyChangedEventArgs (oldKey, value)); } } } @@ -720,6 +720,16 @@ static View FindTopFromView (View view) /// public static View MouseGrabView => mouseGrabView; + /// + /// Event to be invoked when a view want grab the mouse which can be canceled. + /// + public static event EventHandler GrabbingMouse; + + /// + /// Event to be invoked when a view want ungrab the mouse which can be canceled. + /// + public static event EventHandler UnGrabbingMouse; + /// /// Event to be invoked when a view grab the mouse. /// @@ -739,9 +749,11 @@ public static void GrabMouse (View view) { if (view == null) return; - OnGrabbedMouse (view); - mouseGrabView = view; - Driver.UncookMouse (); + if (!OnGrabbingMouse (view)) { + OnGrabbedMouse (view); + mouseGrabView = view; + Driver.UncookMouse (); + } } /// @@ -751,16 +763,36 @@ public static void UngrabMouse () { if (mouseGrabView == null) return; - OnUnGrabbedMouse (mouseGrabView); - mouseGrabView = null; - Driver.CookMouse (); + if (!OnUnGrabbingMouse (mouseGrabView)) { + OnUnGrabbedMouse (mouseGrabView); + mouseGrabView = null; + Driver.CookMouse (); + } + } + + static bool OnGrabbingMouse (View view) + { + if (view == null) + return false; + var evArgs = new GrabMouseEventArgs (view); + GrabbingMouse?.Invoke (view, evArgs); + return evArgs.Cancel; + } + + static bool OnUnGrabbingMouse (View view) + { + if (view == null) + return false; + var evArgs = new GrabMouseEventArgs (view); + UnGrabbingMouse?.Invoke (view, evArgs); + return evArgs.Cancel; } static void OnGrabbedMouse (View view) { if (view == null) return; - GrabbedMouse?.Invoke (view, new ViewEventArgs(view)); + GrabbedMouse?.Invoke (view, new ViewEventArgs (view)); } static void OnUnGrabbedMouse (View view) @@ -1029,7 +1061,7 @@ public static RunState Begin (Toplevel toplevel) Driver.Refresh (); } - NotifyNewRunState?.Invoke (toplevel, new RunStateEventArgs(rs)); + NotifyNewRunState?.Invoke (toplevel, new RunStateEventArgs (rs)); return rs; } @@ -1497,7 +1529,7 @@ public static void RequestStop (Toplevel top = null) static void OnNotifyStopRunState (Toplevel top) { if (ExitRunLoopAfterFirstIteration) { - NotifyStopRunState?.Invoke (top, new ToplevelEventArgs(top)); + NotifyStopRunState?.Invoke (top, new ToplevelEventArgs (top)); } } @@ -1530,7 +1562,7 @@ static void TerminalResized () t.SetRelativeLayout (full); t.LayoutSubviews (); t.PositionToplevels (); - t.OnResized (new SizeChangedEventArgs(full.Size)); + t.OnResized (new SizeChangedEventArgs (full.Size)); } Refresh (); } diff --git a/Terminal.Gui/Core/EventArgs/GrabMouseEventArgs.cs b/Terminal.Gui/Core/EventArgs/GrabMouseEventArgs.cs new file mode 100644 index 0000000000..952dc5ac6b --- /dev/null +++ b/Terminal.Gui/Core/EventArgs/GrabMouseEventArgs.cs @@ -0,0 +1,29 @@ +using System; + +namespace Terminal.Gui { + /// + /// Args for events that relate to specific + /// + public class GrabMouseEventArgs : EventArgs{ + + /// + /// Creates a new instance of the class. + /// + /// The view that the event is about. + public GrabMouseEventArgs (View view) + { + View = view; + } + + /// + /// The view that the event is about. + /// + public View View { get; } + + /// + /// Flag that allows the cancellation of the event. If set to in the + /// event handler, the event will be canceled. + /// + public bool Cancel { get; set; } + } +} diff --git a/Terminal.Gui/Core/Toplevel.cs b/Terminal.Gui/Core/Toplevel.cs index ca53bb8acf..efabbea3bd 100644 --- a/Terminal.Gui/Core/Toplevel.cs +++ b/Terminal.Gui/Core/Toplevel.cs @@ -120,7 +120,7 @@ internal virtual void OnResized (SizeChangedEventArgs size) internal virtual void OnChildUnloaded (Toplevel top) { - ChildUnloaded?.Invoke (this, new ToplevelEventArgs(top)); + ChildUnloaded?.Invoke (this, new ToplevelEventArgs (top)); } internal virtual void OnChildLoaded (Toplevel top) @@ -159,7 +159,7 @@ internal virtual void OnDeactivate (Toplevel activated) internal virtual void OnActivate (Toplevel deactivated) { - Activate?.Invoke (this, new ToplevelEventArgs(deactivated)); + Activate?.Invoke (this, new ToplevelEventArgs (deactivated)); } /// @@ -221,6 +221,9 @@ void Initialize () { ColorScheme = Colors.TopLevel; + Application.GrabbingMouse += Application_GrabbingMouse; + Application.UnGrabbingMouse += Application_UnGrabbingMouse; + // Things this view knows how to do AddCommand (Command.QuitToplevel, () => { QuitToplevel (); return true; }); AddCommand (Command.Suspend, () => { Driver.Suspend (); ; return true; }); @@ -256,6 +259,20 @@ void Initialize () AddKeyBinding (Key.L | Key.CtrlMask, Command.Refresh); } + private void Application_UnGrabbingMouse (object sender, GrabMouseEventArgs e) + { + if (Application.MouseGrabView == this && dragPosition.HasValue) { + e.Cancel = true; + } + } + + private void Application_GrabbingMouse (object sender, GrabMouseEventArgs e) + { + if (Application.MouseGrabView == this && dragPosition.HasValue) { + e.Cancel = true; + } + } + /// /// Invoked when the is changed. /// @@ -824,8 +841,8 @@ public override bool MouseEvent (MouseEvent mouseEvent) } if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Released) && dragPosition.HasValue) { - Application.UngrabMouse (); dragPosition = null; + Application.UngrabMouse (); } //System.Diagnostics.Debug.WriteLine ($"dragPosition after: {dragPosition.HasValue}"); diff --git a/UICatalog/Scenarios/Clipping.cs b/UICatalog/Scenarios/Clipping.cs index 606902bd41..58f89b7a35 100644 --- a/UICatalog/Scenarios/Clipping.cs +++ b/UICatalog/Scenarios/Clipping.cs @@ -37,7 +37,8 @@ public override void Setup () Y = 3, Width = Dim.Fill (3), Height = Dim.Fill (3), - ColorScheme = Colors.Dialog + ColorScheme = Colors.Dialog, + Id = "1" }; var embedded2 = new Window ("2") { @@ -45,7 +46,8 @@ public override void Setup () Y = 3, Width = Dim.Fill (3), Height = Dim.Fill (3), - ColorScheme = Colors.Error + ColorScheme = Colors.Error, + Id = "2" }; embedded1.Add (embedded2); @@ -54,7 +56,8 @@ public override void Setup () Y = 3, Width = Dim.Fill (3), Height = Dim.Fill (3), - ColorScheme = Colors.TopLevel + ColorScheme = Colors.TopLevel, + Id = "3" }; var testButton = new Button (2, 2, "click me"); diff --git a/UnitTests/TopLevels/ToplevelTests.cs b/UnitTests/TopLevels/ToplevelTests.cs index 1da5891e5e..12763a1636 100644 --- a/UnitTests/TopLevels/ToplevelTests.cs +++ b/UnitTests/TopLevels/ToplevelTests.cs @@ -154,28 +154,28 @@ public void Internal_Tests () var eventInvoked = ""; - top.ChildUnloaded += (s,e) => eventInvoked = "ChildUnloaded"; + top.ChildUnloaded += (s, e) => eventInvoked = "ChildUnloaded"; top.OnChildUnloaded (top); Assert.Equal ("ChildUnloaded", eventInvoked); - top.ChildLoaded += (s,e) => eventInvoked = "ChildLoaded"; + top.ChildLoaded += (s, e) => eventInvoked = "ChildLoaded"; top.OnChildLoaded (top); Assert.Equal ("ChildLoaded", eventInvoked); top.Closed += (s, e) => eventInvoked = "Closed"; top.OnClosed (top); Assert.Equal ("Closed", eventInvoked); - top.Closing += (s,e) => eventInvoked = "Closing"; + top.Closing += (s, e) => eventInvoked = "Closing"; top.OnClosing (new ToplevelClosingEventArgs (top)); Assert.Equal ("Closing", eventInvoked); top.AllChildClosed += (s, e) => eventInvoked = "AllChildClosed"; top.OnAllChildClosed (); Assert.Equal ("AllChildClosed", eventInvoked); - top.ChildClosed += (s,e) => eventInvoked = "ChildClosed"; + top.ChildClosed += (s, e) => eventInvoked = "ChildClosed"; top.OnChildClosed (top); Assert.Equal ("ChildClosed", eventInvoked); - top.Deactivate += (s,e) => eventInvoked = "Deactivate"; + top.Deactivate += (s, e) => eventInvoked = "Deactivate"; top.OnDeactivate (top); Assert.Equal ("Deactivate", eventInvoked); - top.Activate += (s,e) => eventInvoked = "Activate"; + top.Activate += (s, e) => eventInvoked = "Activate"; top.OnActivate (top); Assert.Equal ("Activate", eventInvoked); top.Loaded += (s, e) => eventInvoked = "Loaded"; @@ -356,7 +356,7 @@ public void KeyBindings_Command () var top = Application.Top; top.Add (win1, win2); top.Loaded += (s, e) => isRunning = true; - top.Closing += (s,e) => isRunning = false; + top.Closing += (s, e) => isRunning = false; Application.Begin (top); top.Running = true; @@ -589,9 +589,9 @@ public void Added_Event_Should_Not_Be_Used_To_Initialize_Toplevel_Events () void View_Added (object sender, SuperViewChangedEventArgs e) { - Assert.Throws (() => Application.Top.AlternateForwardKeyChanged += (s,e) => alternateForwardKey = e.OldKey); - Assert.Throws (() => Application.Top.AlternateBackwardKeyChanged += (s,e) => alternateBackwardKey = e.OldKey); - Assert.Throws (() => Application.Top.QuitKeyChanged += (s,e) => quitKey = e.OldKey); + Assert.Throws (() => Application.Top.AlternateForwardKeyChanged += (s, e) => alternateForwardKey = e.OldKey); + Assert.Throws (() => Application.Top.AlternateBackwardKeyChanged += (s, e) => alternateBackwardKey = e.OldKey); + Assert.Throws (() => Application.Top.QuitKeyChanged += (s, e) => quitKey = e.OldKey); Assert.False (wasAdded); wasAdded = true; view.Added -= View_Added; @@ -621,7 +621,7 @@ public void AlternateForwardKeyChanged_AlternateBackwardKeyChanged_QuitKeyChange void View_Initialized (object sender, EventArgs e) { - Application.Top.AlternateForwardKeyChanged += (s,e) => alternateForwardKey = e.OldKey; + Application.Top.AlternateForwardKeyChanged += (s, e) => alternateForwardKey = e.OldKey; Application.Top.AlternateBackwardKeyChanged += (s, e) => alternateBackwardKey = e.OldKey; Application.Top.QuitKeyChanged += (s, e) => quitKey = e.OldKey; } @@ -1081,5 +1081,137 @@ void view_LayoutStarted (object sender, View.LayoutEventArgs e) Assert.Equal (new Rect (1, 3, 10, 5), view.Frame); Assert.Equal (new Rect (0, 0, 10, 5), view.NeedDisplay); } + + [Fact, AutoInitShutdown] + public void Toplevel_Inside_ScrollView_MouseGrabView () + { + var scrollView = new ScrollView () { + X = 3, + Y = 3, + Width = 40, + Height = 16, + ContentSize = new Size (200, 100) + }; + var win = new Window ("Window") { X = 3, Y = 3, Width = Dim.Fill (3), Height = Dim.Fill (3) }; + scrollView.Add (win); + var top = Application.Top; + top.Add (scrollView); + Application.Begin (top); + + Assert.Equal (new Rect (0, 0, 80, 25), top.Frame); + Assert.Equal (new Rect (3, 3, 40, 16), scrollView.Frame); + Assert.Equal (new Rect (0, 0, 200, 100), scrollView.Subviews [0].Frame); + Assert.Equal (new Rect (3, 3, 194, 94), win.Frame); + TestHelpers.AssertDriverContentsWithFrameAre (@" + ▲ + ┬ + │ + ┌ Window ───────────────────────────┴ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ▼ + ◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ", output); + + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessMouseEvent", + new MouseEvent () { + X = 6, + Y = 6, + Flags = MouseFlags.Button1Pressed + }); + Assert.Equal (win, Application.MouseGrabView); + Assert.Equal (new Rect (3, 3, 194, 94), win.Frame); + + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessMouseEvent", + new MouseEvent () { + X = 9, + Y = 9, + Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition + }); + Assert.Equal (win, Application.MouseGrabView); + top.SetNeedsLayout (); + top.LayoutSubviews (); + Assert.Equal (new Rect (6, 6, 191, 91), win.Frame); + Application.Refresh (); + TestHelpers.AssertDriverContentsWithFrameAre (@" + ▲ + ┬ + │ + ┴ + ░ + ░ + ┌ Window ────────────────────────░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ▼ + ◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ", output); + + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessMouseEvent", + new MouseEvent () { + X = 5, + Y = 5, + Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition + }); + Assert.Equal (win, Application.MouseGrabView); + top.SetNeedsLayout (); + top.LayoutSubviews (); + Assert.Equal (new Rect (2, 2, 195, 95), win.Frame); + Application.Refresh (); + TestHelpers.AssertDriverContentsWithFrameAre (@" + ▲ + ┬ + ┌ Window ────────────────────────────│ + │ ┴ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ░ + │ ▼ + ◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ", output); + + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessMouseEvent", + new MouseEvent () { + X = 5, + Y = 5, + Flags = MouseFlags.Button1Released + }); + Assert.Null (Application.MouseGrabView); + + ReflectionTools.InvokePrivate ( + typeof (Application), + "ProcessMouseEvent", + new MouseEvent () { + X = 4, + Y = 4, + Flags = MouseFlags.ReportMousePosition + }); + Assert.Equal (scrollView, Application.MouseGrabView); + } } } \ No newline at end of file From 2ed71e284c37fde8c78fdb267e3fb59ee183fd46 Mon Sep 17 00:00:00 2001 From: tznind Date: Wed, 15 Mar 2023 19:35:21 +0000 Subject: [PATCH 28/46] Move all nested eventargs out of parent classes to root --- .../Configuration/ConfigurationManager.cs | 13 --- .../ConfigurationManagerEventArgs.cs | 18 ++++ .../Configuration/ThemeManagerEventArgs.cs | 24 +++++ Terminal.Gui/Configuration/ThemeScope.cs | 20 +--- Terminal.Gui/Core/Application.cs | 16 +--- Terminal.Gui/Core/CollectionNavigator.cs | 21 +--- Terminal.Gui/Core/FocusEventArgs.cs | 25 +++++ Terminal.Gui/Core/KeyEventEventArgs.cs | 25 +++++ .../Core/KeystrokeNavigatorEventArgs.cs | 22 +++++ Terminal.Gui/Core/ResizedEventArgs.cs | 32 +++++++ Terminal.Gui/Core/TitleEventArgs.cs | 46 +++++++++ Terminal.Gui/Core/Toplevel.cs | 22 ----- Terminal.Gui/Core/ToplevelClosingEventArgs.cs | 26 +++++ Terminal.Gui/Core/View.cs | 42 +------- Terminal.Gui/Core/Window.cs | 33 +------ Terminal.Gui/Views/CellActivatedEventArgs.cs | 43 +++++++++ .../Views/ContentsChangedEventArgs.cs | 32 +++++++ Terminal.Gui/Views/DateField.cs | 33 ------- Terminal.Gui/Views/DateTimeEventArgs.cs | 43 +++++++++ Terminal.Gui/Views/HexView.cs | 60 +----------- Terminal.Gui/Views/HexViewEditEventArgs.cs | 37 ++++++++ Terminal.Gui/Views/HexViewEventArgs.cs | 43 +++++++++ Terminal.Gui/Views/HistoryTextItem.cs | 36 +++++++ Terminal.Gui/Views/ListView.cs | 49 ---------- Terminal.Gui/Views/ListViewItemEventArgs.cs | 28 ++++++ Terminal.Gui/Views/ListViewRowEventArgs.cs | 27 ++++++ Terminal.Gui/Views/Menu.cs | 68 ------------- Terminal.Gui/Views/MenuClosingEventArgs.cs | 42 ++++++++ Terminal.Gui/Views/MenuOpeningEventArgs.cs | 32 +++++++ Terminal.Gui/Views/RadioGroup.cs | 26 ----- .../Views/SelectedCellChangedEventArgs.cs | 63 ++++++++++++ Terminal.Gui/Views/SelectedItemChangedArgs.cs | 29 ++++++ Terminal.Gui/Views/SplitterEventArgs.cs | 38 ++++++++ Terminal.Gui/Views/TabChangedEventArgs.cs | 31 ++++++ Terminal.Gui/Views/TabMouseEventArgs.cs | 36 +++++++ Terminal.Gui/Views/TabView.cs | 60 +----------- Terminal.Gui/Views/TableView.cs | 95 +------------------ Terminal.Gui/Views/TextChangedEventArgs.cs | 31 ++++++ Terminal.Gui/Views/TextChangingEventArgs.cs | 34 +++++++ Terminal.Gui/Views/TextField.cs | 42 -------- Terminal.Gui/Views/TextView.cs | 59 +----------- Terminal.Gui/Views/TileView.cs | 70 +------------- Terminal.Gui/Views/TitleEventArgs.cs | 42 ++++++++ Terminal.Gui/Windows/StepChangeEventArgs.cs | 38 ++++++++ Terminal.Gui/Windows/Wizard.cs | 52 +--------- Terminal.Gui/Windows/WizardButtonEventArgs.cs | 24 +++++ UICatalog/Scenarios/CsvEditor.cs | 6 +- UICatalog/Scenarios/HexEditor.cs | 4 +- UICatalog/Scenarios/InteractiveTree.cs | 2 +- UICatalog/Scenarios/MultiColouredTable.cs | 2 +- UICatalog/Scenarios/Notepad.cs | 4 +- UICatalog/Scenarios/TableEditor.cs | 4 +- UICatalog/Scenarios/TreeViewFileSystem.cs | 2 +- UICatalog/Scenarios/VkeyPacketSimulator.cs | 4 +- UICatalog/UICatalog.cs | 2 +- UnitTests/Application/ApplicationTests.cs | 2 +- .../Configuration/ConfigurationMangerTests.cs | 4 +- UnitTests/Core/ViewTests.cs | 6 +- UnitTests/UICatalog/ScenarioTests.cs | 2 +- UnitTests/Views/HexViewTests.cs | 2 +- 60 files changed, 983 insertions(+), 791 deletions(-) create mode 100644 Terminal.Gui/Configuration/ConfigurationManagerEventArgs.cs create mode 100644 Terminal.Gui/Configuration/ThemeManagerEventArgs.cs create mode 100644 Terminal.Gui/Core/FocusEventArgs.cs create mode 100644 Terminal.Gui/Core/KeyEventEventArgs.cs create mode 100644 Terminal.Gui/Core/KeystrokeNavigatorEventArgs.cs create mode 100644 Terminal.Gui/Core/ResizedEventArgs.cs create mode 100644 Terminal.Gui/Core/TitleEventArgs.cs create mode 100644 Terminal.Gui/Core/ToplevelClosingEventArgs.cs create mode 100644 Terminal.Gui/Views/CellActivatedEventArgs.cs create mode 100644 Terminal.Gui/Views/ContentsChangedEventArgs.cs create mode 100644 Terminal.Gui/Views/DateTimeEventArgs.cs create mode 100644 Terminal.Gui/Views/HexViewEditEventArgs.cs create mode 100644 Terminal.Gui/Views/HexViewEventArgs.cs create mode 100644 Terminal.Gui/Views/HistoryTextItem.cs create mode 100644 Terminal.Gui/Views/ListViewItemEventArgs.cs create mode 100644 Terminal.Gui/Views/ListViewRowEventArgs.cs create mode 100644 Terminal.Gui/Views/MenuClosingEventArgs.cs create mode 100644 Terminal.Gui/Views/MenuOpeningEventArgs.cs create mode 100644 Terminal.Gui/Views/SelectedCellChangedEventArgs.cs create mode 100644 Terminal.Gui/Views/SelectedItemChangedArgs.cs create mode 100644 Terminal.Gui/Views/SplitterEventArgs.cs create mode 100644 Terminal.Gui/Views/TabChangedEventArgs.cs create mode 100644 Terminal.Gui/Views/TabMouseEventArgs.cs create mode 100644 Terminal.Gui/Views/TextChangedEventArgs.cs create mode 100644 Terminal.Gui/Views/TextChangingEventArgs.cs create mode 100644 Terminal.Gui/Views/TitleEventArgs.cs create mode 100644 Terminal.Gui/Windows/StepChangeEventArgs.cs create mode 100644 Terminal.Gui/Windows/WizardButtonEventArgs.cs diff --git a/Terminal.Gui/Configuration/ConfigurationManager.cs b/Terminal.Gui/Configuration/ConfigurationManager.cs index 8222195a4a..6048294dd7 100644 --- a/Terminal.Gui/Configuration/ConfigurationManager.cs +++ b/Terminal.Gui/Configuration/ConfigurationManager.cs @@ -301,19 +301,6 @@ internal static Stream ToStream () return stream; } - /// - /// Event arguments for the events. - /// - public class ConfigurationManagerEventArgs : EventArgs { - - /// - /// Initializes a new instance of - /// - public ConfigurationManagerEventArgs () - { - } - } - /// /// Gets or sets whether the should throw an exception if it encounters /// an error on deserialization. If (the default), the error is logged and printed to the diff --git a/Terminal.Gui/Configuration/ConfigurationManagerEventArgs.cs b/Terminal.Gui/Configuration/ConfigurationManagerEventArgs.cs new file mode 100644 index 0000000000..c29405f01a --- /dev/null +++ b/Terminal.Gui/Configuration/ConfigurationManagerEventArgs.cs @@ -0,0 +1,18 @@ +using System; + +#nullable enable + +namespace Terminal.Gui.Configuration { + /// + /// Event arguments for the events. + /// + public class ConfigurationManagerEventArgs : EventArgs { + + /// + /// Initializes a new instance of + /// + public ConfigurationManagerEventArgs () + { + } + } +} diff --git a/Terminal.Gui/Configuration/ThemeManagerEventArgs.cs b/Terminal.Gui/Configuration/ThemeManagerEventArgs.cs new file mode 100644 index 0000000000..fd4d9ca563 --- /dev/null +++ b/Terminal.Gui/Configuration/ThemeManagerEventArgs.cs @@ -0,0 +1,24 @@ +using System; + +#nullable enable + +namespace Terminal.Gui.Configuration { + + /// + /// Event arguments for the events. + /// + public class ThemeManagerEventArgs : EventArgs { + /// + /// The name of the new active theme.. + /// + public string NewTheme { get; set; } = string.Empty; + + /// + /// Initializes a new instance of + /// + public ThemeManagerEventArgs (string newTheme) + { + NewTheme = newTheme; + } + } +} \ No newline at end of file diff --git a/Terminal.Gui/Configuration/ThemeScope.cs b/Terminal.Gui/Configuration/ThemeScope.cs index 35b568b320..6b5ee2eb02 100644 --- a/Terminal.Gui/Configuration/ThemeScope.cs +++ b/Terminal.Gui/Configuration/ThemeScope.cs @@ -110,7 +110,7 @@ internal override bool Apply () /// } /// } /// - public class ThemeManager : IDictionary { + public partial class ThemeManager : IDictionary { private static readonly ThemeManager _instance = new ThemeManager (); static ThemeManager () { } // Make sure it's truly lazy private ThemeManager () { } // Prevent instantiation outside @@ -152,24 +152,6 @@ public string Theme { } } - /// - /// Event arguments for the events. - /// - public class ThemeManagerEventArgs : EventArgs { - /// - /// The name of the new active theme.. - /// - public string NewTheme { get; set; } = string.Empty; - - /// - /// Initializes a new instance of - /// - public ThemeManagerEventArgs (string newTheme) - { - NewTheme = newTheme; - } - } - /// /// Called when the selected theme has changed. Fires the event. /// diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index f38e31b210..561d6a8c40 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -59,7 +59,7 @@ namespace Terminal.Gui { /// to the mainloop, allowing user code to use async/await. /// /// - public static class Application { + public static partial class Application { static readonly Stack toplevels = new Stack (); /// @@ -1501,20 +1501,6 @@ static void OnNotifyStopRunState (Toplevel top) } } - /// - /// Event arguments for the event. - /// - public class ResizedEventArgs : EventArgs { - /// - /// The number of rows in the resized terminal. - /// - public int Rows { get; set; } - /// - /// The number of columns in the resized terminal. - /// - public int Cols { get; set; } - } - /// /// Invoked when the terminal was resized. The new size of the terminal is provided. /// diff --git a/Terminal.Gui/Core/CollectionNavigator.cs b/Terminal.Gui/Core/CollectionNavigator.cs index 054fce1067..e0dc7d44e0 100644 --- a/Terminal.Gui/Core/CollectionNavigator.cs +++ b/Terminal.Gui/Core/CollectionNavigator.cs @@ -15,7 +15,7 @@ namespace Terminal.Gui { /// If the user pauses keystrokes for a short time (see ), the search string is cleared. /// /// - public class CollectionNavigator { + public partial class CollectionNavigator { /// /// Constructs a new CollectionNavigator. /// @@ -44,25 +44,6 @@ public CollectionNavigator () { } /// public IEnumerable Collection { get; set; } - /// - /// Event arguments for the event. - /// - public class KeystrokeNavigatorEventArgs : EventArgs{ - /// - /// he current . - /// - public string SearchString { get; } - - /// - /// Initializes a new instance of - /// - /// The current . - public KeystrokeNavigatorEventArgs (string searchString) - { - SearchString = searchString; - } - } - /// /// This event is invoked when changes. Useful for debugging. /// diff --git a/Terminal.Gui/Core/FocusEventArgs.cs b/Terminal.Gui/Core/FocusEventArgs.cs new file mode 100644 index 0000000000..e019d5a0a6 --- /dev/null +++ b/Terminal.Gui/Core/FocusEventArgs.cs @@ -0,0 +1,25 @@ +using System; + +namespace Terminal.Gui { + + /// + /// Defines the event arguments for + /// + public class FocusEventArgs : EventArgs { + /// + /// Constructs. + /// + /// The view that gets or loses focus. + public FocusEventArgs (View view) { View = view; } + /// + /// Indicates if the current focus event has already been processed and the driver should stop notifying any other event subscriber. + /// Its important to set this value to true specially when updating any View's layout from inside the subscriber method. + /// + public bool Handled { get; set; } + /// + /// Indicates the current view that gets or loses focus. + /// + public View View { get; set; } + } + +} diff --git a/Terminal.Gui/Core/KeyEventEventArgs.cs b/Terminal.Gui/Core/KeyEventEventArgs.cs new file mode 100644 index 0000000000..7e54483a88 --- /dev/null +++ b/Terminal.Gui/Core/KeyEventEventArgs.cs @@ -0,0 +1,25 @@ +using System; + +namespace Terminal.Gui { + + /// + /// Defines the event arguments for + /// + public class KeyEventEventArgs : EventArgs { + /// + /// Constructs. + /// + /// + public KeyEventEventArgs (KeyEvent ke) => KeyEvent = ke; + /// + /// The for the event. + /// + public KeyEvent KeyEvent { get; set; } + /// + /// Indicates if the current Key event has already been processed and the driver should stop notifying any other event subscriber. + /// Its important to set this value to true specially when updating any View's layout from inside the subscriber method. + /// + public bool Handled { get; set; } = false; + } + +} diff --git a/Terminal.Gui/Core/KeystrokeNavigatorEventArgs.cs b/Terminal.Gui/Core/KeystrokeNavigatorEventArgs.cs new file mode 100644 index 0000000000..454f5a1e24 --- /dev/null +++ b/Terminal.Gui/Core/KeystrokeNavigatorEventArgs.cs @@ -0,0 +1,22 @@ +using System; + +namespace Terminal.Gui { + /// + /// Event arguments for the event. + /// + public class KeystrokeNavigatorEventArgs : EventArgs { + /// + /// he current . + /// + public string SearchString { get; } + + /// + /// Initializes a new instance of + /// + /// The current . + public KeystrokeNavigatorEventArgs (string searchString) + { + SearchString = searchString; + } + } +} diff --git a/Terminal.Gui/Core/ResizedEventArgs.cs b/Terminal.Gui/Core/ResizedEventArgs.cs new file mode 100644 index 0000000000..a4cc81a0ba --- /dev/null +++ b/Terminal.Gui/Core/ResizedEventArgs.cs @@ -0,0 +1,32 @@ +// +// Core.cs: The core engine for gui.cs +// +// Authors: +// Miguel de Icaza (miguel@gnome.org) +// +// Pending: +// - Check for NeedDisplay on the hierarchy and repaint +// - Layout support +// - "Colors" type or "Attributes" type? +// - What to surface as "BackgroundCOlor" when clearing a window, an attribute or colors? +// +// Optimizations +// - Add rendering limitation to the exposed area +using System; + +namespace Terminal.Gui { + + /// + /// Event arguments for the event. + /// + public class ResizedEventArgs : EventArgs { + /// + /// The number of rows in the resized terminal. + /// + public int Rows { get; set; } + /// + /// The number of columns in the resized terminal. + /// + public int Cols { get; set; } + } +} diff --git a/Terminal.Gui/Core/TitleEventArgs.cs b/Terminal.Gui/Core/TitleEventArgs.cs new file mode 100644 index 0000000000..c20e9c56ca --- /dev/null +++ b/Terminal.Gui/Core/TitleEventArgs.cs @@ -0,0 +1,46 @@ +// +// Authors: +// Miguel de Icaza (miguel@gnome.org) +// +// NOTE: Window is functionally identical to FrameView with the following exceptions. +// - Window is a Toplevel +// - FrameView Does not support padding (but should) +// - FrameView Does not support mouse dragging +// - FrameView Does not support IEnumerable +// Any updates done here should probably be done in FrameView as well; TODO: Merge these classes + +using System; +using NStack; + +namespace Terminal.Gui { + /// + /// Event arguments for Title change events. + /// + public class TitleEventArgs : EventArgs { + /// + /// The new Window Title. + /// + public ustring NewTitle { get; set; } + + /// + /// The old Window Title. + /// + public ustring OldTitle { get; set; } + + /// + /// Flag which allows canceling the Title change. + /// + public bool Cancel { get; set; } + + /// + /// Initializes a new instance of + /// + /// The that is/has been replaced. + /// The new to be replaced. + public TitleEventArgs (ustring oldTitle, ustring newTitle) + { + OldTitle = oldTitle; + NewTitle = newTitle; + } + } +} diff --git a/Terminal.Gui/Core/Toplevel.cs b/Terminal.Gui/Core/Toplevel.cs index ca53bb8acf..02727aa397 100644 --- a/Terminal.Gui/Core/Toplevel.cs +++ b/Terminal.Gui/Core/Toplevel.cs @@ -1050,26 +1050,4 @@ public int Compare (Toplevel x, Toplevel y) return string.Compare (x.Id.ToString (), y.Id.ToString ()); } } - /// - /// implementation for the event. - /// - public class ToplevelClosingEventArgs : EventArgs { - /// - /// The toplevel requesting stop. - /// - public View RequestingTop { get; } - /// - /// Provides an event cancellation option. - /// - public bool Cancel { get; set; } - - /// - /// Initializes the event arguments with the requesting toplevel. - /// - /// The . - public ToplevelClosingEventArgs (Toplevel requestingTop) - { - RequestingTop = requestingTop; - } - } } diff --git a/Terminal.Gui/Core/ToplevelClosingEventArgs.cs b/Terminal.Gui/Core/ToplevelClosingEventArgs.cs new file mode 100644 index 0000000000..b4b1b0de87 --- /dev/null +++ b/Terminal.Gui/Core/ToplevelClosingEventArgs.cs @@ -0,0 +1,26 @@ +using System; + +namespace Terminal.Gui { + /// + /// implementation for the event. + /// + public class ToplevelClosingEventArgs : EventArgs { + /// + /// The toplevel requesting stop. + /// + public View RequestingTop { get; } + /// + /// Provides an event cancellation option. + /// + public bool Cancel { get; set; } + + /// + /// Initializes the event arguments with the requesting toplevel. + /// + /// The . + public ToplevelClosingEventArgs (Toplevel requestingTop) + { + RequestingTop = requestingTop; + } + } +} diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index 95dde58a5f..1c1372b47e 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -101,7 +101,7 @@ public enum LayoutStyle { /// frames for the vies that use . /// /// - public class View : Responder, ISupportInitializeNotification { + public partial class View : Responder, ISupportInitializeNotification { internal enum Direction { Forward, @@ -1331,26 +1331,6 @@ void SetHasFocus (bool value, View view, bool force = false) } } - /// - /// Defines the event arguments for - /// - public class FocusEventArgs : EventArgs { - /// - /// Constructs. - /// - /// The view that gets or loses focus. - public FocusEventArgs (View view) { View = view; } - /// - /// Indicates if the current focus event has already been processed and the driver should stop notifying any other event subscriber. - /// Its important to set this value to true specially when updating any View's layout from inside the subscriber method. - /// - public bool Handled { get; set; } - /// - /// Indicates the current view that gets or loses focus. - /// - public View View { get; set; } - } - /// /// Method invoked when a subview is being added to this view. /// @@ -1690,26 +1670,6 @@ public void SetFocus () SuperView?.SetFocus (this); } - /// - /// Defines the event arguments for - /// - public class KeyEventEventArgs : EventArgs { - /// - /// Constructs. - /// - /// - public KeyEventEventArgs (KeyEvent ke) => KeyEvent = ke; - /// - /// The for the event. - /// - public KeyEvent KeyEvent { get; set; } - /// - /// Indicates if the current Key event has already been processed and the driver should stop notifying any other event subscriber. - /// Its important to set this value to true specially when updating any View's layout from inside the subscriber method. - /// - public bool Handled { get; set; } = false; - } - /// /// Invoked when a character key is pressed and occurs after the key up event. /// diff --git a/Terminal.Gui/Core/Window.cs b/Terminal.Gui/Core/Window.cs index cbf958a89b..b89845d5c6 100644 --- a/Terminal.Gui/Core/Window.cs +++ b/Terminal.Gui/Core/Window.cs @@ -24,7 +24,7 @@ namespace Terminal.Gui { /// The 'client area' of a is a rectangle deflated by one or more rows/columns from . A this time there is no /// API to determine this rectangle. /// - public class Window : Toplevel { + public partial class Window : Toplevel { View contentView; ustring title = ustring.Empty; @@ -343,37 +343,6 @@ public override TextAlignment TextAlignment { base.TextAlignment = contentView.TextAlignment = value; } } - - /// - /// Event arguments for change events. - /// - public class TitleEventArgs : EventArgs { - /// - /// The new Window Title. - /// - public ustring NewTitle { get; set; } - - /// - /// The old Window Title. - /// - public ustring OldTitle { get; set; } - - /// - /// Flag which allows canceling the Title change. - /// - public bool Cancel { get; set; } - - /// - /// Initializes a new instance of - /// - /// The that is/has been replaced. - /// The new to be replaced. - public TitleEventArgs (ustring oldTitle, ustring newTitle) - { - OldTitle = oldTitle; - NewTitle = newTitle; - } - } /// /// Called before the changes. Invokes the event, which can be cancelled. /// diff --git a/Terminal.Gui/Views/CellActivatedEventArgs.cs b/Terminal.Gui/Views/CellActivatedEventArgs.cs new file mode 100644 index 0000000000..2cb558776f --- /dev/null +++ b/Terminal.Gui/Views/CellActivatedEventArgs.cs @@ -0,0 +1,43 @@ +using System; +using System.Data; + +namespace Terminal.Gui { + + + /// + /// Defines the event arguments for event + /// + public class CellActivatedEventArgs : EventArgs { + /// + /// The current table to which the new indexes refer. May be null e.g. if selection change is the result of clearing the table from the view + /// + /// + public DataTable Table { get; } + + + /// + /// The column index of the cell that is being activated + /// + /// + public int Col { get; } + + /// + /// The row index of the cell that is being activated + /// + /// + public int Row { get; } + + /// + /// Creates a new instance of arguments describing a cell being activated in + /// + /// + /// + /// + public CellActivatedEventArgs (DataTable t, int col, int row) + { + Table = t; + Col = col; + Row = row; + } + } +} diff --git a/Terminal.Gui/Views/ContentsChangedEventArgs.cs b/Terminal.Gui/Views/ContentsChangedEventArgs.cs new file mode 100644 index 0000000000..38c27538ef --- /dev/null +++ b/Terminal.Gui/Views/ContentsChangedEventArgs.cs @@ -0,0 +1,32 @@ +// TextView.cs: multi-line text editing +using System; + +namespace Terminal.Gui { + + /// + /// Event arguments for events for when the contents of the TextView change. E.g. the event. + /// + public class ContentsChangedEventArgs : EventArgs { + /// + /// Creates a new instance. + /// + /// Contains the row where the change occurred. + /// Contains the column where the change occured. + public ContentsChangedEventArgs (int currentRow, int currentColumn) + { + Row = currentRow; + Col = currentColumn; + } + + /// + /// + /// Contains the row where the change occurred. + /// + public int Row { get; private set; } + + /// + /// Contains the column where the change occurred. + /// + public int Col { get; private set; } + } +} diff --git a/Terminal.Gui/Views/DateField.cs b/Terminal.Gui/Views/DateField.cs index 98c1ae095d..8f0c1f5f2e 100644 --- a/Terminal.Gui/Views/DateField.cs +++ b/Terminal.Gui/Views/DateField.cs @@ -421,37 +421,4 @@ public virtual void OnDateChanged (DateTimeEventArgs args) DateChanged?.Invoke (this,args); } } - - /// - /// Defines the event arguments for and events. - /// - public class DateTimeEventArgs : EventArgs { - /// - /// The old or value. - /// - public T OldValue { get; } - - /// - /// The new or value. - /// - public T NewValue { get; } - - /// - /// The or format. - /// - public string Format { get; } - - /// - /// Initializes a new instance of - /// - /// The old or value. - /// The new or value. - /// The or format string. - public DateTimeEventArgs (T oldValue, T newValue, string format) - { - OldValue = oldValue; - NewValue = newValue; - Format = format; - } - } } \ No newline at end of file diff --git a/Terminal.Gui/Views/DateTimeEventArgs.cs b/Terminal.Gui/Views/DateTimeEventArgs.cs new file mode 100644 index 0000000000..2c69bb9973 --- /dev/null +++ b/Terminal.Gui/Views/DateTimeEventArgs.cs @@ -0,0 +1,43 @@ +// +// DateField.cs: text entry for date +// +// Author: Barry Nolte +// +// Licensed under the MIT license +// +using System; + +namespace Terminal.Gui { + /// + /// Defines the event arguments for and events. + /// + public class DateTimeEventArgs : EventArgs { + /// + /// The old or value. + /// + public T OldValue { get; } + + /// + /// The new or value. + /// + public T NewValue { get; } + + /// + /// The or format. + /// + public string Format { get; } + + /// + /// Initializes a new instance of + /// + /// The old or value. + /// The new or value. + /// The or format string. + public DateTimeEventArgs (T oldValue, T newValue, string format) + { + OldValue = oldValue; + NewValue = newValue; + Format = format; + } + } +} \ No newline at end of file diff --git a/Terminal.Gui/Views/HexView.cs b/Terminal.Gui/Views/HexView.cs index 910e9e1050..3d9850f627 100644 --- a/Terminal.Gui/Views/HexView.cs +++ b/Terminal.Gui/Views/HexView.cs @@ -34,7 +34,7 @@ namespace Terminal.Gui { /// to an offset in the stream. /// /// - public class HexView : View { + public partial class HexView : View { SortedDictionary edits = new SortedDictionary (); Stream source; long displayStart, pos; @@ -631,63 +631,5 @@ public override bool OnEnter (View view) return base.OnEnter (view); } - - /// - /// Defines the event arguments for event. - /// - public class HexViewEditEventArgs : EventArgs { - - /// - /// Creates a new instance of the class. - /// - /// - /// - public HexViewEditEventArgs (long position, byte newValue) - { - Position = position; - NewValue = newValue; - } - - /// - /// Gets the location of the edit. - /// - public long Position { get; } - - /// - /// Gets the new value for that . - /// - public byte NewValue { get; } - } - /// - /// Defines the event arguments for event. - /// - public class HexViewEventArgs : EventArgs { - /// - /// Gets the current character position starting at one, related to the . - /// - public long Position { get; private set; } - /// - /// Gets the current cursor position starting at one for both, line and column. - /// - public Point CursorPosition { get; private set; } - - /// - /// The bytes length per line. - /// - public int BytesPerLine { get; private set; } - - /// - /// Initializes a new instance of - /// - /// The character position. - /// The cursor position. - /// Line bytes length. - public HexViewEventArgs (long pos, Point cursor, int lineLength) - { - Position = pos; - CursorPosition = cursor; - BytesPerLine = lineLength; - } - } } } diff --git a/Terminal.Gui/Views/HexViewEditEventArgs.cs b/Terminal.Gui/Views/HexViewEditEventArgs.cs new file mode 100644 index 0000000000..76185b6c4b --- /dev/null +++ b/Terminal.Gui/Views/HexViewEditEventArgs.cs @@ -0,0 +1,37 @@ +// +// HexView.cs: A hexadecimal viewer +// +// TODO: +// - Support searching and highlighting of the search result +// - Bug showing the last line +// +using System; + +namespace Terminal.Gui { + /// + /// Defines the event arguments for event. + /// + public class HexViewEditEventArgs : EventArgs { + + /// + /// Creates a new instance of the class. + /// + /// + /// + public HexViewEditEventArgs (long position, byte newValue) + { + Position = position; + NewValue = newValue; + } + + /// + /// Gets the location of the edit. + /// + public long Position { get; } + + /// + /// Gets the new value for that . + /// + public byte NewValue { get; } + } +} diff --git a/Terminal.Gui/Views/HexViewEventArgs.cs b/Terminal.Gui/Views/HexViewEventArgs.cs new file mode 100644 index 0000000000..7847f68d0f --- /dev/null +++ b/Terminal.Gui/Views/HexViewEventArgs.cs @@ -0,0 +1,43 @@ +// +// HexView.cs: A hexadecimal viewer +// +// TODO: +// - Support searching and highlighting of the search result +// - Bug showing the last line +// +using System; +using System.IO; + +namespace Terminal.Gui { + /// + /// Defines the event arguments for event. + /// + public class HexViewEventArgs : EventArgs { + /// + /// Gets the current character position starting at one, related to the . + /// + public long Position { get; private set; } + /// + /// Gets the current cursor position starting at one for both, line and column. + /// + public Point CursorPosition { get; private set; } + + /// + /// The bytes length per line. + /// + public int BytesPerLine { get; private set; } + + /// + /// Initializes a new instance of + /// + /// The character position. + /// The cursor position. + /// Line bytes length. + public HexViewEventArgs (long pos, Point cursor, int lineLength) + { + Position = pos; + CursorPosition = cursor; + BytesPerLine = lineLength; + } + } +} diff --git a/Terminal.Gui/Views/HistoryTextItem.cs b/Terminal.Gui/Views/HistoryTextItem.cs new file mode 100644 index 0000000000..7b1dfe80ec --- /dev/null +++ b/Terminal.Gui/Views/HistoryTextItem.cs @@ -0,0 +1,36 @@ +// TextView.cs: multi-line text editing +using System; +using System.Collections.Generic; +using Rune = System.Rune; + +namespace Terminal.Gui { + partial class HistoryText { + public class HistoryTextItem : EventArgs{ + public List> Lines; + public Point CursorPosition; + public LineStatus LineStatus; + public bool IsUndoing; + public Point FinalCursorPosition; + public HistoryTextItem RemovedOnAdded; + + public HistoryTextItem (List> lines, Point curPos, LineStatus linesStatus) + { + Lines = lines; + CursorPosition = curPos; + LineStatus = linesStatus; + } + + public HistoryTextItem (HistoryTextItem historyTextItem) + { + Lines = new List> (historyTextItem.Lines); + CursorPosition = new Point (historyTextItem.CursorPosition.X, historyTextItem.CursorPosition.Y); + LineStatus = historyTextItem.LineStatus; + } + + public override string ToString () + { + return $"(Count: {Lines.Count}, Cursor: {CursorPosition}, Status: {LineStatus})"; + } + } + } +} diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index 506cf7019e..ce62a2cf07 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -938,53 +938,4 @@ public int StartsWith (string search) return -1; } } - - /// - /// for events. - /// - public class ListViewItemEventArgs : EventArgs { - /// - /// The index of the item. - /// - public int Item { get; } - /// - /// The item. - /// - public object Value { get; } - - /// - /// Initializes a new instance of - /// - /// The index of the item. - /// The item - public ListViewItemEventArgs (int item, object value) - { - Item = item; - Value = value; - } - } - - /// - /// used by the event. - /// - public class ListViewRowEventArgs : EventArgs { - /// - /// The current row being rendered. - /// - public int Row { get; } - /// - /// The used by current row or - /// null to maintain the current attribute. - /// - public Attribute? RowAttribute { get; set; } - - /// - /// Initializes with the current row. - /// - /// - public ListViewRowEventArgs (int row) - { - Row = row; - } - } } diff --git a/Terminal.Gui/Views/ListViewItemEventArgs.cs b/Terminal.Gui/Views/ListViewItemEventArgs.cs new file mode 100644 index 0000000000..a23efac011 --- /dev/null +++ b/Terminal.Gui/Views/ListViewItemEventArgs.cs @@ -0,0 +1,28 @@ +using System; + +namespace Terminal.Gui { + /// + /// for events. + /// + public class ListViewItemEventArgs : EventArgs { + /// + /// The index of the item. + /// + public int Item { get; } + /// + /// The item. + /// + public object Value { get; } + + /// + /// Initializes a new instance of + /// + /// The index of the item. + /// The item + public ListViewItemEventArgs (int item, object value) + { + Item = item; + Value = value; + } + } +} diff --git a/Terminal.Gui/Views/ListViewRowEventArgs.cs b/Terminal.Gui/Views/ListViewRowEventArgs.cs new file mode 100644 index 0000000000..64caddb7b7 --- /dev/null +++ b/Terminal.Gui/Views/ListViewRowEventArgs.cs @@ -0,0 +1,27 @@ +using System; + +namespace Terminal.Gui { + /// + /// used by the event. + /// + public class ListViewRowEventArgs : EventArgs { + /// + /// The current row being rendered. + /// + public int Row { get; } + /// + /// The used by current row or + /// null to maintain the current attribute. + /// + public Attribute? RowAttribute { get; set; } + + /// + /// Initializes with the current row. + /// + /// + public ListViewRowEventArgs (int row) + { + Row = row; + } + } +} diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs index a8e0cf34ea..230b869ac2 100644 --- a/Terminal.Gui/Views/Menu.cs +++ b/Terminal.Gui/Views/Menu.cs @@ -2004,72 +2004,4 @@ public override bool OnEnter (View view) return base.OnEnter (view); } } - - /// - /// An which allows passing a cancelable menu opening event or replacing with a new . - /// - public class MenuOpeningEventArgs : EventArgs { - /// - /// The current parent. - /// - public MenuBarItem CurrentMenu { get; } - - /// - /// The new to be replaced. - /// - public MenuBarItem NewMenuBarItem { get; set; } - /// - /// Flag that allows the cancellation of the event. If set to in the - /// event handler, the event will be canceled. - /// - public bool Cancel { get; set; } - - /// - /// Initializes a new instance of . - /// - /// The current parent. - public MenuOpeningEventArgs (MenuBarItem currentMenu) - { - CurrentMenu = currentMenu; - } - } - - /// - /// An which allows passing a cancelable menu closing event. - /// - public class MenuClosingEventArgs : EventArgs { - /// - /// The current parent. - /// - public MenuBarItem CurrentMenu { get; } - - /// - /// Indicates whether the current menu will reopen. - /// - public bool Reopen { get; } - - /// - /// Indicates whether the current menu is a sub-menu. - /// - public bool IsSubMenu { get; } - - /// - /// Flag that allows the cancellation of the event. If set to in the - /// event handler, the event will be canceled. - /// - public bool Cancel { get; set; } - - /// - /// Initializes a new instance of . - /// - /// The current parent. - /// Whether the current menu will reopen. - /// Indicates whether it is a sub-menu. - public MenuClosingEventArgs (MenuBarItem currentMenu, bool reopen, bool isSubMenu) - { - CurrentMenu = currentMenu; - Reopen = reopen; - IsSubMenu = isSubMenu; - } - } } diff --git a/Terminal.Gui/Views/MenuClosingEventArgs.cs b/Terminal.Gui/Views/MenuClosingEventArgs.cs new file mode 100644 index 0000000000..934ab1d410 --- /dev/null +++ b/Terminal.Gui/Views/MenuClosingEventArgs.cs @@ -0,0 +1,42 @@ +using System; + +namespace Terminal.Gui { + /// + /// An which allows passing a cancelable menu closing event. + /// + public class MenuClosingEventArgs : EventArgs { + /// + /// The current parent. + /// + public MenuBarItem CurrentMenu { get; } + + /// + /// Indicates whether the current menu will reopen. + /// + public bool Reopen { get; } + + /// + /// Indicates whether the current menu is a sub-menu. + /// + public bool IsSubMenu { get; } + + /// + /// Flag that allows the cancellation of the event. If set to in the + /// event handler, the event will be canceled. + /// + public bool Cancel { get; set; } + + /// + /// Initializes a new instance of . + /// + /// The current parent. + /// Whether the current menu will reopen. + /// Indicates whether it is a sub-menu. + public MenuClosingEventArgs (MenuBarItem currentMenu, bool reopen, bool isSubMenu) + { + CurrentMenu = currentMenu; + Reopen = reopen; + IsSubMenu = isSubMenu; + } + } +} diff --git a/Terminal.Gui/Views/MenuOpeningEventArgs.cs b/Terminal.Gui/Views/MenuOpeningEventArgs.cs new file mode 100644 index 0000000000..a57c8b07b3 --- /dev/null +++ b/Terminal.Gui/Views/MenuOpeningEventArgs.cs @@ -0,0 +1,32 @@ +using System; + +namespace Terminal.Gui { + /// + /// An which allows passing a cancelable menu opening event or replacing with a new . + /// + public class MenuOpeningEventArgs : EventArgs { + /// + /// The current parent. + /// + public MenuBarItem CurrentMenu { get; } + + /// + /// The new to be replaced. + /// + public MenuBarItem NewMenuBarItem { get; set; } + /// + /// Flag that allows the cancellation of the event. If set to in the + /// event handler, the event will be canceled. + /// + public bool Cancel { get; set; } + + /// + /// Initializes a new instance of . + /// + /// The current parent. + public MenuOpeningEventArgs (MenuBarItem currentMenu) + { + CurrentMenu = currentMenu; + } + } +} diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index 474baebc12..6a27d1bcab 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -422,30 +422,4 @@ public enum DisplayModeLayout { /// Horizontal } - - /// - /// Event arguments for the SelectedItemChagned event. - /// - public class SelectedItemChangedArgs : EventArgs { - /// - /// Gets the index of the item that was previously selected. -1 if there was no previous selection. - /// - public int PreviousSelectedItem { get; } - - /// - /// Gets the index of the item that is now selected. -1 if there is no selection. - /// - public int SelectedItem { get; } - - /// - /// Initializes a new class. - /// - /// - /// - public SelectedItemChangedArgs (int selectedItem, int previousSelectedItem) - { - PreviousSelectedItem = previousSelectedItem; - SelectedItem = selectedItem; - } - } } diff --git a/Terminal.Gui/Views/SelectedCellChangedEventArgs.cs b/Terminal.Gui/Views/SelectedCellChangedEventArgs.cs new file mode 100644 index 0000000000..13dd3bfb55 --- /dev/null +++ b/Terminal.Gui/Views/SelectedCellChangedEventArgs.cs @@ -0,0 +1,63 @@ +using System; +using System.Data; + +namespace Terminal.Gui { + + + /// + /// Defines the event arguments for + /// + public class SelectedCellChangedEventArgs : EventArgs { + /// + /// The current table to which the new indexes refer. May be null e.g. if selection change is the result of clearing the table from the view + /// + /// + public DataTable Table { get; } + + + /// + /// The previous selected column index. May be invalid e.g. when the selection has been changed as a result of replacing the existing Table with a smaller one + /// + /// + public int OldCol { get; } + + + /// + /// The newly selected column index. + /// + /// + public int NewCol { get; } + + + /// + /// The previous selected row index. May be invalid e.g. when the selection has been changed as a result of deleting rows from the table + /// + /// + public int OldRow { get; } + + + /// + /// The newly selected row index. + /// + /// + public int NewRow { get; } + + /// + /// Creates a new instance of arguments describing a change in selected cell in a + /// + /// + /// + /// + /// + /// + public SelectedCellChangedEventArgs (DataTable t, int oldCol, int newCol, int oldRow, int newRow) + { + Table = t; + OldCol = oldCol; + NewCol = newCol; + OldRow = oldRow; + NewRow = newRow; + } + } + +} diff --git a/Terminal.Gui/Views/SelectedItemChangedArgs.cs b/Terminal.Gui/Views/SelectedItemChangedArgs.cs new file mode 100644 index 0000000000..60e9728bcf --- /dev/null +++ b/Terminal.Gui/Views/SelectedItemChangedArgs.cs @@ -0,0 +1,29 @@ +using System; + +namespace Terminal.Gui { + /// + /// Event arguments for the SelectedItemChagned event. + /// + public class SelectedItemChangedArgs : EventArgs { + /// + /// Gets the index of the item that was previously selected. -1 if there was no previous selection. + /// + public int PreviousSelectedItem { get; } + + /// + /// Gets the index of the item that is now selected. -1 if there is no selection. + /// + public int SelectedItem { get; } + + /// + /// Initializes a new class. + /// + /// + /// + public SelectedItemChangedArgs (int selectedItem, int previousSelectedItem) + { + PreviousSelectedItem = previousSelectedItem; + SelectedItem = selectedItem; + } + } +} diff --git a/Terminal.Gui/Views/SplitterEventArgs.cs b/Terminal.Gui/Views/SplitterEventArgs.cs new file mode 100644 index 0000000000..cd2faebff3 --- /dev/null +++ b/Terminal.Gui/Views/SplitterEventArgs.cs @@ -0,0 +1,38 @@ +using System; + +namespace Terminal.Gui { + /// + /// Provides data for events. + /// + public class SplitterEventArgs : EventArgs { + + /// + /// Creates a new instance of the class. + /// + /// in which splitter is being moved. + /// Index of the splitter being moved in . + /// The new of the splitter line. + public SplitterEventArgs (TileView tileView, int idx, Pos splitterDistance) + { + SplitterDistance = splitterDistance; + TileView = tileView; + Idx = idx; + } + + /// + /// New position of the splitter line (see ). + /// + public Pos SplitterDistance { get; } + + /// + /// Container (sender) of the event. + /// + public TileView TileView { get; } + + /// + /// Gets the index of the splitter that is being moved. This can be + /// used to index + /// + public int Idx { get; } + } +} diff --git a/Terminal.Gui/Views/TabChangedEventArgs.cs b/Terminal.Gui/Views/TabChangedEventArgs.cs new file mode 100644 index 0000000000..5d890a1bc4 --- /dev/null +++ b/Terminal.Gui/Views/TabChangedEventArgs.cs @@ -0,0 +1,31 @@ +using System; + +namespace Terminal.Gui { + + /// + /// Describes a change in + /// + public class TabChangedEventArgs : EventArgs { + + /// + /// The previously selected tab. May be null + /// + public TabView.Tab OldTab { get; } + + /// + /// The currently selected tab. May be null + /// + public TabView.Tab NewTab { get; } + + /// + /// Documents a tab change + /// + /// + /// + public TabChangedEventArgs (TabView.Tab oldTab, TabView.Tab newTab) + { + OldTab = oldTab; + NewTab = newTab; + } + } +} diff --git a/Terminal.Gui/Views/TabMouseEventArgs.cs b/Terminal.Gui/Views/TabMouseEventArgs.cs new file mode 100644 index 0000000000..e6d06d2b01 --- /dev/null +++ b/Terminal.Gui/Views/TabMouseEventArgs.cs @@ -0,0 +1,36 @@ +using System; + +namespace Terminal.Gui { + + /// + /// Describes a mouse event over a specific in a . + /// + public class TabMouseEventArgs : EventArgs { + + /// + /// Gets the (if any) that the mouse + /// was over when the occurred. + /// + /// This will be null if the click is after last tab + /// or before first. + public TabView.Tab Tab { get; } + + /// + /// Gets the actual mouse event. Use to cancel this event + /// and perform custom behavior (e.g. show a context menu). + /// + public MouseEvent MouseEvent { get; } + + /// + /// Creates a new instance of the class. + /// + /// that the mouse was over when the event occurred. + /// The mouse activity being reported + public TabMouseEventArgs (TabView.Tab tab, MouseEvent mouseEvent) + { + Tab = tab; + MouseEvent = mouseEvent; + } + } + +} diff --git a/Terminal.Gui/Views/TabView.cs b/Terminal.Gui/Views/TabView.cs index 40ba26bd49..35affc9b52 100644 --- a/Terminal.Gui/Views/TabView.cs +++ b/Terminal.Gui/Views/TabView.cs @@ -9,7 +9,7 @@ namespace Terminal.Gui { /// /// Control that hosts multiple sub views, presenting a single one at once /// - public class TabView : View { + public partial class TabView : View { private Tab selectedTab; /// @@ -771,37 +771,6 @@ protected virtual private void OnTabClicked (TabMouseEventArgs tabMouseEventArgs TabClicked?.Invoke (this, tabMouseEventArgs); } - /// - /// Describes a mouse event over a specific in a . - /// - public class TabMouseEventArgs : EventArgs { - - /// - /// Gets the (if any) that the mouse - /// was over when the occurred. - /// - /// This will be null if the click is after last tab - /// or before first. - public Tab Tab { get; } - - /// - /// Gets the actual mouse event. Use to cancel this event - /// and perform custom behavior (e.g. show a context menu). - /// - public MouseEvent MouseEvent { get; } - - /// - /// Creates a new instance of the class. - /// - /// that the mouse was over when the event occurred. - /// The mouse activity being reported - public TabMouseEventArgs (Tab tab, MouseEvent mouseEvent) - { - Tab = tab; - MouseEvent = mouseEvent; - } - } - /// /// A single tab in a /// @@ -867,33 +836,6 @@ public class TabStyle { public bool TabsOnBottom { get; set; } = false; } - - /// - /// Describes a change in - /// - public class TabChangedEventArgs : EventArgs { - - /// - /// The previously selected tab. May be null - /// - public Tab OldTab { get; } - - /// - /// The currently selected tab. May be null - /// - public Tab NewTab { get; } - - /// - /// Documents a tab change - /// - /// - /// - public TabChangedEventArgs (Tab oldTab, Tab newTab) - { - OldTab = oldTab; - NewTab = newTab; - } - } #endregion } } diff --git a/Terminal.Gui/Views/TableView.cs b/Terminal.Gui/Views/TableView.cs index 6ea1925310..06bce35712 100644 --- a/Terminal.Gui/Views/TableView.cs +++ b/Terminal.Gui/Views/TableView.cs @@ -13,44 +13,7 @@ namespace Terminal.Gui { /// /// See TableView Deep Dive for more information. /// - public class TableView : View { - - /// - /// Defines the event arguments for event - /// - public class CellActivatedEventArgs : EventArgs { - /// - /// The current table to which the new indexes refer. May be null e.g. if selection change is the result of clearing the table from the view - /// - /// - public DataTable Table { get; } - - - /// - /// The column index of the cell that is being activated - /// - /// - public int Col { get; } - - /// - /// The row index of the cell that is being activated - /// - /// - public int Row { get; } - - /// - /// Creates a new instance of arguments describing a cell being activated in - /// - /// - /// - /// - public CellActivatedEventArgs (DataTable t, int col, int row) - { - Table = t; - Col = col; - Row = row; - } - } + public partial class TableView : View { private int columnOffset; private int rowOffset; @@ -2001,62 +1964,6 @@ internal RowColorGetterArgs (DataTable table, int rowIdx) } } - /// - /// Defines the event arguments for - /// - public class SelectedCellChangedEventArgs : EventArgs { - /// - /// The current table to which the new indexes refer. May be null e.g. if selection change is the result of clearing the table from the view - /// - /// - public DataTable Table { get; } - - - /// - /// The previous selected column index. May be invalid e.g. when the selection has been changed as a result of replacing the existing Table with a smaller one - /// - /// - public int OldCol { get; } - - - /// - /// The newly selected column index. - /// - /// - public int NewCol { get; } - - - /// - /// The previous selected row index. May be invalid e.g. when the selection has been changed as a result of deleting rows from the table - /// - /// - public int OldRow { get; } - - - /// - /// The newly selected row index. - /// - /// - public int NewRow { get; } - - /// - /// Creates a new instance of arguments describing a change in selected cell in a - /// - /// - /// - /// - /// - /// - public SelectedCellChangedEventArgs (DataTable t, int oldCol, int newCol, int oldRow, int newRow) - { - Table = t; - OldCol = oldCol; - NewCol = newCol; - OldRow = oldRow; - NewRow = newRow; - } - } - /// /// Describes a selected region of the table /// diff --git a/Terminal.Gui/Views/TextChangedEventArgs.cs b/Terminal.Gui/Views/TextChangedEventArgs.cs new file mode 100644 index 0000000000..942a2b267f --- /dev/null +++ b/Terminal.Gui/Views/TextChangedEventArgs.cs @@ -0,0 +1,31 @@ +// +// TextField.cs: single-line text editor with Emacs keybindings +// +// Authors: +// Miguel de Icaza (miguel@gnome.org) +// + +using System; +using NStack; + +namespace Terminal.Gui { + /// + /// Event args for the event + /// + public class TextChangedEventArgs : EventArgs { + + /// + /// Creates a new instance of the class + /// + /// + public TextChangedEventArgs (ustring oldValue) + { + OldValue = oldValue; + } + + /// + /// The old value before the text changed + /// + public ustring OldValue { get; } + } +} diff --git a/Terminal.Gui/Views/TextChangingEventArgs.cs b/Terminal.Gui/Views/TextChangingEventArgs.cs new file mode 100644 index 0000000000..db0b5c8a5d --- /dev/null +++ b/Terminal.Gui/Views/TextChangingEventArgs.cs @@ -0,0 +1,34 @@ +// +// TextField.cs: single-line text editor with Emacs keybindings +// +// Authors: +// Miguel de Icaza (miguel@gnome.org) +// + +using System; +using NStack; + +namespace Terminal.Gui { + /// + /// An which allows passing a cancelable new text value event. + /// + public class TextChangingEventArgs : EventArgs { + /// + /// The new text to be replaced. + /// + public ustring NewText { get; set; } + /// + /// Flag which allows to cancel the new text value. + /// + public bool Cancel { get; set; } + + /// + /// Initializes a new instance of + /// + /// The new to be replaced. + public TextChangingEventArgs (ustring newText) + { + NewText = newText; + } + } +} diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index f907ad5294..062c2e7c09 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -1308,48 +1308,6 @@ public void ClearHistoryChanges () historyText.Clear (Text); } } - - /// - /// An which allows passing a cancelable new text value event. - /// - public class TextChangingEventArgs : EventArgs { - /// - /// The new text to be replaced. - /// - public ustring NewText { get; set; } - /// - /// Flag which allows to cancel the new text value. - /// - public bool Cancel { get; set; } - - /// - /// Initializes a new instance of - /// - /// The new to be replaced. - public TextChangingEventArgs (ustring newText) - { - NewText = newText; - } - } - /// - /// Event args for the event - /// - public class TextChangedEventArgs : EventArgs { - - /// - /// Creates a new instance of the class - /// - /// - public TextChangedEventArgs (ustring oldValue) - { - OldValue = oldValue; - } - - /// - /// The old value before the text changed - /// - public ustring OldValue { get; } - } /// /// Renders an overlay on another view at a given point that allows selecting /// from a range of 'autocomplete' options. diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 424727affd..4883500087 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -515,7 +515,7 @@ internal void ResetContinuousFind (Point point) } } - class HistoryText { + partial class HistoryText { public enum LineStatus { Original, Replaced, @@ -523,34 +523,6 @@ public enum LineStatus { Added } - public class HistoryTextItem : EventArgs{ - public List> Lines; - public Point CursorPosition; - public LineStatus LineStatus; - public bool IsUndoing; - public Point FinalCursorPosition; - public HistoryTextItem RemovedOnAdded; - - public HistoryTextItem (List> lines, Point curPos, LineStatus linesStatus) - { - Lines = lines; - CursorPosition = curPos; - LineStatus = linesStatus; - } - - public HistoryTextItem (HistoryTextItem historyTextItem) - { - Lines = new List> (historyTextItem.Lines); - CursorPosition = new Point (historyTextItem.CursorPosition.X, historyTextItem.CursorPosition.Y); - LineStatus = historyTextItem.LineStatus; - } - - public override string ToString () - { - return $"(Count: {Lines.Count}, Cursor: {CursorPosition}, Status: {LineStatus})"; - } - } - List historyTextItems = new List (); int idxHistoryText = -1; ustring originalText; @@ -1129,7 +1101,7 @@ public int GetWrappedLineColWidth (int line, int col, WordWrapManager wrapManage /// /// /// - public class TextView : View { + public partial class TextView : View { TextModel model = new TextModel (); int topRow; int leftColumn; @@ -2709,33 +2681,6 @@ void Adjust () OnUnwrappedCursorPosition (); } - /// - /// Event arguments for events for when the contents of the TextView change. E.g. the event. - /// - public class ContentsChangedEventArgs : EventArgs { - /// - /// Creates a new instance. - /// - /// Contains the row where the change occurred. - /// Contains the column where the change occured. - public ContentsChangedEventArgs (int currentRow, int currentColumn) - { - Row = currentRow; - Col = currentColumn; - } - - /// - /// - /// Contains the row where the change occurred. - /// - public int Row { get; private set; } - - /// - /// Contains the column where the change occurred. - /// - public int Col { get; private set; } - } - /// /// Called when the contents of the TextView change. E.g. when the user types text or deletes text. Raises /// the event. diff --git a/Terminal.Gui/Views/TileView.cs b/Terminal.Gui/Views/TileView.cs index 5c0a09c6cd..b0b8f5e275 100644 --- a/Terminal.Gui/Views/TileView.cs +++ b/Terminal.Gui/Views/TileView.cs @@ -10,7 +10,7 @@ namespace Terminal.Gui { /// A consisting of a moveable bar that divides /// the display area into resizeable . /// - public class TileView : View { + public partial class TileView : View { TileView parentTileView; /// @@ -24,7 +24,7 @@ public class TileView : View { /// new instances use /// or . /// - public class Tile { + public partial class Tile { /// /// The that is contained in this . /// Add new child views to this member for multiple @@ -61,37 +61,6 @@ public string Title { private string _title = string.Empty; - /// - /// An which allows passing a cancelable new value event. - /// - public class TitleEventArgs : EventArgs { - /// - /// The new Window Title. - /// - public ustring NewTitle { get; set; } - - /// - /// The old Window Title. - /// - public ustring OldTitle { get; set; } - - /// - /// Flag which allows cancelling the Title change. - /// - public bool Cancel { get; set; } - - /// - /// Initializes a new instance of - /// - /// The that is/has been replaced. - /// The new to be replaced. - public TitleEventArgs (ustring oldTitle, ustring newTitle) - { - OldTitle = oldTitle; - NewTitle = newTitle; - } - } - /// /// Called before the changes. Invokes the event, which can be cancelled. /// @@ -1107,41 +1076,6 @@ protected override void Dispose (bool disposing) } - /// - /// Provides data for events. - /// - public class SplitterEventArgs : EventArgs { - - /// - /// Creates a new instance of the class. - /// - /// in which splitter is being moved. - /// Index of the splitter being moved in . - /// The new of the splitter line. - public SplitterEventArgs (TileView tileView, int idx, Pos splitterDistance) - { - SplitterDistance = splitterDistance; - TileView = tileView; - Idx = idx; - } - - /// - /// New position of the splitter line (see ). - /// - public Pos SplitterDistance { get; } - - /// - /// Container (sender) of the event. - /// - public TileView TileView { get; } - - /// - /// Gets the index of the splitter that is being moved. This can be - /// used to index - /// - public int Idx { get; } - } - /// /// Represents a method that will handle splitter events. /// diff --git a/Terminal.Gui/Views/TitleEventArgs.cs b/Terminal.Gui/Views/TitleEventArgs.cs new file mode 100644 index 0000000000..90af8a8af9 --- /dev/null +++ b/Terminal.Gui/Views/TitleEventArgs.cs @@ -0,0 +1,42 @@ +using NStack; +using System; + +namespace Terminal.Gui { + + public partial class TileView { + + public partial class Tile { + /// + /// An which allows passing a cancelable new value event. + /// + public class TitleEventArgs : EventArgs { + /// + /// The new Window Title. + /// + public ustring NewTitle { get; set; } + + /// + /// The old Window Title. + /// + public ustring OldTitle { get; set; } + + /// + /// Flag which allows cancelling the Title change. + /// + public bool Cancel { get; set; } + + /// + /// Initializes a new instance of + /// + /// The that is/has been replaced. + /// The new to be replaced. + public TitleEventArgs (ustring oldTitle, ustring newTitle) + { + OldTitle = oldTitle; + NewTitle = newTitle; + } + } + } + + } +} diff --git a/Terminal.Gui/Windows/StepChangeEventArgs.cs b/Terminal.Gui/Windows/StepChangeEventArgs.cs new file mode 100644 index 0000000000..9bbc0e2407 --- /dev/null +++ b/Terminal.Gui/Windows/StepChangeEventArgs.cs @@ -0,0 +1,38 @@ +using System; + +namespace Terminal.Gui { + + public partial class Wizard { + /// + /// for events. + /// + public class StepChangeEventArgs : EventArgs { + /// + /// The current (or previous) . + /// + public WizardStep OldStep { get; } + + /// + /// The the is changing to or has changed to. + /// + public WizardStep NewStep { get; } + + /// + /// Event handlers can set to true before returning to cancel the step transition. + /// + public bool Cancel { get; set; } + + /// + /// Initializes a new instance of + /// + /// The current . + /// The new . + public StepChangeEventArgs (WizardStep oldStep, WizardStep newStep) + { + OldStep = oldStep; + NewStep = newStep; + Cancel = false; + } + } + } +} \ No newline at end of file diff --git a/Terminal.Gui/Windows/Wizard.cs b/Terminal.Gui/Windows/Wizard.cs index ea774ca963..3d277d8d92 100644 --- a/Terminal.Gui/Windows/Wizard.cs +++ b/Terminal.Gui/Windows/Wizard.cs @@ -54,7 +54,7 @@ namespace Terminal.Gui { /// Application.Shutdown (); /// /// - public class Wizard : Dialog { + public partial class Wizard : Dialog { /// /// Represents a basic step that is displayed in a . The view is divided horizontally in two. On the left is the /// content view where s can be added, On the right is the help for the step. @@ -615,24 +615,6 @@ public void AddStep (WizardStep newStep) } private ustring wizardTitle = ustring.Empty; - /// - /// for transition events. - /// - public class WizardButtonEventArgs : EventArgs { - /// - /// Set to true to cancel the transition to the next step. - /// - public bool Cancel { get; set; } - - /// - /// Initializes a new instance of - /// - public WizardButtonEventArgs () - { - Cancel = false; - } - } - /// /// Raised when the Back button in the is clicked. The Back button is always /// the first button in the array of Buttons passed to the constructor, if any. @@ -663,38 +645,6 @@ public WizardButtonEventArgs () /// public event EventHandler Cancelled; - /// - /// for events. - /// - public class StepChangeEventArgs : EventArgs { - /// - /// The current (or previous) . - /// - public WizardStep OldStep { get; } - - /// - /// The the is changing to or has changed to. - /// - public WizardStep NewStep { get; } - - /// - /// Event handlers can set to true before returning to cancel the step transition. - /// - public bool Cancel { get; set; } - - /// - /// Initializes a new instance of - /// - /// The current . - /// The new . - public StepChangeEventArgs (WizardStep oldStep, WizardStep newStep) - { - OldStep = oldStep; - NewStep = newStep; - Cancel = false; - } - } - /// /// This event is raised when the current ) is about to change. Use /// to abort the transition. diff --git a/Terminal.Gui/Windows/WizardButtonEventArgs.cs b/Terminal.Gui/Windows/WizardButtonEventArgs.cs new file mode 100644 index 0000000000..277aa672f7 --- /dev/null +++ b/Terminal.Gui/Windows/WizardButtonEventArgs.cs @@ -0,0 +1,24 @@ +using System; + +namespace Terminal.Gui { + + public partial class Wizard { + /// + /// for transition events. + /// + public class WizardButtonEventArgs : EventArgs { + /// + /// Set to true to cancel the transition to the next step. + /// + public bool Cancel { get; set; } + + /// + /// Initializes a new instance of + /// + public WizardButtonEventArgs () + { + Cancel = false; + } + } + } +} \ No newline at end of file diff --git a/UICatalog/Scenarios/CsvEditor.cs b/UICatalog/Scenarios/CsvEditor.cs index 14ee9fadeb..7a17beb03e 100644 --- a/UICatalog/Scenarios/CsvEditor.cs +++ b/UICatalog/Scenarios/CsvEditor.cs @@ -114,7 +114,7 @@ private void SelectedCellLabel_TextChanged (object sender, TextChangedEventArgs } } - private void OnSelectedCellChanged (object sender, TableView.SelectedCellChangedEventArgs e) + private void OnSelectedCellChanged (object sender, SelectedCellChangedEventArgs e) { // only update the text box if the user is not manually editing it if (!selectedCellLabel.HasFocus) @@ -472,7 +472,7 @@ private void SetupScrollBar () } - private void TableViewKeyPress (object sender, View.KeyEventEventArgs e) + private void TableViewKeyPress (object sender, KeyEventEventArgs e) { if (e.KeyEvent.Key == Key.DeleteChar) { @@ -540,7 +540,7 @@ private bool GetText (string title, string label, string initialText, out string enteredText = okPressed ? tf.Text.ToString () : null; return okPressed; } - private void EditCurrentCell (object sender, TableView.CellActivatedEventArgs e) + private void EditCurrentCell (object sender, CellActivatedEventArgs e) { if (e.Table == null) return; diff --git a/UICatalog/Scenarios/HexEditor.cs b/UICatalog/Scenarios/HexEditor.cs index cce25fd92d..62f39cdefb 100644 --- a/UICatalog/Scenarios/HexEditor.cs +++ b/UICatalog/Scenarios/HexEditor.cs @@ -64,7 +64,7 @@ public override void Setup () Application.Top.Add (statusBar); } - private void _hexView_PositionChanged (object sender, HexView.HexViewEventArgs obj) + private void _hexView_PositionChanged (object sender, HexViewEventArgs obj) { siPositionChanged.Title = $"Position: {obj.Position} Line: {obj.CursorPosition.Y} Col: {obj.CursorPosition.X} Line length: {obj.BytesPerLine}"; statusBar.SetNeedsDisplay (); @@ -75,7 +75,7 @@ private void ToggleAllowEdits () _hexView.AllowEdits = (bool)(miAllowEdits.Checked = !miAllowEdits.Checked); } - private void _hexView_Edited (object sender, HexView.HexViewEditEventArgs e) + private void _hexView_Edited (object sender, HexViewEditEventArgs e) { _saved = false; } diff --git a/UICatalog/Scenarios/InteractiveTree.cs b/UICatalog/Scenarios/InteractiveTree.cs index 6cfd71fd1c..e209f9d005 100644 --- a/UICatalog/Scenarios/InteractiveTree.cs +++ b/UICatalog/Scenarios/InteractiveTree.cs @@ -49,7 +49,7 @@ public override void Setup () } - private void TreeView_KeyPress (object sender, View.KeyEventEventArgs obj) + private void TreeView_KeyPress (object sender, KeyEventEventArgs obj) { if (obj.KeyEvent.Key == Key.DeleteChar) { diff --git a/UICatalog/Scenarios/MultiColouredTable.cs b/UICatalog/Scenarios/MultiColouredTable.cs index 75b67a0f62..88788ae698 100644 --- a/UICatalog/Scenarios/MultiColouredTable.cs +++ b/UICatalog/Scenarios/MultiColouredTable.cs @@ -98,7 +98,7 @@ private bool GetText (string title, string label, string initialText, out string enteredText = okPressed ? tf.Text.ToString () : null; return okPressed; } - private void EditCurrentCell (object sender, TableView.CellActivatedEventArgs e) + private void EditCurrentCell (object sender, CellActivatedEventArgs e) { if (e.Table == null) return; diff --git a/UICatalog/Scenarios/Notepad.cs b/UICatalog/Scenarios/Notepad.cs index 5fc6edbed0..a55643f453 100644 --- a/UICatalog/Scenarios/Notepad.cs +++ b/UICatalog/Scenarios/Notepad.cs @@ -74,12 +74,12 @@ public override void Setup () New (); } - private void TabView_SelectedTabChanged (object sender, TabView.TabChangedEventArgs e) + private void TabView_SelectedTabChanged (object sender, TabChangedEventArgs e) { lenStatusItem.Title = $"Len:{e.NewTab?.View?.Text?.Length ?? 0}"; } - private void TabView_TabClicked (object sender, TabView.TabMouseEventArgs e) + private void TabView_TabClicked (object sender, TabMouseEventArgs e) { // we are only interested in right clicks if(!e.MouseEvent.Flags.HasFlag(MouseFlags.Button3Clicked)) { diff --git a/UICatalog/Scenarios/TableEditor.cs b/UICatalog/Scenarios/TableEditor.cs index 6a0c9cd179..d7af084cba 100644 --- a/UICatalog/Scenarios/TableEditor.cs +++ b/UICatalog/Scenarios/TableEditor.cs @@ -345,7 +345,7 @@ private void SetupScrollBar () } - private void TableViewKeyPress (object sender, View.KeyEventEventArgs e) + private void TableViewKeyPress (object sender, KeyEventEventArgs e) { if (e.KeyEvent.Key == Key.DeleteChar) { @@ -748,7 +748,7 @@ private void OpenSimple (bool big) tableView.Table = BuildSimpleDataTable (big ? 30 : 5, big ? 1000 : 5); } - private void EditCurrentCell (object sender, TableView.CellActivatedEventArgs e) + private void EditCurrentCell (object sender, CellActivatedEventArgs e) { if (e.Table == null) return; diff --git a/UICatalog/Scenarios/TreeViewFileSystem.cs b/UICatalog/Scenarios/TreeViewFileSystem.cs index b895e48410..d72c7b8835 100644 --- a/UICatalog/Scenarios/TreeViewFileSystem.cs +++ b/UICatalog/Scenarios/TreeViewFileSystem.cs @@ -106,7 +106,7 @@ private void TreeViewFiles_SelectionChanged (object sender, SelectionChangedEven ShowPropertiesOf (e.NewValue); } - private void TreeViewFiles_KeyPress (object sender, View.KeyEventEventArgs obj) + private void TreeViewFiles_KeyPress (object sender, KeyEventEventArgs obj) { if (obj.KeyEvent.Key == (Key.R | Key.CtrlMask)) { diff --git a/UICatalog/Scenarios/VkeyPacketSimulator.cs b/UICatalog/Scenarios/VkeyPacketSimulator.cs index c760509104..5baeacfd31 100644 --- a/UICatalog/Scenarios/VkeyPacketSimulator.cs +++ b/UICatalog/Scenarios/VkeyPacketSimulator.cs @@ -122,7 +122,7 @@ public override void Setup () } }; - View.KeyEventEventArgs unknownChar = null; + KeyEventEventArgs unknownChar = null; tvInput.KeyPress += (s, e) => { if (e.KeyEvent.Key == (Key.Q | Key.CtrlMask)) { @@ -229,7 +229,7 @@ public override void Setup () }; } - private void AddKeyboardStrokes (View.KeyEventEventArgs e) + private void AddKeyboardStrokes (KeyEventEventArgs e) { var ke = e.KeyEvent; var km = new KeyModifiers (); diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index e8e243af50..8c74ca7f96 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -651,7 +651,7 @@ public void ConfigChanged () Application.Top.SetNeedsDisplay (); } - void KeyDownHandler (object sender, View.KeyEventEventArgs a) + void KeyDownHandler (object sender, KeyEventEventArgs a) { if (a.KeyEvent.IsCapslock) { Capslock.Title = "Caps: On"; diff --git a/UnitTests/Application/ApplicationTests.cs b/UnitTests/Application/ApplicationTests.cs index ad73e43ea6..7aec50b33c 100644 --- a/UnitTests/Application/ApplicationTests.cs +++ b/UnitTests/Application/ApplicationTests.cs @@ -582,7 +582,7 @@ public void KeyUp_Event () int keyUps = 0; var output = string.Empty; - Application.Top.KeyUp += (object sender, View.KeyEventEventArgs args) => { + Application.Top.KeyUp += (object sender, KeyEventEventArgs args) => { if (args.KeyEvent.Key != (Key.CtrlMask | Key.Q)) { output += (char)args.KeyEvent.KeyValue; } diff --git a/UnitTests/Configuration/ConfigurationMangerTests.cs b/UnitTests/Configuration/ConfigurationMangerTests.cs index a37833a0c2..73ae84b146 100644 --- a/UnitTests/Configuration/ConfigurationMangerTests.cs +++ b/UnitTests/Configuration/ConfigurationMangerTests.cs @@ -775,7 +775,7 @@ public void Load_FiresUpdated () ConfigurationManager.Updated += ConfigurationManager_Updated; bool fired = false; - void ConfigurationManager_Updated (object sender, ConfigurationManager.ConfigurationManagerEventArgs obj) + void ConfigurationManager_Updated (object sender, ConfigurationManagerEventArgs obj) { fired = true; // assert @@ -801,7 +801,7 @@ public void Apply_FiresApplied () ConfigurationManager.Reset (); ConfigurationManager.Applied += ConfigurationManager_Applied; bool fired = false; - void ConfigurationManager_Applied (object sender, ConfigurationManager.ConfigurationManagerEventArgs obj) + void ConfigurationManager_Applied (object sender, ConfigurationManagerEventArgs obj) { fired = true; // assert diff --git a/UnitTests/Core/ViewTests.cs b/UnitTests/Core/ViewTests.cs index 343768c212..c68a9e86e7 100644 --- a/UnitTests/Core/ViewTests.cs +++ b/UnitTests/Core/ViewTests.cs @@ -1539,7 +1539,7 @@ public void ProcessHotKey_Will_Invoke_ProcessKey_Only_For_The_MostFocused_With_T var tf = new TextField (); tf.KeyPress += Tf_KeyPress; - void Tf_KeyPress (object sender, View.KeyEventEventArgs obj) + void Tf_KeyPress (object sender, KeyEventEventArgs obj) { if (obj.KeyEvent.Key == (Key.Q | Key.CtrlMask)) { obj.Handled = tfQuiting = true; @@ -1551,7 +1551,7 @@ void Tf_KeyPress (object sender, View.KeyEventEventArgs obj) var top = Application.Top; top.KeyPress += Top_KeyPress; - void Top_KeyPress (object sender, View.KeyEventEventArgs obj) + void Top_KeyPress (object sender, KeyEventEventArgs obj) { if (obj.KeyEvent.Key == (Key.Q | Key.CtrlMask)) { obj.Handled = topQuiting = true; @@ -1599,7 +1599,7 @@ public void ProcessHotKey_Will_Invoke_ProcessKey_Only_For_The_MostFocused_Withou var tf = new TextField (); tf.KeyPress += Tf_KeyPress; - void Tf_KeyPress (object sender, View.KeyEventEventArgs obj) + void Tf_KeyPress (object sender, KeyEventEventArgs obj) { if (obj.KeyEvent.Key == (Key.Q | Key.CtrlMask)) { obj.Handled = tfQuiting = true; diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index b530d1d696..dc484eca6c 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -121,7 +121,7 @@ public void Run_Generic () }; var token = Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (ms), abortCallback); - Application.Top.KeyPress += (object sender, View.KeyEventEventArgs args) => { + Application.Top.KeyPress += (object sender, KeyEventEventArgs args) => { Assert.Equal (Key.CtrlMask | Key.Q, args.KeyEvent.Key); }; diff --git a/UnitTests/Views/HexViewTests.cs b/UnitTests/Views/HexViewTests.cs index 41f45f8456..fdfca94de6 100644 --- a/UnitTests/Views/HexViewTests.cs +++ b/UnitTests/Views/HexViewTests.cs @@ -254,7 +254,7 @@ public void CursorPosition_Encoding_Default () public void PositionChanged_Event () { var hv = new HexView (LoadStream ()) { Width = Dim.Fill (), Height = Dim.Fill () }; - HexView.HexViewEventArgs hexViewEventArgs = null; + HexViewEventArgs hexViewEventArgs = null; hv.PositionChanged += (s, e) => hexViewEventArgs = e; Application.Top.Add (hv); Application.Begin (Application.Top); From 7aae407efe76f833fd9c08d060e0513007a4d4fb Mon Sep 17 00:00:00 2001 From: tznind Date: Wed, 15 Mar 2023 19:41:03 +0000 Subject: [PATCH 29/46] Get rid of the EventArgs folder --- Terminal.Gui/Core/Application.cs | 58 +++++-------------- .../{EventArgs => }/GrabMouseEventArgs.cs | 2 +- .../{EventArgs => }/KeyChangedEventArgs.cs | 0 .../{EventArgs => }/MenuOpenedEventArgs.cs | 0 .../MouseFlagsChangedEventArgs.cs | 0 .../Core/{EventArgs => }/PointEventArgs.cs | 0 .../Core/{EventArgs => }/RunStateEventArgs.cs | 0 .../{EventArgs => }/SizeChangedEventArgs.cs | 0 .../SuperViewChangedEventArgs.cs | 0 .../Core/{EventArgs => }/TimeoutEventArgs.cs | 5 +- .../Core/{EventArgs => }/ToggleEventArgs.cs | 0 Terminal.Gui/Core/Toplevel.cs | 23 +------- .../Core/{EventArgs => }/ToplevelEventArgs.cs | 2 +- .../Core/{EventArgs => }/ViewEventArgs.cs | 0 .../EventArgs => Views}/DrawEventArgs.cs | 0 15 files changed, 20 insertions(+), 70 deletions(-) rename Terminal.Gui/Core/{EventArgs => }/GrabMouseEventArgs.cs (93%) rename Terminal.Gui/Core/{EventArgs => }/KeyChangedEventArgs.cs (100%) rename Terminal.Gui/Core/{EventArgs => }/MenuOpenedEventArgs.cs (100%) rename Terminal.Gui/Core/{EventArgs => }/MouseFlagsChangedEventArgs.cs (100%) rename Terminal.Gui/Core/{EventArgs => }/PointEventArgs.cs (100%) rename Terminal.Gui/Core/{EventArgs => }/RunStateEventArgs.cs (100%) rename Terminal.Gui/Core/{EventArgs => }/SizeChangedEventArgs.cs (100%) rename Terminal.Gui/Core/{EventArgs => }/SuperViewChangedEventArgs.cs (100%) rename Terminal.Gui/Core/{EventArgs => }/TimeoutEventArgs.cs (91%) rename Terminal.Gui/Core/{EventArgs => }/ToggleEventArgs.cs (100%) rename Terminal.Gui/Core/{EventArgs => }/ToplevelEventArgs.cs (94%) rename Terminal.Gui/Core/{EventArgs => }/ViewEventArgs.cs (100%) rename Terminal.Gui/{Core/EventArgs => Views}/DrawEventArgs.cs (100%) diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index 990c02e713..561d6a8c40 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -162,7 +162,7 @@ public static Key AlternateForwardKey { if (alternateForwardKey != value) { var oldKey = alternateForwardKey; alternateForwardKey = value; - OnAlternateForwardKeyChanged (new KeyChangedEventArgs (oldKey, value)); + OnAlternateForwardKeyChanged (new KeyChangedEventArgs(oldKey,value)); } } } @@ -186,7 +186,7 @@ public static Key AlternateBackwardKey { if (alternateBackwardKey != value) { var oldKey = alternateBackwardKey; alternateBackwardKey = value; - OnAlternateBackwardKeyChanged (new KeyChangedEventArgs (oldKey, value)); + OnAlternateBackwardKeyChanged (new KeyChangedEventArgs(oldKey,value)); } } } @@ -210,7 +210,7 @@ public static Key QuitKey { if (quitKey != value) { var oldKey = quitKey; quitKey = value; - OnQuitKeyChanged (new KeyChangedEventArgs (oldKey, value)); + OnQuitKeyChanged (new KeyChangedEventArgs(oldKey,value)); } } } @@ -720,16 +720,6 @@ static View FindTopFromView (View view) /// public static View MouseGrabView => mouseGrabView; - /// - /// Event to be invoked when a view want grab the mouse which can be canceled. - /// - public static event EventHandler GrabbingMouse; - - /// - /// Event to be invoked when a view want ungrab the mouse which can be canceled. - /// - public static event EventHandler UnGrabbingMouse; - /// /// Event to be invoked when a view grab the mouse. /// @@ -749,11 +739,9 @@ public static void GrabMouse (View view) { if (view == null) return; - if (!OnGrabbingMouse (view)) { - OnGrabbedMouse (view); - mouseGrabView = view; - Driver.UncookMouse (); - } + OnGrabbedMouse (view); + mouseGrabView = view; + Driver.UncookMouse (); } /// @@ -763,36 +751,16 @@ public static void UngrabMouse () { if (mouseGrabView == null) return; - if (!OnUnGrabbingMouse (mouseGrabView)) { - OnUnGrabbedMouse (mouseGrabView); - mouseGrabView = null; - Driver.CookMouse (); - } - } - - static bool OnGrabbingMouse (View view) - { - if (view == null) - return false; - var evArgs = new GrabMouseEventArgs (view); - GrabbingMouse?.Invoke (view, evArgs); - return evArgs.Cancel; - } - - static bool OnUnGrabbingMouse (View view) - { - if (view == null) - return false; - var evArgs = new GrabMouseEventArgs (view); - UnGrabbingMouse?.Invoke (view, evArgs); - return evArgs.Cancel; + OnUnGrabbedMouse (mouseGrabView); + mouseGrabView = null; + Driver.CookMouse (); } static void OnGrabbedMouse (View view) { if (view == null) return; - GrabbedMouse?.Invoke (view, new ViewEventArgs (view)); + GrabbedMouse?.Invoke (view, new ViewEventArgs(view)); } static void OnUnGrabbedMouse (View view) @@ -1061,7 +1029,7 @@ public static RunState Begin (Toplevel toplevel) Driver.Refresh (); } - NotifyNewRunState?.Invoke (toplevel, new RunStateEventArgs (rs)); + NotifyNewRunState?.Invoke (toplevel, new RunStateEventArgs(rs)); return rs; } @@ -1529,7 +1497,7 @@ public static void RequestStop (Toplevel top = null) static void OnNotifyStopRunState (Toplevel top) { if (ExitRunLoopAfterFirstIteration) { - NotifyStopRunState?.Invoke (top, new ToplevelEventArgs (top)); + NotifyStopRunState?.Invoke (top, new ToplevelEventArgs(top)); } } @@ -1548,7 +1516,7 @@ static void TerminalResized () t.SetRelativeLayout (full); t.LayoutSubviews (); t.PositionToplevels (); - t.OnResized (new SizeChangedEventArgs (full.Size)); + t.OnResized (new SizeChangedEventArgs(full.Size)); } Refresh (); } diff --git a/Terminal.Gui/Core/EventArgs/GrabMouseEventArgs.cs b/Terminal.Gui/Core/GrabMouseEventArgs.cs similarity index 93% rename from Terminal.Gui/Core/EventArgs/GrabMouseEventArgs.cs rename to Terminal.Gui/Core/GrabMouseEventArgs.cs index 952dc5ac6b..b356675742 100644 --- a/Terminal.Gui/Core/EventArgs/GrabMouseEventArgs.cs +++ b/Terminal.Gui/Core/GrabMouseEventArgs.cs @@ -4,7 +4,7 @@ namespace Terminal.Gui { /// /// Args for events that relate to specific /// - public class GrabMouseEventArgs : EventArgs{ + public class GrabMouseEventArgs : EventArgs { /// /// Creates a new instance of the class. diff --git a/Terminal.Gui/Core/EventArgs/KeyChangedEventArgs.cs b/Terminal.Gui/Core/KeyChangedEventArgs.cs similarity index 100% rename from Terminal.Gui/Core/EventArgs/KeyChangedEventArgs.cs rename to Terminal.Gui/Core/KeyChangedEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/MenuOpenedEventArgs.cs b/Terminal.Gui/Core/MenuOpenedEventArgs.cs similarity index 100% rename from Terminal.Gui/Core/EventArgs/MenuOpenedEventArgs.cs rename to Terminal.Gui/Core/MenuOpenedEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/MouseFlagsChangedEventArgs.cs b/Terminal.Gui/Core/MouseFlagsChangedEventArgs.cs similarity index 100% rename from Terminal.Gui/Core/EventArgs/MouseFlagsChangedEventArgs.cs rename to Terminal.Gui/Core/MouseFlagsChangedEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/PointEventArgs.cs b/Terminal.Gui/Core/PointEventArgs.cs similarity index 100% rename from Terminal.Gui/Core/EventArgs/PointEventArgs.cs rename to Terminal.Gui/Core/PointEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/RunStateEventArgs.cs b/Terminal.Gui/Core/RunStateEventArgs.cs similarity index 100% rename from Terminal.Gui/Core/EventArgs/RunStateEventArgs.cs rename to Terminal.Gui/Core/RunStateEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/SizeChangedEventArgs.cs b/Terminal.Gui/Core/SizeChangedEventArgs.cs similarity index 100% rename from Terminal.Gui/Core/EventArgs/SizeChangedEventArgs.cs rename to Terminal.Gui/Core/SizeChangedEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/SuperViewChangedEventArgs.cs b/Terminal.Gui/Core/SuperViewChangedEventArgs.cs similarity index 100% rename from Terminal.Gui/Core/EventArgs/SuperViewChangedEventArgs.cs rename to Terminal.Gui/Core/SuperViewChangedEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/TimeoutEventArgs.cs b/Terminal.Gui/Core/TimeoutEventArgs.cs similarity index 91% rename from Terminal.Gui/Core/EventArgs/TimeoutEventArgs.cs rename to Terminal.Gui/Core/TimeoutEventArgs.cs index 6a8e04c3f8..002342152a 100644 --- a/Terminal.Gui/Core/EventArgs/TimeoutEventArgs.cs +++ b/Terminal.Gui/Core/TimeoutEventArgs.cs @@ -1,5 +1,4 @@ using System; -using Terminal.Gui; using static Terminal.Gui.MainLoop; namespace Terminal.Gui { @@ -26,8 +25,8 @@ public class TimeoutEventArgs : EventArgs { /// public TimeoutEventArgs (Timeout timeout, long ticks) { - this.Timeout = timeout; - this.Ticks = ticks; + Timeout = timeout; + Ticks = ticks; } } } diff --git a/Terminal.Gui/Core/EventArgs/ToggleEventArgs.cs b/Terminal.Gui/Core/ToggleEventArgs.cs similarity index 100% rename from Terminal.Gui/Core/EventArgs/ToggleEventArgs.cs rename to Terminal.Gui/Core/ToggleEventArgs.cs diff --git a/Terminal.Gui/Core/Toplevel.cs b/Terminal.Gui/Core/Toplevel.cs index 7995337baa..02727aa397 100644 --- a/Terminal.Gui/Core/Toplevel.cs +++ b/Terminal.Gui/Core/Toplevel.cs @@ -120,7 +120,7 @@ internal virtual void OnResized (SizeChangedEventArgs size) internal virtual void OnChildUnloaded (Toplevel top) { - ChildUnloaded?.Invoke (this, new ToplevelEventArgs (top)); + ChildUnloaded?.Invoke (this, new ToplevelEventArgs(top)); } internal virtual void OnChildLoaded (Toplevel top) @@ -159,7 +159,7 @@ internal virtual void OnDeactivate (Toplevel activated) internal virtual void OnActivate (Toplevel deactivated) { - Activate?.Invoke (this, new ToplevelEventArgs (deactivated)); + Activate?.Invoke (this, new ToplevelEventArgs(deactivated)); } /// @@ -221,9 +221,6 @@ void Initialize () { ColorScheme = Colors.TopLevel; - Application.GrabbingMouse += Application_GrabbingMouse; - Application.UnGrabbingMouse += Application_UnGrabbingMouse; - // Things this view knows how to do AddCommand (Command.QuitToplevel, () => { QuitToplevel (); return true; }); AddCommand (Command.Suspend, () => { Driver.Suspend (); ; return true; }); @@ -259,20 +256,6 @@ void Initialize () AddKeyBinding (Key.L | Key.CtrlMask, Command.Refresh); } - private void Application_UnGrabbingMouse (object sender, GrabMouseEventArgs e) - { - if (Application.MouseGrabView == this && dragPosition.HasValue) { - e.Cancel = true; - } - } - - private void Application_GrabbingMouse (object sender, GrabMouseEventArgs e) - { - if (Application.MouseGrabView == this && dragPosition.HasValue) { - e.Cancel = true; - } - } - /// /// Invoked when the is changed. /// @@ -841,8 +824,8 @@ public override bool MouseEvent (MouseEvent mouseEvent) } if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Released) && dragPosition.HasValue) { - dragPosition = null; Application.UngrabMouse (); + dragPosition = null; } //System.Diagnostics.Debug.WriteLine ($"dragPosition after: {dragPosition.HasValue}"); diff --git a/Terminal.Gui/Core/EventArgs/ToplevelEventArgs.cs b/Terminal.Gui/Core/ToplevelEventArgs.cs similarity index 94% rename from Terminal.Gui/Core/EventArgs/ToplevelEventArgs.cs rename to Terminal.Gui/Core/ToplevelEventArgs.cs index 76be6603cf..f473839194 100644 --- a/Terminal.Gui/Core/EventArgs/ToplevelEventArgs.cs +++ b/Terminal.Gui/Core/ToplevelEventArgs.cs @@ -4,7 +4,7 @@ namespace Terminal.Gui { /// /// Args for events that relate to a specific . /// - public class ToplevelEventArgs : EventArgs{ + public class ToplevelEventArgs : EventArgs { /// /// Creates a new instance of the class. diff --git a/Terminal.Gui/Core/EventArgs/ViewEventArgs.cs b/Terminal.Gui/Core/ViewEventArgs.cs similarity index 100% rename from Terminal.Gui/Core/EventArgs/ViewEventArgs.cs rename to Terminal.Gui/Core/ViewEventArgs.cs diff --git a/Terminal.Gui/Core/EventArgs/DrawEventArgs.cs b/Terminal.Gui/Views/DrawEventArgs.cs similarity index 100% rename from Terminal.Gui/Core/EventArgs/DrawEventArgs.cs rename to Terminal.Gui/Views/DrawEventArgs.cs From 2d9c4dc65bbee3ab86e4c68f85c345084ec823af Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 17 Mar 2023 11:32:38 +0000 Subject: [PATCH 30/46] Fix ScenarioTests unit test. --- UnitTests/UICatalog/ScenarioTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index ae1d196d3a..6d597e17b0 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -70,7 +70,7 @@ public void Run_All_Scenarios () FakeConsole.PushMockKeyPress (Application.QuitKey); // The only key we care about is the QuitKey - Application.Top.KeyPress += (View.KeyEventEventArgs args) => { + Application.Top.KeyPress += (object sender, KeyEventEventArgs args) => { output.WriteLine ($" Keypress: {args.KeyEvent.Key}"); Assert.Equal (Application.QuitKey, args.KeyEvent.Key); args.Handled = false; From 69a1c6ebdece7bbc2c3dbec007c605ef0972df51 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 17 Mar 2023 11:47:39 +0000 Subject: [PATCH 31/46] Recovering GrabbingMouse and UnGrabbingMouse implementation. --- Terminal.Gui/Core/Application.cs | 58 +++++++++++++++++++++++++------- Terminal.Gui/Core/Toplevel.cs | 23 +++++++++++-- 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index 9229934a01..aeefe0aa67 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -162,7 +162,7 @@ public static Key AlternateForwardKey { if (alternateForwardKey != value) { var oldKey = alternateForwardKey; alternateForwardKey = value; - OnAlternateForwardKeyChanged (new KeyChangedEventArgs(oldKey,value)); + OnAlternateForwardKeyChanged (new KeyChangedEventArgs (oldKey, value)); } } } @@ -186,7 +186,7 @@ public static Key AlternateBackwardKey { if (alternateBackwardKey != value) { var oldKey = alternateBackwardKey; alternateBackwardKey = value; - OnAlternateBackwardKeyChanged (new KeyChangedEventArgs(oldKey,value)); + OnAlternateBackwardKeyChanged (new KeyChangedEventArgs (oldKey, value)); } } } @@ -210,7 +210,7 @@ public static Key QuitKey { if (quitKey != value) { var oldKey = quitKey; quitKey = value; - OnQuitKeyChanged (new KeyChangedEventArgs(oldKey,value)); + OnQuitKeyChanged (new KeyChangedEventArgs (oldKey, value)); } } } @@ -720,6 +720,16 @@ static View FindTopFromView (View view) /// public static View MouseGrabView => mouseGrabView; + /// + /// Event to be invoked when a view want grab the mouse which can be canceled. + /// + public static event EventHandler GrabbingMouse; + + /// + /// Event to be invoked when a view want ungrab the mouse which can be canceled. + /// + public static event EventHandler UnGrabbingMouse; + /// /// Event to be invoked when a view grab the mouse. /// @@ -739,9 +749,11 @@ public static void GrabMouse (View view) { if (view == null) return; - OnGrabbedMouse (view); - mouseGrabView = view; - Driver.UncookMouse (); + if (!OnGrabbingMouse (view)) { + OnGrabbedMouse (view); + mouseGrabView = view; + Driver.UncookMouse (); + } } /// @@ -751,16 +763,36 @@ public static void UngrabMouse () { if (mouseGrabView == null) return; - OnUnGrabbedMouse (mouseGrabView); - mouseGrabView = null; - Driver.CookMouse (); + if (!OnUnGrabbingMouse (mouseGrabView)) { + OnUnGrabbedMouse (mouseGrabView); + mouseGrabView = null; + Driver.CookMouse (); + } + } + + static bool OnGrabbingMouse (View view) + { + if (view == null) + return false; + var evArgs = new GrabMouseEventArgs (view); + GrabbingMouse?.Invoke (view, evArgs); + return evArgs.Cancel; + } + + static bool OnUnGrabbingMouse (View view) + { + if (view == null) + return false; + var evArgs = new GrabMouseEventArgs (view); + UnGrabbingMouse?.Invoke (view, evArgs); + return evArgs.Cancel; } static void OnGrabbedMouse (View view) { if (view == null) return; - GrabbedMouse?.Invoke (view, new ViewEventArgs(view)); + GrabbedMouse?.Invoke (view, new ViewEventArgs (view)); } static void OnUnGrabbedMouse (View view) @@ -1029,7 +1061,7 @@ public static RunState Begin (Toplevel toplevel) Driver.Refresh (); } - NotifyNewRunState?.Invoke (toplevel, new RunStateEventArgs(rs)); + NotifyNewRunState?.Invoke (toplevel, new RunStateEventArgs (rs)); return rs; } @@ -1497,7 +1529,7 @@ public static void RequestStop (Toplevel top = null) static void OnNotifyStopRunState (Toplevel top) { if (ExitRunLoopAfterFirstIteration) { - NotifyStopRunState?.Invoke (top, new ToplevelEventArgs(top)); + NotifyStopRunState?.Invoke (top, new ToplevelEventArgs (top)); } } @@ -1516,7 +1548,7 @@ static void TerminalResized () t.SetRelativeLayout (full); t.LayoutSubviews (); t.PositionToplevels (); - t.OnResized (new SizeChangedEventArgs(full.Size)); + t.OnResized (new SizeChangedEventArgs (full.Size)); } Refresh (); } diff --git a/Terminal.Gui/Core/Toplevel.cs b/Terminal.Gui/Core/Toplevel.cs index 02727aa397..7995337baa 100644 --- a/Terminal.Gui/Core/Toplevel.cs +++ b/Terminal.Gui/Core/Toplevel.cs @@ -120,7 +120,7 @@ internal virtual void OnResized (SizeChangedEventArgs size) internal virtual void OnChildUnloaded (Toplevel top) { - ChildUnloaded?.Invoke (this, new ToplevelEventArgs(top)); + ChildUnloaded?.Invoke (this, new ToplevelEventArgs (top)); } internal virtual void OnChildLoaded (Toplevel top) @@ -159,7 +159,7 @@ internal virtual void OnDeactivate (Toplevel activated) internal virtual void OnActivate (Toplevel deactivated) { - Activate?.Invoke (this, new ToplevelEventArgs(deactivated)); + Activate?.Invoke (this, new ToplevelEventArgs (deactivated)); } /// @@ -221,6 +221,9 @@ void Initialize () { ColorScheme = Colors.TopLevel; + Application.GrabbingMouse += Application_GrabbingMouse; + Application.UnGrabbingMouse += Application_UnGrabbingMouse; + // Things this view knows how to do AddCommand (Command.QuitToplevel, () => { QuitToplevel (); return true; }); AddCommand (Command.Suspend, () => { Driver.Suspend (); ; return true; }); @@ -256,6 +259,20 @@ void Initialize () AddKeyBinding (Key.L | Key.CtrlMask, Command.Refresh); } + private void Application_UnGrabbingMouse (object sender, GrabMouseEventArgs e) + { + if (Application.MouseGrabView == this && dragPosition.HasValue) { + e.Cancel = true; + } + } + + private void Application_GrabbingMouse (object sender, GrabMouseEventArgs e) + { + if (Application.MouseGrabView == this && dragPosition.HasValue) { + e.Cancel = true; + } + } + /// /// Invoked when the is changed. /// @@ -824,8 +841,8 @@ public override bool MouseEvent (MouseEvent mouseEvent) } if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Released) && dragPosition.HasValue) { - Application.UngrabMouse (); dragPosition = null; + Application.UngrabMouse (); } //System.Diagnostics.Debug.WriteLine ($"dragPosition after: {dragPosition.HasValue}"); From 3960ff4e7a26434ae84eeb54eeb1fd8757fc0ce1 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 17 Mar 2023 16:46:08 +0000 Subject: [PATCH 32/46] Grouping views events in the ViewEventArgs.cs file. --- Terminal.Gui/Core/FocusEventArgs.cs | 25 ------------ Terminal.Gui/Core/View.cs | 60 ++++++----------------------- Terminal.Gui/Core/ViewEventArgs.cs | 59 +++++++++++++++++++++++++--- Terminal.Gui/Views/DrawEventArgs.cs | 28 -------------- 4 files changed, 64 insertions(+), 108 deletions(-) delete mode 100644 Terminal.Gui/Core/FocusEventArgs.cs delete mode 100644 Terminal.Gui/Views/DrawEventArgs.cs diff --git a/Terminal.Gui/Core/FocusEventArgs.cs b/Terminal.Gui/Core/FocusEventArgs.cs deleted file mode 100644 index e019d5a0a6..0000000000 --- a/Terminal.Gui/Core/FocusEventArgs.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; - -namespace Terminal.Gui { - - /// - /// Defines the event arguments for - /// - public class FocusEventArgs : EventArgs { - /// - /// Constructs. - /// - /// The view that gets or loses focus. - public FocusEventArgs (View view) { View = view; } - /// - /// Indicates if the current focus event has already been processed and the driver should stop notifying any other event subscriber. - /// Its important to set this value to true specially when updating any View's layout from inside the subscriber method. - /// - public bool Handled { get; set; } - /// - /// Indicates the current view that gets or loses focus. - /// - public View View { get; set; } - } - -} diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index 1c1372b47e..7dc074a9bf 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -139,17 +139,17 @@ internal enum Direction { /// /// Event fired when the view receives the mouse event for the first time. /// - public event EventHandler MouseEnter; + public event EventHandler MouseEnter; /// /// Event fired when the view receives a mouse event for the last time. /// - public event EventHandler MouseLeave; + public event EventHandler MouseLeave; /// /// Event fired when a mouse event is generated. /// - public event EventHandler MouseClick; + public event EventHandler MouseClick; /// /// Event fired when the value is being changed. @@ -827,7 +827,7 @@ protected virtual void ProcessResizeView () void TextFormatter_HotKeyChanged (object sender, KeyChangedEventArgs e) { - HotKeyChanged?.Invoke (this,e); + HotKeyChanged?.Invoke (this, e); } /// @@ -942,7 +942,7 @@ public virtual void Add (View view) } SetNeedsLayout (); SetNeedsDisplay (); - OnAdded (new SuperViewChangedEventArgs (this,view)); + OnAdded (new SuperViewChangedEventArgs (this, view)); if (IsInitialized) { view.BeginInit (); view.EndInit (); @@ -1344,7 +1344,7 @@ public virtual void OnAdded (SuperViewChangedEventArgs e) view.width ??= view.frame.Width; view.height ??= view.frame.Height; - view.Added?.Invoke (this,e); + view.Added?.Invoke (this, e); } /// @@ -1593,7 +1593,7 @@ Rect GetContainerBounds () /// public virtual void OnDrawContent (Rect viewport) { - DrawContent?.Invoke (this, new DrawEventArgs(viewport)); + DrawContent?.Invoke (this, new DrawEventArgs (viewport)); } /// @@ -2239,16 +2239,6 @@ int CalculateNewDimension (Dim d, int location, int dimension, int autosize) } } - /// - /// Event arguments for the event. - /// - public class LayoutEventArgs : EventArgs { - /// - /// The view-relative bounds of the before it was laid out. - /// - public Rect OldBounds { get; set; } - } - /// /// Fired after the View's method has completed. /// @@ -2795,34 +2785,6 @@ public Size GetBoundsTextFormatterSize () frame.Size.Height + GetHotKeySpecifierLength (false)); } - /// - /// Specifies the event arguments for . This is a higher-level construct - /// than the wrapped class and is used for the events defined on - /// and subclasses of View (e.g. and ). - /// - public class MouseEventArgs : EventArgs { - /// - /// Constructs. - /// - /// - public MouseEventArgs (MouseEvent me) => MouseEvent = me; - /// - /// The for the event. - /// - public MouseEvent MouseEvent { get; set; } - - /// - /// Indicates if the current mouse event has already been processed and the driver should stop notifying any other event subscriber. - /// Its important to set this value to true specially when updating any View's layout from inside the subscriber method. - /// - /// This property forwards to the property and is provided as a convenience and for - /// backwards compatibility - public bool Handled { - get => MouseEvent.Handled; - set => MouseEvent.Handled = value; - } - } - /// public override bool OnMouseEnter (MouseEvent mouseEvent) { @@ -2834,7 +2796,7 @@ public override bool OnMouseEnter (MouseEvent mouseEvent) return false; } - var args = new MouseEventArgs (mouseEvent); + var args = new MouseEventEventArgs (mouseEvent); MouseEnter?.Invoke (this, args); return args.Handled || base.OnMouseEnter (mouseEvent); @@ -2851,7 +2813,7 @@ public override bool OnMouseLeave (MouseEvent mouseEvent) return false; } - var args = new MouseEventArgs (mouseEvent); + var args = new MouseEventEventArgs (mouseEvent); MouseLeave?.Invoke (this, args); return args.Handled || base.OnMouseLeave (mouseEvent); @@ -2872,7 +2834,7 @@ public virtual bool OnMouseEvent (MouseEvent mouseEvent) return false; } - var args = new MouseEventArgs (mouseEvent); + var args = new MouseEventEventArgs (mouseEvent); if (OnMouseClick (args)) return true; if (MouseEvent (mouseEvent)) @@ -2892,7 +2854,7 @@ public virtual bool OnMouseEvent (MouseEvent mouseEvent) /// /// Invokes the MouseClick event. /// - protected bool OnMouseClick (MouseEventArgs args) + protected bool OnMouseClick (MouseEventEventArgs args) { if (!Enabled) { return true; diff --git a/Terminal.Gui/Core/ViewEventArgs.cs b/Terminal.Gui/Core/ViewEventArgs.cs index 53b1a985b6..277ddbc673 100644 --- a/Terminal.Gui/Core/ViewEventArgs.cs +++ b/Terminal.Gui/Core/ViewEventArgs.cs @@ -1,17 +1,13 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Terminal.Gui { /// /// Args for events that relate to specific /// - public class ViewEventArgs :EventArgs{ + public class ViewEventArgs : EventArgs { /// - /// Creates a new instance of the class. + /// Creates a new instance of the class. /// /// public ViewEventArgs (View view) @@ -30,4 +26,55 @@ public ViewEventArgs (View view) /// public View View { get; } } + + /// + /// Event arguments for the event. + /// + public class LayoutEventArgs : EventArgs { + /// + /// The view-relative bounds of the before it was laid out. + /// + public Rect OldBounds { get; set; } + } + + /// + /// Event args for draw events + /// + public class DrawEventArgs : EventArgs { + + /// + /// Creates a new instance of the class. + /// + /// Gets the view-relative rectangle describing the currently visible viewport into the . + public DrawEventArgs (Rect rect) + { + Rect = rect; + } + + /// + /// Gets the view-relative rectangle describing the currently visible viewport into the . + /// + public Rect Rect { get; } + } + + /// + /// Defines the event arguments for + /// + public class FocusEventArgs : EventArgs { + /// + /// Constructs. + /// + /// The view that gets or loses focus. + public FocusEventArgs (View view) { View = view; } + /// + /// Indicates if the current focus event has already been processed and the driver should stop notifying any other event subscriber. + /// Its important to set this value to true specially when updating any View's layout from inside the subscriber method. + /// + public bool Handled { get; set; } + /// + /// Indicates the current view that gets or loses focus. + /// + public View View { get; set; } + } + } diff --git a/Terminal.Gui/Views/DrawEventArgs.cs b/Terminal.Gui/Views/DrawEventArgs.cs deleted file mode 100644 index 65aee24388..0000000000 --- a/Terminal.Gui/Views/DrawEventArgs.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Terminal.Gui { - - /// - /// Event args for draw events - /// - public class DrawEventArgs : EventArgs{ - - /// - /// Creates a new instance of the class. - /// - /// Gets the view-relative rectangle describing the currently visible viewport into the . - public DrawEventArgs (Rect rect) - { - Rect = rect; - } - - /// - /// Gets the view-relative rectangle describing the currently visible viewport into the . - /// - public Rect Rect { get; } - } -} From 1154eebc758c34c11c05c521f433bcf2b4b0dc99 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 17 Mar 2023 16:55:14 +0000 Subject: [PATCH 33/46] Grouping Toplevel events in ToplevelEventArgs. --- Terminal.Gui/Core/ToplevelClosingEventArgs.cs | 26 ------------------- Terminal.Gui/Core/ToplevelEventArgs.cs | 23 ++++++++++++++++ 2 files changed, 23 insertions(+), 26 deletions(-) delete mode 100644 Terminal.Gui/Core/ToplevelClosingEventArgs.cs diff --git a/Terminal.Gui/Core/ToplevelClosingEventArgs.cs b/Terminal.Gui/Core/ToplevelClosingEventArgs.cs deleted file mode 100644 index b4b1b0de87..0000000000 --- a/Terminal.Gui/Core/ToplevelClosingEventArgs.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; - -namespace Terminal.Gui { - /// - /// implementation for the event. - /// - public class ToplevelClosingEventArgs : EventArgs { - /// - /// The toplevel requesting stop. - /// - public View RequestingTop { get; } - /// - /// Provides an event cancellation option. - /// - public bool Cancel { get; set; } - - /// - /// Initializes the event arguments with the requesting toplevel. - /// - /// The . - public ToplevelClosingEventArgs (Toplevel requestingTop) - { - RequestingTop = requestingTop; - } - } -} diff --git a/Terminal.Gui/Core/ToplevelEventArgs.cs b/Terminal.Gui/Core/ToplevelEventArgs.cs index f473839194..5d7fa0168a 100644 --- a/Terminal.Gui/Core/ToplevelEventArgs.cs +++ b/Terminal.Gui/Core/ToplevelEventArgs.cs @@ -25,4 +25,27 @@ public ToplevelEventArgs (Toplevel toplevel) /// public Toplevel Toplevel { get; } } + + /// + /// implementation for the event. + /// + public class ToplevelClosingEventArgs : EventArgs { + /// + /// The toplevel requesting stop. + /// + public View RequestingTop { get; } + /// + /// Provides an event cancellation option. + /// + public bool Cancel { get; set; } + + /// + /// Initializes the event arguments with the requesting toplevel. + /// + /// The . + public ToplevelClosingEventArgs (Toplevel requestingTop) + { + RequestingTop = requestingTop; + } + } } From ebb898aa3eb1680bd102bc35675a8b93f3ab1803 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 17 Mar 2023 16:57:58 +0000 Subject: [PATCH 34/46] Grouping Menu events in MenuEventArgs.cs file. --- Terminal.Gui/Core/MenuOpenedEventArgs.cs | 36 -------- Terminal.Gui/Views/MenuClosingEventArgs.cs | 42 ---------- Terminal.Gui/Views/MenuEventArgs.cs | 98 ++++++++++++++++++++++ Terminal.Gui/Views/MenuOpeningEventArgs.cs | 32 ------- 4 files changed, 98 insertions(+), 110 deletions(-) delete mode 100644 Terminal.Gui/Core/MenuOpenedEventArgs.cs delete mode 100644 Terminal.Gui/Views/MenuClosingEventArgs.cs create mode 100644 Terminal.Gui/Views/MenuEventArgs.cs delete mode 100644 Terminal.Gui/Views/MenuOpeningEventArgs.cs diff --git a/Terminal.Gui/Core/MenuOpenedEventArgs.cs b/Terminal.Gui/Core/MenuOpenedEventArgs.cs deleted file mode 100644 index dec4324495..0000000000 --- a/Terminal.Gui/Core/MenuOpenedEventArgs.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Terminal.Gui { - - /// - /// Defines arguments for the event - /// - public class MenuOpenedEventArgs : EventArgs{ - - /// - /// Creates a new instance of the class - /// - /// - /// - public MenuOpenedEventArgs (MenuBarItem parent, MenuItem menuItem) - { - Parent = parent; - MenuItem = menuItem; - } - - /// - /// The parent of . Will be null if menu opening - /// is the root (see ). - /// - public MenuBarItem Parent { get; } - - /// - /// Gets the being opened. - /// - public MenuItem MenuItem { get; } - } -} diff --git a/Terminal.Gui/Views/MenuClosingEventArgs.cs b/Terminal.Gui/Views/MenuClosingEventArgs.cs deleted file mode 100644 index 934ab1d410..0000000000 --- a/Terminal.Gui/Views/MenuClosingEventArgs.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; - -namespace Terminal.Gui { - /// - /// An which allows passing a cancelable menu closing event. - /// - public class MenuClosingEventArgs : EventArgs { - /// - /// The current parent. - /// - public MenuBarItem CurrentMenu { get; } - - /// - /// Indicates whether the current menu will reopen. - /// - public bool Reopen { get; } - - /// - /// Indicates whether the current menu is a sub-menu. - /// - public bool IsSubMenu { get; } - - /// - /// Flag that allows the cancellation of the event. If set to in the - /// event handler, the event will be canceled. - /// - public bool Cancel { get; set; } - - /// - /// Initializes a new instance of . - /// - /// The current parent. - /// Whether the current menu will reopen. - /// Indicates whether it is a sub-menu. - public MenuClosingEventArgs (MenuBarItem currentMenu, bool reopen, bool isSubMenu) - { - CurrentMenu = currentMenu; - Reopen = reopen; - IsSubMenu = isSubMenu; - } - } -} diff --git a/Terminal.Gui/Views/MenuEventArgs.cs b/Terminal.Gui/Views/MenuEventArgs.cs new file mode 100644 index 0000000000..6f3e4c3d30 --- /dev/null +++ b/Terminal.Gui/Views/MenuEventArgs.cs @@ -0,0 +1,98 @@ +using System; + +namespace Terminal.Gui { + /// + /// An which allows passing a cancelable menu opening event or replacing with a new . + /// + public class MenuOpeningEventArgs : EventArgs { + /// + /// The current parent. + /// + public MenuBarItem CurrentMenu { get; } + + /// + /// The new to be replaced. + /// + public MenuBarItem NewMenuBarItem { get; set; } + /// + /// Flag that allows the cancellation of the event. If set to in the + /// event handler, the event will be canceled. + /// + public bool Cancel { get; set; } + + /// + /// Initializes a new instance of . + /// + /// The current parent. + public MenuOpeningEventArgs (MenuBarItem currentMenu) + { + CurrentMenu = currentMenu; + } + } + + /// + /// Defines arguments for the event + /// + public class MenuOpenedEventArgs : EventArgs { + /// + /// Creates a new instance of the class + /// + /// + /// + public MenuOpenedEventArgs (MenuBarItem parent, MenuItem menuItem) + { + Parent = parent; + MenuItem = menuItem; + } + + /// + /// The parent of . Will be null if menu opening + /// is the root (see ). + /// + public MenuBarItem Parent { get; } + + /// + /// Gets the being opened. + /// + public MenuItem MenuItem { get; } + } + + /// + /// An which allows passing a cancelable menu closing event. + /// + public class MenuClosingEventArgs : EventArgs { + /// + /// The current parent. + /// + public MenuBarItem CurrentMenu { get; } + + /// + /// Indicates whether the current menu will reopen. + /// + public bool Reopen { get; } + + /// + /// Indicates whether the current menu is a sub-menu. + /// + public bool IsSubMenu { get; } + + /// + /// Flag that allows the cancellation of the event. If set to in the + /// event handler, the event will be canceled. + /// + public bool Cancel { get; set; } + + /// + /// Initializes a new instance of . + /// + /// The current parent. + /// Whether the current menu will reopen. + /// Indicates whether it is a sub-menu. + public MenuClosingEventArgs (MenuBarItem currentMenu, bool reopen, bool isSubMenu) + { + CurrentMenu = currentMenu; + Reopen = reopen; + IsSubMenu = isSubMenu; + } + } +} diff --git a/Terminal.Gui/Views/MenuOpeningEventArgs.cs b/Terminal.Gui/Views/MenuOpeningEventArgs.cs deleted file mode 100644 index a57c8b07b3..0000000000 --- a/Terminal.Gui/Views/MenuOpeningEventArgs.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; - -namespace Terminal.Gui { - /// - /// An which allows passing a cancelable menu opening event or replacing with a new . - /// - public class MenuOpeningEventArgs : EventArgs { - /// - /// The current parent. - /// - public MenuBarItem CurrentMenu { get; } - - /// - /// The new to be replaced. - /// - public MenuBarItem NewMenuBarItem { get; set; } - /// - /// Flag that allows the cancellation of the event. If set to in the - /// event handler, the event will be canceled. - /// - public bool Cancel { get; set; } - - /// - /// Initializes a new instance of . - /// - /// The current parent. - public MenuOpeningEventArgs (MenuBarItem currentMenu) - { - CurrentMenu = currentMenu; - } - } -} From 9733ba6de3f1c34bfb6fc4ee939e51ecbab37b69 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 17 Mar 2023 16:59:04 +0000 Subject: [PATCH 35/46] Grouping HexView events in HexViewEventArgs.cs file. --- Terminal.Gui/Views/HexViewEditEventArgs.cs | 37 ---------------------- Terminal.Gui/Views/HexViewEventArgs.cs | 27 ++++++++++++++++ 2 files changed, 27 insertions(+), 37 deletions(-) delete mode 100644 Terminal.Gui/Views/HexViewEditEventArgs.cs diff --git a/Terminal.Gui/Views/HexViewEditEventArgs.cs b/Terminal.Gui/Views/HexViewEditEventArgs.cs deleted file mode 100644 index 76185b6c4b..0000000000 --- a/Terminal.Gui/Views/HexViewEditEventArgs.cs +++ /dev/null @@ -1,37 +0,0 @@ -// -// HexView.cs: A hexadecimal viewer -// -// TODO: -// - Support searching and highlighting of the search result -// - Bug showing the last line -// -using System; - -namespace Terminal.Gui { - /// - /// Defines the event arguments for event. - /// - public class HexViewEditEventArgs : EventArgs { - - /// - /// Creates a new instance of the class. - /// - /// - /// - public HexViewEditEventArgs (long position, byte newValue) - { - Position = position; - NewValue = newValue; - } - - /// - /// Gets the location of the edit. - /// - public long Position { get; } - - /// - /// Gets the new value for that . - /// - public byte NewValue { get; } - } -} diff --git a/Terminal.Gui/Views/HexViewEventArgs.cs b/Terminal.Gui/Views/HexViewEventArgs.cs index 7847f68d0f..3af524b061 100644 --- a/Terminal.Gui/Views/HexViewEventArgs.cs +++ b/Terminal.Gui/Views/HexViewEventArgs.cs @@ -40,4 +40,31 @@ public HexViewEventArgs (long pos, Point cursor, int lineLength) BytesPerLine = lineLength; } } + + /// + /// Defines the event arguments for event. + /// + public class HexViewEditEventArgs : EventArgs { + + /// + /// Creates a new instance of the class. + /// + /// + /// + public HexViewEditEventArgs (long position, byte newValue) + { + Position = position; + NewValue = newValue; + } + + /// + /// Gets the location of the edit. + /// + public long Position { get; } + + /// + /// Gets the new value for that . + /// + public byte NewValue { get; } + } } From 7e98e694a30837c091831bc9c7183cde0f749cdc Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 17 Mar 2023 17:01:19 +0000 Subject: [PATCH 36/46] Grouping ListView events in ListViewEventArgs.cs file. --- ...wItemEventArgs.cs => ListViewEventArgs.cs} | 24 +++++++++++++++++ Terminal.Gui/Views/ListViewRowEventArgs.cs | 27 ------------------- 2 files changed, 24 insertions(+), 27 deletions(-) rename Terminal.Gui/Views/{ListViewItemEventArgs.cs => ListViewEventArgs.cs} (55%) delete mode 100644 Terminal.Gui/Views/ListViewRowEventArgs.cs diff --git a/Terminal.Gui/Views/ListViewItemEventArgs.cs b/Terminal.Gui/Views/ListViewEventArgs.cs similarity index 55% rename from Terminal.Gui/Views/ListViewItemEventArgs.cs rename to Terminal.Gui/Views/ListViewEventArgs.cs index a23efac011..8d1dc40606 100644 --- a/Terminal.Gui/Views/ListViewItemEventArgs.cs +++ b/Terminal.Gui/Views/ListViewEventArgs.cs @@ -25,4 +25,28 @@ public ListViewItemEventArgs (int item, object value) Value = value; } } + + /// + /// used by the event. + /// + public class ListViewRowEventArgs : EventArgs { + /// + /// The current row being rendered. + /// + public int Row { get; } + /// + /// The used by current row or + /// null to maintain the current attribute. + /// + public Attribute? RowAttribute { get; set; } + + /// + /// Initializes with the current row. + /// + /// + public ListViewRowEventArgs (int row) + { + Row = row; + } + } } diff --git a/Terminal.Gui/Views/ListViewRowEventArgs.cs b/Terminal.Gui/Views/ListViewRowEventArgs.cs deleted file mode 100644 index 64caddb7b7..0000000000 --- a/Terminal.Gui/Views/ListViewRowEventArgs.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; - -namespace Terminal.Gui { - /// - /// used by the event. - /// - public class ListViewRowEventArgs : EventArgs { - /// - /// The current row being rendered. - /// - public int Row { get; } - /// - /// The used by current row or - /// null to maintain the current attribute. - /// - public Attribute? RowAttribute { get; set; } - - /// - /// Initializes with the current row. - /// - /// - public ListViewRowEventArgs (int row) - { - Row = row; - } - } -} From 5bdce08d49aedb692c8b536ccf38972657b02861 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 17 Mar 2023 17:02:54 +0000 Subject: [PATCH 37/46] Grouping Wizard events in WizardEventArgs.cs file. --- Terminal.Gui/Windows/StepChangeEventArgs.cs | 38 ------------- Terminal.Gui/Windows/WizardButtonEventArgs.cs | 24 --------- Terminal.Gui/Windows/WizardEventArgs.cs | 54 +++++++++++++++++++ 3 files changed, 54 insertions(+), 62 deletions(-) delete mode 100644 Terminal.Gui/Windows/StepChangeEventArgs.cs delete mode 100644 Terminal.Gui/Windows/WizardButtonEventArgs.cs create mode 100644 Terminal.Gui/Windows/WizardEventArgs.cs diff --git a/Terminal.Gui/Windows/StepChangeEventArgs.cs b/Terminal.Gui/Windows/StepChangeEventArgs.cs deleted file mode 100644 index 9bbc0e2407..0000000000 --- a/Terminal.Gui/Windows/StepChangeEventArgs.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; - -namespace Terminal.Gui { - - public partial class Wizard { - /// - /// for events. - /// - public class StepChangeEventArgs : EventArgs { - /// - /// The current (or previous) . - /// - public WizardStep OldStep { get; } - - /// - /// The the is changing to or has changed to. - /// - public WizardStep NewStep { get; } - - /// - /// Event handlers can set to true before returning to cancel the step transition. - /// - public bool Cancel { get; set; } - - /// - /// Initializes a new instance of - /// - /// The current . - /// The new . - public StepChangeEventArgs (WizardStep oldStep, WizardStep newStep) - { - OldStep = oldStep; - NewStep = newStep; - Cancel = false; - } - } - } -} \ No newline at end of file diff --git a/Terminal.Gui/Windows/WizardButtonEventArgs.cs b/Terminal.Gui/Windows/WizardButtonEventArgs.cs deleted file mode 100644 index 277aa672f7..0000000000 --- a/Terminal.Gui/Windows/WizardButtonEventArgs.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; - -namespace Terminal.Gui { - - public partial class Wizard { - /// - /// for transition events. - /// - public class WizardButtonEventArgs : EventArgs { - /// - /// Set to true to cancel the transition to the next step. - /// - public bool Cancel { get; set; } - - /// - /// Initializes a new instance of - /// - public WizardButtonEventArgs () - { - Cancel = false; - } - } - } -} \ No newline at end of file diff --git a/Terminal.Gui/Windows/WizardEventArgs.cs b/Terminal.Gui/Windows/WizardEventArgs.cs new file mode 100644 index 0000000000..a1afa75bc5 --- /dev/null +++ b/Terminal.Gui/Windows/WizardEventArgs.cs @@ -0,0 +1,54 @@ +using System; +using static Terminal.Gui.Wizard; + +namespace Terminal.Gui { + /// + /// for transition events. + /// + public class WizardButtonEventArgs : EventArgs { + /// + /// Set to true to cancel the transition to the next step. + /// + public bool Cancel { get; set; } + + /// + /// Initializes a new instance of + /// + public WizardButtonEventArgs () + { + Cancel = false; + } + } + + /// + /// for events. + /// + public class StepChangeEventArgs : EventArgs { + /// + /// The current (or previous) . + /// + public WizardStep OldStep { get; } + + /// + /// The the is changing to or has changed to. + /// + public WizardStep NewStep { get; } + + /// + /// Event handlers can set to true before returning to cancel the step transition. + /// + public bool Cancel { get; set; } + + /// + /// Initializes a new instance of + /// + /// The current . + /// The new . + public StepChangeEventArgs (WizardStep oldStep, WizardStep newStep) + { + OldStep = oldStep; + NewStep = newStep; + Cancel = false; + } + } +} From 8385f3de1317e9d622b417a3c70d334ff26ca1b4 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 17 Mar 2023 17:04:34 +0000 Subject: [PATCH 38/46] Change MouseEventArgs to MouseEventEventArgs. --- Terminal.Gui/Core/MouseEventEventArgs.cs | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Terminal.Gui/Core/MouseEventEventArgs.cs diff --git a/Terminal.Gui/Core/MouseEventEventArgs.cs b/Terminal.Gui/Core/MouseEventEventArgs.cs new file mode 100644 index 0000000000..4f58274652 --- /dev/null +++ b/Terminal.Gui/Core/MouseEventEventArgs.cs @@ -0,0 +1,31 @@ +using System; + +namespace Terminal.Gui { + /// + /// Specifies the event arguments for . This is a higher-level construct + /// than the wrapped class and is used for the events defined on + /// and subclasses of View (e.g. and ). + /// + public class MouseEventEventArgs : EventArgs { + /// + /// Constructs. + /// + /// The mouse event. + public MouseEventEventArgs (MouseEvent me) => MouseEvent = me; + /// + /// The for the event. + /// + public MouseEvent MouseEvent { get; set; } + + /// + /// Indicates if the current mouse event has already been processed and the driver should stop notifying any other event subscriber. + /// Its important to set this value to true specially when updating any View's layout from inside the subscriber method. + /// + /// This property forwards to the property and is provided as a convenience and for + /// backwards compatibility + public bool Handled { + get => MouseEvent.Handled; + set => MouseEvent.Handled = value; + } + } +} From df3a012b7772a3d7dd9e0c1f941d2530f2ecc2c4 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 17 Mar 2023 17:05:44 +0000 Subject: [PATCH 39/46] Remove unnecessary partial statement. --- Terminal.Gui/Windows/Wizard.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/Windows/Wizard.cs b/Terminal.Gui/Windows/Wizard.cs index 3d277d8d92..6aaf4d6486 100644 --- a/Terminal.Gui/Windows/Wizard.cs +++ b/Terminal.Gui/Windows/Wizard.cs @@ -54,7 +54,7 @@ namespace Terminal.Gui { /// Application.Shutdown (); /// /// - public partial class Wizard : Dialog { + public class Wizard : Dialog { /// /// Represents a basic step that is displayed in a . The view is divided horizontally in two. On the left is the /// content view where s can be added, On the right is the help for the step. From 663a92dd9713618fc4eb8fea9da2e60e07b8e123 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 17 Mar 2023 17:08:37 +0000 Subject: [PATCH 40/46] Reformatting. --- Terminal.Gui/Configuration/ConfigurationManagerEventArgs.cs | 2 +- Terminal.Gui/Core/KeyEventEventArgs.cs | 1 - Terminal.Gui/Core/MouseFlagsChangedEventArgs.cs | 6 +----- Terminal.Gui/Core/PointEventArgs.cs | 6 +----- Terminal.Gui/Core/SizeChangedEventArgs.cs | 2 +- Terminal.Gui/Core/TimeoutEventArgs.cs | 1 - Terminal.Gui/Core/ToggleEventArgs.cs | 4 ---- Terminal.Gui/Views/HistoryTextItem.cs | 2 +- Terminal.Gui/Views/TabMouseEventArgs.cs | 1 - 9 files changed, 5 insertions(+), 20 deletions(-) diff --git a/Terminal.Gui/Configuration/ConfigurationManagerEventArgs.cs b/Terminal.Gui/Configuration/ConfigurationManagerEventArgs.cs index c29405f01a..19a25b5786 100644 --- a/Terminal.Gui/Configuration/ConfigurationManagerEventArgs.cs +++ b/Terminal.Gui/Configuration/ConfigurationManagerEventArgs.cs @@ -14,5 +14,5 @@ public class ConfigurationManagerEventArgs : EventArgs { public ConfigurationManagerEventArgs () { } - } + } } diff --git a/Terminal.Gui/Core/KeyEventEventArgs.cs b/Terminal.Gui/Core/KeyEventEventArgs.cs index 7e54483a88..c7ab9e39a2 100644 --- a/Terminal.Gui/Core/KeyEventEventArgs.cs +++ b/Terminal.Gui/Core/KeyEventEventArgs.cs @@ -21,5 +21,4 @@ public class KeyEventEventArgs : EventArgs { /// public bool Handled { get; set; } = false; } - } diff --git a/Terminal.Gui/Core/MouseFlagsChangedEventArgs.cs b/Terminal.Gui/Core/MouseFlagsChangedEventArgs.cs index 36bf7390f9..bcc95e58b3 100644 --- a/Terminal.Gui/Core/MouseFlagsChangedEventArgs.cs +++ b/Terminal.Gui/Core/MouseFlagsChangedEventArgs.cs @@ -1,14 +1,10 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Terminal.Gui { /// /// Args for events that describe a change in /// - public class MouseFlagsChangedEventArgs : EventArgs{ + public class MouseFlagsChangedEventArgs : EventArgs { /// /// Creates a new instance of the class. diff --git a/Terminal.Gui/Core/PointEventArgs.cs b/Terminal.Gui/Core/PointEventArgs.cs index e8a249496a..0a4079fde5 100644 --- a/Terminal.Gui/Core/PointEventArgs.cs +++ b/Terminal.Gui/Core/PointEventArgs.cs @@ -1,14 +1,10 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Terminal.Gui { /// /// Event args for events which relate to a single /// - public class PointEventArgs : EventArgs{ + public class PointEventArgs : EventArgs { /// /// Creates a new instance of the class diff --git a/Terminal.Gui/Core/SizeChangedEventArgs.cs b/Terminal.Gui/Core/SizeChangedEventArgs.cs index 771643cb95..66c52bf3a2 100644 --- a/Terminal.Gui/Core/SizeChangedEventArgs.cs +++ b/Terminal.Gui/Core/SizeChangedEventArgs.cs @@ -3,7 +3,7 @@ namespace Terminal.Gui { /// - /// Args for events about about Size (e.g. Resized) + /// Args for events about Size (e.g. Resized) /// public class SizeChangedEventArgs : EventArgs { diff --git a/Terminal.Gui/Core/TimeoutEventArgs.cs b/Terminal.Gui/Core/TimeoutEventArgs.cs index 002342152a..c488bdc114 100644 --- a/Terminal.Gui/Core/TimeoutEventArgs.cs +++ b/Terminal.Gui/Core/TimeoutEventArgs.cs @@ -30,4 +30,3 @@ public TimeoutEventArgs (Timeout timeout, long ticks) } } } - diff --git a/Terminal.Gui/Core/ToggleEventArgs.cs b/Terminal.Gui/Core/ToggleEventArgs.cs index a1d5993554..d3e8ad58a3 100644 --- a/Terminal.Gui/Core/ToggleEventArgs.cs +++ b/Terminal.Gui/Core/ToggleEventArgs.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Terminal.Gui { /// diff --git a/Terminal.Gui/Views/HistoryTextItem.cs b/Terminal.Gui/Views/HistoryTextItem.cs index 7b1dfe80ec..f28f4a11f8 100644 --- a/Terminal.Gui/Views/HistoryTextItem.cs +++ b/Terminal.Gui/Views/HistoryTextItem.cs @@ -5,7 +5,7 @@ namespace Terminal.Gui { partial class HistoryText { - public class HistoryTextItem : EventArgs{ + public class HistoryTextItem : EventArgs { public List> Lines; public Point CursorPosition; public LineStatus LineStatus; diff --git a/Terminal.Gui/Views/TabMouseEventArgs.cs b/Terminal.Gui/Views/TabMouseEventArgs.cs index e6d06d2b01..fb2e888ded 100644 --- a/Terminal.Gui/Views/TabMouseEventArgs.cs +++ b/Terminal.Gui/Views/TabMouseEventArgs.cs @@ -32,5 +32,4 @@ public TabMouseEventArgs (TabView.Tab tab, MouseEvent mouseEvent) MouseEvent = mouseEvent; } } - } From 836d868057bcaa24953f735bd07d6ebdfa5e4a74 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 17 Mar 2023 17:11:16 +0000 Subject: [PATCH 41/46] Fix changed event and reformat in Views. --- Terminal.Gui/Views/Label.cs | 2 +- Terminal.Gui/Views/ScrollBarView.cs | 2 +- Terminal.Gui/Views/ScrollView.cs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index 444d4926ad..48be2f90d8 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -92,7 +92,7 @@ void Initialize (bool autosize = true) /// true, if the event was handled, false otherwise. public override bool OnMouseEvent (MouseEvent mouseEvent) { - MouseEventArgs args = new MouseEventArgs (mouseEvent); + MouseEventEventArgs args = new MouseEventEventArgs (mouseEvent); if (OnMouseClick (args)) return true; if (MouseEvent (mouseEvent)) diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index 991a3675d4..1b55a7987d 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -149,7 +149,7 @@ private void Host_EnabledChanged (object sender, EventArgs e) // } //} - void ContentBottomRightCorner_MouseClick (object sender, MouseEventArgs me) + void ContentBottomRightCorner_MouseClick (object sender, MouseEventEventArgs me) { if (me.MouseEvent.Flags == MouseFlags.WheeledDown || me.MouseEvent.Flags == MouseFlags.WheeledUp || me.MouseEvent.Flags == MouseFlags.WheeledRight || me.MouseEvent.Flags == MouseFlags.WheeledLeft) { diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index 659589521b..09a5b62d3b 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -237,14 +237,14 @@ public override void Add (View view) SetNeedsLayout (); } - void View_MouseLeave (object sender, MouseEventArgs e) + void View_MouseLeave (object sender, MouseEventEventArgs e) { if (Application.MouseGrabView != null && Application.MouseGrabView != vertical && Application.MouseGrabView != horizontal) { Application.UngrabMouse (); } } - void View_MouseEnter (object sender, MouseEventArgs e) + void View_MouseEnter (object sender, MouseEventEventArgs e) { Application.GrabMouse (this); } From d9ff0da007c5ba6c0d9644e341a3e37397194bee Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 17 Mar 2023 17:12:10 +0000 Subject: [PATCH 42/46] Fix changed event and reformat in Scenarios. --- UICatalog/Scenarios/ASCIICustomButton.cs | 4 ++-- UICatalog/Scenarios/AllViewsTester.cs | 2 +- UICatalog/Scenarios/CharacterMap.cs | 2 +- UICatalog/Scenarios/TableEditor.cs | 2 +- UICatalog/Scenarios/TextViewAutocompletePopup.cs | 2 +- UICatalog/Scenarios/TreeViewFileSystem.cs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/UICatalog/Scenarios/ASCIICustomButton.cs b/UICatalog/Scenarios/ASCIICustomButton.cs index 9d101be42f..348fd921bd 100644 --- a/UICatalog/Scenarios/ASCIICustomButton.cs +++ b/UICatalog/Scenarios/ASCIICustomButton.cs @@ -106,7 +106,7 @@ private void CustomInitialize (string id, string text, Pos x, Pos y, int width, Add (border, fill, title); } - private void This_MouseClick (object sender, MouseEventArgs obj) + private void This_MouseClick (object sender, MouseEventEventArgs obj) { OnMouseEvent (obj.MouseEvent); } @@ -258,7 +258,7 @@ private void Button_KeyPress (object sender, KeyEventEventArgs obj) } } - private void Button_MouseClick (object sender, MouseEventArgs obj) + private void Button_MouseClick (object sender, MouseEventEventArgs obj) { if (obj.MouseEvent.Flags == MouseFlags.WheeledDown) { scrollView.ContentOffset = new Point (scrollView.ContentOffset.X, diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index 04a85a8983..2033ede63b 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -429,7 +429,7 @@ View CreateClass (Type type) return view; } - void LayoutCompleteHandler (object sender, View.LayoutEventArgs args) + void LayoutCompleteHandler (object sender, LayoutEventArgs args) { UpdateTitle (_curView); } diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index c9a7a07112..a5b5348a8e 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -282,7 +282,7 @@ private void CharMap_DrawContent (object sender, DrawEventArgs e) } ContextMenu _contextMenu = new ContextMenu (); - void Handle_MouseClick (object sender, MouseEventArgs args) + void Handle_MouseClick (object sender, MouseEventEventArgs args) { var me = args.MouseEvent; if (me.Flags == MouseFlags.ReportMousePosition || (me.Flags != MouseFlags.Button1Clicked && diff --git a/UICatalog/Scenarios/TableEditor.cs b/UICatalog/Scenarios/TableEditor.cs index ac78a7d497..34f7009893 100644 --- a/UICatalog/Scenarios/TableEditor.cs +++ b/UICatalog/Scenarios/TableEditor.cs @@ -217,7 +217,7 @@ private string GetProposedNewSortOrder (DataColumn clickedCol, out bool isAsc) return sort; } - private void ShowHeaderContextMenu (DataColumn clickedCol, View.MouseEventArgs e) + private void ShowHeaderContextMenu (DataColumn clickedCol, MouseEventEventArgs e) { var sort = GetProposedNewSortOrder (clickedCol, out var isAsc); diff --git a/UICatalog/Scenarios/TextViewAutocompletePopup.cs b/UICatalog/Scenarios/TextViewAutocompletePopup.cs index ed1c0725f6..8c53342861 100644 --- a/UICatalog/Scenarios/TextViewAutocompletePopup.cs +++ b/UICatalog/Scenarios/TextViewAutocompletePopup.cs @@ -94,7 +94,7 @@ public override void Setup () Win.LayoutStarted += Win_LayoutStarted; } - private void Win_LayoutStarted (object sender, View.LayoutEventArgs obj) + private void Win_LayoutStarted (object sender, LayoutEventArgs obj) { miMultiline.Checked = textViewTopLeft.Multiline; miWrap.Checked = textViewTopLeft.WordWrap; diff --git a/UICatalog/Scenarios/TreeViewFileSystem.cs b/UICatalog/Scenarios/TreeViewFileSystem.cs index c2c0bc7473..73b0d8a943 100644 --- a/UICatalog/Scenarios/TreeViewFileSystem.cs +++ b/UICatalog/Scenarios/TreeViewFileSystem.cs @@ -129,7 +129,7 @@ private void TreeViewFiles_KeyPress (object sender, KeyEventEventArgs obj) } } - private void TreeViewFiles_MouseClick (object sender, View.MouseEventArgs obj) + private void TreeViewFiles_MouseClick (object sender, MouseEventEventArgs obj) { // if user right clicks if (obj.MouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)) { From 0448e53926e2e621e72cbf2ff88ca1cff888aa5e Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 17 Mar 2023 17:12:46 +0000 Subject: [PATCH 43/46] Fix changed event and reformat in UnitTests. --- UnitTests/TopLevels/ToplevelTests.cs | 2 +- UnitTests/UICatalog/ScenarioTests.cs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/UnitTests/TopLevels/ToplevelTests.cs b/UnitTests/TopLevels/ToplevelTests.cs index 90812ca09e..2fc921f698 100644 --- a/UnitTests/TopLevels/ToplevelTests.cs +++ b/UnitTests/TopLevels/ToplevelTests.cs @@ -1060,7 +1060,7 @@ public void IsLoaded_With_Sub_Toplevel_Application_Begin_NeedDisplay () view.LayoutStarted += view_LayoutStarted; - void view_LayoutStarted (object sender, View.LayoutEventArgs e) + void view_LayoutStarted (object sender, LayoutEventArgs e) { Assert.Equal (new Rect (0, 0, 20, 10), view.NeedDisplay); view.LayoutStarted -= view_LayoutStarted; diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index 6d597e17b0..1385818c38 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -59,7 +59,7 @@ public void Run_All_Scenarios () foreach (var scenario in scenarios) { output.WriteLine ($"Running Scenario '{scenario.GetName ()}'"); - + Application.Init (new FakeDriver ()); // Press QuitKey @@ -86,7 +86,6 @@ public void Run_All_Scenarios () //output.WriteLine ($" Add timeout to force quit after {abortTime}ms"); _ = Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (abortTime), forceCloseCallback); - int iterations = 0; Application.Iteration += () => { //output.WriteLine ($" iteration {++iterations}"); if (FakeConsole.MockKeyPresses.Count == 0) { @@ -328,7 +327,7 @@ public void Run_All_Views_Tester_Scenario () _curView = CreateClass (_viewClasses.Values.ToArray () [_classListView.SelectedItem]); }; - _computedCheckBox.Toggled += (s,e) => { + _computedCheckBox.Toggled += (s, e) => { if (_curView != null) { _curView.LayoutStyle = e.OldValue == true ? LayoutStyle.Absolute : LayoutStyle.Computed; _hostPane.LayoutSubviews (); @@ -346,7 +345,7 @@ public void Run_All_Views_Tester_Scenario () } }; - _yText.TextChanged += (s,e) => { + _yText.TextChanged += (s, e) => { try { _yVal = int.Parse (_yText.Text.ToString ()); DimPosChanged (_curView); @@ -355,7 +354,7 @@ public void Run_All_Views_Tester_Scenario () } }; - _yRadioGroup.SelectedItemChanged += (s,selected) => DimPosChanged (_curView); + _yRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); _wRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView); @@ -588,7 +587,7 @@ View CreateClass (Type type) return view; } - void LayoutCompleteHandler (object sender, View.LayoutEventArgs args) + void LayoutCompleteHandler (object sender, LayoutEventArgs args) { UpdateTitle (_curView); } From 1a924d3b99537270bc57439dcb0653a777b2c5af Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 17 Mar 2023 18:18:12 +0000 Subject: [PATCH 44/46] Grouping ConfigurationManager into ConfigurationManagerEventArgs.cs file. --- .../ConfigurationManagerEventArgs.cs | 18 ++++++++++++++ .../Configuration/ThemeManagerEventArgs.cs | 24 ------------------- 2 files changed, 18 insertions(+), 24 deletions(-) delete mode 100644 Terminal.Gui/Configuration/ThemeManagerEventArgs.cs diff --git a/Terminal.Gui/Configuration/ConfigurationManagerEventArgs.cs b/Terminal.Gui/Configuration/ConfigurationManagerEventArgs.cs index 19a25b5786..74acce2ec7 100644 --- a/Terminal.Gui/Configuration/ConfigurationManagerEventArgs.cs +++ b/Terminal.Gui/Configuration/ConfigurationManagerEventArgs.cs @@ -15,4 +15,22 @@ public ConfigurationManagerEventArgs () { } } + + /// + /// Event arguments for the events. + /// + public class ThemeManagerEventArgs : EventArgs { + /// + /// The name of the new active theme.. + /// + public string NewTheme { get; set; } = string.Empty; + + /// + /// Initializes a new instance of + /// + public ThemeManagerEventArgs (string newTheme) + { + NewTheme = newTheme; + } + } } diff --git a/Terminal.Gui/Configuration/ThemeManagerEventArgs.cs b/Terminal.Gui/Configuration/ThemeManagerEventArgs.cs deleted file mode 100644 index fd4d9ca563..0000000000 --- a/Terminal.Gui/Configuration/ThemeManagerEventArgs.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; - -#nullable enable - -namespace Terminal.Gui.Configuration { - - /// - /// Event arguments for the events. - /// - public class ThemeManagerEventArgs : EventArgs { - /// - /// The name of the new active theme.. - /// - public string NewTheme { get; set; } = string.Empty; - - /// - /// Initializes a new instance of - /// - public ThemeManagerEventArgs (string newTheme) - { - NewTheme = newTheme; - } - } -} \ No newline at end of file From 59efe8c5101b2916ea44c67f698961b2f3304135 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 17 Mar 2023 18:38:50 +0000 Subject: [PATCH 45/46] Fix merge issue. --- Terminal.Gui/Views/Menu.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs index 7acfce02e6..1d30722000 100644 --- a/Terminal.Gui/Views/Menu.cs +++ b/Terminal.Gui/Views/Menu.cs @@ -1044,7 +1044,7 @@ public MenuBar (MenuBarItem [] menus) : base () bool _initialCanFocus; - private void MenuBar_Added (View obj) + private void MenuBar_Added (object sender, SuperViewChangedEventArgs e) { _initialCanFocus = CanFocus; Added -= MenuBar_Added; @@ -1276,7 +1276,7 @@ public virtual void OnMenuOpened () parent = openMenu.barItems; mi = parent.Children [openMenu.current]; } - MenuOpened?.Invoke (this, new MenuOpenedEventArgs(parent, mi)); + MenuOpened?.Invoke (this, new MenuOpenedEventArgs (parent, mi)); } /// From 1c3e8e37d382c7c79156ac11760148ba6f054d27 Mon Sep 17 00:00:00 2001 From: tznind Date: Mon, 20 Mar 2023 17:12:14 +0000 Subject: [PATCH 46/46] Fix malformed xmldoc and missing using statement --- Terminal.Gui/Core/View.cs | 4 ++-- Terminal.Gui/Views/FrameView.cs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index c46393c431..8ea963ab18 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -2833,7 +2833,7 @@ public int GetHotKeySpecifierLength (bool isWidth = true) /// /// Gets the dimensions required for ignoring a . - /// /// + /// /// public Size GetSizeNeededForTextWithoutHotKey () { @@ -2843,7 +2843,7 @@ public Size GetSizeNeededForTextWithoutHotKey () /// /// Gets the dimensions required for accounting for a . - /// + /// /// public Size GetSizeNeededForTextAndHotKey () { diff --git a/Terminal.Gui/Views/FrameView.cs b/Terminal.Gui/Views/FrameView.cs index 61471e97e5..72d5789590 100644 --- a/Terminal.Gui/Views/FrameView.cs +++ b/Terminal.Gui/Views/FrameView.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using System.Text.Json.Serialization; using NStack; using Terminal.Gui.Graphs;