Files
Terminal.Gui/UICatalog/Scenarios/HotKeys.cs
Tig 16055c53b0 Fixes #3039. Fix View.HotKey (#3249)
* Added View.DefaultCommand etc... Started on dedicated scenario

* Fixed un-shifted hotkeys -> Fixed Key Equals. Fixed WindowsDriver passing wrong key. Etc.

* Fixed Key Bindings and HotKeys

* Fixed Key Bindings and HotKeys

* Label now correctly supports hotkey

* Disabled unix hot keys because they are annoying and get in the way

* Updated nuget. fixed warnings

* Trying to fix ci/ci issue

* Trying to fix ci/ci issue

* Trying to fix ci/ci issue

* Changed TextChangingEventArgs to inherit from CancelEventArgs

* TextChangingEventArgs -> TextEventArgs

* Simplified Text events by having only on args class

* Fixed unit tests fail

* Simplified by removing TitleEventArgs

* POC of Title being primary for hotkey. Label and Button hacked to work

* POC of Title being primary for hotkey. Label and Button hacked to work - all unit tests pass

* Dropped Microsoft.NETFramework.ReferenceAssemblies

* Fixed Dialogs scenario hotkeys

* Fixed build warnings

* Fixed Border Title render bug

* Regiggering default command handling

* Regiggering default command handling

* Checkbox clean up

* Added StateEventArgs POC

* Command.Default -> Command.HotKey

* Command.Default -> Command.HotKey - fixed TableView

* Command.Default -> Command.HotKey - fixed TableView

* Updated reactive example

* Fixed Toplevel.BringOverlappedTopToFront - was reordering SubViews when it shouldn't

* WIP - broke

* Finished impl of StateEventArgs

* Deleted ToggleEventArgs.cs. Added StateEventArgs.cs

* XML doc fix

* Removed old code

* Removed commented out code

* Label.Clicked -> Label.Accept (missed this before)

* Removed Labels as Buttons scenario as it's not really  useful

* Moved SubView tests to own file

* Moved SubView tests to own file

* Simplified Text test

* Added OnAccept test

* Deleted DefaultCommand

* Modernized CheckBox

* New button test

* Cleaned up RadioGroup; added tests

* KeyCode->Key in ListView

* Added ListView unit tests

* ListView now does Accept correctly

* TreeView now does Accept correctly

* Cleaned up some TextField tests

* TextView now handles Accept properly; updated CharMap and Adornments scenarios to test

* Fixed ComboBox to deal with TextView now handles Accept properly; updated CharMap and Adornments scenarios to test

* Removed un-needed using statement
2024-02-22 15:11:26 -07:00

139 lines
5.3 KiB
C#

