-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from gui-cs/treeview-t-support
TreeView<T> support
- Loading branch information
Showing
20 changed files
with
533 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.CodeDom; | ||
using Terminal.Gui; | ||
using TerminalGuiDesigner.ToCode; | ||
|
||
namespace TerminalGuiDesigner | ||
{ | ||
/// <summary> | ||
/// Provides knowledge about how to handle different T types for generic | ||
/// views e.g. <see cref="Slider{T}"/>, <see cref="TreeView{T}"/> | ||
/// </summary> | ||
public static class TTypes | ||
{ | ||
/// <summary> | ||
/// Returns <see cref="CodeObjectCreateExpression"/> or <see cref="CodePrimitiveExpression"/> | ||
/// or similar that represents <paramref name="value"/>. | ||
/// </summary> | ||
/// <param name="args"></param> | ||
/// <param name="design"></param> | ||
/// <param name="value"></param> | ||
/// <returns></returns> | ||
public static CodeExpression ToCode(CodeDomArgs args, Design design, object? value) | ||
{ | ||
if(value == null || value is string || value.GetType().IsValueType) | ||
{ | ||
return value.ToCodePrimitiveExpression(); | ||
} | ||
|
||
if(value is FileSystemInfo fsi) | ||
{ | ||
return new CodeObjectCreateExpression(value.GetType(), fsi.ToString().ToCodePrimitiveExpression()); | ||
} | ||
|
||
throw new NotSupportedException("Value Type ToCode not known" + value.GetType()); | ||
} | ||
|
||
/// <summary> | ||
/// Returns all Types which can be used with generic view of the given <paramref name="viewType"/>. | ||
/// </summary> | ||
/// <param name="viewType">A generic view type e.g. <see langword="typeof"/>(Slider<>)</param> | ||
/// <returns></returns> | ||
public static IEnumerable<Type> GetSupportedTTypesForGenericViewOfType(Type viewType) | ||
{ | ||
if (viewType == typeof(Slider<>)) | ||
{ | ||
return new[] { typeof(int), typeof(string), typeof(float), typeof(double), typeof(bool) }; | ||
} | ||
|
||
if (viewType == typeof(TreeView<>)) | ||
{ | ||
return new[] { typeof(object), typeof(FileSystemInfo) }; | ||
} | ||
|
||
throw new NotSupportedException($"Generic View {viewType} is not yet supported"); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace TerminalGuiDesigner.ToCode; | ||
|
||
/// <summary> | ||
/// Interface for generic class <see cref="TreeObjectsProperty{T}"/> | ||
/// </summary> | ||
public interface ITreeObjectsProperty | ||
{ | ||
/// <summary> | ||
/// Returns True if the T type the property was constructed with is well | ||
/// supported by the designer (i.e. user can pick objects for their tree). | ||
/// </summary> | ||
/// <returns></returns> | ||
bool IsSupported(); | ||
|
||
/// <summary> | ||
/// Returns true if the collection currently held on the property is empty | ||
/// </summary> | ||
/// <returns></returns> | ||
public bool IsEmpty(); | ||
} |
Oops, something went wrong.