From fda4e21341d6e90845e2e2ef242385bd12780cbb Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 28 Jul 2020 18:31:32 +0100 Subject: [PATCH] Making SetFocus (View) private. --- Example/demo.cs | 26 +++++++++++++++++--------- Terminal.Gui/Core/View.cs | 7 +++---- Terminal.Gui/Views/Button.cs | 4 ++-- Terminal.Gui/Views/Checkbox.cs | 2 +- Terminal.Gui/Views/ComboBox.cs | 14 +++++++------- Terminal.Gui/Views/DateField.cs | 2 +- Terminal.Gui/Views/Label.cs | 2 +- Terminal.Gui/Views/ListView.cs | 2 +- Terminal.Gui/Views/RadioGroup.cs | 4 ++-- Terminal.Gui/Views/TextField.cs | 2 +- Terminal.Gui/Views/TextView.cs | 2 +- Terminal.Gui/Views/TimeField.cs | 2 +- Terminal.Gui/Windows/FileDialog.cs | 2 +- UICatalog/Scenarios/AllViewsTester.cs | 2 +- UICatalog/UICatalog.cs | 4 ++-- 15 files changed, 42 insertions(+), 35 deletions(-) diff --git a/Example/demo.cs b/Example/demo.cs index e8171f6c0..60a27c413 100644 --- a/Example/demo.cs +++ b/Example/demo.cs @@ -253,12 +253,7 @@ static class Demo { }); ntop.Add (menu); - string fname = null; - foreach (var s in new [] { "/etc/passwd", "c:\\windows\\win.ini" }) - if (System.IO.File.Exists (s)) { - fname = s; - break; - } + string fname = GetFileName (); var win = new Window (fname ?? "Untitled") { X = 0, @@ -277,6 +272,18 @@ static class Demo { Application.Run (ntop); } + private static string GetFileName () + { + string fname = null; + foreach (var s in new [] { "/etc/passwd", "c:\\windows\\win.ini" }) + if (System.IO.File.Exists (s)) { + fname = s; + break; + } + + return fname; + } + static bool Quit () { var n = MessageBox.Query (50, 7, "Quit Demo", "Are you sure you want to quit this demo?", "Yes", "No"); @@ -312,7 +319,8 @@ static class Demo { }); ntop.Add (menu); - var win = new Window ("/etc/passwd") { + string fname = GetFileName (); + var win = new Window (fname) { X = 0, Y = 1, Width = Dim.Fill (), @@ -320,7 +328,7 @@ static class Demo { }; ntop.Add (win); - var source = System.IO.File.OpenRead ("/etc/passwd"); + var source = System.IO.File.OpenRead (fname); var hex = new HexView (source) { X = 0, Y = 0, @@ -647,7 +655,7 @@ static class Demo { win.Add (test); win.Add (ml); - var drag = new Label ("Drag: ") { X = 70, Y = 24 }; + var drag = new Label ("Drag: ") { X = 70, Y = 22 }; var dragText = new TextField ("") { X = Pos.Right (drag), Y = Pos.Top (drag), diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index 04c2523f7..69d0ed5c7 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -1274,11 +1274,10 @@ namespace Terminal.Gui { } /// - /// Causes the specified subview to have focus. - /// This does not ensures that the entire parent hierarchy can really get focus and thus not updating the focus order. + /// Causes the specified subview to have focus. /// /// View. - public void SetFocus (View view) + void SetFocus (View view) { if (view == null) return; @@ -1309,7 +1308,7 @@ namespace Terminal.Gui { } /// - /// Causes the specified view and the entire parent hierarchy to have focus. + /// Causes the specified view and the entire parent hierarchy to have the focused order updated. /// public void SetFocus () { diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index 1a0825c3a..41f6796d4 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -154,7 +154,7 @@ namespace Terminal.Gui { bool CheckKey (KeyEvent key) { if (key.Key == (Key.AltMask | HotKey)) { - this.SuperView.SetFocus (this); + SetFocus (); Clicked?.Invoke (); return true; } @@ -210,7 +210,7 @@ namespace Terminal.Gui { me.Flags == MouseFlags.Button1TripleClicked) { if (CanFocus) { if (!HasFocus) { - SuperView?.SetFocus (this); + SetFocus (); SetNeedsDisplay (); } Clicked?.Invoke (); diff --git a/Terminal.Gui/Views/Checkbox.cs b/Terminal.Gui/Views/Checkbox.cs index fcd54ffac..4b17a7489 100644 --- a/Terminal.Gui/Views/Checkbox.cs +++ b/Terminal.Gui/Views/Checkbox.cs @@ -150,7 +150,7 @@ namespace Terminal.Gui { if (!me.Flags.HasFlag (MouseFlags.Button1Clicked) || !CanFocus) return false; - SuperView.SetFocus (this); + SetFocus (); var previousChecked = Checked; Checked = !Checked; OnToggled (previousChecked); diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 2912999f7..2bb2ffde5 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -196,7 +196,7 @@ namespace Terminal.Gui { return true; } else if (me.Flags == MouseFlags.Button1Pressed) { if (!search.HasFocus) { - SetFocus (search); + search.SetFocus (); } return true; @@ -210,7 +210,7 @@ namespace Terminal.Gui { listview.SelectedItem = SelectedItem > -1 ? SelectedItem : 0; if (SelectedItem > -1) { listview.TabStop = true; - this.SetFocus (listview); + listview.SetFocus (); } } @@ -218,7 +218,7 @@ namespace Terminal.Gui { public override bool OnEnter (View view) { if (!search.HasFocus && !listview.HasFocus) { - SetFocus (search); + search.SetFocus (); } search.CursorPosition = search.Text.RuneCount; @@ -301,7 +301,7 @@ namespace Terminal.Gui { if (e.Key == Key.CursorDown && search.HasFocus) { // jump to list if (searchset.Count > 0) { listview.TabStop = true; - this.SetFocus (listview); + listview.SetFocus (); SetValue (searchset [listview.SelectedItem]); return true; } else { @@ -317,7 +317,7 @@ namespace Terminal.Gui { if (e.Key == Key.CursorUp && listview.HasFocus && listview.SelectedItem == 0 && searchset.Count > 0) // jump back to search { search.CursorPosition = search.Text.RuneCount; - this.SetFocus (search); + search.SetFocus (); return true; } @@ -350,7 +350,7 @@ namespace Terminal.Gui { } if (e.Key == Key.Esc) { - this.SetFocus (search); + search.SetFocus (); search.Text = text = ""; OnSelectedChanged (); return true; @@ -431,7 +431,7 @@ namespace Terminal.Gui { listview.Height = CalculatetHeight (); if (Subviews.Count > 0) { - SetFocus (search); + search.SetFocus (); } } diff --git a/Terminal.Gui/Views/DateField.cs b/Terminal.Gui/Views/DateField.cs index 8909a548c..f22987d51 100644 --- a/Terminal.Gui/Views/DateField.cs +++ b/Terminal.Gui/Views/DateField.cs @@ -357,7 +357,7 @@ namespace Terminal.Gui { if (!ev.Flags.HasFlag (MouseFlags.Button1Clicked)) return false; if (!HasFocus) - SuperView.SetFocus (this); + SetFocus (); var point = ev.X; if (point > FieldLen) diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index 18778a86f..63ee0e446 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -87,7 +87,7 @@ namespace Terminal.Gui { if (mouseEvent.Flags == MouseFlags.Button1Clicked) { if (!HasFocus && SuperView != null) { - SuperView.SetFocus (this); + SetFocus (); SetNeedsDisplay (); } diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index a9de56f96..0dff27054 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -577,7 +577,7 @@ namespace Terminal.Gui { return false; if (!HasFocus) - SuperView.SetFocus (this); + SetFocus (); if (source == null) return false; diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index 2c2b21630..2d6e8dc2b 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -224,7 +224,7 @@ namespace Terminal.Gui { SelectedItem = i; cursor = i; if (!HasFocus) - SuperView.SetFocus (this); + SetFocus (); return true; } nextIsHot = false; @@ -267,7 +267,7 @@ namespace Terminal.Gui { if (!me.Flags.HasFlag (MouseFlags.Button1Clicked)) return false; - SuperView.SetFocus (this); + SetFocus (); if (me.Y < radioLabels.Count) { cursor = SelectedItem = me.Y; diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index a30b68302..ab8562338 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -651,7 +651,7 @@ namespace Terminal.Gui { return true; } if (!HasFocus) { - SuperView.SetFocus (this); + SetFocus (); } PositionCursor (ev); if (isButtonReleased) { diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index deff08da7..5ed692385 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -1204,7 +1204,7 @@ namespace Terminal.Gui { } if (!HasFocus) { - SuperView.SetFocus (this); + SetFocus (); } if (ev.Flags == MouseFlags.Button1Clicked) { diff --git a/Terminal.Gui/Views/TimeField.cs b/Terminal.Gui/Views/TimeField.cs index 8e9605f2d..fcb0099b6 100644 --- a/Terminal.Gui/Views/TimeField.cs +++ b/Terminal.Gui/Views/TimeField.cs @@ -275,7 +275,7 @@ namespace Terminal.Gui { if (!ev.Flags.HasFlag (MouseFlags.Button1Clicked)) return false; if (!HasFocus) - SuperView.SetFocus (this); + SetFocus (); var point = ev.X; if (point > FieldLen) diff --git a/Terminal.Gui/Windows/FileDialog.cs b/Terminal.Gui/Windows/FileDialog.cs index f0d75850a..3d41e16b3 100644 --- a/Terminal.Gui/Windows/FileDialog.cs +++ b/Terminal.Gui/Windows/FileDialog.cs @@ -88,7 +88,7 @@ namespace Terminal.Gui { return false; if (!HasFocus) - SuperView.SetFocus (this); + SetFocus (); if (infos == null) return false; diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index 475d6be0b..ce36a4ef5 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -94,7 +94,7 @@ namespace UICatalog { ColorScheme = Colors.TopLevel, }; _classListView.OpenSelectedItem += (a) => { - Top.SetFocus (_settingsPane); + _settingsPane.SetFocus (); }; _classListView.SelectedItemChanged += (args) => { ClearClass (_curView); diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index c240044c7..144b2bb56 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -97,7 +97,7 @@ namespace UICatalog { scenario.Setup (); scenario.Run (); _top.Ready += () => { - _top.SetFocus (_rightPane); + _rightPane.SetFocus (); _top.Ready = null; }; @@ -176,7 +176,7 @@ namespace UICatalog { CanFocus = true, }; _categoryListView.OpenSelectedItem += (a) => { - _top.SetFocus (_rightPane); + _rightPane.SetFocus (); }; _categoryListView.SelectedItemChanged += CategoryListView_SelectedChanged; _leftPane.Add (_categoryListView);