Fixed a bunch of Keybinding issues

This commit is contained in:
Tig Kindel
2024-01-09 17:28:18 -07:00
committed by Tig
parent e7d2e3a55f
commit b2ab344a08
2 changed files with 56 additions and 2 deletions

View File

@@ -8,13 +8,14 @@ public class BarItem : View {
public BarItem ()
{
Height = 1;
AddCommand (Command.ToggleExpandCollapse, () => { Visible = !Visible; return true; });
}
public override string Text {
set {
base.Text = $"{KeyBindings.Bindings.FirstOrDefault (b => b.Value.Scope != KeyBindingScope.Focused).Key} `{value}`";
base.Text = $"{KeyBindings.Bindings.FirstOrDefault (b => b.Value.Scope != KeyBindingScope.Focused).Key} {value}";
}
get {
return $"{KeyBindings.Bindings.FirstOrDefault(b => b.Value.Scope != KeyBindingScope.Focused).Key} `{base.Text}`";
return $"{KeyBindings.Bindings.FirstOrDefault(b => b.Value.Scope != KeyBindingScope.Focused).Key} {base.Text}";
}
}
}
@@ -36,6 +37,7 @@ public class Bar : View {
Height = 1;
AutoSize = false;
ColorScheme = Colors.Menu;
CanFocus = true;
}
public override void Add (View view)

View File

@@ -0,0 +1,52 @@
using Terminal.Gui;
namespace UICatalog.Scenarios;
[ScenarioMetadata (Name: "Bars", Description: "Illustrates Bar views (e.g. StatusBar)")]
[ScenarioCategory ("Controls")]
public class bars : Scenario {
public override void Init ()
{
Application.Init ();
ConfigurationManager.Themes.Theme = Theme;
ConfigurationManager.Apply ();
Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
Application.Top.Loaded += Top_Initialized;
}
// Setting everything up in Initialized handler because we change the
// QuitKey and it only sticks if changed after init
void Top_Initialized (object sender, System.EventArgs e)
{
Application.QuitKey = Key.Z.WithCtrl;
var bar = new Bar () {
};
var barITem = new BarItem () { Text = $"Quit - {Application.QuitKey}", AutoSize = true };
barITem.KeyBindings.Add (Application.QuitKey, KeyBindingScope.Application, Command.QuitToplevel);
bar.Add (barITem);
barITem = new BarItem () { Text = $"Show/Hide - {Key.F10}", AutoSize = true };
barITem.KeyBindings.Add (Key.F10, KeyBindingScope.Application, Command.ToggleExpandCollapse);
bar.Add (barITem);
bar.Add (new Label () { Text = "FocusLabel", CanFocus = true });
var button = new Button ("Press me!") {
AutoSize = true
};
button.Clicked += Button_Clicked;
bar.Add (button);
button = new Button ("Or me!") {
AutoSize = true,
};
button.Clicked += Button_Clicked;
bar.Add (button);
Application.Top.Add (bar);
}
void Button_Clicked (object sender, System.EventArgs e) => MessageBox.Query("Hi", $"You clicked {sender}");
}