Code style - Use file scoped namespaces

Code style - Ran code cleanup
This commit is contained in:
Robert committed 2022-08-21 11:36:15 +02:00
1 parent e68e16df4d
commit f6090dc296
691 files changed
+37301 -38119

No files matched your search

@@ -1,19 +1,17 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace Artemis.UI.Screens.Root
{
public partial class DefaultTitleBarView : UserControl
{
public DefaultTitleBarView()
{
InitializeComponent();
}
namespace Artemis.UI.Screens.Root;
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
public class DefaultTitleBarView : UserControl
{
public DefaultTitleBarView()
{
InitializeComponent();
}
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
@@ -1,20 +1,19 @@
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared;
namespace Artemis.UI.Screens.Root
namespace Artemis.UI.Screens.Root;
public class DefaultTitleBarViewModel : ViewModelBase
{
public class DefaultTitleBarViewModel : ViewModelBase
private readonly IDebugService _debugService;
public DefaultTitleBarViewModel(IDebugService debugService)
{
private readonly IDebugService _debugService;
_debugService = debugService;
}
public DefaultTitleBarViewModel(IDebugService debugService)
{
_debugService = debugService;
}
public void ShowDebugger()
{
_debugService.ShowDebugger();
}
public void ShowDebugger()
{
_debugService.ShowDebugger();
}
}
+11 -12
View File
@@ -1,18 +1,17 @@
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
namespace Artemis.UI.Screens.Root
{
public class RootView : ReactiveUserControl<RootViewModel>
{
public RootView()
{
InitializeComponent();
}
namespace Artemis.UI.Screens.Root;
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
public class RootView : ReactiveUserControl<RootViewModel>
{
public RootView()
{
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
+181 -183
View File
@@ -14,199 +14,197 @@ using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Platform;
using Avalonia.Threading;
using JetBrains.Annotations;
using ReactiveUI;
namespace Artemis.UI.Screens.Root
namespace Artemis.UI.Screens.Root;
public class RootViewModel : ActivatableViewModelBase, IScreen, IMainWindowProvider
{
public class RootViewModel : ActivatableViewModelBase, IScreen, IMainWindowProvider
private readonly IAssetLoader _assetLoader;
private readonly ICoreService _coreService;
private readonly IDebugService _debugService;
private readonly DefaultTitleBarViewModel _defaultTitleBarViewModel;
private readonly IClassicDesktopStyleApplicationLifetime _lifeTime;
private readonly ISettingsService _settingsService;
private readonly ISidebarVmFactory _sidebarVmFactory;
private readonly IUpdateService _updateService;
private readonly IWindowService _windowService;
private SidebarViewModel? _sidebarViewModel;
private ViewModelBase? _titleBarViewModel;
public RootViewModel(ICoreService coreService,
ISettingsService settingsService,
IRegistrationService registrationService,
IWindowService windowService,
IMainWindowService mainWindowService,
IDebugService debugService,
IUpdateService updateService,
IAssetLoader assetLoader,
DefaultTitleBarViewModel defaultTitleBarViewModel,
ISidebarVmFactory sidebarVmFactory)
{
private readonly DefaultTitleBarViewModel _defaultTitleBarViewModel;
private readonly ICoreService _coreService;
private readonly ISettingsService _settingsService;
private readonly IWindowService _windowService;
private readonly IDebugService _debugService;
private readonly IUpdateService _updateService;
private readonly IAssetLoader _assetLoader;
private readonly IClassicDesktopStyleApplicationLifetime _lifeTime;
private readonly ISidebarVmFactory _sidebarVmFactory;
private SidebarViewModel? _sidebarViewModel;
private ViewModelBase? _titleBarViewModel;
Router = new RoutingState();
public RootViewModel(ICoreService coreService,
ISettingsService settingsService,
IRegistrationService registrationService,
IWindowService windowService,
IMainWindowService mainWindowService,
IDebugService debugService,
IUpdateService updateService,
IAssetLoader assetLoader,
DefaultTitleBarViewModel defaultTitleBarViewModel,
ISidebarVmFactory sidebarVmFactory)
_coreService = coreService;
_settingsService = settingsService;
_windowService = windowService;
_debugService = debugService;
_updateService = updateService;
_assetLoader = assetLoader;
_defaultTitleBarViewModel = defaultTitleBarViewModel;
_sidebarVmFactory = sidebarVmFactory;
_lifeTime = (IClassicDesktopStyleApplicationLifetime) Application.Current!.ApplicationLifetime!;
coreService.StartupArguments = _lifeTime.Args.ToList();
mainWindowService.ConfigureMainWindowProvider(this);
DisplayAccordingToSettings();
Router.CurrentViewModel.Subscribe(UpdateTitleBarViewModel);
Task.Run(() =>
{
Router = new RoutingState();
_coreService = coreService;
_settingsService = settingsService;
_windowService = windowService;
_debugService = debugService;
_updateService = updateService;
_assetLoader = assetLoader;
_defaultTitleBarViewModel = defaultTitleBarViewModel;
_sidebarVmFactory = sidebarVmFactory;
_lifeTime = (IClassicDesktopStyleApplicationLifetime) Application.Current!.ApplicationLifetime!;
coreService.StartupArguments = _lifeTime.Args.ToList();
mainWindowService.ConfigureMainWindowProvider(this);
DisplayAccordingToSettings();
Router.CurrentViewModel.Subscribe(UpdateTitleBarViewModel);
Task.Run(() =>
{
coreService.Initialize();
registrationService.RegisterBuiltInDataModelDisplays();
registrationService.RegisterBuiltInDataModelInputs();
registrationService.RegisterBuiltInPropertyEditors();
});
}
private void UpdateTitleBarViewModel(IRoutableViewModel? viewModel)
{
if (viewModel is MainScreenViewModel mainScreenViewModel && mainScreenViewModel.TitleBarViewModel != null)
TitleBarViewModel = mainScreenViewModel.TitleBarViewModel;
else
TitleBarViewModel = _defaultTitleBarViewModel;
}
public SidebarViewModel? SidebarViewModel
{
get => _sidebarViewModel;
set => RaiseAndSetIfChanged(ref _sidebarViewModel, value);
}
public ViewModelBase? TitleBarViewModel
{
get => _titleBarViewModel;
set => RaiseAndSetIfChanged(ref _titleBarViewModel, value);
}
private void CurrentMainWindowOnClosing(object? sender, EventArgs e)
{
_lifeTime.MainWindow = null;
SidebarViewModel = null;
Router.NavigateAndReset.Execute(new EmptyViewModel(this, "blank")).Subscribe();
OnMainWindowClosed();
}
private void DisplayAccordingToSettings()
{
bool autoRunning = _coreService.StartupArguments.Contains("--autorun");
bool minimized = _coreService.StartupArguments.Contains("--minimized");
bool showOnAutoRun = _settingsService.GetSetting("UI.ShowOnStartup", true).Value;
if (autoRunning && !showOnAutoRun || minimized)
{
// TODO: Auto-update
}
else
{
ShowSplashScreen();
_coreService.Initialized += (_, _) => Dispatcher.UIThread.InvokeAsync(OpenMainWindow);
}
}
private void ShowSplashScreen()
{
_windowService.ShowWindow<SplashViewModel>();
}
/// <inheritdoc />
public RoutingState Router { get; }
#region Tray commands
public void OpenScreen(string displayName)
{
// The window will open on the UI thread at some point, respond to that to select the chosen screen
MainWindowOpened += OnEventHandler;
OpenMainWindow();
void OnEventHandler(object? sender, EventArgs args)
{
if (SidebarViewModel != null)
SidebarViewModel.SelectedSidebarScreen = SidebarViewModel.SidebarScreens.FirstOrDefault(s => s.DisplayName == displayName);
MainWindowOpened -= OnEventHandler;
}
}
public async Task OpenDebugger()
{
await Dispatcher.UIThread.InvokeAsync(() => _debugService.ShowDebugger());
}
public async Task Exit()
{
// Don't freeze the UI right after clicking
await Task.Delay(200);
Utilities.Shutdown();
}
#endregion
#region Implementation of IMainWindowProvider
/// <inheritdoc />
public bool IsMainWindowOpen => _lifeTime.MainWindow != null;
/// <inheritdoc />
public void OpenMainWindow()
{
Dispatcher.UIThread.Post(() =>
{
if (_lifeTime.MainWindow == null)
{
SidebarViewModel = _sidebarVmFactory.SidebarViewModel(this);
_lifeTime.MainWindow = new MainWindow {DataContext = this};
_lifeTime.MainWindow.Show();
_lifeTime.MainWindow.Closing += CurrentMainWindowOnClosing;
}
_lifeTime.MainWindow.WindowState = WindowState.Normal;
_lifeTime.MainWindow.Activate();
OnMainWindowOpened();
});
}
/// <inheritdoc />
public void CloseMainWindow()
{
Dispatcher.UIThread.Post(() => { _lifeTime.MainWindow?.Close(); });
}
/// <inheritdoc />
public event EventHandler? MainWindowOpened;
/// <inheritdoc />
public event EventHandler? MainWindowClosed;
protected virtual void OnMainWindowOpened()
{
MainWindowOpened?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnMainWindowClosed()
{
MainWindowClosed?.Invoke(this, EventArgs.Empty);
}
#endregion
coreService.Initialize();
registrationService.RegisterBuiltInDataModelDisplays();
registrationService.RegisterBuiltInDataModelInputs();
registrationService.RegisterBuiltInPropertyEditors();
});
}
internal class EmptyViewModel : MainScreenViewModel
public SidebarViewModel? SidebarViewModel
{
/// <inheritdoc />
public EmptyViewModel(IScreen hostScreen, string urlPathSegment) : base(hostScreen, urlPathSegment)
get => _sidebarViewModel;
set => RaiseAndSetIfChanged(ref _sidebarViewModel, value);
}
public ViewModelBase? TitleBarViewModel
{
get => _titleBarViewModel;
set => RaiseAndSetIfChanged(ref _titleBarViewModel, value);
}
private void UpdateTitleBarViewModel(IRoutableViewModel? viewModel)
{
if (viewModel is MainScreenViewModel mainScreenViewModel && mainScreenViewModel.TitleBarViewModel != null)
TitleBarViewModel = mainScreenViewModel.TitleBarViewModel;
else
TitleBarViewModel = _defaultTitleBarViewModel;
}
private void CurrentMainWindowOnClosing(object? sender, EventArgs e)
{
_lifeTime.MainWindow = null;
SidebarViewModel = null;
Router.NavigateAndReset.Execute(new EmptyViewModel(this, "blank")).Subscribe();
OnMainWindowClosed();
}
private void DisplayAccordingToSettings()
{
bool autoRunning = _coreService.StartupArguments.Contains("--autorun");
bool minimized = _coreService.StartupArguments.Contains("--minimized");
bool showOnAutoRun = _settingsService.GetSetting("UI.ShowOnStartup", true).Value;
if ((autoRunning && !showOnAutoRun) || minimized)
{
// TODO: Auto-update
}
else
{
ShowSplashScreen();
_coreService.Initialized += (_, _) => Dispatcher.UIThread.InvokeAsync(OpenMainWindow);
}
}
private void ShowSplashScreen()
{
_windowService.ShowWindow<SplashViewModel>();
}
/// <inheritdoc />
public RoutingState Router { get; }
#region Tray commands
public void OpenScreen(string displayName)
{
// The window will open on the UI thread at some point, respond to that to select the chosen screen
MainWindowOpened += OnEventHandler;
OpenMainWindow();
void OnEventHandler(object? sender, EventArgs args)
{
if (SidebarViewModel != null)
SidebarViewModel.SelectedSidebarScreen = SidebarViewModel.SidebarScreens.FirstOrDefault(s => s.DisplayName == displayName);
MainWindowOpened -= OnEventHandler;
}
}
public async Task OpenDebugger()
{
await Dispatcher.UIThread.InvokeAsync(() => _debugService.ShowDebugger());
}
public async Task Exit()
{
// Don't freeze the UI right after clicking
await Task.Delay(200);
Utilities.Shutdown();
}
#endregion
#region Implementation of IMainWindowProvider
/// <inheritdoc />
public bool IsMainWindowOpen => _lifeTime.MainWindow != null;
/// <inheritdoc />
public void OpenMainWindow()
{
Dispatcher.UIThread.Post(() =>
{
if (_lifeTime.MainWindow == null)
{
SidebarViewModel = _sidebarVmFactory.SidebarViewModel(this);
_lifeTime.MainWindow = new MainWindow {DataContext = this};
_lifeTime.MainWindow.Show();
_lifeTime.MainWindow.Closing += CurrentMainWindowOnClosing;
}
_lifeTime.MainWindow.WindowState = WindowState.Normal;
_lifeTime.MainWindow.Activate();
OnMainWindowOpened();
});
}
/// <inheritdoc />
public void CloseMainWindow()
{
Dispatcher.UIThread.Post(() => { _lifeTime.MainWindow?.Close(); });
}
/// <inheritdoc />
public event EventHandler? MainWindowOpened;
/// <inheritdoc />
public event EventHandler? MainWindowClosed;
protected virtual void OnMainWindowOpened()
{
MainWindowOpened?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnMainWindowClosed()
{
MainWindowClosed?.Invoke(this, EventArgs.Empty);
}
#endregion
}
internal class EmptyViewModel : MainScreenViewModel
{
/// <inheritdoc />
public EmptyViewModel(IScreen hostScreen, string urlPathSegment) : base(hostScreen, urlPathSegment)
{
}
}
+19 -20
View File
@@ -7,27 +7,26 @@ using Avalonia.ReactiveUI;
using Avalonia.Threading;
using ReactiveUI;
namespace Artemis.UI.Screens.Root
{
public class SplashView : ReactiveWindow<SplashViewModel>
{
public SplashView()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
this.WhenActivated(disposables =>
{
Observable.FromEventPattern(x => ViewModel!.CoreService.Initialized += x, x => ViewModel!.CoreService.Initialized -= x)
.Subscribe(_ => Dispatcher.UIThread.Post(Close))
.DisposeWith(disposables);
});
}
namespace Artemis.UI.Screens.Root;
private void InitializeComponent()
public class SplashView : ReactiveWindow<SplashViewModel>
{
public SplashView()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
this.WhenActivated(disposables =>
{
AvaloniaXamlLoader.Load(this);
}
Observable.FromEventPattern(x => ViewModel!.CoreService.Initialized += x, x => ViewModel!.CoreService.Initialized -= x)
.Subscribe(_ => Dispatcher.UIThread.Post(Close))
.DisposeWith(disposables);
});
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
+49 -52
View File
@@ -2,70 +2,67 @@
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Shared;
using Humanizer;
using ReactiveUI;
namespace Artemis.UI.Screens.Root
namespace Artemis.UI.Screens.Root;
public class SplashViewModel : ViewModelBase
{
public class SplashViewModel : ViewModelBase
private string _status;
public SplashViewModel(ICoreService coreService, IPluginManagementService pluginManagementService)
{
private string _status;
public SplashViewModel(ICoreService coreService, IPluginManagementService pluginManagementService)
{
CoreService = coreService;
_status = "Initializing Core";
CoreService = coreService;
_status = "Initializing Core";
pluginManagementService.CopyingBuildInPlugins += OnPluginManagementServiceOnCopyingBuildInPluginsManagement;
pluginManagementService.PluginLoading += OnPluginManagementServiceOnPluginManagementLoading;
pluginManagementService.PluginLoaded += OnPluginManagementServiceOnPluginManagementLoaded;
pluginManagementService.PluginEnabling += PluginManagementServiceOnPluginManagementEnabling;
pluginManagementService.PluginEnabled += PluginManagementServiceOnPluginManagementEnabled;
pluginManagementService.PluginFeatureEnabling += PluginManagementServiceOnPluginFeatureEnabling;
pluginManagementService.PluginFeatureEnabled += PluginManagementServiceOnPluginFeatureEnabled;
}
pluginManagementService.CopyingBuildInPlugins += OnPluginManagementServiceOnCopyingBuildInPluginsManagement;
pluginManagementService.PluginLoading += OnPluginManagementServiceOnPluginManagementLoading;
pluginManagementService.PluginLoaded += OnPluginManagementServiceOnPluginManagementLoaded;
pluginManagementService.PluginEnabling += PluginManagementServiceOnPluginManagementEnabling;
pluginManagementService.PluginEnabled += PluginManagementServiceOnPluginManagementEnabled;
pluginManagementService.PluginFeatureEnabling += PluginManagementServiceOnPluginFeatureEnabling;
pluginManagementService.PluginFeatureEnabled += PluginManagementServiceOnPluginFeatureEnabled;
}
public ICoreService CoreService { get; }
public ICoreService CoreService { get; }
public string Status
{
get => _status;
set => RaiseAndSetIfChanged(ref _status, value);
}
public string Status
{
get => _status;
set => RaiseAndSetIfChanged(ref _status, value);
}
private void OnPluginManagementServiceOnPluginManagementLoaded(object? sender, PluginEventArgs args)
{
Status = "Initializing UI";
}
private void OnPluginManagementServiceOnPluginManagementLoaded(object? sender, PluginEventArgs args)
{
Status = "Initializing UI";
}
private void OnPluginManagementServiceOnPluginManagementLoading(object? sender, PluginEventArgs args)
{
Status = "Loading plugin: " + args.Plugin.Info.Name;
}
private void OnPluginManagementServiceOnPluginManagementLoading(object? sender, PluginEventArgs args)
{
Status = "Loading plugin: " + args.Plugin.Info.Name;
}
private void PluginManagementServiceOnPluginManagementEnabled(object? sender, PluginEventArgs args)
{
Status = "Initializing UI";
}
private void PluginManagementServiceOnPluginManagementEnabled(object? sender, PluginEventArgs args)
{
Status = "Initializing UI";
}
private void PluginManagementServiceOnPluginManagementEnabling(object? sender, PluginEventArgs args)
{
Status = "Enabling plugin: " + args.Plugin.Info.Name;
}
private void PluginManagementServiceOnPluginManagementEnabling(object? sender, PluginEventArgs args)
{
Status = "Enabling plugin: " + args.Plugin.Info.Name;
}
private void PluginManagementServiceOnPluginFeatureEnabling(object? sender, PluginFeatureEventArgs e)
{
Status = "Enabling: " + e.PluginFeature.Info.Name;
}
private void PluginManagementServiceOnPluginFeatureEnabling(object? sender, PluginFeatureEventArgs e)
{
Status = "Enabling: " + e.PluginFeature.Info.Name;
}
private void PluginManagementServiceOnPluginFeatureEnabled(object? sender, PluginFeatureEventArgs e)
{
Status = "Initializing UI";
}
private void PluginManagementServiceOnPluginFeatureEnabled(object? sender, PluginFeatureEventArgs e)
{
Status = "Initializing UI";
}
private void OnPluginManagementServiceOnCopyingBuildInPluginsManagement(object? sender, EventArgs args)
{
Status = "Updating built-in plugins";
}
private void OnPluginManagementServiceOnCopyingBuildInPluginsManagement(object? sender, EventArgs args)
{
Status = "Updating built-in plugins";
}
}