diff --git a/RecodeItGUI/GUI/Main.Designer.cs b/RecodeItGUI/GUI/Main.Designer.cs index 3761dda..343161f 100644 --- a/RecodeItGUI/GUI/Main.Designer.cs +++ b/RecodeItGUI/GUI/Main.Designer.cs @@ -33,6 +33,7 @@ partial class ReCodeItForm TabPageRemapper = new TabPage(); RemapTreeView = new TreeView(); groupBox1 = new GroupBox(); + EditRemapButton = new Button(); ConstuctorCountUpDown = new NumericUpDown(); ConstructorCountEnabled = new CheckBox(); LoadMappingFileButton = new Button(); @@ -93,7 +94,7 @@ partial class ReCodeItForm HasGenericParametersUpDown = new DomainUpDown(); IsEnumUpDown = new DomainUpDown(); NestedTypeCountUpDown = new NumericUpDown(); - AddRemapButton = new Button(); + SaveRemapButton = new Button(); IsDerivedUpDown = new DomainUpDown(); IsNestedUpDown = new DomainUpDown(); HasAttributeUpDown = new DomainUpDown(); @@ -157,7 +158,7 @@ partial class ReCodeItForm TabPageRemapper.Padding = new Padding(3); TabPageRemapper.Size = new Size(1336, 953); TabPageRemapper.TabIndex = 1; - TabPageRemapper.Text = "ReCodeItRemapper"; + TabPageRemapper.Text = "Remapper"; // // RemapTreeView // @@ -168,6 +169,7 @@ partial class ReCodeItForm // // groupBox1 // + groupBox1.Controls.Add(EditRemapButton); groupBox1.Controls.Add(ConstuctorCountUpDown); groupBox1.Controls.Add(ConstructorCountEnabled); groupBox1.Controls.Add(LoadMappingFileButton); @@ -192,7 +194,7 @@ partial class ReCodeItForm groupBox1.Controls.Add(HasGenericParametersUpDown); groupBox1.Controls.Add(IsEnumUpDown); groupBox1.Controls.Add(NestedTypeCountUpDown); - groupBox1.Controls.Add(AddRemapButton); + groupBox1.Controls.Add(SaveRemapButton); groupBox1.Controls.Add(IsDerivedUpDown); groupBox1.Controls.Add(IsNestedUpDown); groupBox1.Controls.Add(HasAttributeUpDown); @@ -206,6 +208,16 @@ partial class ReCodeItForm groupBox1.TabStop = false; groupBox1.Text = "Remap Editor"; // + // EditRemapButton + // + EditRemapButton.Location = new Point(580, 145); + EditRemapButton.Name = "EditRemapButton"; + EditRemapButton.Size = new Size(168, 34); + EditRemapButton.TabIndex = 21; + EditRemapButton.Text = "Edit Remap"; + EditRemapButton.UseVisualStyleBackColor = true; + EditRemapButton.Click += EditRemapButton_Click; + // // ConstuctorCountUpDown // ConstuctorCountUpDown.Location = new Point(224, 178); @@ -245,7 +257,7 @@ partial class ReCodeItForm // // RunRemapButton // - RunRemapButton.Location = new Point(580, 145); + RunRemapButton.Location = new Point(580, 185); RunRemapButton.Name = "RunRemapButton"; RunRemapButton.Size = new Size(168, 34); RunRemapButton.TabIndex = 16; @@ -789,15 +801,15 @@ partial class ReCodeItForm NestedTypeCountUpDown.Size = new Size(55, 31); NestedTypeCountUpDown.TabIndex = 4; // - // AddRemapButton + // SaveRemapButton // - AddRemapButton.Location = new Point(580, 64); - AddRemapButton.Name = "AddRemapButton"; - AddRemapButton.Size = new Size(168, 34); - AddRemapButton.TabIndex = 4; - AddRemapButton.Text = "Add Remap"; - AddRemapButton.UseVisualStyleBackColor = true; - AddRemapButton.Click += AddRemapButton_Click; + SaveRemapButton.Location = new Point(580, 64); + SaveRemapButton.Name = "SaveRemapButton"; + SaveRemapButton.Size = new Size(168, 34); + SaveRemapButton.TabIndex = 4; + SaveRemapButton.Text = "Save Remap"; + SaveRemapButton.UseVisualStyleBackColor = true; + SaveRemapButton.Click += AddRemapButton_Click; // // IsDerivedUpDown // @@ -1188,7 +1200,7 @@ partial class ReCodeItForm private TextBox OriginalTypeName; private TextBox NewTypeName; private Button RemoveRemapButton; - private Button AddRemapButton; + private Button SaveRemapButton; private ListView RemapListView; private TabControl TabControlMain; private DomainUpDown IsPublicUpDown; @@ -1234,4 +1246,5 @@ partial class ReCodeItForm private NumericUpDown AutoMapperRequiredMatchesUpDown; private Label label1; private Label label2; + private Button EditRemapButton; } diff --git a/RecodeItGUI/GUI/Main.cs b/RecodeItGUI/GUI/Main.cs index c4a9a0a..58ce604 100644 --- a/RecodeItGUI/GUI/Main.cs +++ b/RecodeItGUI/GUI/Main.cs @@ -9,6 +9,8 @@ public partial class ReCodeItForm : Form { public static ReCodeItRemapper Remapper { get; private set; } = new(); + private RemapModel CurrentRemap { get; set; } + public ReCodeItForm() { InitializeComponent(); @@ -35,7 +37,7 @@ public partial class ReCodeItForm : Form return; } - var remap = new RemapModel + var newRemap = new RemapModel { Succeeded = false, FailureReason = EFailureReason.None, @@ -83,8 +85,31 @@ public partial class ReCodeItForm : Form } }; - RemapTreeView.Nodes.Add(GUIHelpers.GenerateTreeNode(remap, this)); - DataProvider.Remaps.Add(remap); + var existingRemap = DataProvider.Remaps + .Where(remap => remap.NewTypeName == NewTypeName.Text) + .FirstOrDefault(); + + // Handle overwriting an existing remap + if (existingRemap != null) + { + var index = DataProvider.Remaps.IndexOf(existingRemap); + + DataProvider.Remaps.Remove(existingRemap); + RemapTreeView.Nodes.RemoveAt(index); + + DataProvider.Remaps.Insert(index, newRemap); + RemapTreeView.Nodes.Insert(index, GUIHelpers.GenerateTreeNode(newRemap, this)); + + CurrentRemap = existingRemap; + + ResetAll(); + return; + } + + CurrentRemap = newRemap; + RemapTreeView.Nodes.Add(GUIHelpers.GenerateTreeNode(newRemap, this)); + DataProvider.Remaps.Add(newRemap); + ResetAll(); } @@ -94,6 +119,11 @@ public partial class ReCodeItForm : Form RemapTreeView.SelectedNode?.Remove(); } + private void EditRemapButton_Click(object sender, EventArgs e) + { + EditSelectedRemap(); + } + private void RunRemapButton_Click(object sender, EventArgs e) { if (ReCodeItRemapper.IsRunning) { return; } @@ -425,6 +455,7 @@ public partial class ReCodeItForm : Form // Numeric UpDowns + ConstuctorCountUpDown.Value = 0; MethodCountUpDown.Value = 0; FieldCountUpDown.Value = 0; PropertyCountUpDown.Value = 0; @@ -433,6 +464,7 @@ public partial class ReCodeItForm : Form // Check boxes ForceRenameCheckbox.Checked = false; + ConstructorCountEnabled.Checked = false; MethodCountEnabled.Checked = false; FieldCountEnabled.Checked = false; PropertyCountEnabled.Checked = false; @@ -450,6 +482,82 @@ public partial class ReCodeItForm : Form NestedTypesExcludeBox.Items.Clear(); } + private void EditSelectedRemap() + { + ResetAll(); + var remap = DataProvider.Remaps.ElementAt(RemapTreeView.SelectedNode.Index); + + NewTypeName.Text = remap.NewTypeName; + OriginalTypeName.Text = remap.OriginalTypeName; + ForceRenameCheckbox.Checked = remap.UseForceRename; + + BaseClassIncludeTextFIeld.Text = remap.SearchParams.MatchBaseClass; + BaseClassExcludeTextField.Text = remap.SearchParams.IgnoreBaseClass; + NestedTypeParentName.Text = remap.SearchParams.ParentName; + + ConstructorCountEnabled.Checked = remap.SearchParams.ConstructorParameterCount != null ? remap.SearchParams.ConstructorParameterCount > 0 : false; + MethodCountEnabled.Checked = remap.SearchParams.MethodCount != null ? remap.SearchParams.MethodCount > 0 : false; + FieldCountEnabled.Checked = remap.SearchParams.FieldCount != null ? remap.SearchParams.FieldCount > 0 : false; + PropertyCountEnabled.Checked = remap.SearchParams.PropertyCount != null ? remap.SearchParams.PropertyCount > 0 : false; + NestedTypeCountEnabled.Checked = remap.SearchParams.NestedTypeCount != null ? remap.SearchParams.NestedTypeCount > 0 : false; + + ConstuctorCountUpDown.Value = (decimal)((remap.SearchParams.ConstructorParameterCount != null ? remap.SearchParams.ConstructorParameterCount : 0)); + MethodCountUpDown.Value = (decimal)(remap.SearchParams.MethodCount != null ? remap.SearchParams.MethodCount : 0); + FieldCountUpDown.Value = (decimal)(remap.SearchParams.FieldCount != null ? remap.SearchParams.FieldCount : 0); + PropertyCountUpDown.Value = (decimal)(remap.SearchParams.PropertyCount != null ? remap.SearchParams.PropertyCount : 0); + NestedTypeCountUpDown.Value = (decimal)(remap.SearchParams.NestedTypeCount != null ? remap.SearchParams.NestedTypeCount : 0); + + IsPublicUpDown.BuildStringList("IsPublic", remap.SearchParams.IsPublic); + IsAbstractUpDown.BuildStringList("IsAbstract", remap.SearchParams.IsAbstract); + IsInterfaceUpDown.BuildStringList("IsInterface", remap.SearchParams.IsInterface); + IsEnumUpDown.BuildStringList("IsEnum", remap.SearchParams.IsEnum); + IsNestedUpDown.BuildStringList("IsNested", remap.SearchParams.IsNested); + IsSealedUpDown.BuildStringList("IsSealed", remap.SearchParams.IsSealed); + HasAttributeUpDown.BuildStringList("HasAttribute", remap.SearchParams.HasAttribute); + IsDerivedUpDown.BuildStringList("IsDerived", remap.SearchParams.IsDerived); + HasGenericParametersUpDown.BuildStringList("HasGenericParams", remap.SearchParams.HasGenericParameters); + + foreach (var method in remap.SearchParams.IncludeMethods) + { + MethodIncludeBox.Items.Add(method); + } + + foreach (var method in remap.SearchParams.ExcludeMethods) + { + MethodExcludeBox.Items.Add(method); + } + + foreach (var method in remap.SearchParams.IncludeFields) + { + FieldIncludeBox.Items.Add(method); + } + + foreach (var method in remap.SearchParams.ExcludeFields) + { + FieldExcludeBox.Items.Add(method); + } + + foreach (var method in remap.SearchParams.IncludeProperties) + { + PropertiesIncludeBox.Items.Add(method); + } + + foreach (var method in remap.SearchParams.ExcludeProperties) + { + PropertiesExcludeBox.Items.Add(method); + } + + foreach (var method in remap.SearchParams.IncludeNestedTypes) + { + NestedTypesIncludeBox.Items.Add(method); + } + + foreach (var method in remap.SearchParams.ExcludeNestedTypes) + { + NestedTypesExcludeBox.Items.Add(method); + } + } + private void PopulateDomainUpDowns() { // Clear them all first just incase diff --git a/RecodeItGUI/Utils/GUIHelpers.cs b/RecodeItGUI/Utils/GUIHelpers.cs index 5e2f98a..aec7dfc 100644 --- a/RecodeItGUI/Utils/GUIHelpers.cs +++ b/RecodeItGUI/Utils/GUIHelpers.cs @@ -38,7 +38,7 @@ internal static class GUIHelpers /// /// /// - public static void BuildStringList(this DomainUpDown domainUpDown, string name) + public static void BuildStringList(this DomainUpDown domainUpDown, string name, bool? update = null) { domainUpDown.Items.Clear(); domainUpDown.Text = name + " (Disabled)"; @@ -51,6 +51,11 @@ internal static class GUIHelpers "False", }; + if (update != null) + { + domainUpDown.Text = update.ToString(); + } + domainUpDown.Items.AddRange(list); } @@ -71,7 +76,7 @@ internal static class GUIHelpers var IsDerived = model.SearchParams.IsDerived == null ? null : model.SearchParams.IsDerived; var HasGenericParameters = model.SearchParams.HasGenericParameters == null ? null : model.SearchParams.HasGenericParameters; - var remapTreeItem = new TreeNode($"Remap: {model.NewTypeName}"); + var remapTreeItem = new TreeNode($"{model.NewTypeName}"); var originalTypeName = new TreeNode($"Original Name: {model.OriginalTypeName}");