gui-cs / TerminalGuiDesigner

Forms Designer for Terminal.Gui (aka gui.cs)
MIT License
423 stars 28 forks source link

TreeView<T> support #280

Closed tznind closed 8 months ago

tznind commented 8 months ago

Fixes #267

tree-view-t

Adding TreeView\ then TreeView\ to a Window (with save/open)

Designer.cs Code ```csharp //------------------------------------------------------------------------------ // // This code was generated by: // TerminalGuiDesigner v1.1.0.0 // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // // ----------------------------------------------------------------------------- namespace YourNamespace { using System; using Terminal.Gui; using System.Collections; using System.Collections.Generic; public partial class MyView : Terminal.Gui.Window { private Terminal.Gui.TreeView treeView1; private Terminal.Gui.TreeView treeView2; private void InitializeComponent() { this.treeView2 = new Terminal.Gui.TreeView(); this.treeView1 = new Terminal.Gui.TreeView(); this.Width = Dim.Fill(0); this.Height = Dim.Fill(0); this.X = 0; this.Y = 0; this.Visible = true; this.Modal = false; this.TextAlignment = Terminal.Gui.TextAlignment.Left; this.Title = ""; this.treeView1.Width = 21; this.treeView1.Height = 12; this.treeView1.X = 14; this.treeView1.Y = 4; this.treeView1.Visible = true; this.treeView1.Data = "treeView1"; this.treeView1.Text = ""; this.treeView1.TextAlignment = Terminal.Gui.TextAlignment.Left; this.treeView1.Style.CollapseableSymbol = new System.Text.Rune('-'); this.treeView1.Style.ColorExpandSymbol = false; this.treeView1.Style.ExpandableSymbol = new System.Text.Rune('+'); this.treeView1.Style.InvertExpandSymbolColors = false; this.treeView1.Style.LeaveLastRow = false; this.treeView1.Style.ShowBranchLines = true; this.Add(this.treeView1); this.treeView2.Width = 42; this.treeView2.Height = 13; this.treeView2.X = 38; this.treeView2.Y = 5; this.treeView2.Visible = true; this.treeView2.Data = "treeView2"; this.treeView2.Text = ""; this.treeView2.TextAlignment = Terminal.Gui.TextAlignment.Left; this.treeView2.Style.CollapseableSymbol = new System.Text.Rune('-'); this.treeView2.Style.ColorExpandSymbol = false; this.treeView2.Style.ExpandableSymbol = new System.Text.Rune('+'); this.treeView2.Style.InvertExpandSymbolColors = false; this.treeView2.Style.LeaveLastRow = false; this.treeView2.Style.ShowBranchLines = true; this.treeView2.AddObjects(new System.IO.FileSystemInfo[] { new System.IO.DirectoryInfo("D:\\Repos\\TerminalGuiDesigner\\src\\bin\\Debug\\net8.0"), new System.IO.FileInfo("D:\\Repos\\TerminalGuiDesigner\\src\\bin\\Debug\\net8.0\\Basic.Reference.Assemblies.Net7" + "0.dll"), new System.IO.FileInfo("D:\\Repos\\TerminalGuiDesigner\\src\\bin\\Debug\\net8.0\\Basic.Reference.Assemblies.Net8" + "0.dll")}); this.treeView2.TreeBuilder = new Terminal.Gui.DelegateTreeBuilder( (p) => p is System.IO.DirectoryInfo d ? d.GetFileSystemInfos() : System.Linq.Enumerable.Empty()); this.Add(this.treeView2); } } } ```

We now have:

This is probably a good place to chat about any refactoring and future proofing of this functionality

User defined Types (e.g. MyGameObject) are currently off the cards but should be kept in mind as a future goal.

Use Case

As a TerminalGuiDesigner user I want to be able to add any of the core generic views.

  • When I add the view I should be asked what T type I want
  • Code gen should work
  • I should be able to edit relevant properties (e.g. Options in a Slider, Objects in a TreeView) where it is sensible
  • I understand that there are limitations to object selection e.g. I cant edit the objects in a TreeView<object>.

Current Implementation

Currently things are a bit all over the place so we need some tidy up.

Classes I like: TTypes - Describes what Types can be picked for T in a given generic View

For any given T type we need:

  • to know what generic Views it can be selected for (currently in TTypes.GetSupportedTTypesForGenericViewOfType)
  • explicit code to describe how to 'pick a value' (currently in ValueFactory
  • ToCode that can represent the value being instantiated (currently in TTypes.ToCode)
  • TreeBuilder codegen (if applicable)

image

tznind commented 8 months ago

@dodexahedron any thoughts on the structure of this new code?

dodexahedron commented 8 months ago

@dodexahedron any thoughts on the structure of this new code?

I've been unable to touch any of this since a couple days ago, but I'll certainly have a look as soon as possible and let you know if I have any thoughts. That'll probably either be later tonight, or at some point tomorrow.

dodexahedron commented 8 months ago

First thing I'd mention, just from the class diagram (haven't checked the code itself yet), is something I've been meaning to mention at Terminal.Gui and made a side mention of in an unrelated issue over there:

Attributes.

One big application is I think we should consider a means of helping us to avoid having to maintain all these type arrays everywhere, by having either an interface or an attribute (or both) that we can decorate TG types with, to indicate TGD support.

An attribute would be nice, because it can be parameterized and those parameters can be used by TGD to protect itself against potential future breaking changes to a type in TG by inspecting such parameters at application launch and taking whatever action is appropriate. For example, those actions could be anything from simply showing a warning to disabling certain functionality all the way to showing a critical error, telling the user to revert to an earlier TG version to use TGD with it, and gracefully exiting before things can get weird.

An interface would also be nice, for strong-typing reasons, even when reflection is used, and that's exactly what interfaces are for. If a type in TG can guarantee that it supports a given interface contract we come up with, based on what TGD needs to support that type, the interface can be applied to that type and then TGD can assume that it can use that type. Makes integration testing easier, too.

Anyway... I'll take a look at the code itself in a little bit. I'm still going through my github notifications. 😅

dodexahedron commented 8 months ago

Side note... I'm excited to see this, in any state! :)

tznind commented 8 months ago

Now asks if you want to add a DirectoryInfo or FileInfo

image

dodexahedron commented 8 months ago

Nice

Gets the job done safely, and that's what matters. :) 🥳