using Terminal.Gui;
namespace UICatalog.Scenarios;
[ScenarioMetadata ("HotKeys", "Demonstrates how HotKeys work.")]
[ScenarioCategory ("Controls")]
[ScenarioCategory("Mouse and Keyboard")]
public class HotKeys : Scenario
{
public override void Init ()
{
Application.Init ();
ConfigurationManager.Themes.Theme = Theme;
ConfigurationManager.Apply ();
Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
Application.Top.BorderStyle = LineStyle.RoundedDotted;
Application.Top.Title = $"{Application.QuitKey} to _Quit - Scenario: {GetName ()}";
}
public override void Run ()
{
var textViewLabel = new Label { Text = "_TextView:", X = 0, Y = 0 };
Application.Top.Add (textViewLabel);
var textField = new TextField (){ X = Pos.Right (textViewLabel) + 1, Y = 0, Width = 10 };
Application.Top.Add (textField);
var viewLabel = new Label { Text = "_View:", X = 0, Y = Pos.Bottom (textField) + 1 };
Application.Top.Add (viewLabel);
var view = new View () {
Title = "View (_focusable)",
Text = "Text renders _Underscore",
CanFocus = true,
X = Pos.Right (viewLabel) + 1, Y = Pos.Top (viewLabel), Width = 30, Height = 3,
BorderStyle = LineStyle.Dashed,
};
Application.Top.Add (view);
viewLabel = new Label { Text = "Vi_ew:", X = 0, Y = Pos.Bottom (view) + 1 };
Application.Top.Add (viewLabel);
view = new View ()
{
Title = "View (n_ot focusable)",
Text = "Text renders _Underscore",
X = Pos.Right (viewLabel) + 1, Y = Pos.Top (viewLabel), Width = 30, Height = 3,
BorderStyle = LineStyle.Dashed,
};
Application.Top.Add (view);
var labelWithFrameLabel = new Label { Text = "_Label with Frame:", X = 0, Y = Pos.Bottom (view) + 1 };
Application.Top.Add (labelWithFrameLabel);
var labelWithFrameFocusable = new Label ()
{
AutoSize = false,
Title = "Label _with Frame (focusable)",
CanFocus = true,
X = Pos.Right (labelWithFrameLabel) + 1, Y = Pos.Top (labelWithFrameLabel), Width = 40, Height = 3,
BorderStyle = LineStyle.Dashed,
};
Application.Top.Add (labelWithFrameFocusable);
labelWithFrameLabel = new Label { Text = "L_abel with Frame:", X = 0, Y = Pos.Bottom (labelWithFrameFocusable) + 1 };
Application.Top.Add (labelWithFrameLabel);
var labelWithFrame = new Label ()
{
AutoSize = false,
Title = "Label with Frame (_not focusable)",
X = Pos.Right (labelWithFrameLabel) + 1, Y = Pos.Top (labelWithFrameLabel), Width = 40, Height = 3,
BorderStyle = LineStyle.Dashed,
};
Application.Top.Add (labelWithFrame);
var buttonWithFrameLabel = new Label { Text = "_Button with Frame:", X = 0, Y = Pos.Bottom (labelWithFrame) + 1 };
Application.Top.Add (buttonWithFrameLabel);
var buttonWithFrameFocusable = new Button ()
{
AutoSize = false,
Title = "B_utton with Frame (focusable)",
CanFocus = true,
X = Pos.Right (buttonWithFrameLabel) + 1, Y = Pos.Top (buttonWithFrameLabel), Width = 40, Height = 3,
BorderStyle = LineStyle.Dashed,
};
Application.Top.Add (buttonWithFrameFocusable);
buttonWithFrameLabel = new Label { Text = "Butt_on with Frame:", X = 0, Y = Pos.Bottom (buttonWithFrameFocusable) + 1 };
Application.Top.Add (buttonWithFrameLabel);
var buttonWithFrame = new Button ()
{
AutoSize = false,
Title = "Button with Frame (not focusab_le)",
X = Pos.Right (buttonWithFrameLabel) + 1, Y = Pos.Top (buttonWithFrameLabel), Width = 40, Height = 3,
CanFocus = false,
BorderStyle = LineStyle.Dashed,
};
Application.Top.Add (buttonWithFrame);
var checkboxWithFrameLabel = new Label { Text = "_Checkbox with Frame:", X = 0, Y = Pos.Bottom (buttonWithFrame) + 1 };
Application.Top.Add (checkboxWithFrameLabel);
var checkboxWithFrameFocusable = new CheckBox
{
AutoSize = false,
Title = "C_heckbox with Frame (focusable)",
CanFocus = true,
X = Pos.Right (checkboxWithFrameLabel) + 1, Y = Pos.Top (checkboxWithFrameLabel), Width = 40, Height = 3,
BorderStyle = LineStyle.Dashed,
};
Application.Top.Add (checkboxWithFrameFocusable);
checkboxWithFrameLabel = new Label { Text = "Checkb_ox with Frame:", X = 0, Y = Pos.Bottom (checkboxWithFrameFocusable) + 1 };
Application.Top.Add (checkboxWithFrameLabel);
var checkboxWithFrame = new CheckBox
{
AutoSize = false,
Title = "Checkbox with Frame (not focusable)",
X = Pos.Right (checkboxWithFrameLabel) + 1, Y = Pos.Top (checkboxWithFrameLabel), Width = 40, Height = 3,
CanFocus = false,
BorderStyle = LineStyle.Dashed,
};
Application.Top.Add (checkboxWithFrame);
var button = new Button { X = Pos.Center (), Y = Pos.AnchorEnd (1), Text = "_Press me!" };
Application.Top.Add (button);
Application.Run (Application.Top);
}
}