Convert remaining files to file-scoped namespace
This commit is contained in:
@@ -4,16 +4,14 @@ using System.ComponentModel;
|
|||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
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
|
// https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.inotifypropertychanged?view=netframework-4.7.2
|
||||||
class ChangeNotifier : INotifyPropertyChanged
|
class ChangeNotifier : INotifyPropertyChanged
|
||||||
|
{
|
||||||
|
public event PropertyChangedEventHandler? PropertyChanged;
|
||||||
|
protected void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
|
||||||
{
|
{
|
||||||
public event PropertyChangedEventHandler? PropertyChanged;
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
protected void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
|
|
||||||
{
|
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,43 +5,42 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
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;
|
_viewModelChanger = viewModelChanger;
|
||||||
ITopLevelGrabber? _topLevelGrabber;
|
_topLevelGrabber = null;
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,47 +4,46 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace MayShow.ViewModels
|
namespace MayShow.ViewModels;
|
||||||
|
|
||||||
|
class MainWindowViewModel : ChangeNotifier, IChangeViewModel
|
||||||
{
|
{
|
||||||
class MainWindowViewModel : ChangeNotifier, IChangeViewModel
|
BaseViewModel _currentViewModel;
|
||||||
|
Stack<BaseViewModel> _viewModels;
|
||||||
|
|
||||||
|
public MainWindowViewModel(ITopLevelGrabber topLevelGrabber)
|
||||||
{
|
{
|
||||||
BaseViewModel _currentViewModel;
|
_viewModels = new Stack<BaseViewModel>();
|
||||||
Stack<BaseViewModel> _viewModels;
|
var initialViewModel = new MainViewModel(this)
|
||||||
|
|
||||||
public MainWindowViewModel(ITopLevelGrabber topLevelGrabber)
|
|
||||||
{
|
{
|
||||||
_viewModels = new Stack<BaseViewModel>();
|
TopLevelGrabber = topLevelGrabber
|
||||||
var initialViewModel = new MainViewModel(this)
|
};
|
||||||
{
|
_viewModels.Push(initialViewModel);
|
||||||
TopLevelGrabber = topLevelGrabber
|
_currentViewModel = initialViewModel;
|
||||||
};
|
|
||||||
_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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,30 +2,29 @@
|
|||||||
using MayShow.Helpers;
|
using MayShow.Helpers;
|
||||||
using MayShow.Models;
|
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)
|
public ReportFile File
|
||||||
{
|
{
|
||||||
_file = file;
|
get => _file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReportFile File
|
public void KeepItem()
|
||||||
{
|
{
|
||||||
get => _file;
|
DialogHost.Close("DialogHost", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void KeepItem()
|
public void RemoveItem()
|
||||||
{
|
{
|
||||||
DialogHost.Close("DialogHost", false);
|
DialogHost.Close("DialogHost", true);
|
||||||
}
|
|
||||||
|
|
||||||
public void RemoveItem()
|
|
||||||
{
|
|
||||||
DialogHost.Close("DialogHost", true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,35 +5,34 @@ using Avalonia;
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
|
||||||
namespace MayShow.Views
|
namespace MayShow.Views;
|
||||||
{
|
|
||||||
public partial class AboutView : UserControl
|
|
||||||
{
|
|
||||||
public AboutView()
|
|
||||||
{
|
|
||||||
this.InitializeComponent();
|
|
||||||
|
|
||||||
// set license text
|
public partial class AboutView : UserControl
|
||||||
var processDir = Path.GetDirectoryName(Environment.ProcessPath) ?? "";
|
{
|
||||||
var licenseFileName = Path.Combine(processDir, "Assets", "LICENSES.txt");
|
public AboutView()
|
||||||
var licenseText = "";
|
{
|
||||||
|
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))
|
if (File.Exists(licenseFileName))
|
||||||
{
|
{
|
||||||
licenseText = File.ReadAllText(licenseFileName);
|
licenseText = File.ReadAllText(licenseFileName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
licenseFileName = Path.Combine(processDir, "../Resources/Assets/LICENSES.txt");
|
licenseText = "Error: Unable to find license file!";
|
||||||
if (File.Exists(licenseFileName))
|
|
||||||
{
|
|
||||||
licenseText = File.ReadAllText(licenseFileName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
licenseText = "Error: Unable to find license file!";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
LicenseTextBlock.Text = licenseText.Trim();
|
|
||||||
}
|
}
|
||||||
|
LicenseTextBlock.Text = licenseText.Trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,12 @@ using Avalonia;
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-25
@@ -5,41 +5,40 @@ using Avalonia.Input;
|
|||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
using MayShow.ViewModels;
|
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;
|
||||||
this.InitializeComponent();
|
FilesGrid.CellEditEnded += FileCellEditEnded;
|
||||||
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);
|
mvm?.HasUnsavedWork = true;
|
||||||
topLevel?.FocusManager?.ClearFocus();
|
|
||||||
if (DataContext is MainViewModel mvm)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,12 @@ using Avalonia;
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user