From 77725ea5d7d5d2bdcca8449cb2371a5b2e80ac72 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Sat, 15 Jul 2023 22:30:52 +0100 Subject: [PATCH] Consolidate NotifyPropertyChanged ViewModels --- .../Bootstrapper/BootstrapperDialogViewModel.cs | 5 +---- .../Bootstrapper/ByfronDialogViewModel.cs | 2 +- .../UI/ViewModels/Menu/AppearanceViewModel.cs | 5 +---- .../UI/ViewModels/Menu/BehaviourViewModel.cs | 5 +---- .../UI/ViewModels/Menu/FastFlagsViewModel.cs | 5 +---- .../UI/ViewModels/Menu/InstallationViewModel.cs | 5 +---- .../UI/ViewModels/Menu/IntegrationsViewModel.cs | 5 +---- .../UI/ViewModels/Menu/MainWindowViewModel.cs | 5 +---- Bloxstrap/UI/ViewModels/Menu/ModsViewModel.cs | 5 +---- .../ViewModels/NotifyPropertyChangedViewModel.cs | 15 +++++++++++++++ 10 files changed, 24 insertions(+), 33 deletions(-) create mode 100644 Bloxstrap/UI/ViewModels/NotifyPropertyChangedViewModel.cs diff --git a/Bloxstrap/UI/ViewModels/Bootstrapper/BootstrapperDialogViewModel.cs b/Bloxstrap/UI/ViewModels/Bootstrapper/BootstrapperDialogViewModel.cs index 95866b66..5867d5c4 100644 --- a/Bloxstrap/UI/ViewModels/Bootstrapper/BootstrapperDialogViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Bootstrapper/BootstrapperDialogViewModel.cs @@ -9,11 +9,8 @@ namespace Bloxstrap.UI.ViewModels.Bootstrapper { - public class BootstrapperDialogViewModel : INotifyPropertyChanged + public class BootstrapperDialogViewModel : NotifyPropertyChangedViewModel { - public event PropertyChangedEventHandler? PropertyChanged; - public void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - private readonly IBootstrapperDialog _dialog; public ICommand CancelInstallCommand => new RelayCommand(CancelInstall); diff --git a/Bloxstrap/UI/ViewModels/Bootstrapper/ByfronDialogViewModel.cs b/Bloxstrap/UI/ViewModels/Bootstrapper/ByfronDialogViewModel.cs index 4cc3d686..568fe34b 100644 --- a/Bloxstrap/UI/ViewModels/Bootstrapper/ByfronDialogViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Bootstrapper/ByfronDialogViewModel.cs @@ -8,7 +8,7 @@ namespace Bloxstrap.UI.ViewModels.Bootstrapper { - public class ByfronDialogViewModel : BootstrapperDialogViewModel, INotifyPropertyChanged + public class ByfronDialogViewModel : BootstrapperDialogViewModel { // Using dark theme for default values. public ImageSource ByfronLogoLocation { get; set; } = new BitmapImage(new Uri("pack://application:,,,/Resources/BootstrapperStyles/ByfronDialog/ByfronLogoDark.jpg")); diff --git a/Bloxstrap/UI/ViewModels/Menu/AppearanceViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/AppearanceViewModel.cs index c22ba1f1..19a5224b 100644 --- a/Bloxstrap/UI/ViewModels/Menu/AppearanceViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/AppearanceViewModel.cs @@ -15,11 +15,8 @@ namespace Bloxstrap.UI.ViewModels.Menu { - public class AppearanceViewModel : INotifyPropertyChanged + public class AppearanceViewModel : NotifyPropertyChangedViewModel { - public event PropertyChangedEventHandler? PropertyChanged; - public void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - private readonly Page _page; public ICommand PreviewBootstrapperCommand => new RelayCommand(PreviewBootstrapper); diff --git a/Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs index 331c9974..07688194 100644 --- a/Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs @@ -12,11 +12,8 @@ namespace Bloxstrap.UI.ViewModels.Menu { - public class BehaviourViewModel : INotifyPropertyChanged + public class BehaviourViewModel : NotifyPropertyChangedViewModel { - public event PropertyChangedEventHandler? PropertyChanged; - public void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - private bool _manualChannelEntry = !RobloxDeployment.SelectableChannels.Contains(App.Settings.Prop.Channel); public BehaviourViewModel() diff --git a/Bloxstrap/UI/ViewModels/Menu/FastFlagsViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/FastFlagsViewModel.cs index f1a17061..30ea3703 100644 --- a/Bloxstrap/UI/ViewModels/Menu/FastFlagsViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/FastFlagsViewModel.cs @@ -10,11 +10,8 @@ namespace Bloxstrap.UI.ViewModels.Menu { - public class FastFlagsViewModel : INotifyPropertyChanged + public class FastFlagsViewModel : NotifyPropertyChangedViewModel { - public event PropertyChangedEventHandler? PropertyChanged; - public void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - public ICommand OpenClientSettingsCommand => new RelayCommand(OpenClientSettings); private void OpenClientSettings() => Utilities.ShellExecute(Path.Combine(Directories.Modifications, "ClientSettings\\ClientAppSettings.json")); diff --git a/Bloxstrap/UI/ViewModels/Menu/InstallationViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/InstallationViewModel.cs index 6ad864b0..389abe84 100644 --- a/Bloxstrap/UI/ViewModels/Menu/InstallationViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/InstallationViewModel.cs @@ -6,11 +6,8 @@ namespace Bloxstrap.UI.ViewModels.Menu { - public class InstallationViewModel : INotifyPropertyChanged + public class InstallationViewModel : NotifyPropertyChangedViewModel { - public event PropertyChangedEventHandler? PropertyChanged; - public void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - private string _originalInstallLocation = App.BaseDirectory; public ICommand BrowseInstallLocationCommand => new RelayCommand(BrowseInstallLocation); diff --git a/Bloxstrap/UI/ViewModels/Menu/IntegrationsViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/IntegrationsViewModel.cs index 5847e6e9..d0425ac6 100644 --- a/Bloxstrap/UI/ViewModels/Menu/IntegrationsViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/IntegrationsViewModel.cs @@ -8,11 +8,8 @@ namespace Bloxstrap.UI.ViewModels.Menu { - public class IntegrationsViewModel : INotifyPropertyChanged + public class IntegrationsViewModel : NotifyPropertyChangedViewModel { - public event PropertyChangedEventHandler? PropertyChanged; - public void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - public ICommand AddIntegrationCommand => new RelayCommand(AddIntegration); public ICommand DeleteIntegrationCommand => new RelayCommand(DeleteIntegration); diff --git a/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs index 91c88f54..cad2e8d9 100644 --- a/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs @@ -16,11 +16,8 @@ namespace Bloxstrap.UI.ViewModels.Menu { - public class MainWindowViewModel : INotifyPropertyChanged + public class MainWindowViewModel : NotifyPropertyChangedViewModel { - public event PropertyChangedEventHandler? PropertyChanged; - public void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - private readonly Window _window; private readonly IDialogService _dialogService; private readonly string _originalBaseDirectory = App.BaseDirectory; // we need this to check if the basedirectory changes diff --git a/Bloxstrap/UI/ViewModels/Menu/ModsViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/ModsViewModel.cs index 7859f4af..7616c589 100644 --- a/Bloxstrap/UI/ViewModels/Menu/ModsViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/ModsViewModel.cs @@ -15,11 +15,8 @@ namespace Bloxstrap.UI.ViewModels.Menu { - public class ModsViewModel : INotifyPropertyChanged + public class ModsViewModel : NotifyPropertyChangedViewModel { - public event PropertyChangedEventHandler? PropertyChanged; - public void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - private void OpenModsFolder() => Process.Start("explorer.exe", Directories.Modifications); private string _customFontLocation = Path.Combine(Directories.Modifications, "content\\fonts\\CustomFont.ttf"); diff --git a/Bloxstrap/UI/ViewModels/NotifyPropertyChangedViewModel.cs b/Bloxstrap/UI/ViewModels/NotifyPropertyChangedViewModel.cs new file mode 100644 index 00000000..54acc1fd --- /dev/null +++ b/Bloxstrap/UI/ViewModels/NotifyPropertyChangedViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bloxstrap.UI.ViewModels +{ + public class NotifyPropertyChangedViewModel : INotifyPropertyChanged + { + public event PropertyChangedEventHandler? PropertyChanged; + public void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } +}