Browse Source

Remove PageChangeRequested event

pull/109/head
Ionite 1 year ago
parent
commit
58782b4b29
No known key found for this signature in database
  1. 3
      StabilityMatrix.Avalonia/App.axaml.cs
  2. 22
      StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs
  3. 4
      StabilityMatrix.Core/Helper/EventManager.cs

3
StabilityMatrix.Avalonia/App.axaml.cs

@ -210,8 +210,7 @@ public sealed class App : Application
services.AddSingleton<MainWindowViewModel>(provider => services.AddSingleton<MainWindowViewModel>(provider =>
new MainWindowViewModel(provider.GetRequiredService<ISettingsManager>(), new MainWindowViewModel(provider.GetRequiredService<ISettingsManager>(),
provider.GetRequiredService<IDiscordRichPresenceService>(), provider.GetRequiredService<IDiscordRichPresenceService>(),
provider.GetRequiredService<ServiceManager<ViewModelBase>>(), provider.GetRequiredService<ServiceManager<ViewModelBase>>())
provider.GetRequiredService<INavigationService>())
{ {
Pages = Pages =
{ {

22
StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs

@ -25,7 +25,6 @@ public partial class MainWindowViewModel : ViewModelBase
private readonly ISettingsManager settingsManager; private readonly ISettingsManager settingsManager;
private readonly ServiceManager<ViewModelBase> dialogFactory; private readonly ServiceManager<ViewModelBase> dialogFactory;
private readonly IDiscordRichPresenceService discordRichPresenceService; private readonly IDiscordRichPresenceService discordRichPresenceService;
private readonly INavigationService navigationService;
public string Greeting => "Welcome to Avalonia!"; public string Greeting => "Welcome to Avalonia!";
[ObservableProperty] [ObservableProperty]
@ -46,13 +45,11 @@ public partial class MainWindowViewModel : ViewModelBase
public MainWindowViewModel( public MainWindowViewModel(
ISettingsManager settingsManager, ISettingsManager settingsManager,
IDiscordRichPresenceService discordRichPresenceService, IDiscordRichPresenceService discordRichPresenceService,
ServiceManager<ViewModelBase> dialogFactory, ServiceManager<ViewModelBase> dialogFactory)
INavigationService navigationService)
{ {
this.settingsManager = settingsManager; this.settingsManager = settingsManager;
this.dialogFactory = dialogFactory; this.dialogFactory = dialogFactory;
this.discordRichPresenceService = discordRichPresenceService; this.discordRichPresenceService = discordRichPresenceService;
this.navigationService = navigationService;
ProgressManagerViewModel = dialogFactory.Get<ProgressManagerViewModel>(); ProgressManagerViewModel = dialogFactory.Get<ProgressManagerViewModel>();
UpdateViewModel = dialogFactory.Get<UpdateViewModel>(); UpdateViewModel = dialogFactory.Get<UpdateViewModel>();
@ -65,8 +62,6 @@ public partial class MainWindowViewModel : ViewModelBase
// Set only if null, since this may be called again when content dialogs open // Set only if null, since this may be called again when content dialogs open
CurrentPage ??= Pages.FirstOrDefault(); CurrentPage ??= Pages.FirstOrDefault();
SelectedCategory ??= Pages.FirstOrDefault(); SelectedCategory ??= Pages.FirstOrDefault();
EventManager.Instance.PageChangeRequested += OnPageChangeRequested;
} }
public override async Task OnLoadedAsync() public override async Task OnLoadedAsync()
@ -198,19 +193,4 @@ public partial class MainWindowViewModel : ViewModelBase
await dialog.ShowAsync(); await dialog.ShowAsync();
} }
private void OnPageChangeRequested(object? sender, Type e)
{
CurrentPage = Pages.FirstOrDefault(p => p.GetType() == e);
SelectedCategory = Pages.FirstOrDefault(p => p.GetType() == e);
}
partial void OnSelectedCategoryChanged(object? value)
{
if (value is PageViewModelBase page)
{
// CurrentPage = page;
// navigationService.NavigateTo(page);
}
}
} }

4
StabilityMatrix.Core/Helper/EventManager.cs

@ -16,19 +16,17 @@ public class EventManager
} }
public event EventHandler<int>? GlobalProgressChanged; public event EventHandler<int>? GlobalProgressChanged;
public event EventHandler<Type>? PageChangeRequested;
public event EventHandler? InstalledPackagesChanged; public event EventHandler? InstalledPackagesChanged;
public event EventHandler<bool>? OneClickInstallFinished; public event EventHandler<bool>? OneClickInstallFinished;
public event EventHandler? TeachingTooltipNeeded; public event EventHandler? TeachingTooltipNeeded;
public event EventHandler<bool>? DevModeSettingChanged; public event EventHandler<bool>? DevModeSettingChanged;
public event EventHandler<UpdateInfo>? UpdateAvailable; public event EventHandler<UpdateInfo>? UpdateAvailable;
public event EventHandler<Guid> PackageLaunchRequested; public event EventHandler<Guid>? PackageLaunchRequested;
public event EventHandler? ScrollToBottomRequested; public event EventHandler? ScrollToBottomRequested;
public event EventHandler<ProgressItem>? ProgressChanged; public event EventHandler<ProgressItem>? ProgressChanged;
public event EventHandler<RunningPackageStatusChangedEventArgs>? RunningPackageStatusChanged; public event EventHandler<RunningPackageStatusChangedEventArgs>? RunningPackageStatusChanged;
public void OnGlobalProgressChanged(int progress) => GlobalProgressChanged?.Invoke(this, progress); public void OnGlobalProgressChanged(int progress) => GlobalProgressChanged?.Invoke(this, progress);
public void RequestPageChange(Type pageType) => PageChangeRequested?.Invoke(this, pageType);
public void OnInstalledPackagesChanged() => InstalledPackagesChanged?.Invoke(this, EventArgs.Empty); public void OnInstalledPackagesChanged() => InstalledPackagesChanged?.Invoke(this, EventArgs.Empty);
public void OnOneClickInstallFinished(bool skipped) => OneClickInstallFinished?.Invoke(this, skipped); public void OnOneClickInstallFinished(bool skipped) => OneClickInstallFinished?.Invoke(this, skipped);
public void OnTeachingTooltipNeeded() => TeachingTooltipNeeded?.Invoke(this, EventArgs.Empty); public void OnTeachingTooltipNeeded() => TeachingTooltipNeeded?.Invoke(this, EventArgs.Empty);

Loading…
Cancel
Save