question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`View.IsOverridden` doesn't work

See original GitHub issue

I wrote these unit tests (ViewTests.cs) to prove it.

		[Fact, AutoInitShutdown]
		public void IsOverridden_False_IfNotOverriden ()
		{
			var view = new DerivedView () { Text = "DerivedView does not override MouseEvent", Width = 10, Height = 10 };
			
			Assert.False (view.IsOverridden (view, "MouseEvent"));
		}

		[Fact, AutoInitShutdown]
		public void IsOverridden_True_IfOverriden ()
		{
			var view = new Button () { Text = "Button overrides MouseEvent", Width = 10, Height = 10 };

			Assert.True (view.IsOverridden (view, "MouseEvent"));
		}
image

@BDisp - Where’d you get this code from?

		/// <summary>
		/// Check if the <paramref name="method"/> is overridden in the <paramref name="view"/>.
		/// </summary>
		/// <param name="view">The view.</param>
		/// <param name="method">The method name.</param>
		/// <returns><see langword="true"/> if it's overridden, <see langword="false"/> otherwise.</returns>
		public bool IsOverridden (View view, string method)
		{
			Type t = view.GetType ();
			MethodInfo m = t.GetMethod (method);

			return (m.DeclaringType == t || m.ReflectedType == t) && m.GetBaseDefinition ().DeclaringType == typeof (Responder);
		}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
tigcommented, Nov 1, 2022

This passes the tests:

		/// <summary>
		/// Check if the <paramref name="method"/> is overridden in the <paramref name="view"/>.
		/// </summary>
		/// <param name="view">The view.</param>
		/// <param name="method">The method name.</param>
		/// <returns><see langword="true"/> if it's overridden, <see langword="false"/> otherwise.</returns>
		public static bool IsOverridden (View view, string method)
		{
			MethodInfo m = view.GetType ().GetMethod (method, 
				BindingFlags.Instance 
				| BindingFlags.Public 
				| BindingFlags.NonPublic 
				| BindingFlags.DeclaredOnly);
			if (m == null) {
				return false;
			}
			return m.GetBaseDefinition ().DeclaringType != m.DeclaringType;
		}
0reactions
BDispcommented, Nov 2, 2022

Your fix also fix the #2140. Only replace the ComboBoxTests HideDropdownListOnClick_True_Highlight_Current_Item in the line 827 with this. Because now the SelectedItem default value is -1 then no item are selected on the ListView of the ComboBox.

Edit: Is better replace all this test because we have to consider all the frame.

		[Fact, AutoInitShutdown]
		public void HideDropdownListOnClick_True_Highlight_Current_Item ()
		{
			var selected = "";
			var cb = new ComboBox {
				Width = 6,
				Height = 4,
				HideDropdownListOnClick = true,
			};
			cb.SetSource (new List<string> { "One", "Two", "Three" });
			cb.OpenSelectedItem += (e) => selected = e.Value.ToString ();
			Application.Top.Add (cb);
			Application.Begin (Application.Top);

			Assert.True (cb.HideDropdownListOnClick);
			Assert.False (cb.IsShow);
			Assert.Equal (-1, cb.SelectedItem);
			Assert.Equal ("", cb.Text);

			Assert.True (cb.MouseEvent (new MouseEvent {
				X = cb.Bounds.Right - 1,
				Y = 0,
				Flags = MouseFlags.Button1Pressed
			}));
			Assert.Equal ("", selected);
			Assert.True (cb.IsShow);
			Assert.Equal (-1, cb.SelectedItem);
			Assert.Equal ("", cb.Text);
			cb.Redraw (cb.Bounds);
			TestHelpers.AssertDriverContentsWithFrameAre (@"
     ▼
One   
Two   
Three ", output);

			var attributes = new Attribute [] {
				// 0
				cb.Subviews [0].ColorScheme.Focus,
				// 1
				cb.Subviews [1].ColorScheme.HotFocus,
				// 2
				cb.Subviews [1].GetNormalColor ()
			};

			TestHelpers.AssertDriverColorsAre (@"
000000
222222
222222
222222", attributes);

			Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
			Assert.Equal ("", selected);
			Assert.True (cb.IsShow);
			Assert.Equal (-1, cb.SelectedItem);
			Assert.Equal ("", cb.Text);
			cb.Redraw (cb.Bounds);
			TestHelpers.AssertDriverColorsAre (@"
000000
222222
000002
222222", attributes);

			Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
			Assert.Equal ("", selected);
			Assert.True (cb.IsShow);
			Assert.Equal (-1, cb.SelectedItem);
			Assert.Equal ("", cb.Text);
			cb.Redraw (cb.Bounds);
			TestHelpers.AssertDriverColorsAre (@"
000000
222222
222222
000002", attributes);

			Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
			Assert.Equal ("Three", selected);
			Assert.False (cb.IsShow);
			Assert.Equal (2, cb.SelectedItem);
			Assert.Equal ("Three", cb.Text);

			Assert.True (cb.ProcessKey (new KeyEvent (Key.F4, new KeyModifiers ())));
			Assert.Equal ("Three", selected);
			Assert.True (cb.IsShow);
			Assert.Equal (2, cb.SelectedItem);
			Assert.Equal ("Three", cb.Text);
			cb.Redraw (cb.Bounds);
			TestHelpers.AssertDriverColorsAre (@"
000000
222222
222222
000002", attributes);

			Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
			Assert.Equal ("Three", selected);
			Assert.True (cb.IsShow);
			Assert.Equal (2, cb.SelectedItem);
			Assert.Equal ("Three", cb.Text);
			cb.Redraw (cb.Bounds);
			TestHelpers.AssertDriverColorsAre (@"
000000
222222
000002
111112", attributes);

			Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
			Assert.Equal ("Three", selected);
			Assert.True (cb.IsShow);
			Assert.Equal (2, cb.SelectedItem);
			Assert.Equal ("Three", cb.Text);
			cb.Redraw (cb.Bounds);
			TestHelpers.AssertDriverColorsAre (@"
000000
000002
222222
111112", attributes);

			Assert.True (cb.ProcessKey (new KeyEvent (Key.F4, new KeyModifiers ())));
			Assert.Equal ("Three", selected);
			Assert.False (cb.IsShow);
			Assert.Equal (2, cb.SelectedItem);
			Assert.Equal ("Three", cb.Text);
		}

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Override doesn't seem to work
Change the visibility of the filter() method to protected in Super class so it can be overridden. Private methods cannot be override.
Read more >
Graphic overrides by category doesn´t work consistently in ...
Users reported that graphic overrides by category doesn´t work consistently in certain Revit views. In some views an Override by Category ...
Read more >
Unable to override default "View" action
When I try to override the view action using the Lightning Component Bundle in Classic, it works with out any issue.
Read more >
Overriding a specific display doesn't work - Drupal Answers
I created a view in Drupal 8 with 2 displays. I want to keep a display content view mode as teaser and the...
Read more >
Is it possible to override Razor MVC Views in module? #5128
As per documentation overriding razor view is possible in theme But it doesn't explain on how to override views in a module.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found