mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
* Remove NStack and replace ustring to string.
* Add unit test and improving some code.
* Adjust code and fix all unit tests errors.
* Add XML Document and move the Rune folder into the Text folder.
* Improve unit tests with byte array on DecodeRune and DecodeLastRune.
* Fix unit test.
* 😂Code review
* Reduce unit tests code.
* Change StringExtensions.Make to StringExtensions.ToString and added some more unit tests.
* Fix merge errors.
* Remove GetTextWidth and calls replaced with StringExtensions.GetColumns.
* Hack to use UseSystemConsole passed in the command line arguments.
* Revert "Hack to use UseSystemConsole passed in the command line arguments."
This reverts commit b74d11c786.
* Remove Application.UseSystemConsole from the config file.
* Fix errors related by removing UseSystemConsole from the config file.
* Fixes #2633. DecodeEscSeq throw an exception if cki is null.
* Fix an exception if SelectedItem is -1.
* Set SelectedItem to 0 and remove unnecessary ToString.
* Using a unique ToString method for Rune and other for byte.
* Fix a bug where a wider rune is added with only a width of 1.
* Force the SelectedGlyph is the one that was typed after jumpList is executed.
* Added more InlineData to RuneTests.
* Reducing significantly the code by using Theory attribute in the TextFormatterTests.
* Override PositionCursor to handle the CharMap cursor position.
* Fix merge errors.
* Minor tweaks to API docs
---------
Co-authored-by: Tig Kindel <tig@users.noreply.github.com>
132 lines
4.2 KiB
C#
132 lines
4.2 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
using Terminal.Gui;
|
|
using System.Text;
|
|
|
|
namespace UICatalog.Scenarios {
|
|
[ScenarioMetadata (Name: "ListView & ComboBox", Description: "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
|
|
var items = new List<string> ();
|
|
foreach (var 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 ("Listview") {
|
|
ColorScheme = Colors.TopLevel,
|
|
X = 0,
|
|
Width = Dim.Percent (40)
|
|
};
|
|
|
|
var listview = new ListView (items) {
|
|
X = 0,
|
|
Y = Pos.Bottom (lbListView) + 1,
|
|
Height = Dim.Fill(2),
|
|
Width = Dim.Percent (40)
|
|
};
|
|
listview.SelectedItemChanged += (object s, ListViewItemEventArgs 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 ("ComboBox") {
|
|
ColorScheme = Colors.TopLevel,
|
|
X = Pos.Right (lbListView) + 1,
|
|
Width = Dim.Percent(40)
|
|
};
|
|
|
|
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 += (object s, ListViewItemEventArgs 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 ("Move _Up") {
|
|
X = 1,
|
|
Y = Pos.Bottom(lbListView),
|
|
};
|
|
btnMoveUp.Clicked += (s,e) => {
|
|
listview.MoveUp ();
|
|
};
|
|
|
|
var btnMoveDown = new Button ("Move _Down") {
|
|
X = Pos.Right (btnMoveUp) + 1,
|
|
Y = Pos.Bottom (lbListView),
|
|
};
|
|
btnMoveDown.Clicked += (s,e) => {
|
|
listview.MoveDown ();
|
|
};
|
|
|
|
Win.Add (btnMoveUp, btnMoveDown);
|
|
}
|
|
}
|
|
}
|