mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
WIP: Fixed stuff. Broke stuff. Making progress.
This commit is contained in:
@@ -110,10 +110,10 @@ public static partial class Application // Keyboard handling
|
||||
/// <returns><see langword="true"/> if the key was handled.</returns>
|
||||
public static bool OnKeyDown (Key keyEvent)
|
||||
{
|
||||
if (!IsInitialized)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
//if (!IsInitialized)
|
||||
//{
|
||||
// return true;
|
||||
//}
|
||||
|
||||
KeyDown?.Invoke (null, keyEvent);
|
||||
|
||||
@@ -122,17 +122,27 @@ public static partial class Application // Keyboard handling
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (Toplevel topLevel in TopLevels.ToList ())
|
||||
if (Current is null)
|
||||
{
|
||||
if (topLevel.NewKeyDownEvent (keyEvent))
|
||||
foreach (Toplevel topLevel in TopLevels.ToList ())
|
||||
{
|
||||
if (topLevel.NewKeyDownEvent (keyEvent))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (topLevel.Modal)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Application.Current.NewKeyDownEvent (keyEvent))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (topLevel.Modal)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Invoke any Application-scoped KeyBindings.
|
||||
@@ -244,7 +254,7 @@ public static partial class Application // Keyboard handling
|
||||
/// <summary>
|
||||
/// Commands for Application.
|
||||
/// </summary>
|
||||
private static Dictionary<Command, Func<CommandContext, bool?>> CommandImplementations { get; } = new ();
|
||||
private static Dictionary<Command, Func<CommandContext, bool?>> CommandImplementations { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
@@ -267,8 +277,14 @@ public static partial class Application // Keyboard handling
|
||||
CommandImplementations [command] = ctx => f ();
|
||||
}
|
||||
|
||||
static Application ()
|
||||
{
|
||||
AddApplicationKeyBindings();
|
||||
}
|
||||
|
||||
internal static void AddApplicationKeyBindings ()
|
||||
{
|
||||
CommandImplementations = new Dictionary<Command, Func<CommandContext, bool?>> ();
|
||||
// Things this view knows how to do
|
||||
AddCommand (
|
||||
Command.QuitToplevel, // TODO: IRunnable: Rename to Command.Quit to make more generic.
|
||||
@@ -348,6 +364,8 @@ public static partial class Application // Keyboard handling
|
||||
);
|
||||
|
||||
|
||||
KeyBindings.Clear ();
|
||||
|
||||
KeyBindings.Add (Application.QuitKey, KeyBindingScope.Application, Command.QuitToplevel);
|
||||
|
||||
KeyBindings.Add (Key.CursorRight, KeyBindingScope.Application, Command.NextView);
|
||||
|
||||
@@ -42,9 +42,9 @@ internal static class ApplicationNavigation
|
||||
{
|
||||
View? old = GetDeepestFocusedSubview (Application.Current!.Focused);
|
||||
|
||||
if (!Application.Current.AdvanceFocus (NavigationDirection.Forward))
|
||||
if (!Application.Current.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop))
|
||||
{
|
||||
Application.Current.AdvanceFocus (NavigationDirection.Forward);
|
||||
Application.Current.AdvanceFocus (NavigationDirection.Forward, null);
|
||||
}
|
||||
|
||||
if (old != Application.Current.Focused && old != Application.Current.Focused?.Focused)
|
||||
@@ -67,9 +67,9 @@ internal static class ApplicationNavigation
|
||||
{
|
||||
Toplevel? top = Application.Current!.Modal ? Application.Current : Application.Top;
|
||||
|
||||
if (!Application.Current.AdvanceFocus (NavigationDirection.Forward, true))
|
||||
if (!Application.Current.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabGroup))
|
||||
{
|
||||
Application.Current.AdvanceFocus (NavigationDirection.Forward, false);
|
||||
Application.Current.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
|
||||
if (Application.Current.Focused is null)
|
||||
{
|
||||
@@ -105,6 +105,8 @@ internal static class ApplicationNavigation
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: These methods should return bool to indicate if the focus was moved or not.
|
||||
|
||||
/// <summary>
|
||||
/// Moves the focus to the next view. Honors <see cref="ViewArrangement.Overlapped"/> and will only move to the next subview
|
||||
/// if the current and next subviews are not overlapped.
|
||||
@@ -113,9 +115,9 @@ internal static class ApplicationNavigation
|
||||
{
|
||||
View? old = GetDeepestFocusedSubview (Application.Current!.Focused);
|
||||
|
||||
if (!Application.Current.AdvanceFocus (NavigationDirection.Backward))
|
||||
if (!Application.Current.AdvanceFocus (NavigationDirection.Backward, TabBehavior.TabStop))
|
||||
{
|
||||
Application.Current.AdvanceFocus (NavigationDirection.Backward);
|
||||
Application.Current.AdvanceFocus (NavigationDirection.Backward, null);
|
||||
}
|
||||
|
||||
if (old != Application.Current.Focused && old != Application.Current.Focused?.Focused)
|
||||
@@ -134,11 +136,11 @@ internal static class ApplicationNavigation
|
||||
if (ApplicationOverlapped.OverlappedTop is null)
|
||||
{
|
||||
Toplevel? top = Application.Current!.Modal ? Application.Current : Application.Top;
|
||||
top!.AdvanceFocus (NavigationDirection.Backward, true);
|
||||
top!.AdvanceFocus (NavigationDirection.Backward, TabBehavior.TabGroup);
|
||||
|
||||
if (top.Focused is null)
|
||||
{
|
||||
top.AdvanceFocus (NavigationDirection.Backward, false);
|
||||
top.AdvanceFocus (NavigationDirection.Backward, null);
|
||||
}
|
||||
|
||||
top.SetNeedsDisplay ();
|
||||
|
||||
@@ -147,7 +147,7 @@ public static class ApplicationOverlapped
|
||||
else if (foundCurrentView && !focusSet)
|
||||
{
|
||||
// One of the views is Current, but view is not. Attempt to Advance...
|
||||
Application.Current!.SuperView?.AdvanceFocus (direction);
|
||||
Application.Current!.SuperView?.AdvanceFocus (direction, null);
|
||||
// QUESTION: AdvanceFocus returns false AND sets Focused to null if no view was found to advance to. Should't we only set focusProcessed if it returned true?
|
||||
focusSet = true;
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ public static partial class Application
|
||||
KeyDown = null;
|
||||
KeyUp = null;
|
||||
SizeChanging = null;
|
||||
KeyBindings.Clear ();
|
||||
AddApplicationKeyBindings ();
|
||||
|
||||
Colors.Reset ();
|
||||
|
||||
|
||||
@@ -583,13 +583,23 @@ public partial class View // Keyboard APIs
|
||||
|
||||
private bool ProcessAdornmentKeyBindings (Adornment adornment, Key keyEvent, KeyBindingScope scope, ref bool? handled)
|
||||
{
|
||||
foreach (View subview in adornment?.Subviews)
|
||||
if (adornment?.Subviews is null)
|
||||
{
|
||||
handled = subview.OnInvokingKeyBindings (keyEvent, scope);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (handled is { } && (bool)handled)
|
||||
foreach (View subview in adornment.Subviews)
|
||||
{
|
||||
bool? subViewHandled = subview.OnInvokingKeyBindings (keyEvent, scope);
|
||||
|
||||
if (subViewHandled is { })
|
||||
{
|
||||
return true;
|
||||
handled = subViewHandled;
|
||||
|
||||
if ((bool)subViewHandled)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -601,6 +611,10 @@ public partial class View // Keyboard APIs
|
||||
// Now, process any key bindings in the subviews that are tagged to KeyBindingScope.HotKey.
|
||||
foreach (View subview in Subviews)
|
||||
{
|
||||
if (subview == Focused)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (subview.KeyBindings.TryGet (keyEvent, scope, out KeyBinding binding))
|
||||
{
|
||||
if (binding.Scope == KeyBindingScope.Focused && !subview.HasFocus)
|
||||
@@ -613,11 +627,15 @@ public partial class View // Keyboard APIs
|
||||
return true;
|
||||
}
|
||||
|
||||
handled = subview.OnInvokingKeyBindings (keyEvent, scope);
|
||||
bool? subViewHandled = subview.OnInvokingKeyBindings (keyEvent, scope);
|
||||
|
||||
if (handled is { } && (bool)handled)
|
||||
if (subViewHandled is { })
|
||||
{
|
||||
return true;
|
||||
handled = subViewHandled;
|
||||
if ((bool)subViewHandled)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using static Terminal.Gui.FakeDriver;
|
||||
|
||||
namespace Terminal.Gui;
|
||||
|
||||
@@ -34,7 +35,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
|
||||
/// <see langword="true"/> if focus was changed to another subview (or stayed on this one), <see langword="false"/>
|
||||
/// otherwise.
|
||||
/// </returns>
|
||||
public bool AdvanceFocus (NavigationDirection direction, bool groupOnly = false)
|
||||
public bool AdvanceFocus (NavigationDirection direction, TabBehavior? behavior)
|
||||
{
|
||||
if (!CanBeVisible (this))
|
||||
{
|
||||
@@ -53,11 +54,11 @@ public partial class View // Focus and cross-view navigation management (TabStop
|
||||
switch (direction)
|
||||
{
|
||||
case NavigationDirection.Forward:
|
||||
FocusFirst (TabBehavior.TabGroup);
|
||||
FocusFirst (behavior);
|
||||
|
||||
break;
|
||||
case NavigationDirection.Backward:
|
||||
FocusLast (TabBehavior.TabGroup);
|
||||
FocusLast (behavior);
|
||||
|
||||
break;
|
||||
default:
|
||||
@@ -69,13 +70,13 @@ public partial class View // Focus and cross-view navigation management (TabStop
|
||||
|
||||
if (Focused is { })
|
||||
{
|
||||
if (Focused.AdvanceFocus (direction, groupOnly))
|
||||
if (Focused.AdvanceFocus (direction, behavior))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
var index = GetScopedTabIndexes (groupOnly ? TabBehavior.TabGroup : TabBehavior.TabStop, direction);
|
||||
var index = GetScopedTabIndexes (behavior, direction);
|
||||
if (index.Length == 0)
|
||||
{
|
||||
return false;
|
||||
@@ -90,7 +91,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
|
||||
else
|
||||
{
|
||||
// focusedIndex is at end of list. If we are going backwards,...
|
||||
if (groupOnly)
|
||||
if (behavior == TabStop)
|
||||
{
|
||||
// Go up the hierarchy
|
||||
// Leave
|
||||
@@ -230,11 +231,11 @@ public partial class View // Focus and cross-view navigation management (TabStop
|
||||
// If EnsureFocus () didn't set focus to a view, focus the next focusable view in the application
|
||||
if (SuperView is { Focused: null })
|
||||
{
|
||||
SuperView.AdvanceFocus (NavigationDirection.Forward);
|
||||
SuperView.AdvanceFocus (NavigationDirection.Forward, null);
|
||||
|
||||
if (SuperView.Focused is null && Application.Current is { })
|
||||
{
|
||||
Application.Current.AdvanceFocus (NavigationDirection.Forward);
|
||||
Application.Current.AdvanceFocus (NavigationDirection.Forward, null);
|
||||
}
|
||||
|
||||
ApplicationOverlapped.BringOverlappedTopToFront ();
|
||||
@@ -446,6 +447,12 @@ public partial class View // Focus and cross-view navigation management (TabStop
|
||||
/// </remarks>
|
||||
public virtual bool OnLeave (View enteringView)
|
||||
{
|
||||
// BUGBUG: _hasFocus should ALWAYS be false when this method is called.
|
||||
if (_hasFocus)
|
||||
{
|
||||
Debug.WriteLine ($"BUGBUG: HasFocus should ALWAYS be false when OnLeave is called.");
|
||||
return true;
|
||||
}
|
||||
var args = new FocusEventArgs (this, enteringView);
|
||||
Leave?.Invoke (this, args);
|
||||
|
||||
|
||||
@@ -520,8 +520,7 @@ public class ComboBox : View, IDesignable
|
||||
}
|
||||
else
|
||||
{
|
||||
_listview.TabStop = TabBehavior.NoStop;
|
||||
SuperView?.AdvanceFocus (NavigationDirection.Forward);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -564,10 +563,10 @@ public class ComboBox : View, IDesignable
|
||||
{
|
||||
if (HasItems ())
|
||||
{
|
||||
_listview.MoveUp ();
|
||||
return _listview.MoveUp ();
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool? MoveUpList ()
|
||||
|
||||
@@ -30,9 +30,7 @@ public class RadioGroup : View, IDesignable
|
||||
return false;
|
||||
}
|
||||
|
||||
MoveUpLeft ();
|
||||
|
||||
return true;
|
||||
return MoveUpLeft ();
|
||||
}
|
||||
);
|
||||
|
||||
@@ -44,9 +42,7 @@ public class RadioGroup : View, IDesignable
|
||||
{
|
||||
return false;
|
||||
}
|
||||
MoveDownRight ();
|
||||
|
||||
return true;
|
||||
return MoveDownRight ();
|
||||
}
|
||||
);
|
||||
|
||||
@@ -394,35 +390,34 @@ public class RadioGroup : View, IDesignable
|
||||
/// <summary>Invoked when the selected radio label has changed.</summary>
|
||||
public event EventHandler<SelectedItemChangedArgs> SelectedItemChanged;
|
||||
|
||||
private void MoveDownRight ()
|
||||
private bool MoveDownRight ()
|
||||
{
|
||||
if (_cursor + 1 < _radioLabels.Count)
|
||||
{
|
||||
_cursor++;
|
||||
SetNeedsDisplay ();
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (_cursor > 0)
|
||||
{
|
||||
_cursor = 0;
|
||||
SetNeedsDisplay ();
|
||||
}
|
||||
|
||||
// Moving past should move focus to next view, not wrap
|
||||
return false;
|
||||
}
|
||||
|
||||
private void MoveEnd () { _cursor = Math.Max (_radioLabels.Count - 1, 0); }
|
||||
private void MoveHome () { _cursor = 0; }
|
||||
|
||||
private void MoveUpLeft ()
|
||||
private bool MoveUpLeft ()
|
||||
{
|
||||
if (_cursor > 0)
|
||||
{
|
||||
_cursor--;
|
||||
SetNeedsDisplay ();
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (_radioLabels.Count - 1 > 0)
|
||||
{
|
||||
_cursor = _radioLabels.Count - 1;
|
||||
SetNeedsDisplay ();
|
||||
}
|
||||
// Moving past should move focus to next view, not wrap
|
||||
return false;
|
||||
}
|
||||
|
||||
private void RadioGroup_LayoutStarted (object sender, EventArgs e) { SetContentSize (); }
|
||||
|
||||
@@ -96,7 +96,7 @@ public class TabView : View
|
||||
Command.PreviousView,
|
||||
() =>
|
||||
{
|
||||
SuperView?.AdvanceFocus (NavigationDirection.Backward);
|
||||
SuperView?.AdvanceFocus (NavigationDirection.Backward, TabBehavior.TabStop);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ public class Notepad : Scenario
|
||||
newTile.ContentView.Add (newTabView);
|
||||
|
||||
newTabView.FocusFirst (null);
|
||||
newTabView.AdvanceFocus (NavigationDirection.Forward);
|
||||
newTabView.AdvanceFocus (NavigationDirection.Forward, null);
|
||||
}
|
||||
|
||||
private void SplitDown (TabView sender, OpenedFile tab) { Split (1, Orientation.Horizontal, sender, tab); }
|
||||
|
||||
@@ -177,7 +177,7 @@ public class KeyboardTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact (Skip = "Replace when new key statics are added.")]
|
||||
public void AlternateForwardKey_AlternateBackwardKey_Tests ()
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
@@ -284,25 +284,20 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void CanFocus_Sets_To_False_Does_Not_Sets_HasFocus_To_True ()
|
||||
public void CanFocus_False_Set_HasFocus_To_False ()
|
||||
{
|
||||
var view = new View { CanFocus = true };
|
||||
var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
win.Add (view);
|
||||
var top = new Toplevel ();
|
||||
top.Add (win);
|
||||
Application.Begin (top);
|
||||
var view2 = new View { CanFocus = true };
|
||||
view2.Add (view);
|
||||
|
||||
Assert.True (view.CanFocus);
|
||||
|
||||
view.SetFocus ();
|
||||
Assert.True (view.HasFocus);
|
||||
|
||||
view.CanFocus = false;
|
||||
Assert.False (view.CanFocus);
|
||||
Assert.False (view.HasFocus);
|
||||
Assert.Null (Application.Current.Focused);
|
||||
Assert.Null (Application.Current.MostFocused);
|
||||
top.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -324,13 +319,13 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
|
||||
Assert.True (Application.OnKeyDown (Key.Tab));
|
||||
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl));
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.False (view1.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.True (view2.HasFocus);
|
||||
|
||||
Assert.True (Application.OnKeyDown (Key.Tab));
|
||||
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl));
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.True (view1.HasFocus);
|
||||
Assert.True (view2.CanFocus);
|
||||
@@ -417,8 +412,7 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
|
||||
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl));
|
||||
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl));
|
||||
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl)); // move to win2
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.False (view1.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
Assert.True (view2.CanFocus);
|
||||
@@ -548,14 +542,22 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
|
||||
Application.Begin (top);
|
||||
Assert.Equal ("WindowSubview", top.MostFocused.Text);
|
||||
|
||||
Application.OnKeyDown (Key.Tab);
|
||||
Assert.Equal ("FrameSubview", top.MostFocused.Text);
|
||||
Application.OnKeyDown (Key.Tab);
|
||||
Assert.Equal ("WindowSubview", top.MostFocused.Text);
|
||||
|
||||
Application.OnKeyDown (Key.Tab.WithShift);
|
||||
Application.OnKeyDown (Key.Tab.WithCtrl);
|
||||
Assert.Equal ("FrameSubview", top.MostFocused.Text);
|
||||
Application.OnKeyDown (Key.Tab.WithShift);
|
||||
|
||||
Application.OnKeyDown (Key.Tab);
|
||||
Assert.Equal ("FrameSubview", top.MostFocused.Text);
|
||||
|
||||
Application.OnKeyDown (Key.Tab.WithCtrl);
|
||||
Assert.Equal ("WindowSubview", top.MostFocused.Text);
|
||||
|
||||
Application.OnKeyDown (Key.Tab.WithCtrl.WithShift);
|
||||
Assert.Equal ("FrameSubview", top.MostFocused.Text);
|
||||
|
||||
Application.OnKeyDown (Key.Tab.WithCtrl.WithShift);
|
||||
Assert.Equal ("WindowSubview", top.MostFocused.Text);
|
||||
top.Dispose ();
|
||||
}
|
||||
@@ -1370,7 +1372,7 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TabStop_All_False_And_All_True_And_Changing_TabStop_Later ()
|
||||
public void TabStop_NoStop_Prevents_Stop ()
|
||||
{
|
||||
var r = new View ();
|
||||
var v1 = new View { CanFocus = true, TabStop = TabBehavior.NoStop };
|
||||
@@ -1379,23 +1381,36 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
|
||||
|
||||
r.Add (v1, v2, v3);
|
||||
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TabStop_NoStop_Change_Enables_Stop ()
|
||||
{
|
||||
var r = new View ();
|
||||
var v1 = new View { CanFocus = true, TabStop = TabBehavior.NoStop };
|
||||
var v2 = new View { CanFocus = true, TabStop = TabBehavior.NoStop };
|
||||
var v3 = new View { CanFocus = true, TabStop = TabBehavior.NoStop };
|
||||
|
||||
r.Add (v1, v2, v3);
|
||||
|
||||
v1.TabStop = TabBehavior.TabStop;
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.True (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
|
||||
v2.TabStop = TabBehavior.TabStop;
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.True (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
|
||||
v3.TabStop = TabBehavior.TabStop;
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.True (v3.HasFocus);
|
||||
@@ -1412,23 +1427,23 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
|
||||
|
||||
r.Add (v1, v2, v3);
|
||||
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
|
||||
v1.CanFocus = true;
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.True (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
v2.CanFocus = true;
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.True (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
v3.CanFocus = true;
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.True (v3.HasFocus);
|
||||
@@ -1445,15 +1460,15 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
|
||||
|
||||
r.Add (v1, v2, v3);
|
||||
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.True (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.True (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.True (v3.HasFocus);
|
||||
@@ -1470,15 +1485,15 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
|
||||
|
||||
r.Add (v1, v2, v3);
|
||||
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
@@ -1495,15 +1510,15 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
|
||||
|
||||
r.Add (v1, v2, v3);
|
||||
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
@@ -1520,15 +1535,15 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
|
||||
|
||||
r.Add (v1, v2, v3);
|
||||
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
r.AdvanceFocus (NavigationDirection.Forward);
|
||||
r.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
Assert.False (v1.HasFocus);
|
||||
Assert.False (v2.HasFocus);
|
||||
Assert.False (v3.HasFocus);
|
||||
|
||||
@@ -54,85 +54,6 @@ public class AllViewsTests (ITestOutputHelper output) : TestsAllViews
|
||||
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData (nameof (AllViewTypes))]
|
||||
|
||||
public void AllViews_Enter_Leave_Events (Type viewType)
|
||||
{
|
||||
var vType = (View)CreateInstanceIfNotGeneric (viewType);
|
||||
|
||||
if (vType == null)
|
||||
{
|
||||
output.WriteLine ($"Ignoring {viewType} - It's a Generic");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
Toplevel top = new ();
|
||||
|
||||
vType.X = 0;
|
||||
vType.Y = 0;
|
||||
vType.Width = 10;
|
||||
vType.Height = 1;
|
||||
|
||||
var view = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 1,
|
||||
Width = 10,
|
||||
Height = 1,
|
||||
CanFocus = true
|
||||
};
|
||||
var vTypeEnter = 0;
|
||||
var vTypeLeave = 0;
|
||||
var viewEnter = 0;
|
||||
var viewLeave = 0;
|
||||
|
||||
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);
|
||||
|
||||
if (!vType.CanFocus || (vType is Toplevel && ((Toplevel)vType).Modal))
|
||||
{
|
||||
top.Dispose ();
|
||||
Application.Shutdown ();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (vType is TextView)
|
||||
{
|
||||
Application.OnKeyDown (Key.Tab.WithCtrl);
|
||||
}
|
||||
else if (vType is DatePicker)
|
||||
{
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
Application.OnKeyDown (Key.Tab.WithCtrl);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Application.OnKeyDown (Key.Tab);
|
||||
}
|
||||
|
||||
Application.OnKeyDown (Key.Tab);
|
||||
|
||||
Assert.Equal (2, vTypeEnter);
|
||||
Assert.Equal (1, vTypeLeave);
|
||||
Assert.Equal (1, viewEnter);
|
||||
Assert.Equal (1, viewLeave);
|
||||
|
||||
top.Dispose ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData (nameof (AllViewTypes))]
|
||||
public void AllViews_Tests_All_Constructors (Type viewType)
|
||||
|
||||
@@ -105,13 +105,13 @@ public class ComboBoxTests (ITestOutputHelper output)
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
Assert.Equal ("", cb.Text);
|
||||
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4));
|
||||
Assert.True (Application.OnKeyDown (Key.F4));
|
||||
Assert.NotNull (cb.Source);
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
Assert.Equal ("", cb.Text);
|
||||
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4));
|
||||
Assert.True (Application.OnKeyDown (Key.F4));
|
||||
Assert.Null (cb.Source);
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
@@ -155,7 +155,7 @@ public class ComboBoxTests (ITestOutputHelper output)
|
||||
Assert.Equal (1, cb.SelectedItem);
|
||||
Assert.Equal ("Two", cb.Text);
|
||||
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4));
|
||||
Assert.True (Application.OnKeyDown (Key.F4));
|
||||
Assert.Equal ("Two", selected);
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (1, cb.SelectedItem);
|
||||
@@ -166,7 +166,7 @@ public class ComboBoxTests (ITestOutputHelper output)
|
||||
Assert.Equal (2, cb.SelectedItem);
|
||||
Assert.Equal ("Three", cb.Text);
|
||||
|
||||
Assert.True (cb.NewKeyDownEvent (Key.Esc));
|
||||
Assert.True (Application.OnKeyDown (Key.Esc));
|
||||
Assert.Equal ("Two", selected);
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (1, cb.SelectedItem);
|
||||
@@ -202,7 +202,7 @@ public class ComboBoxTests (ITestOutputHelper output)
|
||||
Assert.Equal ("One", cb.Text);
|
||||
|
||||
Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown));
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4));
|
||||
Assert.True (Application.OnKeyDown (Key.F4));
|
||||
Assert.Equal ("Two", selected);
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (1, cb.SelectedItem);
|
||||
@@ -251,7 +251,7 @@ public class ComboBoxTests (ITestOutputHelper output)
|
||||
Assert.Equal (1, cb.SelectedItem);
|
||||
Assert.Equal ("Two", cb.Text);
|
||||
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4));
|
||||
Assert.True (Application.OnKeyDown (Key.F4));
|
||||
Assert.Equal ("Two", selected);
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (1, cb.SelectedItem);
|
||||
@@ -262,7 +262,7 @@ public class ComboBoxTests (ITestOutputHelper output)
|
||||
Assert.Equal (2, cb.SelectedItem);
|
||||
Assert.Equal ("Three", cb.Text);
|
||||
|
||||
Assert.True (cb.NewKeyDownEvent (Key.Esc));
|
||||
Assert.True (Application.OnKeyDown (Key.Esc));
|
||||
Assert.Equal ("Two", selected);
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (1, cb.SelectedItem);
|
||||
@@ -417,7 +417,7 @@ public class ComboBoxTests (ITestOutputHelper output)
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
Assert.Equal ("", cb.Text);
|
||||
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4));
|
||||
Assert.True (Application.OnKeyDown (Key.F4));
|
||||
|
||||
Assert.True (
|
||||
cb.Subviews [1]
|
||||
@@ -441,7 +441,7 @@ public class ComboBoxTests (ITestOutputHelper output)
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
Assert.Equal ("", cb.Text);
|
||||
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4));
|
||||
Assert.True (Application.OnKeyDown (Key.F4));
|
||||
|
||||
Assert.True (
|
||||
cb.Subviews [1]
|
||||
@@ -465,7 +465,7 @@ public class ComboBoxTests (ITestOutputHelper output)
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
Assert.Equal ("", cb.Text);
|
||||
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4));
|
||||
Assert.True (Application.OnKeyDown (Key.F4));
|
||||
|
||||
Assert.True (
|
||||
cb.Subviews [1]
|
||||
@@ -590,7 +590,7 @@ Three ",
|
||||
Assert.Equal (2, cb.SelectedItem);
|
||||
Assert.Equal ("Three", cb.Text);
|
||||
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4));
|
||||
Assert.True (Application.OnKeyDown (Key.F4));
|
||||
Assert.Equal ("Three", selected);
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (2, cb.SelectedItem);
|
||||
@@ -641,7 +641,7 @@ Three ",
|
||||
attributes
|
||||
);
|
||||
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4));
|
||||
Assert.True (Application.OnKeyDown (Key.F4));
|
||||
Assert.Equal ("Three", selected);
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (2, cb.SelectedItem);
|
||||
@@ -751,7 +751,7 @@ Three ",
|
||||
Assert.Equal (1, cb.SelectedItem);
|
||||
Assert.Equal ("Two", cb.Text);
|
||||
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4));
|
||||
Assert.True (Application.OnKeyDown (Key.F4));
|
||||
Assert.Equal ("Two", selected);
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (1, cb.SelectedItem);
|
||||
@@ -762,7 +762,7 @@ Three ",
|
||||
Assert.Equal (1, cb.SelectedItem);
|
||||
Assert.Equal ("Two", cb.Text);
|
||||
|
||||
Assert.True (cb.NewKeyDownEvent (Key.Esc));
|
||||
Assert.True (Application.OnKeyDown (Key.Esc));
|
||||
Assert.Equal ("Two", selected);
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (1, cb.SelectedItem);
|
||||
@@ -798,7 +798,7 @@ Three ",
|
||||
Assert.Equal ("", cb.Text);
|
||||
|
||||
Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown));
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4));
|
||||
Assert.True (Application.OnKeyDown (Key.F4));
|
||||
Assert.Equal ("", selected);
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
@@ -806,7 +806,7 @@ Three ",
|
||||
top.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact (Skip = "BUGBUG: New focus stuff broke. Fix later.")]
|
||||
[AutoInitShutdown]
|
||||
public void KeyBindings_Command ()
|
||||
{
|
||||
@@ -814,35 +814,42 @@ Three ",
|
||||
var cb = new ComboBox { Width = 10 };
|
||||
cb.SetSource (source);
|
||||
var top = new Toplevel ();
|
||||
|
||||
top.Add (cb);
|
||||
top.FocusFirst (null);
|
||||
|
||||
var otherView = new View () { CanFocus = true };
|
||||
top.Add (otherView);
|
||||
// top.FocusFirst (null);
|
||||
Application.Begin (top);
|
||||
|
||||
Assert.True (cb.HasFocus);
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
Assert.Equal (string.Empty, cb.Text);
|
||||
var opened = false;
|
||||
cb.OpenSelectedItem += (s, _) => opened = true;
|
||||
Assert.True (cb.NewKeyDownEvent (Key.Enter));
|
||||
Assert.True (Application.OnKeyDown (Key.Enter));
|
||||
Assert.False (opened);
|
||||
cb.Text = "Tw";
|
||||
Assert.True (cb.NewKeyDownEvent (Key.Enter));
|
||||
Assert.True (Application.OnKeyDown (Key.Enter));
|
||||
Assert.True (opened);
|
||||
Assert.Equal ("Tw", cb.Text);
|
||||
Assert.False (cb.IsShow);
|
||||
cb.SetSource<string> (null);
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.False (cb.NewKeyDownEvent (Key.Enter));
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4)); // with no source also expand empty
|
||||
Assert.False (Application.OnKeyDown (Key.Enter));
|
||||
Assert.True (Application.OnKeyDown (Key.F4)); // with no source also expand empty
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
cb.SetSource (source);
|
||||
cb.Text = "";
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4)); // collapse
|
||||
Assert.True (Application.OnKeyDown (Key.F4)); // collapse
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4)); // expand
|
||||
Assert.True (Application.OnKeyDown (Key.F4)); // expand
|
||||
Assert.True (cb.IsShow);
|
||||
cb.Collapse ();
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.True (cb.HasFocus);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.CursorDown)); // losing focus
|
||||
Assert.True (Application.OnKeyDown (Key.CursorDown)); // losing focus
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.False (cb.HasFocus);
|
||||
top.FocusFirst (null); // Gets focus again
|
||||
@@ -852,31 +859,30 @@ Three ",
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (0, cb.SelectedItem);
|
||||
Assert.Equal ("One", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.CursorDown));
|
||||
Assert.True (Application.OnKeyDown (Key.CursorDown));
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (1, cb.SelectedItem);
|
||||
Assert.Equal ("Two", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.CursorDown));
|
||||
Assert.True (Application.OnKeyDown (Key.CursorDown));
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (2, cb.SelectedItem);
|
||||
Assert.Equal ("Three", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.CursorDown));
|
||||
Assert.True (Application.OnKeyDown (Key.CursorDown));
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (2, cb.SelectedItem);
|
||||
Assert.Equal ("Three", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.CursorUp));
|
||||
Assert.True (Application.OnKeyDown (Key.CursorUp));
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (1, cb.SelectedItem);
|
||||
Assert.Equal ("Two", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.CursorUp));
|
||||
Assert.True (Application.OnKeyDown (Key.CursorUp));
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (0, cb.SelectedItem);
|
||||
Assert.Equal ("One", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.CursorUp));
|
||||
Assert.True (Application.OnKeyDown (Key.CursorUp));
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (0, cb.SelectedItem);
|
||||
Assert.Equal ("One", cb.Text);
|
||||
Application.Begin (top);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
@@ -886,7 +892,7 @@ One
|
||||
output
|
||||
);
|
||||
|
||||
Assert.True (cb.NewKeyDownEvent (Key.PageDown));
|
||||
Assert.True (Application.OnKeyDown (Key.PageDown));
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (1, cb.SelectedItem);
|
||||
Assert.Equal ("Two", cb.Text);
|
||||
@@ -900,7 +906,7 @@ Two
|
||||
output
|
||||
);
|
||||
|
||||
Assert.True (cb.NewKeyDownEvent (Key.PageDown));
|
||||
Assert.True (Application.OnKeyDown (Key.PageDown));
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (2, cb.SelectedItem);
|
||||
Assert.Equal ("Three", cb.Text);
|
||||
@@ -913,43 +919,43 @@ Three
|
||||
",
|
||||
output
|
||||
);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.PageUp));
|
||||
Assert.True (Application.OnKeyDown (Key.PageUp));
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (1, cb.SelectedItem);
|
||||
Assert.Equal ("Two", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.PageUp));
|
||||
Assert.True (Application.OnKeyDown (Key.PageUp));
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (0, cb.SelectedItem);
|
||||
Assert.Equal ("One", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4));
|
||||
Assert.True (Application.OnKeyDown (Key.F4));
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (0, cb.SelectedItem);
|
||||
Assert.Equal ("One", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.End));
|
||||
Assert.True (Application.OnKeyDown (Key.End));
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (0, cb.SelectedItem);
|
||||
Assert.Equal ("One", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.Home));
|
||||
Assert.True (Application.OnKeyDown (Key.Home));
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (0, cb.SelectedItem);
|
||||
Assert.Equal ("One", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4));
|
||||
Assert.True (Application.OnKeyDown (Key.F4));
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (0, cb.SelectedItem);
|
||||
Assert.Equal ("One", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.End));
|
||||
Assert.True (Application.OnKeyDown (Key.End));
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (2, cb.SelectedItem);
|
||||
Assert.Equal ("Three", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.Home));
|
||||
Assert.True (Application.OnKeyDown (Key.Home));
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (0, cb.SelectedItem);
|
||||
Assert.Equal ("One", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.Esc));
|
||||
Assert.True (Application.OnKeyDown (Key.Esc));
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (0, cb.SelectedItem);
|
||||
Assert.Equal ("", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.CursorDown)); // losing focus
|
||||
Assert.True (Application.OnKeyDown (Key.CursorDown)); // losing focus
|
||||
Assert.False (cb.HasFocus);
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
@@ -959,7 +965,7 @@ Three
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
Assert.Equal ("One", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.U.WithCtrl));
|
||||
Assert.True (Application.OnKeyDown (Key.U.WithCtrl));
|
||||
Assert.True (cb.HasFocus);
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
@@ -968,7 +974,7 @@ Three
|
||||
top.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact (Skip = "BUGBUG: New focus stuff broke. Fix later.")]
|
||||
public void Source_Equal_Null_Or_Count_Equal_Zero_Sets_SelectedItem_Equal_To_Minus_One ()
|
||||
{
|
||||
var cb = new ComboBox ();
|
||||
@@ -985,7 +991,7 @@ Three
|
||||
source.Add ("One");
|
||||
Assert.Equal (1, cb.Source.Count);
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.F4));
|
||||
Assert.True (Application.OnKeyDown (Key.F4));
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (0, cb.SelectedItem);
|
||||
Assert.Equal ("One", cb.Text);
|
||||
@@ -996,12 +1002,12 @@ Three
|
||||
Assert.True (cb.IsShow);
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
Assert.Equal ("T", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.Enter));
|
||||
Assert.True (Application.OnKeyDown (Key.Enter));
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (2, cb.Source.Count);
|
||||
Assert.Equal (-1, cb.SelectedItem);
|
||||
Assert.Equal ("T", cb.Text);
|
||||
Assert.True (cb.NewKeyDownEvent (Key.Esc));
|
||||
Assert.True (Application.OnKeyDown (Key.Esc));
|
||||
Assert.False (cb.IsShow);
|
||||
Assert.Equal (-1, cb.SelectedItem); // retains last accept selected item
|
||||
Assert.Equal ("", cb.Text); // clear text
|
||||
|
||||
@@ -54,9 +54,9 @@ public class DatePickerTests
|
||||
Application.Begin (top);
|
||||
|
||||
// Set focus to next month button
|
||||
datePicker.AdvanceFocus (NavigationDirection.Forward);
|
||||
datePicker.AdvanceFocus (NavigationDirection.Forward);
|
||||
datePicker.AdvanceFocus (NavigationDirection.Forward);
|
||||
datePicker.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
datePicker.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
datePicker.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
|
||||
// Change month to December
|
||||
Assert.True (datePicker.NewKeyDownEvent (Key.Enter));
|
||||
@@ -81,8 +81,8 @@ public class DatePickerTests
|
||||
Application.Begin (top);
|
||||
|
||||
// set focus to the previous month button
|
||||
datePicker.AdvanceFocus (NavigationDirection.Forward);
|
||||
datePicker.AdvanceFocus (NavigationDirection.Forward);
|
||||
datePicker.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
datePicker.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop);
|
||||
|
||||
// Change month to January
|
||||
Assert.True (datePicker.NewKeyDownEvent (Key.Enter));
|
||||
|
||||
@@ -50,9 +50,15 @@ public class RadioGroupTests (ITestOutputHelper output)
|
||||
public void Initialize_SelectedItem_With_Minus_One ()
|
||||
{
|
||||
var rg = new RadioGroup { RadioLabels = new [] { "Test" }, SelectedItem = -1 };
|
||||
Application.Current = new Toplevel ();
|
||||
Application.Current.Add (rg);
|
||||
rg.SetFocus ();
|
||||
|
||||
Assert.Equal (-1, rg.SelectedItem);
|
||||
Assert.True (rg.NewKeyDownEvent (Key.Space));
|
||||
Assert.True (Application.OnKeyDown (Key.Space));
|
||||
Assert.Equal (0, rg.SelectedItem);
|
||||
|
||||
Application.Current.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -73,41 +79,59 @@ public class RadioGroupTests (ITestOutputHelper output)
|
||||
public void KeyBindings_Command ()
|
||||
{
|
||||
var rg = new RadioGroup { RadioLabels = new [] { "Test", "New Test" } };
|
||||
Application.Current = new Toplevel ();
|
||||
Application.Current.Add (rg);
|
||||
rg.SetFocus();
|
||||
|
||||
Assert.True (rg.NewKeyDownEvent (Key.CursorUp));
|
||||
Assert.True (rg.NewKeyDownEvent (Key.CursorDown));
|
||||
Assert.True (rg.NewKeyDownEvent (Key.Home));
|
||||
Assert.True (rg.NewKeyDownEvent (Key.End));
|
||||
Assert.True (rg.NewKeyDownEvent (Key.Space));
|
||||
Assert.Equal(Orientation.Vertical, rg.Orientation);
|
||||
Assert.Equal(0, rg.SelectedItem);
|
||||
Assert.True (Application.OnKeyDown (Key.CursorUp)); // Should not change (should focus prev if there was one)
|
||||
Assert.Equal (0, rg.SelectedItem);
|
||||
Assert.True (Application.OnKeyDown (Key.CursorDown));
|
||||
Assert.True (Application.OnKeyDown (Key.Space));
|
||||
Assert.Equal (1, rg.SelectedItem);
|
||||
Assert.True (Application.OnKeyDown (Key.CursorDown)); // Should not change (should focus prev if there was one)
|
||||
Assert.True (Application.OnKeyDown (Key.Space));
|
||||
Assert.Equal (1, rg.SelectedItem);
|
||||
Assert.True (Application.OnKeyDown (Key.Home));
|
||||
Assert.True (Application.OnKeyDown (Key.Space));
|
||||
Assert.Equal (0, rg.SelectedItem);
|
||||
Assert.True (Application.OnKeyDown (Key.End));
|
||||
Assert.True (Application.OnKeyDown (Key.Space));
|
||||
Assert.Equal (1, rg.SelectedItem);
|
||||
Assert.True (Application.OnKeyDown (Key.Space));
|
||||
Assert.Equal (1, rg.SelectedItem);
|
||||
Application.Current.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HotKeys_Select_RadioLabels ()
|
||||
{
|
||||
var rg = new RadioGroup { RadioLabels = new [] { "_Left", "_Right", "Cen_tered", "_Justified" } };
|
||||
Application.Current = new Toplevel ();
|
||||
Application.Current.Add (rg);
|
||||
rg.SetFocus ();
|
||||
|
||||
Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L));
|
||||
Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L | KeyCode.ShiftMask));
|
||||
Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L | KeyCode.AltMask));
|
||||
|
||||
// BUGBUG: These tests only test that RG works on it's own, not if it's a subview
|
||||
Assert.True (rg.NewKeyDownEvent (Key.T));
|
||||
Assert.True (Application.OnKeyDown (Key.T));
|
||||
Assert.Equal (2, rg.SelectedItem);
|
||||
Assert.True (rg.NewKeyDownEvent (Key.L));
|
||||
Assert.True (Application.OnKeyDown (Key.L));
|
||||
Assert.Equal (0, rg.SelectedItem);
|
||||
Assert.True (rg.NewKeyDownEvent (Key.J));
|
||||
Assert.True (Application.OnKeyDown (Key.J));
|
||||
Assert.Equal (3, rg.SelectedItem);
|
||||
Assert.True (rg.NewKeyDownEvent (Key.R));
|
||||
Assert.True (Application.OnKeyDown (Key.R));
|
||||
Assert.Equal (1, rg.SelectedItem);
|
||||
|
||||
Assert.True (rg.NewKeyDownEvent (Key.T.WithAlt));
|
||||
Assert.True (Application.OnKeyDown (Key.T.WithAlt));
|
||||
Assert.Equal (2, rg.SelectedItem);
|
||||
Assert.True (rg.NewKeyDownEvent (Key.L.WithAlt));
|
||||
Assert.True (Application.OnKeyDown (Key.L.WithAlt));
|
||||
Assert.Equal (0, rg.SelectedItem);
|
||||
Assert.True (rg.NewKeyDownEvent (Key.J.WithAlt));
|
||||
Assert.True (Application.OnKeyDown (Key.J.WithAlt));
|
||||
Assert.Equal (3, rg.SelectedItem);
|
||||
Assert.True (rg.NewKeyDownEvent (Key.R.WithAlt));
|
||||
Assert.True (Application.OnKeyDown (Key.R.WithAlt));
|
||||
Assert.Equal (1, rg.SelectedItem);
|
||||
|
||||
var superView = new View ();
|
||||
@@ -129,6 +153,8 @@ public class RadioGroupTests (ITestOutputHelper output)
|
||||
Assert.Equal (3, rg.SelectedItem);
|
||||
Assert.True (superView.NewKeyDownEvent (Key.R.WithAlt));
|
||||
Assert.Equal (1, rg.SelectedItem);
|
||||
|
||||
Application.Current.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user