From abf1fbf1675c73923c9e5ab09799bd760ba04683 Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Mon, 17 Jun 2024 01:22:11 -0400 Subject: [PATCH] Start work on WPF project --- ReCodeItGUI_WPF/App.xaml | 10 ++ ReCodeItGUI_WPF/App.xaml.cs | 14 ++ ReCodeItGUI_WPF/AssemblyInfo.cs | 10 ++ ReCodeItGUI_WPF/Helpers/GUIExtentions.cs | 156 ++++++++++++++++++ ReCodeItGUI_WPF/MainWindow.xaml | 197 +++++++++++++++++++++++ ReCodeItGUI_WPF/MainWindow.xaml.cs | 94 +++++++++++ ReCodeItGUI_WPF/ReCodeItGUI_WPF.csproj | 23 +++ RecodeIt.sln | 6 + RecodeItLib/Models/TypeDatabase.cs | 50 ++++++ 9 files changed, 560 insertions(+) create mode 100644 ReCodeItGUI_WPF/App.xaml create mode 100644 ReCodeItGUI_WPF/App.xaml.cs create mode 100644 ReCodeItGUI_WPF/AssemblyInfo.cs create mode 100644 ReCodeItGUI_WPF/Helpers/GUIExtentions.cs create mode 100644 ReCodeItGUI_WPF/MainWindow.xaml create mode 100644 ReCodeItGUI_WPF/MainWindow.xaml.cs create mode 100644 ReCodeItGUI_WPF/ReCodeItGUI_WPF.csproj create mode 100644 RecodeItLib/Models/TypeDatabase.cs diff --git a/ReCodeItGUI_WPF/App.xaml b/ReCodeItGUI_WPF/App.xaml new file mode 100644 index 0000000..d33d2b8 --- /dev/null +++ b/ReCodeItGUI_WPF/App.xaml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/ReCodeItGUI_WPF/App.xaml.cs b/ReCodeItGUI_WPF/App.xaml.cs new file mode 100644 index 0000000..828021e --- /dev/null +++ b/ReCodeItGUI_WPF/App.xaml.cs @@ -0,0 +1,14 @@ +using System.Configuration; +using System.Data; +using System.Windows; + +namespace ReCodeItGUI_WPF +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } + +} diff --git a/ReCodeItGUI_WPF/AssemblyInfo.cs b/ReCodeItGUI_WPF/AssemblyInfo.cs new file mode 100644 index 0000000..b0ec827 --- /dev/null +++ b/ReCodeItGUI_WPF/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/ReCodeItGUI_WPF/Helpers/GUIExtentions.cs b/ReCodeItGUI_WPF/Helpers/GUIExtentions.cs new file mode 100644 index 0000000..143c74f --- /dev/null +++ b/ReCodeItGUI_WPF/Helpers/GUIExtentions.cs @@ -0,0 +1,156 @@ +using Microsoft.Win32; +using ReCodeIt.Models; +using System.Windows.Controls; +using Xceed.Wpf.Toolkit; + +namespace ReCodeItGUI_WPF.Helpers +{ + internal static class GUIExtentions + { + #region EXT_METHODS + + public static void AddToListView(this ListView listView, TextBox textBox) + { + if (!string.IsNullOrWhiteSpace(textBox.Text) && !listView.Items.Contains(textBox.Text)) + { + listView.Items.Add(textBox.Text); + textBox.Clear(); + } + } + + public static void RemoveSelectedItem(this ListView listView) + { + if (listView.SelectedItem != null) + { + listView.Items.RemoveAt(listView.SelectedIndex); + } + } + + #endregion EXT_METHODS + + /// + /// Returns the string result of the dialog + /// + /// Path if valid, or empty string + public static string OpenFileDialog(bool dll = false) + { + var title = dll ? "Select a DLL File" : "Select a Json File"; + + var defaultExt = dll ? ".dll" : ".jsonc"; + + var dllFilter = "DLL files (*.dll)|*.dll|All files (*.*)|*.*"; + var jsonFilter = "JSON/JSONC files (*.json;*.jsonc)|*.json;*.jsonc|All files (*.*)|*.*"; + + var openFileDialog = new OpenFileDialog(); + openFileDialog.Title = title; + openFileDialog.Filter = dll ? dllFilter : jsonFilter; + openFileDialog.DefaultExt = defaultExt; + + bool? result = openFileDialog.ShowDialog(); + + if (result == true) + { + return openFileDialog.FileName; + } + + return string.Empty; + } + + public static RemapModel CreateRemapFromGui(this MainWindow window) + { + var model = new RemapModel + { + NewTypeName = window.NewTypeNameTextBox.Text, + OriginalTypeName = window.OriginalTypeNameTextBox.Text ?? string.Empty, + UseForceRename = (bool)window.UseForceRenameCheckbox.IsChecked, + SearchParams = new SearchParams + { + IsPublic = window.IsPublicComboBox.IsComboEnabled(), + IsAbstract = window.IsAbstractComboBox.IsComboEnabled(), + IsInterface = window.IsInterfaceComboBox.IsComboEnabled(), + IsEnum = window.IsEnumComboBox.IsComboEnabled(), + IsNested = window.IsNestedComboBox.IsComboEnabled(), + IsSealed = window.IsSealedComboBox.IsComboEnabled(), + HasAttribute = window.HasAttributeComboBox.IsComboEnabled(), + IsDerived = window.IsDerivedComboBox.IsComboEnabled(), + HasGenericParameters = window.HasAttributeComboBox.IsComboEnabled(), + ParentName = window.ParentNameTextBox.GetText(), + MatchBaseClass = window.IncludeBaseClassTextBox.GetText(), + IgnoreBaseClass = window.IgnoreBaseClassTextBox.GetText(), + ConstructorParameterCount = window.CtorParamCountUpDown.GetValIfEnabled(window.CtorCheckbox), + MethodCount = window.MethodCountUpDown.GetValIfEnabled(window.MethodCheckbox), + FieldCount = window.FieldCountUpDown.GetValIfEnabled(window.FieldCountCheckbox), + PropertyCount = window.PropertyCountUpDown.GetValIfEnabled(window.PropertyCountCheckBox), + NestedTypeCount = window.NestedTypeCountUpDown.GetValIfEnabled(window.NestedTypeCountCheckBox), + IncludeMethods = window.MethodIncludeListView.GetItems(), + ExcludeMethods = window.MethodExcludeListView.GetItems(), + IncludeFields = window.FieldIncludeListView.GetItems(), + ExcludeFields = window.FieldExcludeListView.GetItems(), + IncludeProperties = window.PropertyIncludeListBox.GetItems(), + ExcludeProperties = window.PropertyExcludeListBox.GetItems(), + IncludeNestedTypes = window.NestedTypeIncludeListView.GetItems(), + ExcludeNestedTypes = window.NestedTypeExcludeListView.GetItems(), + } + }; + + return model; + } + + /// + /// True or false if selected, otherwise null + /// + /// + /// + public static bool? IsComboEnabled(this ComboBox comboBox) + { + if (bool.TryParse(comboBox.Text, out var result)) + { + return result; + } + + return null; + } + + /// + /// returns the text in the box if exists, or null + /// + /// + /// + public static string? GetText(this TextBox textBox) + { + if (textBox.Text != string.Empty) + { + return textBox.Text; + } + + return null; + } + + public static int? GetValIfEnabled(this IntegerUpDown intUpDown, CheckBox cBox) + { + if ((bool)cBox.IsChecked) + { + return intUpDown.Value; + } + + return null; + } + + /// + /// Converts list view objects to string list + /// + /// + /// + public static List GetItems(this ListView listView) + { + var tmp = new List(); + + foreach (var item in listView.Items) + { + tmp.Add(item.ToString()); + } + + return tmp; + } + } +} \ No newline at end of file diff --git a/ReCodeItGUI_WPF/MainWindow.xaml b/ReCodeItGUI_WPF/MainWindow.xaml new file mode 100644 index 0000000..6e80674 --- /dev/null +++ b/ReCodeItGUI_WPF/MainWindow.xaml @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + +