Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b0f050f
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig Mar 21, 2025
a64b4bc
touching publish.yml
tig Mar 21, 2025
320384e
Merge branch 'v2_release' into v2_develop
tig Mar 21, 2025
4048436
Merge branch 'gui-cs:v2_develop' into v2_develop
tig Mar 29, 2025
3b0311d
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig Mar 29, 2025
ae79c48
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig Mar 30, 2025
1c39896
Merge branch 'gui-cs:v2_develop' into v2_develop
tig Apr 1, 2025
2cee67f
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig Apr 1, 2025
9560cf3
Merge branch 'gui-cs:v2_develop' into v2_develop
tig Apr 2, 2025
0795dd1
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig Apr 2, 2025
4baccd7
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig Apr 3, 2025
7d7ffad
Merge branch 'gui-cs:v2_develop' into v2_develop
tig Apr 5, 2025
c37210a
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig Apr 5, 2025
680e5ae
Merge branch 'gui-cs:v2_develop' into v2_develop
tig Apr 16, 2025
3cba0a5
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig Apr 23, 2025
9bbec08
Merge branch 'gui-cs:v2_develop' into v2_develop
tig Apr 24, 2025
64403fa
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig Apr 24, 2025
5e1251c
Merge branch 'gui-cs:v2_develop' into v2_develop
tig Apr 24, 2025
49cd335
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig Apr 25, 2025
9a8e4e3
Merge branch 'gui-cs:v2_develop' into v2_develop
tig Apr 25, 2025
ef6d193
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig Apr 25, 2025
4c0c504
Merge branch 'gui-cs:v2_develop' into v2_develop
tig Apr 25, 2025
6d4cfe5
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig Apr 25, 2025
4f5fca2
Merge branch 'gui-cs:v2_develop' into v2_develop
tig Apr 28, 2025
f8bfab8
Merge branch 'gui-cs:v2_develop' into v2_develop
tig Apr 28, 2025
898c2de
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig Apr 28, 2025
0386a89
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig May 7, 2025
cd10bb3
Merge branch 'gui-cs:v2_develop' into v2_develop
tig May 7, 2025
4b6e0c5
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig May 7, 2025
39f153f
Added unit tests.
tig May 9, 2025
e56931f
Merge branch 'v2_develop' into v2_4074-Popover_Eats_Space
tig May 9, 2025
242d938
Merge branch 'v2_develop' into v2_4074-Popover_Eats_Space
tig May 9, 2025
edc9948
Actually fixed bug.
tig May 11, 2025
d8c5528
Addres Bdisp feedback
tig May 11, 2025
1c64ed0
Addres Bdisp feedback2
tig May 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Terminal.Gui/View/View.Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ private void SetupCommands ()

SetFocus ();

// Always return true on hotkey, even if SetFocus fails because
// hotkeys are always handled by the View (unless RaiseHandlingHotKey cancels).
return true;
});

Expand All @@ -45,9 +47,9 @@ private void SetupCommands ()

if (CanFocus)
{
SetFocus ();

return true;
// For Select, if the view is focusable and SetFocus succeeds, by defition,
// the event is handled. So return what SetFocus returns.
return SetFocus ();
}

return false;
Expand Down
9 changes: 6 additions & 3 deletions Terminal.Gui/Views/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Label ()
Width = Dim.Auto (DimAutoStyle.Text);

// On HoKey, pass it to the next view
AddCommand (Command.HotKey, InvokeHotKeyOnNext);
AddCommand (Command.HotKey, InvokeHotKeyOnNextPeer);

TitleChanged += Label_TitleChanged;
MouseClick += Label_MouseClick;
Expand Down Expand Up @@ -59,7 +59,7 @@ public override Rune HotKeySpecifier
set => TextFormatter.HotKeySpecifier = base.HotKeySpecifier = value;
}

