2024-06-14 19:06:21 -04:00
|
|
|
|
using ReCodeIt.Models;
|
2024-06-14 11:01:21 -04:00
|
|
|
|
|
2024-06-14 19:06:21 -04:00
|
|
|
|
namespace ReCodeIt.GUI;
|
2024-06-13 21:20:48 -04:00
|
|
|
|
|
2024-06-14 19:06:21 -04:00
|
|
|
|
internal static class GUIHelpers
|
2024-06-13 21:20:48 -04:00
|
|
|
|
{
|
2024-06-13 22:58:26 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the value of the count or null if disabled
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="box"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static int? GetCount(this CheckBox box, NumericUpDown upDown)
|
2024-06-13 21:20:48 -04:00
|
|
|
|
{
|
2024-06-13 22:58:26 -04:00
|
|
|
|
if (box.Checked)
|
|
|
|
|
{
|
|
|
|
|
return (int?)upDown.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
2024-06-13 21:20:48 -04:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-13 22:58:26 -04:00
|
|
|
|
public static bool? GetEnabled(this DomainUpDown domainUpDown)
|
2024-06-13 21:20:48 -04:00
|
|
|
|
{
|
2024-06-13 22:58:26 -04:00
|
|
|
|
if (domainUpDown.Text == "True")
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (domainUpDown.Text == "False")
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
2024-06-13 21:20:48 -04:00
|
|
|
|
}
|
2024-06-14 11:01:21 -04:00
|
|
|
|
|
2024-06-14 13:47:30 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Builds the name list for the this updown
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="domainUpDown"></param>
|
|
|
|
|
/// <param name="name"></param>
|
2024-06-14 20:52:16 -04:00
|
|
|
|
public static void BuildStringList(this DomainUpDown domainUpDown, string name, bool? update = null)
|
2024-06-14 13:47:30 -04:00
|
|
|
|
{
|
|
|
|
|
domainUpDown.Items.Clear();
|
|
|
|
|
domainUpDown.Text = name + " (Disabled)";
|
|
|
|
|
domainUpDown.ReadOnly = true;
|
|
|
|
|
|
|
|
|
|
var list = new List<string>
|
|
|
|
|
{
|
|
|
|
|
name + " (Disabled)",
|
|
|
|
|
"True",
|
|
|
|
|
"False",
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-14 20:52:16 -04:00
|
|
|
|
if (update != null)
|
|
|
|
|
{
|
|
|
|
|
domainUpDown.Text = update.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 13:47:30 -04:00
|
|
|
|
domainUpDown.Items.AddRange(list);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 11:01:21 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generates a tree node to display on the GUI
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-06-14 19:06:21 -04:00
|
|
|
|
public static TreeNode GenerateTreeNode(RemapModel model, ReCodeItForm gui)
|
2024-06-14 11:01:21 -04:00
|
|
|
|
{
|
|
|
|
|
var isPublic = model.SearchParams.IsPublic == null ? null : model.SearchParams.IsPublic;
|
|
|
|
|
var isAbstract = model.SearchParams.IsAbstract == null ? null : model.SearchParams.IsAbstract;
|
|
|
|
|
var isInterface = model.SearchParams.IsInterface == null ? null : model.SearchParams.IsInterface;
|
|
|
|
|
var isEnum = model.SearchParams.IsEnum == null ? null : model.SearchParams.IsEnum;
|
|
|
|
|
var isNested = model.SearchParams.IsNested == null ? null : model.SearchParams.IsNested;
|
|
|
|
|
var IsSealed = model.SearchParams.IsSealed == null ? null : model.SearchParams.IsSealed;
|
|
|
|
|
var HasAttribute = model.SearchParams.HasAttribute == null ? null : model.SearchParams.HasAttribute;
|
|
|
|
|
var IsDerived = model.SearchParams.IsDerived == null ? null : model.SearchParams.IsDerived;
|
|
|
|
|
var HasGenericParameters = model.SearchParams.HasGenericParameters == null ? null : model.SearchParams.HasGenericParameters;
|
|
|
|
|
|
2024-06-14 20:52:16 -04:00
|
|
|
|
var remapTreeItem = new TreeNode($"{model.NewTypeName}");
|
2024-06-14 11:01:21 -04:00
|
|
|
|
|
2024-06-14 14:21:03 -04:00
|
|
|
|
var originalTypeName = new TreeNode($"Original Name: {model.OriginalTypeName}");
|
|
|
|
|
|
2024-06-14 11:53:43 -04:00
|
|
|
|
var forceRenameNode = new TreeNode($"Force Rename: {(model.UseForceRename ? model.UseForceRename : "Disabled")}");
|
|
|
|
|
|
|
|
|
|
var ispublicNode = new TreeNode($"IsPublic: {(isPublic != null ? isPublic : "Disabled")}");
|
|
|
|
|
|
|
|
|
|
var isAbstractNode = new TreeNode($"IsAbstract: {(isAbstract != null ? isAbstract : "Disabled")}");
|
|
|
|
|
|
|
|
|
|
var isInterfaceNode = new TreeNode($"IsInterface: {(isInterface != null ? isInterface : "Disabled")}");
|
|
|
|
|
|
|
|
|
|
var IsEnumNode = new TreeNode($"IsEnum: {(isEnum != null ? isEnum : "Disabled")}");
|
|
|
|
|
|
|
|
|
|
var IsNestedNode = new TreeNode($"IsNested: {(isNested != null ? isNested : "Disabled")}");
|
|
|
|
|
|
|
|
|
|
var IsSealedNode = new TreeNode($"IsSealed: {(IsSealed != null ? IsSealed : "Disabled")}");
|
|
|
|
|
|
|
|
|
|
var HasAttrNode = new TreeNode($"HasAttribute: {(HasAttribute != null ? HasAttribute : "Disabled")}");
|
|
|
|
|
|
|
|
|
|
var IsDerivedNode = new TreeNode($"IsDerived: {(IsDerived != null ? IsDerived : "Disabled")}");
|
|
|
|
|
|
|
|
|
|
var HasGenericsNode = new TreeNode($"HasGenericParameters: {(HasGenericParameters != null ? HasGenericParameters : "Disabled")}");
|
2024-06-14 11:01:21 -04:00
|
|
|
|
|
2024-06-14 13:47:30 -04:00
|
|
|
|
if (model.SearchParams.ConstructorParameterCount > 0)
|
|
|
|
|
{
|
|
|
|
|
remapTreeItem.Nodes.Add(new TreeNode($"Constructor Parameter Count: {model.SearchParams.ConstructorParameterCount}"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (model.SearchParams.MethodCount > 0)
|
|
|
|
|
{
|
|
|
|
|
remapTreeItem.Nodes.Add(new TreeNode($"Method Count: {model.SearchParams.MethodCount}"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (model.SearchParams.FieldCount > 0)
|
|
|
|
|
{
|
|
|
|
|
remapTreeItem.Nodes.Add(new TreeNode($"Field Count: {model.SearchParams.FieldCount}"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (model.SearchParams.PropertyCount > 0)
|
|
|
|
|
{
|
|
|
|
|
remapTreeItem.Nodes.Add(new TreeNode($"Property Count: {model.SearchParams.PropertyCount}"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (model.SearchParams.NestedTypeCount > 0)
|
|
|
|
|
{
|
|
|
|
|
remapTreeItem.Nodes.Add(new TreeNode($"Nested Type Count: {model.SearchParams.NestedTypeCount}"));
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 14:21:03 -04:00
|
|
|
|
remapTreeItem.Nodes.Add(originalTypeName);
|
2024-06-14 11:01:21 -04:00
|
|
|
|
remapTreeItem.Nodes.Add(forceRenameNode);
|
|
|
|
|
remapTreeItem.Nodes.Add(ispublicNode);
|
|
|
|
|
remapTreeItem.Nodes.Add(isAbstractNode);
|
|
|
|
|
remapTreeItem.Nodes.Add(isInterfaceNode);
|
|
|
|
|
remapTreeItem.Nodes.Add(IsEnumNode);
|
|
|
|
|
remapTreeItem.Nodes.Add(IsNestedNode);
|
|
|
|
|
remapTreeItem.Nodes.Add(IsSealedNode);
|
|
|
|
|
remapTreeItem.Nodes.Add(HasAttrNode);
|
|
|
|
|
remapTreeItem.Nodes.Add(IsDerivedNode);
|
|
|
|
|
remapTreeItem.Nodes.Add(HasGenericsNode);
|
|
|
|
|
|
2024-06-14 14:34:24 -04:00
|
|
|
|
if (model.SearchParams.IncludeMethods?.Count > 0)
|
2024-06-14 11:53:43 -04:00
|
|
|
|
{
|
|
|
|
|
var includeMethodsNode =
|
|
|
|
|
GenerateNodeFromList(model.SearchParams.IncludeMethods, "Include Methods");
|
|
|
|
|
|
|
|
|
|
remapTreeItem.Nodes.Add(includeMethodsNode);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 14:34:24 -04:00
|
|
|
|
if (model.SearchParams.ExcludeMethods?.Count > 0)
|
2024-06-14 11:53:43 -04:00
|
|
|
|
{
|
|
|
|
|
var excludeMethodsNode =
|
|
|
|
|
GenerateNodeFromList(model.SearchParams.ExcludeMethods, "Exclude Methods");
|
|
|
|
|
|
|
|
|
|
remapTreeItem.Nodes.Add(excludeMethodsNode);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 14:34:24 -04:00
|
|
|
|
if (model.SearchParams.IncludeFields?.Count > 0)
|
2024-06-14 11:53:43 -04:00
|
|
|
|
{
|
|
|
|
|
var includeFieldsNode =
|
|
|
|
|
GenerateNodeFromList(model.SearchParams.IncludeFields, "Include Fields");
|
|
|
|
|
|
|
|
|
|
remapTreeItem.Nodes.Add(includeFieldsNode);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 14:34:24 -04:00
|
|
|
|
if (model.SearchParams.ExcludeFields?.Count > 0)
|
2024-06-14 11:53:43 -04:00
|
|
|
|
{
|
|
|
|
|
var excludeFieldsNode =
|
|
|
|
|
GenerateNodeFromList(model.SearchParams.ExcludeFields, "Exclude Fields");
|
|
|
|
|
|
|
|
|
|
remapTreeItem.Nodes.Add(excludeFieldsNode);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 14:34:24 -04:00
|
|
|
|
if (model.SearchParams.IncludeProperties?.Count > 0)
|
2024-06-14 11:53:43 -04:00
|
|
|
|
{
|
|
|
|
|
var includeProperties =
|
|
|
|
|
GenerateNodeFromList(model.SearchParams.IncludeProperties, "Include Properties");
|
|
|
|
|
|
|
|
|
|
remapTreeItem.Nodes.Add(includeProperties);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 14:34:24 -04:00
|
|
|
|
if (model.SearchParams.ExcludeProperties?.Count > 0)
|
2024-06-14 11:53:43 -04:00
|
|
|
|
{
|
|
|
|
|
var excludeProperties =
|
|
|
|
|
GenerateNodeFromList(model.SearchParams.ExcludeProperties, "Exclude Properties");
|
|
|
|
|
|
|
|
|
|
remapTreeItem.Nodes.Add(excludeProperties);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 14:34:24 -04:00
|
|
|
|
if (model.SearchParams.IncludeNestedTypes?.Count > 0)
|
2024-06-14 11:53:43 -04:00
|
|
|
|
{
|
|
|
|
|
var includeNestedTypes =
|
|
|
|
|
GenerateNodeFromList(model.SearchParams.IncludeNestedTypes, "Include Nested Types");
|
|
|
|
|
|
|
|
|
|
remapTreeItem.Nodes.Add(includeNestedTypes);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 14:34:24 -04:00
|
|
|
|
if (model.SearchParams.IncludeNestedTypes?.Count > 0)
|
2024-06-14 11:53:43 -04:00
|
|
|
|
{
|
|
|
|
|
var excludeNestedTypes =
|
|
|
|
|
GenerateNodeFromList(model.SearchParams.ExcludeNestedTypes, "Exclude Nested Types");
|
|
|
|
|
|
|
|
|
|
remapTreeItem.Nodes.Add(excludeNestedTypes);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 11:01:21 -04:00
|
|
|
|
return remapTreeItem;
|
|
|
|
|
}
|
2024-06-14 11:53:43 -04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generates a new node from a list of strings
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="items"></param>
|
|
|
|
|
/// <param name="name"></param>
|
|
|
|
|
/// <returns>A new tree node, or null if the provided list is empty</returns>
|
|
|
|
|
private static TreeNode GenerateNodeFromList(List<string> items, string name)
|
|
|
|
|
{
|
|
|
|
|
var node = new TreeNode(name);
|
|
|
|
|
|
|
|
|
|
foreach (var item in items)
|
|
|
|
|
{
|
|
|
|
|
node.Nodes.Add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Buils a list of strings from list box entries
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="lb"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static List<string> GetAllEntriesFromListBox(ListBox lb)
|
|
|
|
|
{
|
|
|
|
|
var tmp = new List<string>();
|
|
|
|
|
|
|
|
|
|
foreach (var entry in lb.Items)
|
|
|
|
|
{
|
|
|
|
|
tmp.Add((string)entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
2024-06-13 21:20:48 -04:00
|
|
|
|
}
|