浏览代码

Making SetFocus (View) private.

BDisp 5 年之前
父节点
当前提交
fda4e21341

+ 17 - 9
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),

+ 3 - 4
Terminal.Gui/Core/View.cs

@@ -1274,11 +1274,10 @@ namespace Terminal.Gui {
 		}
 
 		/// <summary>
-		/// 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.
 		/// </summary>
 		/// <param name="view">View.</param>
-		public void SetFocus (View view)
+		void SetFocus (View view)
 		{
 			if (view == null)
 				return;
@@ -1309,7 +1308,7 @@ namespace Terminal.Gui {
 		}
 
 		/// <summary>
-		/// 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.
 		/// </summary>
 		public void SetFocus ()
 		{

+ 2 - 2
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 ();

+ 1 - 1
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);

+ 7 - 7
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 ();
 			}
 		}
 

+ 1 - 1
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)

+ 1 - 1
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 ();
 				}
 

+ 1 - 1
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;

+ 2 - 2
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;

+ 1 - 1
Terminal.Gui/Views/TextField.cs

@@ -651,7 +651,7 @@ namespace Terminal.Gui {
 					return true;
 				}
 				if (!HasFocus) {
-					SuperView.SetFocus (this);
+					SetFocus ();
 				}
 				PositionCursor (ev);
 				if (isButtonReleased) {

+ 1 - 1
Terminal.Gui/Views/TextView.cs

@@ -1204,7 +1204,7 @@ namespace Terminal.Gui {
 			}
 
 			if (!HasFocus) {
-				SuperView.SetFocus (this);
+				SetFocus ();
 			}
 
 			if (ev.Flags == MouseFlags.Button1Clicked) {

+ 1 - 1
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)

+ 1 - 1
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;

+ 1 - 1
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);

+ 2 - 2
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);