Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TreeView<T> support #280

Merged
merged 15 commits into from
Jan 5, 2024
Merged

TreeView<T> support #280

merged 15 commits into from
Jan 5, 2024

Conversation

tznind
Copy link
Collaborator

@tznind tznind commented Jan 2, 2024

Fixes #267

tree-view-t

Adding TreeView<object> then TreeView<FileSystemInfo> to a Window (with save/open)

Designer.cs Code
//------------------------------------------------------------------------------

//  <auto-generated>
//      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.
//  </auto-generated>
// -----------------------------------------------------------------------------
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<object> treeView1;
        
        private Terminal.Gui.TreeView<System.IO.FileSystemInfo> treeView2;
        
        private void InitializeComponent() {
            this.treeView2 = new Terminal.Gui.TreeView<System.IO.FileSystemInfo>();
            this.treeView1 = new Terminal.Gui.TreeView<object>();
            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<System.IO.FileSystemInfo>(
    (p) => p is System.IO.DirectoryInfo d ? d.GetFileSystemInfos() : System.Linq.Enumerable.Empty<System.IO.FileSystemInfo>());
            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 tznind changed the title Treeview t support TreeView<T> t support Jan 2, 2024
@tznind tznind changed the title TreeView<T> t support TreeView<T> support Jan 2, 2024
@tznind tznind requested a review from BDisp January 2, 2024 14:23
@tznind
Copy link
Collaborator Author

tznind commented Jan 2, 2024

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

Copy link
Contributor

@BDisp BDisp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good work. Congrats.

@dodexahedron
Copy link
Contributor

@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
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to expand on these tests, both by adding some new ones and just a few tweaks to these two, but that can be added as part of the work I'm doing if you'd rather focus on other stuff.

src/UI/ValueFactory.cs Outdated Show resolved Hide resolved
src/UI/ValueFactory.cs Outdated Show resolved Hide resolved
src/UI/ValueFactory.cs Outdated Show resolved Hide resolved
src/UI/ValueFactory.cs Outdated Show resolved Hide resolved
src/UI/ValueFactory.cs Outdated Show resolved Hide resolved
dodexahedron

This comment was marked as resolved.

@tznind
Copy link
Collaborator Author

tznind commented Jan 5, 2024

Now asks if you want to add a DirectoryInfo or FileInfo

image

@tznind tznind merged commit ea3c0c4 into v2 Jan 5, 2024
1 check passed
@tznind tznind deleted the treeview-t-support branch January 5, 2024 10:18
@dodexahedron
Copy link
Contributor

Nice

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants