Skip to content

Commit

Permalink
Fix 1130 broken links (gui-cs#1131)
Browse files Browse the repository at this point in the history
* fixed table & treeview docs

* regen docs

* relnote
  • Loading branch information
tig committed Mar 9, 2021
1 parent 1cf2ce1 commit 4da9ad0
Show file tree
Hide file tree
Showing 51 changed files with 584 additions and 1,509 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -22,8 +22,8 @@ Nuget also contains pre-release versions of 1.0; they are identified with `-pre`
* [CheckBox](https://migueldeicaza.github.io/gui.cs/api/Terminal.Gui/Terminal.Gui.CheckBox.html)
* [ComboBox](https://migueldeicaza.github.io/gui.cs/api/Terminal.Gui/Terminal.Gui.ComboBox.html)
* [Dialog](https://migueldeicaza.github.io/gui.cs/api/Terminal.Gui/Terminal.Gui.Dialog.html)
* [OpenDialog](https://migueldeicaza.github.io/gui.cs/api/Terminal.Gui/Terminal.Gui.OpenDialog.html)
* [SaveDialog](https://migueldeicaza.github.io/gui.cs/api/Terminal.Gui/Terminal.Gui.SaveDialog.html)
* [OpenDialog](https://migueldeicaza.github.io/gui.cs/api/Terminal.Gui/Terminal.Gui.OpenDialog.html)
* [SaveDialog](https://migueldeicaza.github.io/gui.cs/api/Terminal.Gui/Terminal.Gui.SaveDialog.html)
* [FrameView](https://migueldeicaza.github.io/gui.cs/api/Terminal.Gui/Terminal.Gui.FrameView.html)
* [Hex viewer/editor](https://migueldeicaza.github.io/gui.cs/api/Terminal.Gui/Terminal.Gui.HexView.html)
* [Label](https://migueldeicaza.github.io/gui.cs/api/Terminal.Gui/Terminal.Gui.Label.html)
Expand Down
1 change: 1 addition & 0 deletions Terminal.Gui/Terminal.Gui.csproj
Expand Up @@ -19,6 +19,7 @@
<PackageReleaseNotes>
v1.0.???
* Fixes #1048 - BrighCyan to BrightCyan spelling
* Fixes #1130 - Broken Table/TreeView links in docs.

v1.0.0-beta.8
* Now using MinVer to generate version numbers from git tags.
Expand Down
15 changes: 11 additions & 4 deletions Terminal.Gui/Views/TableView.cs
Expand Up @@ -7,7 +7,10 @@
namespace Terminal.Gui {

/// <summary>
/// Describes how to render a given column in a <see cref="TableView"/> including <see cref="Alignment"/> and textual representation of cells (e.g. date formats)
/// Describes how to render a given column in a <see cref="TableView"/> including <see cref="Alignment"/>
/// and textual representation of cells (e.g. date formats)
///
/// <a href="https://migueldeicaza.github.io/gui.cs/articles/tableview.html">See TableView Deep Dive for more information</a>.
/// </summary>
public class ColumnStyle {

Expand Down Expand Up @@ -75,7 +78,9 @@ public string GetRepresentation (object value)
}
}
/// <summary>
/// Defines rendering options that affect how the table is displayed
/// Defines rendering options that affect how the table is displayed.
///
/// <a href="https://migueldeicaza.github.io/gui.cs/articles/tableview.html">See TableView Deep Dive for more information</a>.
/// </summary>
public class TableStyle {

Expand Down Expand Up @@ -132,9 +137,11 @@ public ColumnStyle GetOrCreateColumnStyle (DataColumn col)
return ColumnStyles[col];
}
}

/// <summary>
/// View for tabular data based on a <see cref="DataTable"/>
/// View for tabular data based on a <see cref="DataTable"/>.
///
/// <a href="https://migueldeicaza.github.io/gui.cs/articles/tableview.html">See TableView Deep Dive for more information</a>.
/// </summary>
public class TableView : View {

Expand Down
10 changes: 7 additions & 3 deletions Terminal.Gui/Views/TreeView.cs
Expand Up @@ -12,10 +12,10 @@ namespace Terminal.Gui {

/// <summary>
/// Interface for all non generic members of <see cref="TreeView{T}"/>
///
/// <a href="https://migueldeicaza.github.io/gui.cs/articles/treeview.html">See TreeView Deep Dive for more information</a>.
/// </summary>
public interface ITreeView {


/// <summary>
/// Contains options for changing how the tree is rendered
/// </summary>
Expand All @@ -34,7 +34,9 @@ public interface ITreeView {

/// <summary>
/// Convenience implementation of generic <see cref="TreeView{T}"/> for any tree were all nodes
/// implement <see cref="ITreeNode"/>
/// implement <see cref="ITreeNode"/>.
///
/// <a href="https://migueldeicaza.github.io/gui.cs/articles/treeview.html">See TreeView Deep Dive for more information</a>.
/// </summary>
public class TreeView : TreeView<ITreeNode> {

Expand All @@ -52,6 +54,8 @@ public TreeView ()
/// <summary>
/// Hierarchical tree view with expandable branches. Branch objects are dynamically determined
/// when expanded using a user defined <see cref="ITreeBuilder{T}"/>
///
/// <a href="https://migueldeicaza.github.io/gui.cs/articles/treeview.html">See TreeView Deep Dive for more information</a>.
/// </summary>
public class TreeView<T> : View, ITreeView where T : class {
private int scrollOffsetVertical;
Expand Down
1 change: 1 addition & 0 deletions docfx/articles/index.md
Expand Up @@ -3,4 +3,5 @@
* [Terminal.Gui Overview](overview.html)
* [Keyboard Event Processing](keyboard.html)
* [Event Processing and the Application Main Loop](mainloop.md)
* [TableView Deep Dive](tableview.md)
* [TreeView Deep Dive](treeview.md)
22 changes: 11 additions & 11 deletions docfx/articles/tableview.md
@@ -1,24 +1,25 @@
# Table View

This control supports viewing and editing tabular data. It provides a view of a [System.DataTable](https://docs.microsoft.com/en-us/dotnet/api/system.data.datatable?view=net-5.0).
This control supports viewing and editing tabular data. It provides a view of a [System.DataTable](https://docs.microsoft.com/en-us/dotnet/api/system.data.datatable?view=net-5.0).

System.DataTable is a core class of .net standard and can be created very easily

[TableView API Reference](api/Terminal.Gui/Terminal.Gui.TableView.html)

## Csv Example

You can create a DataTable from a CSV file by creating a new instance and adding columns and rows as you read them. For a robust solution however you might want to look into a CSV parser library that deals with escaping, multi line rows etc.
You can create a DataTable from a CSV file by creating a new instance and adding columns and rows as you read them. For a robust solution however you might want to look into a CSV parser library that deals with escaping, multi line rows etc.

```csharp
var dt = new DataTable();
var lines = File.ReadAllLines(filename);

foreach(var h in lines[0].Split(',')){
dt.Columns.Add(h);
dt.Columns.Add(h);
}


foreach(var line in lines.Skip(1)) {
dt.Rows.Add(line.Split(','));
dt.Rows.Add(line.Split(','));
}
```

Expand All @@ -45,12 +46,11 @@ Once you have set up your data table set it in the view:

```csharp
tableView = new TableView () {
X = 0,
Y = 0,
Width = 50,
Height = 10,
X = 0,
Y = 0,
Width = 50,
Height = 10,
};

tableView.Table = yourDataTable;
```

114 changes: 58 additions & 56 deletions docfx/articles/treeview.md
Expand Up @@ -2,11 +2,12 @@

TreeView is a control for navigating hierarchical objects. It comes in two forms `TreeView` and `TreeView<T>`.

[TreeView API Reference](api/Terminal.Gui/Terminal.Gui.TreeView.html)

## Using TreeView

The basic non generic TreeView class is populated by `ITreeNode` objects. The simplest tree you can make would look something like:


```csharp
var tree = new TreeView()
{
Expand Down Expand Up @@ -36,23 +37,23 @@ Having to create a bunch of TreeNode objects can be a pain especially if you alr
// Your data class
private class House : TreeNode {

// Your properties
public string Address {get;set;}
public List<Room> Rooms {get;set;}
// Your properties
public string Address {get;set;}
public List<Room> Rooms {get;set;}

// ITreeNode member:
public override IList<ITreeNode> Children => Rooms.Cast<ITreeNode>().ToList();
// ITreeNode member:
public override IList<ITreeNode> Children => Rooms.Cast<ITreeNode>().ToList();

public override string Text { get => Address; set => Address = value; }
public override string Text { get => Address; set => Address = value; }
}


// Your other data class
private class Room : TreeNode{

public string Name {get;set;}

public override string Text{get=>Name;set{Name=value;}}
public string Name {get;set;}

public override string Text{get=>Name;set{Name=value;}}
}
```

Expand All @@ -62,20 +63,20 @@ After implementing the interface you can add your objects directly to the tree

var myHouse = new House()
{
Address = "23 Nowhere Street",
Rooms = new List<Room>{
new Room(){Name = "Ballroom"},
new Room(){Name = "Bedroom 1"},
new Room(){Name = "Bedroom 2"}
}
Address = "23 Nowhere Street",
Rooms = new List<Room>{
new Room(){Name = "Ballroom"},
new Room(){Name = "Bedroom 1"},
new Room(){Name = "Bedroom 2"}
}
};

var tree = new TreeView()
{
X = 0,
Y = 0,
Width = 40,
Height = 20
X = 0,
Y = 0,
Width = 40,
Height = 20
};

tree.AddObject(myHouse);
Expand All @@ -99,25 +100,26 @@ private abstract class GameObject
{

}

private class Army : GameObject
{
public string Designation {get;set;}
public List<Unit> Units {get;set;}
public string Designation {get;set;}
public List<Unit> Units {get;set;}


public override string ToString ()
{
return Designation;
}
public override string ToString ()
{
return Designation;
}
}

private class Unit : GameObject
{
public string Name {get;set;}
public override string ToString ()
{
return Name;
}
public string Name {get;set;}
public override string ToString ()
{
return Name;
}
}

```
Expand All @@ -127,20 +129,20 @@ An `ITreeBuilder<T>` for these classes might look like:
```csharp

private class GameObjectTreeBuilder : ITreeBuilder<GameObject> {
public bool SupportsCanExpand => true;
public bool SupportsCanExpand => true;

public bool CanExpand (GameObject model)
{
return model is Army;
}
public bool CanExpand (GameObject model)
{
return model is Army;
}

public IEnumerable<GameObject> GetChildren (GameObject model)
{
if(model is Army a)
return a.Units;
public IEnumerable<GameObject> GetChildren (GameObject model)
{
if(model is Army a)
return a.Units;

return Enumerable.Empty<GameObject>();
}
return Enumerable.Empty<GameObject>();
}
}
```

Expand All @@ -149,21 +151,21 @@ To use the builder in a tree you would use:
```csharp
var army1 = new Army()
{
Designation = "3rd Infantry",
Units = new List<Unit>{
new Unit(){Name = "Orc"},
new Unit(){Name = "Troll"},
new Unit(){Name = "Goblin"},
}
Designation = "3rd Infantry",
Units = new List<Unit>{
new Unit(){Name = "Orc"},
new Unit(){Name = "Troll"},
new Unit(){Name = "Goblin"},
}
};

var tree = new TreeView<GameObject>()
{
X = 0,
Y = 0,
Width = 40,
Height = 20,
TreeBuilder = new GameObjectTreeBuilder()
X = 0,
Y = 0,
Width = 40,
Height = 20,
TreeBuilder = new GameObjectTreeBuilder()
};


Expand All @@ -174,13 +176,13 @@ Alternatively you can use `DelegateTreeBuilder<T>` instead of implementing your

```csharp
tree.TreeBuilder = new DelegateTreeBuilder<GameObject>(
(o)=>o is Army a ? a.Units
: Enumerable.Empty<GameObject>());
(o)=>o is Army a ? a.Units
: Enumerable.Empty<GameObject>());
```

## Node Text and ToString

The default behaviour of TreeView is to use the `ToString` method on the objects for rendering. You can customise this by changing the `AspectGetter`. For example:
The default behavior of TreeView is to use the `ToString` method on the objects for rendering. You can customise this by changing the `AspectGetter`. For example:

```csharp
treeViewFiles.AspectGetter = (f)=>f.FullName;
Expand Down
1 change: 1 addition & 0 deletions docfx/index.md
Expand Up @@ -10,6 +10,7 @@ A simple UI toolkit for .NET, .NET Core, and Mono that works on Windows, the Mac
* [Terminal.Gui API Overview](articles/overview.html)
* [Keyboard Event Processing](articles/keyboard.html)
* [Event Processing and the Application Main Loop](articles/mainloop.md)
* [TableView Deep Dive](articles/tableview.md)
* [TreeView Deep Dive](articles/treeview.md)

## UI Catalog
Expand Down
1 change: 1 addition & 0 deletions docs/api/Terminal.Gui/Terminal.Gui.Application.html
Expand Up @@ -759,6 +759,7 @@ <h4 id="Terminal_Gui_Application_Run__1_System_Func_System_Exception_System_Bool
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public static void Run&lt;T&gt;(Func&lt;Exception, bool&gt; errorHandler = null)

where T : Toplevel, new()</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
Expand Down
Expand Up @@ -92,6 +92,7 @@ <h6><strong>Assembly</strong>: Terminal.Gui.dll</h6>
<h5 id="Terminal_Gui_AspectGetterDelegate_1_syntax">Syntax</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public delegate string AspectGetterDelegate&lt;T&gt;(T toRender)

where T : class;</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
Expand Down

0 comments on commit 4da9ad0

Please sign in to comment.