mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
* 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
159 lines
6.8 KiB
C#
159 lines
6.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Terminal.Gui;
|
|
|
|
namespace UICatalog.Scenarios;
|
|
|
|
[ScenarioMetadata ("ListView & ComboBox", "Demonstrates a ListView populating a ComboBox that acts as a filter.")]
|
|
[ScenarioCategory ("Controls")]
|
|
[ScenarioCategory ("ListView")]
|
|
[ScenarioCategory ("ComboBox")]
|
|
public class ListsAndCombos : Scenario
|
|
{
|
|
public override void Setup ()
|
|
{
|
|
//TODO: Duplicated code in Demo.cs Consider moving to shared assembly
|
|
List<string> items = new ();
|
|
|
|
foreach (string dir in new [] { "/etc", @$"{Environment.GetEnvironmentVariable ("SystemRoot")}\System32" })
|
|
{
|
|
if (Directory.Exists (dir))
|
|
{
|
|
items = Directory.GetFiles (dir)
|
|
.Union (Directory.GetDirectories (dir))
|
|
.Select (Path.GetFileName)
|
|
.Where (x => char.IsLetterOrDigit (x [0]))
|
|
.OrderBy (x => x)
|
|
.Select (x => x)
|
|
.ToList ();
|
|
}
|
|
}
|
|
|
|
// ListView
|
|
var lbListView = new Label
|
|
{
|
|
ColorScheme = Colors.ColorSchemes ["TopLevel"],
|
|
X = 0,
|
|
AutoSize = false,
|
|
Width = Dim.Percent (40),
|
|
Text = "Listview"
|
|
};
|
|
|
|
var listview = new ListView
|
|
{
|
|
X = 0,
|
|
Y = Pos.Bottom (lbListView) + 1,
|
|
Height = Dim.Fill (2),
|
|
Width = Dim.Percent (40),
|
|
Source = new ListWrapper (items)
|
|
};
|
|
listview.SelectedItemChanged += (s, e) => lbListView.Text = items [listview.SelectedItem];
|
|
Win.Add (lbListView, listview);
|
|
|
|
var scrollBar = new ScrollBarView (listview, true);
|
|
|
|
scrollBar.ChangedPosition += (s, e) =>
|
|
{
|
|
listview.TopItem = scrollBar.Position;
|
|
|
|
if (listview.TopItem != scrollBar.Position)
|
|
{
|
|
scrollBar.Position = listview.TopItem;
|
|
}
|
|
|
|
listview.SetNeedsDisplay ();
|
|
};
|
|
|
|
scrollBar.OtherScrollBarView.ChangedPosition += (s, e) =>
|
|
{
|
|
listview.LeftItem = scrollBar.OtherScrollBarView.Position;
|
|
|
|
if (listview.LeftItem != scrollBar.OtherScrollBarView.Position)
|
|
{
|
|
scrollBar.OtherScrollBarView.Position = listview.LeftItem;
|
|
}
|
|
|
|
listview.SetNeedsDisplay ();
|
|
};
|
|
|
|
listview.DrawContent += (s, e) =>
|
|
{
|
|
scrollBar.Size = listview.Source.Count - 1;
|
|
scrollBar.Position = listview.TopItem;
|
|
scrollBar.OtherScrollBarView.Size = listview.MaxLength - 1;
|
|
scrollBar.OtherScrollBarView.Position = listview.LeftItem;
|
|
scrollBar.Refresh ();
|
|
};
|
|
|
|
// ComboBox
|
|
var lbComboBox = new Label
|
|
{
|
|
ColorScheme = Colors.ColorSchemes ["TopLevel"],
|
|
X = Pos.Right (lbListView) + 1,
|
|
AutoSize = false,
|
|
Width = Dim.Percent (40),
|
|
Text = "ComboBox"
|
|
};
|
|
|
|
var comboBox = new ComboBox
|
|
{
|
|
X = Pos.Right (listview) + 1,
|
|
Y = Pos.Bottom (lbListView) + 1,
|
|
Height = Dim.Fill (2),
|
|
Width = Dim.Percent (40)
|
|
};
|
|
comboBox.SetSource (items);
|
|
|
|
comboBox.SelectedItemChanged += (s, text) => lbComboBox.Text = text.Value.ToString ();
|
|
Win.Add (lbComboBox, comboBox);
|
|
|
|
var scrollBarCbx = new ScrollBarView (comboBox.Subviews [1], true);
|
|
|
|
scrollBarCbx.ChangedPosition += (s, e) =>
|
|
{
|
|
((ListView)comboBox.Subviews [1]).TopItem = scrollBarCbx.Position;
|
|
|
|
if (((ListView)comboBox.Subviews [1]).TopItem != scrollBarCbx.Position)
|
|
{
|
|
scrollBarCbx.Position = ((ListView)comboBox.Subviews [1]).TopItem;
|
|
}
|
|
|
|
comboBox.SetNeedsDisplay ();
|
|
};
|
|
|
|
scrollBarCbx.OtherScrollBarView.ChangedPosition += (s, e) =>
|
|
{
|
|
((ListView)comboBox.Subviews [1]).LeftItem = scrollBarCbx.OtherScrollBarView.Position;
|
|
|
|
if (((ListView)comboBox.Subviews [1]).LeftItem != scrollBarCbx.OtherScrollBarView.Position)
|
|
{
|
|
scrollBarCbx.OtherScrollBarView.Position = ((ListView)comboBox.Subviews [1]).LeftItem;
|
|
}
|
|
|
|
comboBox.SetNeedsDisplay ();
|
|
};
|
|
|
|
comboBox.DrawContent += (s, e) =>
|
|
{
|
|
scrollBarCbx.Size = comboBox.Source.Count;
|
|
scrollBarCbx.Position = ((ListView)comboBox.Subviews [1]).TopItem;
|
|
scrollBarCbx.OtherScrollBarView.Size = ((ListView)comboBox.Subviews [1]).MaxLength - 1;
|
|
scrollBarCbx.OtherScrollBarView.Position = ((ListView)comboBox.Subviews [1]).LeftItem;
|
|
scrollBarCbx.Refresh ();
|
|
};
|
|
|
|
var btnMoveUp = new Button { X = 1, Y = Pos.Bottom (lbListView), Text = "Move _Up" };
|
|
btnMoveUp.Accept += (s, e) => { listview.MoveUp (); };
|
|
|
|
var btnMoveDown = new Button
|
|
{
|
|
X = Pos.Right (btnMoveUp) + 1, Y = Pos.Bottom (lbListView), Text = "Move _Down"
|
|
};
|
|
btnMoveDown.Accept += (s, e) => { listview.MoveDown (); };
|
|
|
|
Win.Add (btnMoveUp, btnMoveDown);
|
|
}
|
|
}
|