private bool? InvokeHotKeyOnNext (ICommandContext commandContext)
private bool? InvokeHotKeyOnNextPeer (ICommandContext commandContext)
{
if (RaiseHandlingHotKey () == true)
{
Expand All @@ -70,16 +70,19 @@ public override Rune HotKeySpecifier
{
SetFocus ();

// Always return true on hotkey, even if SetFocus fails because
// hotkeys are always handled by the View (unless RaiseHandlingHotKey cancels).
// This is the same behavior as the base (View).
return true;
}

if (HotKey.IsValid)
{
// If the Label has a hotkey, we need to find the next view in the subview list
int me = SuperView?.SubViews.IndexOf (this) ?? -1;

if (me != -1 && me < SuperView?.SubViews.Count - 1)
{

return SuperView?.SubViews.ElementAt (me + 1).InvokeCommand (Command.HotKey) == true;
}
}
Expand Down
75 changes: 75 additions & 0 deletions Tests/IntegrationTests/FluentTests/MenuBarv2Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,79 @@ public void MenuBarItem_Without_QuitKey_Open_QuitKey_Does_Not_Quit_MenuBar_Super
.WriteOutLogs (_out)
.Stop ();
}

[Theory]
[ClassData (typeof (V2TestDrivers))]
public void MenuBar_Not_Active_DoesNotEat_Space (V2TestDriver d)
{
int spaceKeyDownCount = 0;
View testView = new View ()
{
CanFocus = true,
Id = "testView",
};

testView.KeyDown += (sender, key) =>
{
if (key == Key.Space)
{
spaceKeyDownCount++;
}
};

using GuiTestContext c = With.A<Window> (50, 20, d)
.Then (
() =>
{
var menuBar = new MenuBarv2 ();
Toplevel top = Application.Top!;
menuBar.EnableForDesign (ref top);
Application.Top!.Add (menuBar);
})
.Add (testView)
.WaitIteration ()
.Focus (testView)
.RaiseKeyDownEvent (Key.Space)
.Then (() => Assert.Equal (1, spaceKeyDownCount))
.WriteOutLogs (_out)
.Stop ();
}

[Theory]
[ClassData (typeof (V2TestDrivers))]
public void MenuBar_Not_Active_DoesNotEat_Enter (V2TestDriver d)
{
int enterKeyDownCount = 0;
View testView = new View ()
{
CanFocus = true,
Id = "testView",
};

testView.KeyDown += (sender, key) =>
{
if (key == Key.Enter)
{
enterKeyDownCount++;
}
};

using GuiTestContext c = With.A<Window> (50, 20, d)
.Then (
() =>
{
var menuBar = new MenuBarv2 ();
Toplevel top = Application.Top!;
menuBar.EnableForDesign (ref top);
Application.Top!.Add (menuBar);
})
.Add (testView)
.WaitIteration ()
.Focus (testView)
.RaiseKeyDownEvent (Key.Enter)
.Then (() => Assert.Equal (1, enterKeyDownCount))
.WriteOutLogs (_out)
.Stop ();
}

}
120 changes: 112 additions & 8 deletions Tests/IntegrationTests/FluentTests/PopverMenuTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public void EnableForDesign_CreatesMenuItems (V2TestDriver d)
[ClassData (typeof (V2TestDrivers))]
public void Activate_Sets_Application_Navigation_Correctly (V2TestDriver d)
{
MenuBarv2? menuBar = null;

using GuiTestContext c = With.A<Window> (50, 20, d)
.Then (
() =>
Expand Down Expand Up @@ -93,8 +91,6 @@ public void Activate_Sets_Application_Navigation_Correctly (V2TestDriver d)
[ClassData (typeof (V2TestDrivers))]
public void QuitKey_Hides (V2TestDriver d)
{
MenuBarv2? menuBar = null;

using GuiTestContext c = With.A<Window> (50, 20, d)
.Then (
() =>
Expand Down Expand Up @@ -145,8 +141,6 @@ public void QuitKey_Hides (V2TestDriver d)
[ClassData (typeof (V2TestDrivers))]
public void QuitKey_Restores_Focus_Correctly (V2TestDriver d)
{
MenuBarv2? menuBar = null;

using GuiTestContext c = With.A<Window> (50, 20, d)
.Then (
() =>
Expand Down Expand Up @@ -195,8 +189,6 @@ public void QuitKey_Restores_Focus_Correctly (V2TestDriver d)
[ClassData (typeof (V2TestDrivers))]
public void MenuBarItem_With_QuitKey_Open_QuitKey_Does_Not_Quit_App (V2TestDriver d)
{
MenuBarv2? menuBar = null;

using GuiTestContext c = With.A<Window> (50, 20, d)
.Then (
() =>
Expand Down Expand Up @@ -240,4 +232,116 @@ public void MenuBarItem_With_QuitKey_Open_QuitKey_Does_Not_Quit_App (V2TestDrive
.WriteOutLogs (_out)
.Stop ();
}


[Theory]
[ClassData (typeof (V2TestDrivers))]
public void Not_Active_DoesNotEat_Space (V2TestDriver d)
{
int spaceKeyDownCount = 0;
View testView = new View ()
{
CanFocus = true,
Id = "testView",
};

testView.KeyDown += (sender, key) =>
{
if (key == Key.Space)
{
spaceKeyDownCount++;
}
};

using GuiTestContext c = With.A<Window> (50, 20, d)
.Then (
() =>
{
var popoverMenu = new PopoverMenu();
Toplevel top = Application.Top!;
popoverMenu.EnableForDesign (ref top);
Application.Popover!.Register (popoverMenu);
})
.Add (testView)
.WaitIteration ()
.Focus (testView)
.RaiseKeyDownEvent (Key.Space)
.Then (() => Assert.Equal (1, spaceKeyDownCount))
.WriteOutLogs (_out)
.Stop ();
}

[Theory]
[ClassData (typeof (V2TestDrivers))]
public void Not_Active_DoesNotEat_Enter (V2TestDriver d)
{
int enterKeyDownCount = 0;
View testView = new View ()
{
CanFocus = true,
Id = "testView",
};

testView.KeyDown += (sender, key) =>
{
if (key == Key.Enter)
{
enterKeyDownCount++;
}
};

using GuiTestContext c = With.A<Window> (50, 20, d)
.Then (
() =>
{
var popoverMenu = new PopoverMenu ();
Toplevel top = Application.Top!;
popoverMenu.EnableForDesign (ref top);
Application.Popover!.Register (popoverMenu);
})
.Add (testView)
.WaitIteration ()
.Focus (testView)
.RaiseKeyDownEvent (Key.Enter)
.Then (() => Assert.Equal (1, enterKeyDownCount))
.WriteOutLogs (_out)
.Stop ();
}

[Theory]
[ClassData (typeof (V2TestDrivers))]
public void Not_Active_DoesNotEat_QuitKey (V2TestDriver d)
{
int quitKeyDownCount = 0;
View testView = new View ()
{
CanFocus = true,
Id = "testView",
};

testView.KeyDown += (sender, key) =>
{
if (key == Application.QuitKey)
{
quitKeyDownCount++;
}
};

using GuiTestContext c = With.A<Window> (50, 20, d)
.Then (
() =>
{
var popoverMenu = new PopoverMenu ();
Toplevel top = Application.Top!;
popoverMenu.EnableForDesign (ref top);
Application.Popover!.Register (popoverMenu);
})
.Add (testView)
.WaitIteration ()
.Focus (testView)
.RaiseKeyDownEvent (Application.QuitKey)
.Then (() => Assert.Equal (1, quitKeyDownCount))
.WriteOutLogs (_out)
.Stop ();
}
}
4 changes: 2 additions & 2 deletions Tests/UnitTests/View/ViewCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void Button_CanFocus_False_Raises_Accepted_Correctly ()
};

int btnAcceptedCount = 0;
bool btnCancelAccepting = false;
bool btnCancelAccepting = true;
var btn = new Button ()
{
Title = "Button",
Expand Down Expand Up @@ -148,7 +148,7 @@ public void Button_CanFocus_False_Raises_Accepted_Correctly ()
});

Assert.Equal (1, btnAcceptedCount);
Assert.Equal (2, wAcceptedCount);
Assert.Equal (0, wAcceptedCount);

Application.ResetState (true);
}
Expand Down
Loading