mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 00:46:39 +01:00
Updated ListViewWithSelection
This commit is contained in:
@@ -12,15 +12,13 @@ public class LineViewExample : Scenario
|
||||
public override void Main ()
|
||||
{
|
||||
// Setup - Create a top-level application window and configure it.
|
||||
Toplevel appWindow = new ()
|
||||
{
|
||||
};
|
||||
Toplevel appWindow = new ();
|
||||
|
||||
var menu = new MenuBar
|
||||
{
|
||||
Menus =
|
||||
[
|
||||
new MenuBarItem ("_File", new MenuItem [] { new ("_Quit", "", () => Quit ()) })
|
||||
new ("_File", new MenuItem [] { new ("_Quit", "", () => Quit ()) })
|
||||
]
|
||||
};
|
||||
appWindow.Add (menu);
|
||||
|
||||
@@ -47,19 +47,24 @@ public class ListColumns : Scenario
|
||||
return list;
|
||||
}
|
||||
|
||||
public override void Setup ()
|
||||
public override void Main ()
|
||||
{
|
||||
Win.Title = GetName ();
|
||||
Win.Y = 1; // menu
|
||||
Win.Height = Dim.Fill (1); // status bar
|
||||
// Init
|
||||
Application.Init ();
|
||||
|
||||
_listColView = new()
|
||||
// Setup - Create a top-level application window and configure it.
|
||||
Toplevel appWindow = new ()
|
||||
{
|
||||
Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
|
||||
};
|
||||
|
||||
_listColView = new ()
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Y = 1,
|
||||
Width = Dim.Fill (),
|
||||
Height = Dim.Fill (1),
|
||||
Style = new()
|
||||
Style = new ()
|
||||
{
|
||||
ShowHeaders = false,
|
||||
ShowHorizontalHeaderOverline = false,
|
||||
@@ -209,38 +214,20 @@ public class ListColumns : Scenario
|
||||
]
|
||||
};
|
||||
|
||||
Top.Add (menu);
|
||||
appWindow.Add (menu);
|
||||
|
||||
var statusBar = new StatusBar (
|
||||
#if V2_STATUSBAR
|
||||
new StatusItem []
|
||||
new Shortcut []
|
||||
{
|
||||
new (
|
||||
KeyCode.F2,
|
||||
"~F2~ OpenBigListEx",
|
||||
() => OpenSimpleList (true)
|
||||
),
|
||||
new (
|
||||
KeyCode.F3,
|
||||
"~F3~ CloseExample",
|
||||
() => CloseExample ()
|
||||
),
|
||||
new (
|
||||
KeyCode.F4,
|
||||
"~F4~ OpenSmListEx",
|
||||
() => OpenSimpleList (false)
|
||||
),
|
||||
new (
|
||||
Application.QuitKey,
|
||||
$"{Application.QuitKey} to Quit",
|
||||
() => Quit ()
|
||||
)
|
||||
new (Key.F2, "OpenBigListEx", () => OpenSimpleList (true)),
|
||||
new (Key.F3, "CloseExample", CloseExample),
|
||||
new (Key.F4, "OpenSmListEx", () => OpenSimpleList (false)),
|
||||
new (Application.QuitKey, "Quit", Quit)
|
||||
}
|
||||
#endif
|
||||
);
|
||||
Top.Add (statusBar);
|
||||
appWindow.Add (statusBar);
|
||||
|
||||
Win.Add (_listColView);
|
||||
appWindow.Add (_listColView);
|
||||
|
||||
var selectedCellLabel = new Label
|
||||
{
|
||||
@@ -252,18 +239,18 @@ public class ListColumns : Scenario
|
||||
TextAlignment = Alignment.End
|
||||
};
|
||||
|
||||
Win.Add (selectedCellLabel);
|
||||
appWindow.Add (selectedCellLabel);
|
||||
|
||||
_listColView.SelectedCellChanged += (s, e) => { selectedCellLabel.Text = $"{_listColView.SelectedRow},{_listColView.SelectedColumn}"; };
|
||||
_listColView.KeyDown += TableViewKeyPress;
|
||||
|
||||
SetupScrollBar ();
|
||||
|
||||
_alternatingColorScheme = new()
|
||||
_alternatingColorScheme = new ()
|
||||
{
|
||||
Disabled = Win.ColorScheme.Disabled,
|
||||
HotFocus = Win.ColorScheme.HotFocus,
|
||||
Focus = Win.ColorScheme.Focus,
|
||||
Disabled = appWindow.ColorScheme.Disabled,
|
||||
HotFocus = appWindow.ColorScheme.HotFocus,
|
||||
Focus = appWindow.ColorScheme.Focus,
|
||||
Normal = new (Color.White, Color.BrightBlue)
|
||||
};
|
||||
|
||||
@@ -271,6 +258,13 @@ public class ListColumns : Scenario
|
||||
_listColView.MouseClick += (s, e) => { _listColView.ScreenToCell (e.MouseEvent.Position, out int? clickedCol); };
|
||||
|
||||
_listColView.KeyBindings.Add (Key.Space, Command.Accept);
|
||||
|
||||
// Run - Start the application.
|
||||
Application.Run (appWindow);
|
||||
appWindow.Dispose ();
|
||||
|
||||
// Shutdown - Calling Application.Shutdown is required.
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
private void CloseExample () { _listColView.Table = null; }
|
||||
@@ -372,7 +366,7 @@ public class ListColumns : Scenario
|
||||
|
||||
private void TableViewKeyPress (object sender, Key e)
|
||||
{
|
||||
if (e.KeyCode == KeyCode.Delete)
|
||||
if (e.KeyCode == Key.Delete)
|
||||
{
|
||||
// set all selected cells to null
|
||||
foreach (Point pt in _listColView.GetAllSelectedCells ())
|
||||
|
||||
Reference in New Issue
Block a user