diff --git a/ReCodeItGUI_WPF/App.xaml b/ReCodeItGUI_WPF/App.xaml index d33d2b8..2493fa6 100644 --- a/ReCodeItGUI_WPF/App.xaml +++ b/ReCodeItGUI_WPF/App.xaml @@ -1,10 +1,17 @@ - + + + + + + + - \ No newline at end of file + diff --git a/ReCodeItGUI_WPF/App.xaml.cs b/ReCodeItGUI_WPF/App.xaml.cs index 828021e..52db7ad 100644 --- a/ReCodeItGUI_WPF/App.xaml.cs +++ b/ReCodeItGUI_WPF/App.xaml.cs @@ -1,14 +1,94 @@ -using System.Configuration; -using System.Data; -using System.Windows; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using ReCodeItGUI_WPF.Services; +using ReCodeItGUI_WPF.ViewModels.Pages; +using ReCodeItGUI_WPF.ViewModels.Windows; +using ReCodeItGUI_WPF.Views.Pages; +using ReCodeItGUI_WPF.Views.Windows; +using System.IO; +using System.Reflection; +using System.Windows.Threading; +using Wpf.Ui; namespace ReCodeItGUI_WPF { /// /// Interaction logic for App.xaml /// - public partial class App : Application + public partial class App { - } + // The.NET Generic Host provides dependency injection, configuration, logging, and other services. + // https://docs.microsoft.com/dotnet/core/extensions/generic-host + // https://docs.microsoft.com/dotnet/core/extensions/dependency-injection + // https://docs.microsoft.com/dotnet/core/extensions/configuration + // https://docs.microsoft.com/dotnet/core/extensions/logging + private static readonly IHost _host = Host + .CreateDefaultBuilder() + .ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)); }) + .ConfigureServices((context, services) => + { + services.AddHostedService(); + // Page resolver service + services.AddSingleton(); + + // Theme manipulation + services.AddSingleton(); + + // TaskBar manipulation + services.AddSingleton(); + + // Service containing navigation, same as INavigationWindow... but without window + services.AddSingleton(); + + // Main window with navigation + services.AddSingleton(); + services.AddSingleton(); + + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + }).Build(); + + /// + /// Gets registered service. + /// + /// Type of the service to get. + /// Instance of the service or . + public static T GetService() + where T : class + { + return _host.Services.GetService(typeof(T)) as T; + } + + /// + /// Occurs when the application is loading. + /// + private void OnStartup(object sender, StartupEventArgs e) + { + _host.Start(); + } + + /// + /// Occurs when the application is closing. + /// + private async void OnExit(object sender, ExitEventArgs e) + { + await _host.StopAsync(); + + _host.Dispose(); + } + + /// + /// Occurs when an exception is thrown by an application but not handled. + /// + private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) + { + // For more info see https://docs.microsoft.com/en-us/dotnet/api/system.windows.application.dispatcherunhandledexception?view=windowsdesktop-6.0 + } + } } diff --git a/ReCodeItGUI_WPF/AssemblyInfo.cs b/ReCodeItGUI_WPF/AssemblyInfo.cs index b0ec827..7ad982e 100644 --- a/ReCodeItGUI_WPF/AssemblyInfo.cs +++ b/ReCodeItGUI_WPF/AssemblyInfo.cs @@ -1,10 +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) + 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/Assets/wpfui-icon-1024.png b/ReCodeItGUI_WPF/Assets/wpfui-icon-1024.png new file mode 100644 index 0000000..b70c4ed Binary files /dev/null and b/ReCodeItGUI_WPF/Assets/wpfui-icon-1024.png differ diff --git a/ReCodeItGUI_WPF/Assets/wpfui-icon-256.png b/ReCodeItGUI_WPF/Assets/wpfui-icon-256.png new file mode 100644 index 0000000..6b5cf5d Binary files /dev/null and b/ReCodeItGUI_WPF/Assets/wpfui-icon-256.png differ diff --git a/ReCodeItGUI_WPF/Helpers/EnumToBooleanConverter.cs b/ReCodeItGUI_WPF/Helpers/EnumToBooleanConverter.cs new file mode 100644 index 0000000..5d225a4 --- /dev/null +++ b/ReCodeItGUI_WPF/Helpers/EnumToBooleanConverter.cs @@ -0,0 +1,36 @@ +using System.Globalization; +using System.Windows.Data; +using Wpf.Ui.Appearance; + +namespace ReCodeItGUI_WPF.Helpers +{ + internal class EnumToBooleanConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (parameter is not String enumString) + { + throw new ArgumentException("ExceptionEnumToBooleanConverterParameterMustBeAnEnumName"); + } + + if (!Enum.IsDefined(typeof(ApplicationTheme), value)) + { + throw new ArgumentException("ExceptionEnumToBooleanConverterValueMustBeAnEnum"); + } + + var enumValue = Enum.Parse(typeof(ApplicationTheme), enumString); + + return enumValue.Equals(value); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (parameter is not String enumString) + { + throw new ArgumentException("ExceptionEnumToBooleanConverterParameterMustBeAnEnumName"); + } + + return Enum.Parse(typeof(ApplicationTheme), enumString); + } + } +} diff --git a/ReCodeItGUI_WPF/Helpers/GUIExtentions.cs b/ReCodeItGUI_WPF/Helpers/GUIExtentions.cs deleted file mode 100644 index 143c74f..0000000 --- a/ReCodeItGUI_WPF/Helpers/GUIExtentions.cs +++ /dev/null @@ -1,156 +0,0 @@ -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 deleted file mode 100644 index 6e80674..0000000 --- a/ReCodeItGUI_WPF/MainWindow.xaml +++ /dev/null @@ -1,197 +0,0 @@ - - - - - - - - - - - - - - - - - - - -