From 478f67aa82898ee014ac21950680f6330234e27a Mon Sep 17 00:00:00 2001 From: Michael Babienco Date: Tue, 3 Mar 2026 12:54:27 +0900 Subject: [PATCH] Convert remaining files to file-scoped namespace --- src/Helpers/ChangeNotifier.cs | 16 ++-- src/ViewModels/BaseViewModel.cs | 71 +++++++++--------- src/ViewModels/MainWindowViewModel.cs | 77 ++++++++++---------- src/ViewModels/WarningDeleteItemViewModel.cs | 39 +++++----- src/Views/AboutView.axaml.cs | 41 +++++------ src/Views/EditFile.axaml.cs | 11 ++- src/Views/MainView.axaml.cs | 49 ++++++------- src/Views/WarningDeleteItem.axaml.cs | 11 ++- 8 files changed, 153 insertions(+), 162 deletions(-) diff --git a/src/Helpers/ChangeNotifier.cs b/src/Helpers/ChangeNotifier.cs index d1ac2fb..d3f7136 100644 --- a/src/Helpers/ChangeNotifier.cs +++ b/src/Helpers/ChangeNotifier.cs @@ -4,16 +4,14 @@ using System.ComponentModel; using System.Runtime.CompilerServices; using System.Text; -namespace MayShow.Helpers -{ +namespace MayShow.Helpers; - // https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.inotifypropertychanged?view=netframework-4.7.2 - class ChangeNotifier : INotifyPropertyChanged +// https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.inotifypropertychanged?view=netframework-4.7.2 +class ChangeNotifier : INotifyPropertyChanged +{ + public event PropertyChangedEventHandler? PropertyChanged; + protected void NotifyPropertyChanged([CallerMemberName] string propertyName = "") { - public event PropertyChangedEventHandler? PropertyChanged; - protected void NotifyPropertyChanged([CallerMemberName] string propertyName = "") - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } diff --git a/src/ViewModels/BaseViewModel.cs b/src/ViewModels/BaseViewModel.cs index bc5a82c..24daa94 100644 --- a/src/ViewModels/BaseViewModel.cs +++ b/src/ViewModels/BaseViewModel.cs @@ -5,43 +5,42 @@ using System; using System.Collections.Generic; using System.Text; -namespace MayShow.ViewModels +namespace MayShow.ViewModels; + +class BaseViewModel : ChangeNotifier { - class BaseViewModel : ChangeNotifier + IChangeViewModel _viewModelChanger; + ITopLevelGrabber? _topLevelGrabber; + + public BaseViewModel(IChangeViewModel viewModelChanger) { - IChangeViewModel _viewModelChanger; - ITopLevelGrabber? _topLevelGrabber; - - public BaseViewModel(IChangeViewModel viewModelChanger) - { - _viewModelChanger = viewModelChanger; - _topLevelGrabber = null; - } - - public ITopLevelGrabber? TopLevelGrabber - { - get => _topLevelGrabber; - set { _topLevelGrabber = value; } - } - - public IChangeViewModel ViewModelChanger - { - get { return _viewModelChanger; } - set { _viewModelChanger = value; } - } - - #region IChangeViewModel - - public void PopViewModel() - { - _viewModelChanger?.PopViewModel(); - } - - public void PushViewModel(BaseViewModel model) - { - _viewModelChanger?.PushViewModel(model); - } - - #endregion + _viewModelChanger = viewModelChanger; + _topLevelGrabber = null; } + + public ITopLevelGrabber? TopLevelGrabber + { + get => _topLevelGrabber; + set { _topLevelGrabber = value; } + } + + public IChangeViewModel ViewModelChanger + { + get { return _viewModelChanger; } + set { _viewModelChanger = value; } + } + + #region IChangeViewModel + + public void PopViewModel() + { + _viewModelChanger?.PopViewModel(); + } + + public void PushViewModel(BaseViewModel model) + { + _viewModelChanger?.PushViewModel(model); + } + + #endregion } diff --git a/src/ViewModels/MainWindowViewModel.cs b/src/ViewModels/MainWindowViewModel.cs index 88deedf..5885e41 100644 --- a/src/ViewModels/MainWindowViewModel.cs +++ b/src/ViewModels/MainWindowViewModel.cs @@ -4,47 +4,46 @@ using System; using System.Collections.Generic; using System.Text; -namespace MayShow.ViewModels +namespace MayShow.ViewModels; + +class MainWindowViewModel : ChangeNotifier, IChangeViewModel { - class MainWindowViewModel : ChangeNotifier, IChangeViewModel + BaseViewModel _currentViewModel; + Stack _viewModels; + + public MainWindowViewModel(ITopLevelGrabber topLevelGrabber) { - BaseViewModel _currentViewModel; - Stack _viewModels; - - public MainWindowViewModel(ITopLevelGrabber topLevelGrabber) + _viewModels = new Stack(); + var initialViewModel = new MainViewModel(this) { - _viewModels = new Stack(); - var initialViewModel = new MainViewModel(this) - { - TopLevelGrabber = topLevelGrabber - }; - _viewModels.Push(initialViewModel); - _currentViewModel = initialViewModel; - } - - public BaseViewModel CurrentViewModel - { - get { return _currentViewModel; } - set { _currentViewModel = value; NotifyPropertyChanged(); } - } - - #region IChangeViewModel - - public void PushViewModel(BaseViewModel model) - { - _viewModels.Push(model); - CurrentViewModel = model; - } - - public void PopViewModel() - { - if (_viewModels.Count > 1) - { - _viewModels.Pop(); - CurrentViewModel = _viewModels.Peek(); - } - } - - #endregion + TopLevelGrabber = topLevelGrabber + }; + _viewModels.Push(initialViewModel); + _currentViewModel = initialViewModel; } + + public BaseViewModel CurrentViewModel + { + get { return _currentViewModel; } + set { _currentViewModel = value; NotifyPropertyChanged(); } + } + + #region IChangeViewModel + + public void PushViewModel(BaseViewModel model) + { + _viewModels.Push(model); + CurrentViewModel = model; + } + + public void PopViewModel() + { + if (_viewModels.Count > 1) + { + _viewModels.Pop(); + CurrentViewModel = _viewModels.Peek(); + } + } + + #endregion } diff --git a/src/ViewModels/WarningDeleteItemViewModel.cs b/src/ViewModels/WarningDeleteItemViewModel.cs index 9a165f1..589e8f2 100644 --- a/src/ViewModels/WarningDeleteItemViewModel.cs +++ b/src/ViewModels/WarningDeleteItemViewModel.cs @@ -2,30 +2,29 @@ using MayShow.Helpers; using MayShow.Models; -namespace MayShow.ViewModels +namespace MayShow.ViewModels; + +class WarningDeleteItemViewModel : ChangeNotifier { - class WarningDeleteItemViewModel : ChangeNotifier + ReportFile _file; + + public WarningDeleteItemViewModel(ReportFile file) { - ReportFile _file; + _file = file; + } - public WarningDeleteItemViewModel(ReportFile file) - { - _file = file; - } + public ReportFile File + { + get => _file; + } - public ReportFile File - { - get => _file; - } + public void KeepItem() + { + DialogHost.Close("DialogHost", false); + } - public void KeepItem() - { - DialogHost.Close("DialogHost", false); - } - - public void RemoveItem() - { - DialogHost.Close("DialogHost", true); - } + public void RemoveItem() + { + DialogHost.Close("DialogHost", true); } } diff --git a/src/Views/AboutView.axaml.cs b/src/Views/AboutView.axaml.cs index eab6a53..7a3c2ef 100644 --- a/src/Views/AboutView.axaml.cs +++ b/src/Views/AboutView.axaml.cs @@ -5,35 +5,34 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; -namespace MayShow.Views -{ - public partial class AboutView : UserControl - { - public AboutView() - { - this.InitializeComponent(); +namespace MayShow.Views; - // set license text - var processDir = Path.GetDirectoryName(Environment.ProcessPath) ?? ""; - var licenseFileName = Path.Combine(processDir, "Assets", "LICENSES.txt"); - var licenseText = ""; +public partial class AboutView : UserControl +{ + public AboutView() + { + this.InitializeComponent(); + + // set license text + var processDir = Path.GetDirectoryName(Environment.ProcessPath) ?? ""; + var licenseFileName = Path.Combine(processDir, "Assets", "LICENSES.txt"); + var licenseText = ""; + if (File.Exists(licenseFileName)) + { + licenseText = File.ReadAllText(licenseFileName); + } + else + { + licenseFileName = Path.Combine(processDir, "../Resources/Assets/LICENSES.txt"); if (File.Exists(licenseFileName)) { licenseText = File.ReadAllText(licenseFileName); } else { - licenseFileName = Path.Combine(processDir, "../Resources/Assets/LICENSES.txt"); - if (File.Exists(licenseFileName)) - { - licenseText = File.ReadAllText(licenseFileName); - } - else - { - licenseText = "Error: Unable to find license file!"; - } + licenseText = "Error: Unable to find license file!"; } - LicenseTextBlock.Text = licenseText.Trim(); } + LicenseTextBlock.Text = licenseText.Trim(); } } diff --git a/src/Views/EditFile.axaml.cs b/src/Views/EditFile.axaml.cs index d866ba6..eb60d8d 100644 --- a/src/Views/EditFile.axaml.cs +++ b/src/Views/EditFile.axaml.cs @@ -3,13 +3,12 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; -namespace MayShow.Views +namespace MayShow.Views; + +public partial class EditFile : UserControl { - public partial class EditFile : UserControl + public EditFile() { - public EditFile() - { - this.InitializeComponent(); - } + this.InitializeComponent(); } } diff --git a/src/Views/MainView.axaml.cs b/src/Views/MainView.axaml.cs index b257af3..8b5e590 100644 --- a/src/Views/MainView.axaml.cs +++ b/src/Views/MainView.axaml.cs @@ -5,41 +5,40 @@ using Avalonia.Input; using Avalonia.Markup.Xaml; using MayShow.ViewModels; -namespace MayShow.Views +namespace MayShow.Views; + +public partial class MainView : UserControl { - public partial class MainView : UserControl + public MainView() { - public MainView() - { - this.InitializeComponent(); - LogBlock.PropertyChanged += LogBlock_PropertyChanged; - FilesGrid.CellEditEnded += FileCellEditEnded; - } + this.InitializeComponent(); + LogBlock.PropertyChanged += LogBlock_PropertyChanged; + FilesGrid.CellEditEnded += FileCellEditEnded; + } - private void LogBlock_PropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e) + private void LogBlock_PropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e) + { + if (e.Property.ToString() == "Text") { - if (e.Property.ToString() == "Text") - { - LogScrollView.ScrollToEnd(); - } + LogScrollView.ScrollToEnd(); } + } - public void UnfocusTextbox() + public void UnfocusTextbox() + { + var topLevel = TopLevel.GetTopLevel(this); + topLevel?.FocusManager?.ClearFocus(); + if (DataContext is MainViewModel mvm) { - var topLevel = TopLevel.GetTopLevel(this); - topLevel?.FocusManager?.ClearFocus(); - if (DataContext is MainViewModel mvm) - { - mvm?.HasUnsavedWork = true; - } + mvm?.HasUnsavedWork = true; } + } - private void FileCellEditEnded(object? sender, DataGridCellEditEndedEventArgs args) + private void FileCellEditEnded(object? sender, DataGridCellEditEndedEventArgs args) + { + if (args.EditAction == DataGridEditAction.Commit && DataContext is MainViewModel mvm) { - if (args.EditAction == DataGridEditAction.Commit && DataContext is MainViewModel mvm) - { - mvm?.HasUnsavedWork = true; - } + mvm?.HasUnsavedWork = true; } } } diff --git a/src/Views/WarningDeleteItem.axaml.cs b/src/Views/WarningDeleteItem.axaml.cs index 872bab3..0b61561 100644 --- a/src/Views/WarningDeleteItem.axaml.cs +++ b/src/Views/WarningDeleteItem.axaml.cs @@ -3,13 +3,12 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; -namespace MayShow.Views +namespace MayShow.Views; + +public partial class WarningDeleteItem : UserControl { - public partial class WarningDeleteItem : UserControl + public WarningDeleteItem() { - public WarningDeleteItem() - { - this.InitializeComponent(); - } + this.InitializeComponent(); } }