mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* WIP: Add ITableDataSource * WIP: Refactor TableView * WIP: Port CSVEditor * WIP: Port TableEditor * WIP: Port MultiColouredTable scenario * Fix bug of adding duplicate column styles * Update tests to use DataTableSource * Tidy up * Add EnumerableTableDataSource<T> * Add test for EnumerableTableDataSource * Add test for EnumerableTableDataSource * Add code example to xmldoc * Add ProcessTable scenario * Rename ITableDataSource to ITableSource and update docs * Rename EnumerableTableDataSource to EnumerableTableSource * Fixed Frame != Bounds; changed UICat Scenarios list to use tableview! * Fix scroll resetting in ProcessTable scenario * Fix unit tests by setting Frame to same as Bounds * Document why we have to measure our data for use with TableView --------- Co-authored-by: Tig Kindel <tig@users.noreply.github.com>
63 lines
1.5 KiB
C#
63 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using Terminal.Gui;
|
|
using System.Linq;
|
|
using System.Globalization;
|
|
using static Terminal.Gui.TableView;
|
|
using System.Diagnostics;
|
|
|
|
namespace UICatalog.Scenarios {
|
|
|
|
[ScenarioMetadata (Name: "ProcessTable", Description: "Demonstrates TableView with the currently running processes.")]
|
|
[ScenarioCategory ("TableView")]
|
|
public class ProcessTable : Scenario {
|
|
TableView tableView;
|
|
public override void Setup ()
|
|
{
|
|
Win.Title = this.GetName ();
|
|
Win.Y = 1; // menu
|
|
Win.Height = Dim.Fill (1); // status bar
|
|
Application.Top.LayoutSubviews ();
|
|
|
|
this.tableView = new TableView () {
|
|
X = 0,
|
|
Y = 0,
|
|
Width = Dim.Fill (),
|
|
Height = Dim.Fill (1),
|
|
};
|
|
|
|
// First time
|
|
CreateProcessTable ();
|
|
|
|
// Then every second
|
|
Application.MainLoop.AddTimeout (TimeSpan.FromSeconds (1),
|
|
(s) => {
|
|
CreateProcessTable ();
|
|
return true;
|
|
});
|
|
|
|
Win.Add (tableView);
|
|
|
|
}
|
|
|
|
private void CreateProcessTable ()
|
|
{
|
|
var ro = tableView.RowOffset;
|
|
var co = tableView.ColumnOffset;
|
|
tableView.Table = new EnumerableTableSource<Process> (Process.GetProcesses (),
|
|
new Dictionary<string, Func<Process, object>>() {
|
|
{ "ID",(p)=>p.Id},
|
|
{ "Name",(p)=>p.ProcessName},
|
|
{ "Threads",(p)=>p.Threads.Count},
|
|
{ "Virtual Memory",(p)=>p.VirtualMemorySize64},
|
|
{ "Working Memory",(p)=>p.WorkingSet64},
|
|
});
|
|
|
|
tableView.RowOffset = ro;
|
|
tableView.ColumnOffset = co;
|
|
tableView.EnsureValidScrollOffsets ();
|
|
}
|
|
}
|
|
}
|