From 823205fa69e9b495b70f68cd2dfec8bec7b14ec9 Mon Sep 17 00:00:00 2001 From: Felix Seidl Date: Sat, 27 Mar 2021 18:08:51 +0100 Subject: [PATCH] Migrate to WCT MVVM --- .../SettingsServiceTests.cs | 26 ++- .../EventArgs/NewTabRequestedEventArgs.cs | 3 +- .../Exceptions/SaveTextFileException.cs | 2 - .../FluentTerminal.App.Services.csproj | 2 +- .../Implementation/SettingsService.cs | 40 ++-- .../EnvironmentVariableViewModel.cs | 8 +- .../FluentTerminal.App.ViewModels.csproj | 2 +- .../Infrastructure/AsyncCommand.cs | 125 ----------- .../Infrastructure/IAsyncCommand.cs | 20 -- .../MainViewModel.cs | 200 +++++++++--------- .../Menu/Mdl2Icon.cs | 6 +- .../Menu/MenuItemKeyBindingViewModel.cs | 16 +- .../Menu/MenuItemViewModel.cs | 2 +- .../Menu/MenuItemViewModelBase.cs | 10 +- .../Menu/MenuViewModel.cs | 4 +- .../OverlayViewModel.cs | 8 +- .../ProfileViewModelBase.cs | 32 +-- .../CommonProfileProviderViewModel.cs | 17 +- .../Profiles/ProfileProviderViewModelBase.cs | 26 +-- .../Profiles/SshConnectViewModel.cs | 21 +- .../Settings/AboutPageViewModel.cs | 21 +- .../Settings/GeneralPageViewModel.cs | 65 +++--- .../Settings/KeyBindingViewModel.cs | 25 +-- .../Settings/KeyBindingsPageViewModel.cs | 15 +- .../Settings/KeyBindingsViewModel.cs | 6 +- .../Settings/MousePageViewModel.cs | 17 +- .../Settings/ProfilesPageViewModel.cs | 13 +- .../Settings/SshProfilesPageViewModel.cs | 13 +- .../Settings/TerminalPageViewModel.cs | 35 +-- .../Settings/ThemesPageViewModel.cs | 26 +-- .../SettingsViewModel.cs | 4 +- .../ShellProfileViewModel.cs | 12 +- .../TabThemeViewModel.cs | 6 +- .../TerminalViewModel.cs | 116 +++++----- .../ThemeViewModel.cs | 73 ++++--- FluentTerminal.App/App.xaml.cs | 4 +- .../ColorResourceKeyFallbackConverter.cs | 1 - .../MenuViewModelToFlyoutMenuConverter.cs | 1 - .../Converters/TabThemeSelectedConverter.cs | 1 - .../Dialogs/CreateKeyBindingDialog.xaml.cs | 18 +- .../Dialogs/CustomCommandDialog.xaml.cs | 7 +- .../Dialogs/SshInfoDialog.xaml.cs | 11 +- FluentTerminal.App/FluentTerminal.App.csproj | 3 + .../Services/CommandHistoryService.cs | 8 +- .../ViewModels/CommandItemViewModel.cs | 8 +- .../CommandProfileProviderViewModel.cs | 4 +- .../SettingsPages/GeneralSettings.xaml.cs | 4 +- .../SettingsPages/KeyBindingSettings.xaml.cs | 1 - FluentTerminal.App/Views/TabBar.xaml.cs | 8 +- .../Views/TabBarBackgroundBindingHelper.cs | 3 +- FluentTerminal.App/Views/TerminalView.xaml.cs | 15 +- FluentTerminal.Models/Enums/TabThemeKey.cs | 6 +- .../ExportedTerminalTheme.cs | 4 +- FluentTerminal.Models/FontInfo.cs | 6 +- FluentTerminal.Models/ImageFile.cs | 5 +- .../ApplicationSettingsChangedMessage.cs | 2 +- FluentTerminal.Models/TabTheme.cs | 4 +- FluentTerminal.SystemTray/ProcessUtils.cs | 3 - .../Services/TerminalsManager.cs | 4 +- .../Services/ToggleWindowService.cs | 3 - 60 files changed, 488 insertions(+), 663 deletions(-) delete mode 100644 FluentTerminal.App.ViewModels/Infrastructure/AsyncCommand.cs delete mode 100644 FluentTerminal.App.ViewModels/Infrastructure/IAsyncCommand.cs diff --git a/FluentTerminal.App.Services.Test/SettingsServiceTests.cs b/FluentTerminal.App.Services.Test/SettingsServiceTests.cs index dbf4ec7..0ea2629 100644 --- a/FluentTerminal.App.Services.Test/SettingsServiceTests.cs +++ b/FluentTerminal.App.Services.Test/SettingsServiceTests.cs @@ -1,7 +1,6 @@ using AutoFixture; using FluentAssertions; using FluentTerminal.App.Services.Implementation; -using FluentTerminal.App.Services.Utilities; using FluentTerminal.Models; using FluentTerminal.Models.Enums; using Moq; @@ -11,8 +10,8 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using FluentTerminal.Models.Messages; -using GalaSoft.MvvmLight.Messaging; using Xunit; +using Microsoft.Toolkit.Mvvm.Messaging; namespace FluentTerminal.App.Services.Test { @@ -167,8 +166,8 @@ namespace FluentTerminal.App.Services.Test }; var currentThemeChangedEventInvoked = false; var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers); - Messenger.Default.Register(this, - message => currentThemeChangedEventInvoked = true); + WeakReferenceMessenger.Default.Register(this, + (r, m) => currentThemeChangedEventInvoked = true); settingsService.SaveCurrentThemeId(currentThemeId); @@ -217,8 +216,8 @@ namespace FluentTerminal.App.Services.Test SshProfiles = Mock.Of() }; var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers); - Messenger.Default.Register(this, - message => currentThemeChangedEventInvoked = true); + WeakReferenceMessenger.Default.Register(this, + (r, m) => currentThemeChangedEventInvoked = true); settingsService.SaveTheme(theme); @@ -382,8 +381,8 @@ namespace FluentTerminal.App.Services.Test SshProfiles = Mock.Of() }; var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers); - Messenger.Default.Register(this, - message => terminalOptionsChangedEventInvoked = true); + WeakReferenceMessenger.Default.Register(this, + (r, m) => terminalOptionsChangedEventInvoked = true); settingsService.SaveTerminalOptions(terminalOptions); @@ -453,8 +452,7 @@ namespace FluentTerminal.App.Services.Test SshProfiles = Mock.Of() }; var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers); - Messenger.Default.Register(this, - a => applicationSettingsChangedEventInvoked = true); + WeakReferenceMessenger.Default.Register(this, (r, m) => applicationSettingsChangedEventInvoked = true); settingsService.SaveApplicationSettings(applicationSettings); @@ -556,8 +554,8 @@ namespace FluentTerminal.App.Services.Test SshProfiles = Mock.Of() }; var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers); - Messenger.Default.Register(this, - message => keyBindingsChangedEventInvoked = true); + WeakReferenceMessenger.Default.Register(this, + (r, m) => keyBindingsChangedEventInvoked = true); settingsService.SaveKeyBindings(command.ToString(), keyBindings); @@ -605,8 +603,8 @@ namespace FluentTerminal.App.Services.Test SshProfiles = Mock.Of() }; var settingsService = new SettingsService(defaultValueProvider, applicationDataContainers); - Messenger.Default.Register(this, - message => keyBindingsChangedEventInvoked = true); + WeakReferenceMessenger.Default.Register(this, + (r, m) => keyBindingsChangedEventInvoked = true); settingsService.ResetKeyBindings(); diff --git a/FluentTerminal.App.Services/EventArgs/NewTabRequestedEventArgs.cs b/FluentTerminal.App.Services/EventArgs/NewTabRequestedEventArgs.cs index 82e40d1..4d28f3b 100644 --- a/FluentTerminal.App.Services/EventArgs/NewTabRequestedEventArgs.cs +++ b/FluentTerminal.App.Services/EventArgs/NewTabRequestedEventArgs.cs @@ -1,5 +1,4 @@ -using System; -using Windows.UI.Xaml; +using Windows.UI.Xaml; namespace FluentTerminal.App.Services.EventArgs { diff --git a/FluentTerminal.App.Services/Exceptions/SaveTextFileException.cs b/FluentTerminal.App.Services/Exceptions/SaveTextFileException.cs index 92b284c..086618c 100644 --- a/FluentTerminal.App.Services/Exceptions/SaveTextFileException.cs +++ b/FluentTerminal.App.Services/Exceptions/SaveTextFileException.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace FluentTerminal.App.Services.Exceptions { diff --git a/FluentTerminal.App.Services/FluentTerminal.App.Services.csproj b/FluentTerminal.App.Services/FluentTerminal.App.Services.csproj index 900cff4..2f5cb8c 100644 --- a/FluentTerminal.App.Services/FluentTerminal.App.Services.csproj +++ b/FluentTerminal.App.Services/FluentTerminal.App.Services.csproj @@ -7,7 +7,7 @@ - + diff --git a/FluentTerminal.App.Services/Implementation/SettingsService.cs b/FluentTerminal.App.Services/Implementation/SettingsService.cs index f6dce64..c0016f9 100644 --- a/FluentTerminal.App.Services/Implementation/SettingsService.cs +++ b/FluentTerminal.App.Services/Implementation/SettingsService.cs @@ -7,7 +7,7 @@ using System.Collections.ObjectModel; using System.Linq; using FluentTerminal.App.Services.Utilities; using FluentTerminal.Models.Messages; -using GalaSoft.MvvmLight.Messaging; +using Microsoft.Toolkit.Mvvm.Messaging; namespace FluentTerminal.App.Services.Implementation { @@ -169,14 +169,14 @@ namespace FluentTerminal.App.Services.Implementation public void DeleteShellProfile(Guid id) { _shellProfiles.Delete(id.ToString()); - Messenger.Default.Send(new ShellProfileDeletedMessage(id)); + WeakReferenceMessenger.Default.Send(new ShellProfileDeletedMessage(id)); } public void DeleteSshProfile(Guid id) { _sshProfiles.Delete(id.ToString()); - Messenger.Default.Send(new ShellProfileDeletedMessage(id)); - Messenger.Default.Send(new KeyBindingsChangedMessage()); + WeakReferenceMessenger.Default.Send(new ShellProfileDeletedMessage(id)); + WeakReferenceMessenger.Default.Send(new KeyBindingsChangedMessage()); } @@ -193,7 +193,7 @@ namespace FluentTerminal.App.Services.Implementation } } - Messenger.Default.Send(new ThemeDeletedMessage(id)); + WeakReferenceMessenger.Default.Send(new ThemeDeletedMessage(id)); } public ApplicationSettings GetApplicationSettings() @@ -333,32 +333,32 @@ namespace FluentTerminal.App.Services.Implementation _keyBindings.WriteValueAsJson(command.ToString(), _defaultValueProvider.GetDefaultKeyBindings(command)); } - Messenger.Default.Send(new KeyBindingsChangedMessage()); + WeakReferenceMessenger.Default.Send(new KeyBindingsChangedMessage()); } public void SaveApplicationSettings(ApplicationSettings applicationSettings) { _roamingSettings.WriteValueAsJson(nameof(ApplicationSettings), applicationSettings); - Messenger.Default.Send(new ApplicationSettingsChangedMessage(applicationSettings.Clone())); + WeakReferenceMessenger.Default.Send(new ApplicationSettingsChangedMessage(applicationSettings.Clone())); } public void NotifyApplicationSettingsChanged(ApplicationSettings applicationSettings) { - Messenger.Default.Send(new ApplicationSettingsChangedMessage(applicationSettings.Clone())); + WeakReferenceMessenger.Default.Send(new ApplicationSettingsChangedMessage(applicationSettings.Clone())); } public void SaveCurrentThemeId(Guid id) { _roamingSettings.SetValue(CurrentThemeKey, id); - Messenger.Default.Send(new CurrentThemeChangedMessage(id)); + WeakReferenceMessenger.Default.Send(new CurrentThemeChangedMessage(id)); } public void SaveDefaultShellProfileId(Guid id) { _localSettings.SetValue(DefaultShellProfileKey, id); - Messenger.Default.Send(new DefaultShellProfileChangedMessage(id)); + WeakReferenceMessenger.Default.Send(new DefaultShellProfileChangedMessage(id)); } public void SaveKeyBindings(string command, ICollection keyBindings) @@ -369,7 +369,7 @@ namespace FluentTerminal.App.Services.Implementation } _keyBindings.WriteValueAsJson(enumValue.ToString(), keyBindings); - Messenger.Default.Send(new KeyBindingsChangedMessage()); + WeakReferenceMessenger.Default.Send(new KeyBindingsChangedMessage()); } public void SaveShellProfile(ShellProfile shellProfile, bool newShell = false) @@ -377,15 +377,15 @@ namespace FluentTerminal.App.Services.Implementation _shellProfiles.WriteValueAsJson(shellProfile.Id.ToString(), shellProfile); // When saving the shell profile, we also need to update keybindings for everywhere. - Messenger.Default.Send(new KeyBindingsChangedMessage()); + WeakReferenceMessenger.Default.Send(new KeyBindingsChangedMessage()); if (newShell) { - Messenger.Default.Send(new ShellProfileAddedMessage(shellProfile)); + WeakReferenceMessenger.Default.Send(new ShellProfileAddedMessage(shellProfile)); } else { - Messenger.Default.Send(new ShellProfileChangedMessage(shellProfile)); + WeakReferenceMessenger.Default.Send(new ShellProfileChangedMessage(shellProfile)); } } @@ -394,22 +394,22 @@ namespace FluentTerminal.App.Services.Implementation _sshProfiles.WriteValueAsJson(sshProfile.Id.ToString(), sshProfile); // When saving the shell profile, we also need to update keybindings for everywhere. - Messenger.Default.Send(new KeyBindingsChangedMessage()); + WeakReferenceMessenger.Default.Send(new KeyBindingsChangedMessage()); if (newShell) { - Messenger.Default.Send(new ShellProfileAddedMessage(sshProfile)); + WeakReferenceMessenger.Default.Send(new ShellProfileAddedMessage(sshProfile)); } else { - Messenger.Default.Send(new ShellProfileChangedMessage(sshProfile)); + WeakReferenceMessenger.Default.Send(new ShellProfileChangedMessage(sshProfile)); } } public void SaveTerminalOptions(TerminalOptions terminalOptions) { _roamingSettings.WriteValueAsJson(nameof(TerminalOptions), terminalOptions); - Messenger.Default.Send(new TerminalOptionsChangedMessage(terminalOptions)); + WeakReferenceMessenger.Default.Send(new TerminalOptionsChangedMessage(terminalOptions)); } public void SaveTheme(TerminalTheme theme, bool newTheme = false) @@ -418,12 +418,12 @@ namespace FluentTerminal.App.Services.Implementation if (theme.Id == GetCurrentThemeId()) { - Messenger.Default.Send(new CurrentThemeChangedMessage(theme.Id)); + WeakReferenceMessenger.Default.Send(new CurrentThemeChangedMessage(theme.Id)); } if (newTheme) { - Messenger.Default.Send(new ThemeAddedMessage(theme)); + WeakReferenceMessenger.Default.Send(new ThemeAddedMessage(theme)); } } } diff --git a/FluentTerminal.App.ViewModels/EnvironmentVariableViewModel.cs b/FluentTerminal.App.ViewModels/EnvironmentVariableViewModel.cs index f0963a2..96fa102 100644 --- a/FluentTerminal.App.ViewModels/EnvironmentVariableViewModel.cs +++ b/FluentTerminal.App.ViewModels/EnvironmentVariableViewModel.cs @@ -1,9 +1,9 @@ -using GalaSoft.MvvmLight; +using Microsoft.Toolkit.Mvvm.ComponentModel; using System; namespace FluentTerminal.App.ViewModels { - public class EnvironmentVariableViewModel : ViewModelBase + public class EnvironmentVariableViewModel : ObservableObject { private string _name; private string _value; @@ -13,13 +13,13 @@ namespace FluentTerminal.App.ViewModels public string Name { get => _name; - set => Set(ref _name, value); + set => SetProperty(ref _name, value); } public string Value { get => _value; - set => Set(ref _value, value); + set => SetProperty(ref _value, value); } } } diff --git a/FluentTerminal.App.ViewModels/FluentTerminal.App.ViewModels.csproj b/FluentTerminal.App.ViewModels/FluentTerminal.App.ViewModels.csproj index 59de5dc..c0081f1 100644 --- a/FluentTerminal.App.ViewModels/FluentTerminal.App.ViewModels.csproj +++ b/FluentTerminal.App.ViewModels/FluentTerminal.App.ViewModels.csproj @@ -5,7 +5,7 @@ - + diff --git a/FluentTerminal.App.ViewModels/Infrastructure/AsyncCommand.cs b/FluentTerminal.App.ViewModels/Infrastructure/AsyncCommand.cs deleted file mode 100644 index 16c4de6..0000000 --- a/FluentTerminal.App.ViewModels/Infrastructure/AsyncCommand.cs +++ /dev/null @@ -1,125 +0,0 @@ -using FluentTerminal.App.ViewModels.Utilities; -using System; -using System.Threading.Tasks; -using System.Windows.Input; - -namespace FluentTerminal.App.ViewModels.Infrastructure -{ - public class AsyncCommand : IAsyncCommand - { - public event EventHandler CanExecuteChanged; - - private bool _isExecuting; - private readonly Func _execute; - private readonly Func _canExecute; - private readonly IErrorHandler _errorHandler; - - public AsyncCommand( - Func execute, - Func canExecute = null, - IErrorHandler errorHandler = null) - { - _execute = execute; - _canExecute = canExecute; - _errorHandler = errorHandler; - } - - public bool CanExecute() - { - return !_isExecuting && (_canExecute?.Invoke() ?? true); - } - - public async Task ExecuteAsync() - { - if (CanExecute()) - { - try - { - // TODO: If we're using class field _isExecuting, maybe we should introduce some locking? - _isExecuting = true; - await _execute(); - } - finally - { - _isExecuting = false; - } - } - - RaiseCanExecuteChanged(); - } - - public void RaiseCanExecuteChanged() - { - CanExecuteChanged?.Invoke(this, EventArgs.Empty); - } - - #region Explicit implementations - bool ICommand.CanExecute(object parameter) - { - return CanExecute(); - } - - void ICommand.Execute(object parameter) - { - ExecuteAsync().FireAndForgetSafeAsync(_errorHandler); - } - #endregion - } - - public class AsyncCommand : IAsyncCommand - { - public event EventHandler CanExecuteChanged; - - private bool _isExecuting; - private readonly Func _execute; - private readonly Func _canExecute; - private readonly IErrorHandler _errorHandler; - - public AsyncCommand(Func execute, Func canExecute = null, IErrorHandler errorHandler = null) - { - _execute = execute; - _canExecute = canExecute; - _errorHandler = errorHandler; - } - - public bool CanExecute(T parameter) - { - return !_isExecuting && (_canExecute?.Invoke(parameter) ?? true); - } - - public async Task ExecuteAsync(T parameter) - { - if (CanExecute(parameter)) - { - try - { - _isExecuting = true; - await _execute(parameter); - } - finally - { - _isExecuting = false; - } - } - - RaiseCanExecuteChanged(); - } - - public void RaiseCanExecuteChanged() - { - CanExecuteChanged?.Invoke(this, EventArgs.Empty); - } - - #region Explicit implementations - bool ICommand.CanExecute(object parameter) - { - return CanExecute((T)parameter); - } - - void ICommand.Execute(object parameter) - { - ExecuteAsync((T)parameter).FireAndForgetSafeAsync(_errorHandler); - } - #endregion - } -} diff --git a/FluentTerminal.App.ViewModels/Infrastructure/IAsyncCommand.cs b/FluentTerminal.App.ViewModels/Infrastructure/IAsyncCommand.cs deleted file mode 100644 index 1b06675..0000000 --- a/FluentTerminal.App.ViewModels/Infrastructure/IAsyncCommand.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Threading.Tasks; -using System.Windows.Input; - -namespace FluentTerminal.App.ViewModels.Infrastructure -{ - /// - /// based on: https://github.com/johnthiriet/AsyncVoid - /// - public interface IAsyncCommand : ICommand - { - Task ExecuteAsync(); - bool CanExecute(); - } - - public interface IAsyncCommand : ICommand - { - Task ExecuteAsync(T parameter); - bool CanExecute(T parameter); - } -} diff --git a/FluentTerminal.App.ViewModels/MainViewModel.cs b/FluentTerminal.App.ViewModels/MainViewModel.cs index b23e4a6..6bf7e2d 100644 --- a/FluentTerminal.App.ViewModels/MainViewModel.cs +++ b/FluentTerminal.App.ViewModels/MainViewModel.cs @@ -3,7 +3,6 @@ using FluentTerminal.App.Services.EventArgs; using FluentTerminal.App.Services.Utilities; using FluentTerminal.Models; using FluentTerminal.Models.Enums; -using GalaSoft.MvvmLight; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -14,13 +13,22 @@ using System.Threading.Tasks; using Windows.UI.Core; using FluentTerminal.App.ViewModels.Menu; using FluentTerminal.Models.Messages; -using GalaSoft.MvvmLight.Command; -using FluentTerminal.App.ViewModels.Infrastructure; using System.Windows.Input; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Messaging; +using Microsoft.Toolkit.Mvvm.Input; namespace FluentTerminal.App.ViewModels { - public class MainViewModel : ViewModelBase + public class MainViewModel : ObservableObject, + IRecipient, + IRecipient, + IRecipient, + IRecipient, + IRecipient, + IRecipient, + IRecipient, + IRecipient { private readonly IClipboardService _clipboardService; private readonly IDialogService _dialogService; @@ -39,15 +47,6 @@ namespace FluentTerminal.App.ViewModels public MainViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService, IKeyboardCommandService keyboardCommandService, IApplicationView applicationView, IClipboardService clipboardService, ICommandHistoryService commandHistoryService) { - MessengerInstance.Register(this, OnApplicationSettingsChanged); - MessengerInstance.Register(this, OnShellProfileAdded); - MessengerInstance.Register(this, OnShellProfileDeleted); - MessengerInstance.Register(this, OnShellProfileChanged); - MessengerInstance.Register(this, OnDefaultShellProfileChanged); - MessengerInstance.Register(this, OnTerminalOptionsChanged); - MessengerInstance.Register(this, OnCommandHistoryChanged); - MessengerInstance.Register(this, OnKeyBindingChanged); - _settingsService = settingsService; _trayProcessCommunicationService = trayProcessCommunicationService; @@ -69,7 +68,7 @@ namespace FluentTerminal.App.ViewModels _keyboardCommandService.RegisterCommandHandler(nameof(Command.ChangeTabTitle), async () => await SelectedTerminal.EditTitleAsync()); _keyboardCommandService.RegisterCommandHandler(nameof(Command.CloseTab), CloseCurrentTab); _keyboardCommandService.RegisterCommandHandler(nameof(Command.DuplicateTab), async () => await AddTabAsync(SelectedTerminal.ShellProfile.Clone())); - _keyboardCommandService.RegisterCommandHandler(nameof(Command.ReconnectTab), async () => { if (SelectedTerminal.ReconnectTabCommand.CanExecute()) await SelectedTerminal.ReconnectTabAsync(); }); + _keyboardCommandService.RegisterCommandHandler(nameof(Command.ReconnectTab), async () => { if (SelectedTerminal.ReconnectTabCommand.CanExecute(null)) await SelectedTerminal.ReconnectTabAsync(); }); // empty command handlers for copy and paste so that the main window does not execute these when copy keyboard shortcut is used in a popup search panel // in such a case an exception would be thrown if no handlers are available so these empty ones mitigate that. Also there is no need for these on the main window anyway @@ -126,8 +125,8 @@ namespace FluentTerminal.App.ViewModels _newQuickLaunchWindowCommand = new RelayCommand(async () => await AddQuickLaunchProfileAsync(NewTerminalLocation.Window)); _settingsCommand = new RelayCommand(ShowSettings); - _aboutCommand = new RelayCommand(async () => await _dialogService.ShowAboutDialogAsync()); - _quitCommand = new AsyncCommand(() => _trayProcessCommunicationService.QuitApplicationAsync()); + _aboutCommand = new AsyncRelayCommand(_dialogService.ShowAboutDialogAsync); + _quitCommand = new AsyncRelayCommand(_trayProcessCommunicationService.QuitApplicationAsync); _defaultProfile = _settingsService.GetDefaultShellProfile(); @@ -156,7 +155,7 @@ namespace FluentTerminal.App.ViewModels private void OnClosed(object sender, EventArgs e) { - MessengerInstance.Unregister(this); + //MessengerInstance.Unregister(this); todo do we still need this? ApplicationView.CloseRequested -= OnCloseRequest; ApplicationView.Closed -= OnClosed; @@ -171,41 +170,10 @@ namespace FluentTerminal.App.ViewModels Closed?.Invoke(this, e); } - private void OnShellProfileDeleted(ShellProfileDeletedMessage message) - { - _keyboardCommandService.DeregisterCommandHandler(message.ProfileId.ToString()); - - UpdateDefaultShellProfile(); - - ApplicationView.ExecuteOnUiThreadAsync(CreateMenuViewModel, CoreDispatcherPriority.Low, true); - } - - private void OnShellProfileChanged(ShellProfileChangedMessage message) - { - UpdateDefaultShellProfile(); - - ApplicationView.ExecuteOnUiThreadAsync(CreateMenuViewModel, CoreDispatcherPriority.Low, true); - } - - private void OnShellProfileAdded(ShellProfileAddedMessage message) - { - _keyboardCommandService.RegisterCommandHandler(message.ShellProfile.Id.ToString(), - async () => await AddProfileByGuidAsync(message.ShellProfile.Id)); - - UpdateDefaultShellProfile(); - - ApplicationView.ExecuteOnUiThreadAsync(CreateMenuViewModel, CoreDispatcherPriority.Low, true); - } - - private void OnDefaultShellProfileChanged(DefaultShellProfileChangedMessage message) - { - UpdateDefaultShellProfile(); - } - private void OnTerminalsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { - RaisePropertyChanged(nameof(ShowTabsOnTop)); - RaisePropertyChanged(nameof(ShowTabsOnBottom)); + OnPropertyChanged(nameof(ShowTabsOnTop)); + OnPropertyChanged(nameof(ShowTabsOnBottom)); } public event EventHandler Closed; @@ -228,14 +196,14 @@ namespace FluentTerminal.App.ViewModels ActivatedMv?.Invoke(this, EventArgs.Empty); } - public RelayCommand AddDefaultTabCommand { get; private set; } + public ICommand AddDefaultTabCommand { get; private set; } public string WindowTitle { get => _windowTitle; set { - if (Set(ref _windowTitle, value)) + if (SetProperty(ref _windowTitle, value)) { ApplicationView.Title = value; } @@ -255,13 +223,13 @@ namespace FluentTerminal.App.ViewModels public bool UseAcrylicBackground { get => _useAcrylicBackground; - set => Set(ref _useAcrylicBackground, value); + set => SetProperty(ref _useAcrylicBackground, value); } public double BackgroundOpacity { get => _backgroundOpacity; - set => Set(ref _backgroundOpacity, value); + set => SetProperty(ref _backgroundOpacity, value); } public TerminalViewModel SelectedTerminal @@ -271,7 +239,7 @@ namespace FluentTerminal.App.ViewModels { var oldValue = _selectedTerminal; - if (Set(ref _selectedTerminal, value)) + if (SetProperty(ref _selectedTerminal, value)) { if (oldValue != null) { @@ -292,7 +260,7 @@ namespace FluentTerminal.App.ViewModels public TabsPosition TabsPosition { get => _tabsPosition; - set => Set(ref _tabsPosition, value); + set => SetProperty(ref _tabsPosition, value); } public ObservableCollection Terminals { get; } = new ObservableCollection(); @@ -428,7 +396,7 @@ namespace FluentTerminal.App.ViewModels await Task.WhenAll(Terminals.Where(t => t != terminal).Select(t => { Logger.Instance.Debug("Terminal with Id: {@id} closed.", t.Terminal.Id); - return t.CloseCommand.ExecuteAsync(); + return t.CloseAsync(); })).ConfigureAwait(false); } } @@ -442,7 +410,7 @@ namespace FluentTerminal.App.ViewModels await Task.WhenAll(toRemove.Select(t => { Logger.Instance.Debug("Terminal with Id: {@id} closed.", t.Terminal.Id); - return t.CloseCommand.ExecuteAsync(); + return t.CloseAsync(); })).ConfigureAwait(false); } } @@ -456,7 +424,7 @@ namespace FluentTerminal.App.ViewModels await Task.WhenAll(toRemove.Select(t => { Logger.Instance.Debug("Terminal with Id: {@id} closed.", t.Terminal.Id); - return t.CloseCommand.ExecuteAsync(); + return t.CloseAsync(); })).ConfigureAwait(false); } } @@ -477,33 +445,7 @@ namespace FluentTerminal.App.ViewModels private void CloseCurrentTab() { - SelectedTerminal?.CloseCommand.ExecuteAsync(); - } - - private void OnApplicationSettingsChanged(ApplicationSettingsChangedMessage message) - { - var updateMenu = _applicationSettings != null && - (_applicationSettings.TabWindowCascadingAppMenu != - message.ApplicationSettings.TabWindowCascadingAppMenu || - !message.ApplicationSettings.TabWindowCascadingAppMenu && - _applicationSettings.NewTerminalLocation != - message.ApplicationSettings.NewTerminalLocation); - - _applicationSettings = message.ApplicationSettings; - - SetWindowTitle(SelectedTerminal); - - ApplicationView.ExecuteOnUiThreadAsync(() => - { - TabsPosition = message.ApplicationSettings.TabsPosition; - RaisePropertyChanged(nameof(ShowTabsOnTop)); - RaisePropertyChanged(nameof(ShowTabsOnBottom)); - }); - - if (updateMenu) - { - ApplicationView.ExecuteOnUiThreadAsync(CreateMenuViewModel, CoreDispatcherPriority.Low, true); - } + SelectedTerminal?.CloseAsync(); } private async Task OnCloseRequest(object sender, CancelableEventArgs e) @@ -561,7 +503,64 @@ namespace FluentTerminal.App.ViewModels }); } - private void OnTerminalOptionsChanged(TerminalOptionsChangedMessage message) + public void Receive(ShellProfileDeletedMessage message) + { + _keyboardCommandService.DeregisterCommandHandler(message.ProfileId.ToString()); + + UpdateDefaultShellProfile(); + + ApplicationView.ExecuteOnUiThreadAsync(CreateMenuViewModel, CoreDispatcherPriority.Low, true); + } + + public void Receive(ShellProfileChangedMessage message) + { + UpdateDefaultShellProfile(); + + ApplicationView.ExecuteOnUiThreadAsync(CreateMenuViewModel, CoreDispatcherPriority.Low, true); + } + + public void Receive(ShellProfileAddedMessage message) + { + _keyboardCommandService.RegisterCommandHandler(message.ShellProfile.Id.ToString(), + async () => await AddProfileByGuidAsync(message.ShellProfile.Id)); + + UpdateDefaultShellProfile(); + + ApplicationView.ExecuteOnUiThreadAsync(CreateMenuViewModel, CoreDispatcherPriority.Low, true); + } + + public void Receive(DefaultShellProfileChangedMessage message) + { + UpdateDefaultShellProfile(); + } + + public void Receive(ApplicationSettingsChangedMessage message) + { + var updateMenu = _applicationSettings != null && + (_applicationSettings.TabWindowCascadingAppMenu != + message.ApplicationSettings.TabWindowCascadingAppMenu || + !message.ApplicationSettings.TabWindowCascadingAppMenu && + _applicationSettings.NewTerminalLocation != + message.ApplicationSettings.NewTerminalLocation); + + _applicationSettings = message.ApplicationSettings; + + SetWindowTitle(SelectedTerminal); + + ApplicationView.ExecuteOnUiThreadAsync(() => + { + TabsPosition = message.ApplicationSettings.TabsPosition; + OnPropertyChanged(nameof(ShowTabsOnTop)); + OnPropertyChanged(nameof(ShowTabsOnBottom)); + }); + + if (updateMenu) + { + ApplicationView.ExecuteOnUiThreadAsync(CreateMenuViewModel, CoreDispatcherPriority.Low, true); + } + } + + public void Receive(TerminalOptionsChangedMessage message) { ApplicationView.ExecuteOnUiThreadAsync(() => { @@ -570,14 +569,14 @@ namespace FluentTerminal.App.ViewModels }, CoreDispatcherPriority.Low); } - private void OnKeyBindingChanged(KeyBindingsChangedMessage message) + public void Receive(KeyBindingsChangedMessage message) { LoadKeyBindings(); ApplicationView.ExecuteOnUiThreadAsync(CreateMenuViewModel, CoreDispatcherPriority.Low, true); } - private void OnCommandHistoryChanged(CommandHistoryChangedMessage message) + public void Receive(CommandHistoryChangedMessage message) { ApplicationView.ExecuteOnUiThreadAsync(CreateMenuViewModel, CoreDispatcherPriority.Low, true); } @@ -631,20 +630,20 @@ namespace FluentTerminal.App.ViewModels private MenuViewModel _menuViewModel; - private readonly RelayCommand _newDefaultTabCommand; - private readonly RelayCommand _newDefaultWindowCommand; - private readonly RelayCommand _newRemoteTabCommand; - private readonly RelayCommand _newRemoteWindowCommand; - private readonly RelayCommand _newQuickLaunchTabCommand; - private readonly RelayCommand _newQuickLaunchWindowCommand; - private readonly RelayCommand _settingsCommand; - private readonly RelayCommand _aboutCommand; + private readonly ICommand _newDefaultTabCommand; + private readonly ICommand _newDefaultWindowCommand; + private readonly ICommand _newRemoteTabCommand; + private readonly ICommand _newRemoteWindowCommand; + private readonly ICommand _newQuickLaunchTabCommand; + private readonly ICommand _newQuickLaunchWindowCommand; + private readonly ICommand _settingsCommand; + private readonly ICommand _aboutCommand; private readonly ICommand _quitCommand; public MenuViewModel AppMenuViewModel { get => _menuViewModel; - private set => Set(ref _menuViewModel, value); + private set => SetProperty(ref _menuViewModel, value); } private void CreateMenuViewModel() @@ -787,7 +786,7 @@ namespace FluentTerminal.App.ViewModels foreach (var profile in _settingsService.GetShellProfiles().Concat(_settingsService.GetSshProfiles()).OrderBy(x => x.Name)) { - items.Add(new MenuItemViewModel(profile.Name, new AsyncCommand(() => AddProfileAsync(profile, location)))); + items.Add(new MenuItemViewModel(profile.Name, new AsyncRelayCommand(() => AddProfileAsync(profile, location)))); } } @@ -797,8 +796,7 @@ namespace FluentTerminal.App.ViewModels private MenuItemViewModel CommandToMenuItem(ExecutedCommand command) { - var itemCommand = new RelayCommand(async () => await AddProfileAsync(command.ShellProfile), - keepTargetAlive: true); + var itemCommand = new AsyncRelayCommand(() => AddProfileAsync(command.ShellProfile)); var keyBinding = command.ShellProfile.KeyBindings?.FirstOrDefault() is KeyBinding kb ? new MenuItemKeyBindingViewModel(kb) : null; diff --git a/FluentTerminal.App.ViewModels/Menu/Mdl2Icon.cs b/FluentTerminal.App.ViewModels/Menu/Mdl2Icon.cs index 833f4f4..c200ed5 100644 --- a/FluentTerminal.App.ViewModels/Menu/Mdl2Icon.cs +++ b/FluentTerminal.App.ViewModels/Menu/Mdl2Icon.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace FluentTerminal.App.ViewModels.Menu +namespace FluentTerminal.App.ViewModels.Menu { public sealed class Mdl2Icon { diff --git a/FluentTerminal.App.ViewModels/Menu/MenuItemKeyBindingViewModel.cs b/FluentTerminal.App.ViewModels/Menu/MenuItemKeyBindingViewModel.cs index e30874f..9d1e69c 100644 --- a/FluentTerminal.App.ViewModels/Menu/MenuItemKeyBindingViewModel.cs +++ b/FluentTerminal.App.ViewModels/Menu/MenuItemKeyBindingViewModel.cs @@ -1,21 +1,21 @@ using FluentTerminal.App.Services.Utilities; using FluentTerminal.Models; using FluentTerminal.Models.Enums; -using GalaSoft.MvvmLight; +using Microsoft.Toolkit.Mvvm.ComponentModel; using System; using System.Collections.Generic; using Windows.System; namespace FluentTerminal.App.ViewModels.Menu { - public class MenuItemKeyBindingViewModel : ViewModelBase + public class MenuItemKeyBindingViewModel : ObservableObject { private int _key; public int Key { get => _key; - set => Set(ref _key, value); + set => SetProperty(ref _key, value); } private int _keyModifiers; @@ -24,7 +24,7 @@ namespace FluentTerminal.App.ViewModels.Menu public int KeyModifiers { get => _keyModifiers; - private set => Set(ref _keyModifiers, value); + private set => SetProperty(ref _keyModifiers, value); } private bool _ctrl; @@ -34,7 +34,7 @@ namespace FluentTerminal.App.ViewModels.Menu get => _ctrl; set { - if (Set(ref _ctrl, value)) + if (SetProperty(ref _ctrl, value)) { SetKeyModifiers(); } @@ -48,7 +48,7 @@ namespace FluentTerminal.App.ViewModels.Menu get => _alt; set { - if (Set(ref _alt, value)) + if (SetProperty(ref _alt, value)) { SetKeyModifiers(); } @@ -62,7 +62,7 @@ namespace FluentTerminal.App.ViewModels.Menu get => _shift; set { - if (Set(ref _shift, value)) + if (SetProperty(ref _shift, value)) { SetKeyModifiers(); } @@ -76,7 +76,7 @@ namespace FluentTerminal.App.ViewModels.Menu get => _windows; set { - if (Set(ref _windows, value)) + if (SetProperty(ref _windows, value)) { SetKeyModifiers(); } diff --git a/FluentTerminal.App.ViewModels/Menu/MenuItemViewModel.cs b/FluentTerminal.App.ViewModels/Menu/MenuItemViewModel.cs index 4aacf88..70dbe48 100644 --- a/FluentTerminal.App.ViewModels/Menu/MenuItemViewModel.cs +++ b/FluentTerminal.App.ViewModels/Menu/MenuItemViewModel.cs @@ -12,7 +12,7 @@ namespace FluentTerminal.App.ViewModels.Menu public MenuItemKeyBindingViewModel KeyBinding { get => _keyBinding; - set => Set(ref _keyBinding, value); + set => SetProperty(ref _keyBinding, value); } public ICommand Command { get; } diff --git a/FluentTerminal.App.ViewModels/Menu/MenuItemViewModelBase.cs b/FluentTerminal.App.ViewModels/Menu/MenuItemViewModelBase.cs index 193c42c..0eedac8 100644 --- a/FluentTerminal.App.ViewModels/Menu/MenuItemViewModelBase.cs +++ b/FluentTerminal.App.ViewModels/Menu/MenuItemViewModelBase.cs @@ -1,9 +1,9 @@ using FluentTerminal.Models; -using GalaSoft.MvvmLight; +using Microsoft.Toolkit.Mvvm.ComponentModel; namespace FluentTerminal.App.ViewModels.Menu { - public class MenuItemViewModelBase : ViewModelBase + public class MenuItemViewModelBase : ObservableObject { #region Properties @@ -12,7 +12,7 @@ namespace FluentTerminal.App.ViewModels.Menu public string Text { get => _text; - set => Set(ref _text, value); + set => SetProperty(ref _text, value); } private string _description; @@ -20,7 +20,7 @@ namespace FluentTerminal.App.ViewModels.Menu public string Description { get => _description; - set => Set(ref _description, value); + set => SetProperty(ref _description, value); } private Mdl2Icon _icon; @@ -28,7 +28,7 @@ namespace FluentTerminal.App.ViewModels.Menu public Mdl2Icon Icon { get => _icon; - set => Set(ref _icon, value); + set => SetProperty(ref _icon, value); } #endregion Properties diff --git a/FluentTerminal.App.ViewModels/Menu/MenuViewModel.cs b/FluentTerminal.App.ViewModels/Menu/MenuViewModel.cs index c9c8348..de04da6 100644 --- a/FluentTerminal.App.ViewModels/Menu/MenuViewModel.cs +++ b/FluentTerminal.App.ViewModels/Menu/MenuViewModel.cs @@ -1,11 +1,11 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using GalaSoft.MvvmLight; +using Microsoft.Toolkit.Mvvm.ComponentModel; namespace FluentTerminal.App.ViewModels.Menu { - public class MenuViewModel : ViewModelBase + public class MenuViewModel : ObservableObject { public ObservableCollection Items { get; } diff --git a/FluentTerminal.App.ViewModels/OverlayViewModel.cs b/FluentTerminal.App.ViewModels/OverlayViewModel.cs index 0612cc8..d403000 100644 --- a/FluentTerminal.App.ViewModels/OverlayViewModel.cs +++ b/FluentTerminal.App.ViewModels/OverlayViewModel.cs @@ -1,10 +1,10 @@ -using GalaSoft.MvvmLight; +using Microsoft.Toolkit.Mvvm.ComponentModel; using System; using Windows.UI.Xaml; namespace FluentTerminal.App.ViewModels { - public class OverlayViewModel : ViewModelBase + public class OverlayViewModel : ObservableObject { private readonly DispatcherTimer _overlayTimer; private bool _showOverlay; @@ -19,13 +19,13 @@ namespace FluentTerminal.App.ViewModels public bool ShowOverlay { get => _showOverlay; - set => Set(ref _showOverlay, value); + set => SetProperty(ref _showOverlay, value); } public string OverlayContent { get => _overlayContent; - set => Set(ref _overlayContent, value); + set => SetProperty(ref _overlayContent, value); } public void Show(string message) diff --git a/FluentTerminal.App.ViewModels/ProfileViewModelBase.cs b/FluentTerminal.App.ViewModels/ProfileViewModelBase.cs index 327d854..569525b 100644 --- a/FluentTerminal.App.ViewModels/ProfileViewModelBase.cs +++ b/FluentTerminal.App.ViewModels/ProfileViewModelBase.cs @@ -3,21 +3,21 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; +using System.Windows.Input; using FluentTerminal.App.Services; using FluentTerminal.App.Services.Utilities; -using FluentTerminal.App.ViewModels.Infrastructure; using FluentTerminal.App.ViewModels.Profiles; using FluentTerminal.App.ViewModels.Settings; using FluentTerminal.Models; -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; namespace FluentTerminal.App.ViewModels { /// /// Base class for all profile view models. Implements logic for saving, editing, resetting, etc. /// - public abstract class ProfileViewModelBase : ViewModelBase where T : ProfileProviderViewModelBase + public abstract class ProfileViewModelBase : ObservableObject where T : ProfileProviderViewModelBase { #region Fields @@ -41,7 +41,7 @@ namespace FluentTerminal.App.ViewModels public bool InEditMode { get => _inEditMode; - set => Set(ref _inEditMode, value); + set => SetProperty(ref _inEditMode, value); } private string _name; @@ -49,7 +49,7 @@ namespace FluentTerminal.App.ViewModels public string Name { get => _name; - set => Set(ref _name, value); + set => SetProperty(ref _name, value); } public KeyBindingsViewModel KeyBindings { get; } @@ -69,15 +69,15 @@ namespace FluentTerminal.App.ViewModels #region Commands - public IAsyncCommand CancelEditCommand { get; } + public ICommand CancelEditCommand { get; } - public IAsyncCommand DeleteCommand { get; } + public ICommand DeleteCommand { get; } - public RelayCommand EditCommand { get; } + public ICommand EditCommand { get; } - public IAsyncCommand SaveChangesCommand { get; } + public ICommand SaveChangesCommand { get; } - public IAsyncCommand AddKeyboardShortcutCommand { get; } + public ICommand AddKeyboardShortcutCommand { get; } #endregion Commands @@ -102,11 +102,11 @@ namespace FluentTerminal.App.ViewModels Initialize(shellProfile); - DeleteCommand = new AsyncCommand(DeleteAsync, CanDelete); + DeleteCommand = new AsyncRelayCommand(DeleteAsync, CanDelete); EditCommand = new RelayCommand(Edit); - CancelEditCommand = new AsyncCommand(CancelEditAsync); - SaveChangesCommand = new AsyncCommand(SaveChangesAsync); - AddKeyboardShortcutCommand = new AsyncCommand(AddKeyboardShortcut); + CancelEditCommand = new AsyncRelayCommand(CancelEditAsync); + SaveChangesCommand = new AsyncRelayCommand(SaveChangesAsync); + AddKeyboardShortcutCommand = new AsyncRelayCommand(AddKeyboardShortcutAsync); } #endregion Constructor @@ -248,7 +248,7 @@ namespace FluentTerminal.App.ViewModels IsNew = false; } - private Task AddKeyboardShortcut() + private Task AddKeyboardShortcutAsync() { return KeyBindings.ShowAddKeyBindingDialogAsync(); } diff --git a/FluentTerminal.App.ViewModels/Profiles/CommonProfileProviderViewModel.cs b/FluentTerminal.App.ViewModels/Profiles/CommonProfileProviderViewModel.cs index d1ffbf4..774450f 100644 --- a/FluentTerminal.App.ViewModels/Profiles/CommonProfileProviderViewModel.cs +++ b/FluentTerminal.App.ViewModels/Profiles/CommonProfileProviderViewModel.cs @@ -1,8 +1,9 @@ using System.Threading.Tasks; +using System.Windows.Input; using FluentTerminal.App.Services; using FluentTerminal.App.Services.Utilities; -using FluentTerminal.App.ViewModels.Infrastructure; using FluentTerminal.Models; +using Microsoft.Toolkit.Mvvm.Input; namespace FluentTerminal.App.ViewModels.Profiles { @@ -26,7 +27,7 @@ namespace FluentTerminal.App.ViewModels.Profiles public string Location { get => _location; - set => Set(ref _location, value); + set => SetProperty(ref _location, value); } private string _workingDirectory; @@ -34,7 +35,7 @@ namespace FluentTerminal.App.ViewModels.Profiles public string WorkingDirectory { get => _workingDirectory; - set => Set(ref _workingDirectory, value); + set => SetProperty(ref _workingDirectory, value); } private string _arguments; @@ -42,16 +43,16 @@ namespace FluentTerminal.App.ViewModels.Profiles public string Arguments { get => _arguments; - set => Set(ref _arguments, value); + set => SetProperty(ref _arguments, value); } #endregion Properties #region Commands - public IAsyncCommand BrowseForCustomShellCommand { get; } + public ICommand BrowseForCustomShellCommand { get; } - public IAsyncCommand BrowseForWorkingDirectoryCommand { get; } + public ICommand BrowseForWorkingDirectoryCommand { get; } #endregion Commands @@ -63,8 +64,8 @@ namespace FluentTerminal.App.ViewModels.Profiles { _fileSystemService = fileSystemService; - BrowseForCustomShellCommand = new AsyncCommand(BrowseForCustomShell); - BrowseForWorkingDirectoryCommand = new AsyncCommand(BrowseForWorkingDirectory); + BrowseForCustomShellCommand = new AsyncRelayCommand(BrowseForCustomShell); + BrowseForWorkingDirectoryCommand = new AsyncRelayCommand(BrowseForWorkingDirectory); Initialize(Model); } diff --git a/FluentTerminal.App.ViewModels/Profiles/ProfileProviderViewModelBase.cs b/FluentTerminal.App.ViewModels/Profiles/ProfileProviderViewModelBase.cs index a4370dd..06218cd 100644 --- a/FluentTerminal.App.ViewModels/Profiles/ProfileProviderViewModelBase.cs +++ b/FluentTerminal.App.ViewModels/Profiles/ProfileProviderViewModelBase.cs @@ -8,7 +8,8 @@ using Windows.UI.Core; using FluentTerminal.App.Services; using FluentTerminal.Models; using FluentTerminal.Models.Messages; -using GalaSoft.MvvmLight; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Messaging; namespace FluentTerminal.App.ViewModels.Profiles { @@ -16,7 +17,9 @@ namespace FluentTerminal.App.ViewModels.Profiles /// Base class for all profile view model classes. It contains properties shared by all other view models /// (theme-related properties, line-ending translation, and WinPTY/ConPTY selection). /// - public abstract class ProfileProviderViewModelBase : ViewModelBase + public abstract class ProfileProviderViewModelBase : ObservableObject, + IRecipient, + IRecipient { #region Fields @@ -78,7 +81,7 @@ namespace FluentTerminal.App.ViewModels.Profiles ? value : TabThemes.FirstOrDefault(t => t.Id == value.Id) ?? TabThemes.First(); - if (Set(ref _selectedTabTheme, theme)) + if (SetProperty(ref _selectedTabTheme, theme)) { _tabThemeId = theme.Id; } @@ -92,7 +95,7 @@ namespace FluentTerminal.App.ViewModels.Profiles get => _tabThemeId; set { - if (Set(ref _tabThemeId, value)) + if (SetProperty(ref _tabThemeId, value)) { SelectedTabTheme = TabThemes.FirstOrDefault(t => t.Id.Equals(value)); } @@ -119,7 +122,7 @@ namespace FluentTerminal.App.ViewModels.Profiles theme = TerminalThemes.FirstOrDefault(t => t.Id.Equals(theme.Id)) ?? TerminalThemes.First(); } - if (Set(ref _selectedTerminalTheme, theme)) + if (SetProperty(ref _selectedTerminalTheme, theme)) { _terminalThemeId = theme.Id; } @@ -133,7 +136,7 @@ namespace FluentTerminal.App.ViewModels.Profiles get => _terminalThemeId; set { - if (Set(ref _terminalThemeId, value)) + if (SetProperty(ref _terminalThemeId, value)) { SelectedTerminalTheme = TerminalThemes.FirstOrDefault(t => t.Id.Equals(value)); } @@ -145,7 +148,7 @@ namespace FluentTerminal.App.ViewModels.Profiles public bool UseConPty { get => _useConPty; - set => Set(ref _useConPty, value); + set => SetProperty(ref _useConPty, value); } private bool _useBuffer; @@ -153,7 +156,7 @@ namespace FluentTerminal.App.ViewModels.Profiles public bool UseBuffer { get => _useBuffer; - set => Set(ref _useBuffer, value); + set => SetProperty(ref _useBuffer, value); } #endregion Properties @@ -179,9 +182,6 @@ namespace FluentTerminal.App.ViewModels.Profiles SelectedTerminalTheme = TerminalThemes.First(); - MessengerInstance.Register(this, OnThemeAdded); - MessengerInstance.Register(this, OnThemeDeleted); - Initialize(Model); } @@ -189,7 +189,7 @@ namespace FluentTerminal.App.ViewModels.Profiles #region Methods - private void OnThemeDeleted(ThemeDeletedMessage message) + public void Receive(ThemeDeletedMessage message) { var theme = TerminalThemes.FirstOrDefault(t => t.Id.Equals(message.ThemeId)); @@ -209,7 +209,7 @@ namespace FluentTerminal.App.ViewModels.Profiles }, CoreDispatcherPriority.Low, true); } - private void OnThemeAdded(ThemeAddedMessage message) + public void Receive(ThemeAddedMessage message) { ApplicationView.ExecuteOnUiThreadAsync(() => TerminalThemes.Add(message.Theme), CoreDispatcherPriority.Low); } diff --git a/FluentTerminal.App.ViewModels/Profiles/SshConnectViewModel.cs b/FluentTerminal.App.ViewModels/Profiles/SshConnectViewModel.cs index 974197d..8c4ff72 100644 --- a/FluentTerminal.App.ViewModels/Profiles/SshConnectViewModel.cs +++ b/FluentTerminal.App.ViewModels/Profiles/SshConnectViewModel.cs @@ -6,10 +6,11 @@ using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Web; +using System.Windows.Input; using FluentTerminal.App.Services; using FluentTerminal.App.Services.Utilities; -using FluentTerminal.App.ViewModels.Infrastructure; using FluentTerminal.Models; +using Microsoft.Toolkit.Mvvm.Input; namespace FluentTerminal.App.ViewModels.Profiles { @@ -59,7 +60,7 @@ namespace FluentTerminal.App.ViewModels.Profiles public string Host { get => _host; - set => Set(ref _host, value); + set => SetProperty(ref _host, value); } private ushort _sshPort; @@ -67,7 +68,7 @@ namespace FluentTerminal.App.ViewModels.Profiles public ushort SshPort { get => _sshPort; - set => Set(ref _sshPort, value); + set => SetProperty(ref _sshPort, value); } private string _username; @@ -75,7 +76,7 @@ namespace FluentTerminal.App.ViewModels.Profiles public string Username { get => _username; - set => Set(ref _username, value); + set => SetProperty(ref _username, value); } private string _identityFile; @@ -83,7 +84,7 @@ namespace FluentTerminal.App.ViewModels.Profiles public string IdentityFile { get => _identityFile; - set => Set(ref _identityFile, value); + set => SetProperty(ref _identityFile, value); } private bool _useMosh; @@ -91,7 +92,7 @@ namespace FluentTerminal.App.ViewModels.Profiles public bool UseMosh { get => _useMosh; - set => Set(ref _useMosh, value); + set => SetProperty(ref _useMosh, value); } private ushort _moshPortFrom; @@ -99,7 +100,7 @@ namespace FluentTerminal.App.ViewModels.Profiles public ushort MoshPortFrom { get => _moshPortFrom; - set => Set(ref _moshPortFrom, value); + set => SetProperty(ref _moshPortFrom, value); } private ushort _moshPortTo; @@ -107,14 +108,14 @@ namespace FluentTerminal.App.ViewModels.Profiles public ushort MoshPortTo { get => _moshPortTo; - set => Set(ref _moshPortTo, value); + set => SetProperty(ref _moshPortTo, value); } #endregion Properties #region Commands - public IAsyncCommand BrowseForIdentityFileCommand { get; } + public ICommand BrowseForIdentityFileCommand { get; } #endregion Commands @@ -132,7 +133,7 @@ namespace FluentTerminal.App.ViewModels.Profiles Initialize((SshProfile)Model); - BrowseForIdentityFileCommand = new AsyncCommand(BrowseForIdentityFileAsync); + BrowseForIdentityFileCommand = new AsyncRelayCommand(BrowseForIdentityFileAsync); } #endregion Constructor diff --git a/FluentTerminal.App.ViewModels/Settings/AboutPageViewModel.cs b/FluentTerminal.App.ViewModels/Settings/AboutPageViewModel.cs index 356b3e1..fee43f1 100644 --- a/FluentTerminal.App.ViewModels/Settings/AboutPageViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/AboutPageViewModel.cs @@ -1,11 +1,12 @@ using FluentTerminal.App.Services; -using FluentTerminal.App.ViewModels.Infrastructure; -using GalaSoft.MvvmLight; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; using System.Threading.Tasks; +using System.Windows.Input; namespace FluentTerminal.App.ViewModels.Settings { - public class AboutPageViewModel : ViewModelBase + public class AboutPageViewModel : ObservableObject { private const string BaseUrl = "https://github.com/felixse/FluentTerminal/releases/tag/"; private readonly IUpdateService _updateService; @@ -17,10 +18,10 @@ namespace FluentTerminal.App.ViewModels.Settings _updateService = updateService; _applicationView = applicationView; - CheckForUpdatesCommand = new AsyncCommand(() => CheckForUpdateAsync(true)); + CheckForUpdatesCommand = new AsyncRelayCommand(() => CheckForUpdateAsync(true)); } - public IAsyncCommand CheckForUpdatesCommand { get; } + public ICommand CheckForUpdatesCommand { get; } public string CurrentVersion { @@ -38,12 +39,12 @@ namespace FluentTerminal.App.ViewModels.Settings get => _latestVersion; set { - if (Set(ref _latestVersion, value)) + if (SetProperty(ref _latestVersion, value)) { - RaisePropertyChanged(nameof(LatestVersionFound)); - RaisePropertyChanged(nameof(LatestVersionLoading)); - RaisePropertyChanged(nameof(LatestVersionNotFound)); - RaisePropertyChanged(nameof(LatestVersionReleaseNotesURL)); + OnPropertyChanged(nameof(LatestVersionFound)); + OnPropertyChanged(nameof(LatestVersionLoading)); + OnPropertyChanged(nameof(LatestVersionNotFound)); + OnPropertyChanged(nameof(LatestVersionReleaseNotesURL)); } } } diff --git a/FluentTerminal.App.ViewModels/Settings/GeneralPageViewModel.cs b/FluentTerminal.App.ViewModels/Settings/GeneralPageViewModel.cs index 8b94429..86310c1 100644 --- a/FluentTerminal.App.ViewModels/Settings/GeneralPageViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/GeneralPageViewModel.cs @@ -1,15 +1,16 @@ using FluentTerminal.App.Services; using FluentTerminal.App.Services.Utilities; -using FluentTerminal.App.ViewModels.Infrastructure; using FluentTerminal.Models; using FluentTerminal.Models.Enums; -using GalaSoft.MvvmLight; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; using System.Collections.Generic; using System.Threading.Tasks; +using System.Windows.Input; namespace FluentTerminal.App.ViewModels.Settings { - public class GeneralPageViewModel : ViewModelBase + public class GeneralPageViewModel : ObservableObject { private readonly ApplicationSettings _applicationSettings; private readonly IDefaultValueProvider _defaultValueProvider; @@ -39,8 +40,8 @@ namespace FluentTerminal.App.ViewModels.Settings _applicationSettings = _settingsService.GetApplicationSettings(); - RestoreDefaultsCommand = new AsyncCommand(RestoreDefaultsAsync); - BrowseLogDirectoryCommand = new AsyncCommand(BrowseLogDirectoryAsync); + RestoreDefaultsCommand = new AsyncRelayCommand(RestoreDefaultsAsync); + BrowseLogDirectoryCommand = new AsyncRelayCommand(BrowseLogDirectoryAsync); } public IEnumerable Languages => _applicationLanguageService.Languages; @@ -48,7 +49,7 @@ namespace FluentTerminal.App.ViewModels.Settings public bool NeedsToRestart { get => _needsToRestart; - set => Set(ref _needsToRestart, value); + set => SetProperty(ref _needsToRestart, value); } public string SelectedLanguage @@ -78,7 +79,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.ShowCustomTitleInTitlebar = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -92,7 +93,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.EnableTrayIcon = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); // Toggle message telling user to restart the program ShouldRestartForTrayMessage = !ShouldRestartForTrayMessage; @@ -103,7 +104,7 @@ namespace FluentTerminal.App.ViewModels.Settings public bool ShouldRestartForTrayMessage { get => _shouldRestartForTrayMessage; - set => Set(ref _shouldRestartForTrayMessage, value); + set => SetProperty(ref _shouldRestartForTrayMessage, value); } public bool ShowNewOutputIndicator @@ -115,7 +116,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.ShowNewOutputIndicator = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -129,7 +130,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.UseMoshByDefault = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -143,7 +144,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.AutoFallbackToWindowsUsernameInLinks = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -157,7 +158,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.RTrimCopiedLines = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -171,7 +172,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.MuteTerminalBeeps = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); _trayProcessCommunicationService.MuteTerminalAsync(value); } @@ -186,7 +187,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.EnableLogging = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -200,7 +201,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.PrintableOutputOnly = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -214,7 +215,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.LogDirectoryPath = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -228,7 +229,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.UseConPty = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -242,7 +243,7 @@ namespace FluentTerminal.App.ViewModels.Settings public bool CanEnableStartupTask { get => _canEnableStartupTask; - set => Set(ref _canEnableStartupTask, value); + set => SetProperty(ref _canEnableStartupTask, value); } public bool ConfirmClosingTabs @@ -254,7 +255,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.ConfirmClosingTabs = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -268,7 +269,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.ConfirmClosingWindows = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -282,8 +283,8 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.NewTerminalLocation = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); - RaisePropertyChanged(nameof(TabIsSelected)); + OnPropertyChanged(); + OnPropertyChanged(nameof(TabIsSelected)); } } } @@ -297,21 +298,21 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.TabWindowCascadingAppMenu = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } - public IAsyncCommand RestoreDefaultsCommand { get; } + public ICommand RestoreDefaultsCommand { get; } - public IAsyncCommand BrowseLogDirectoryCommand { get; } + public ICommand BrowseLogDirectoryCommand { get; } public bool StartupTaskEnabled { get => _startupTaskEnabled; set { - if (Set(ref _startupTaskEnabled, value)) + if (SetProperty(ref _startupTaskEnabled, value)) { // ReSharper disable once AssignmentIsFullyDiscarded _ = SetStartupTaskStateAsync(value); @@ -322,7 +323,7 @@ namespace FluentTerminal.App.ViewModels.Settings public string StartupTaskErrorMessage { get => _startupTaskErrorMessage; - set => Set(ref _startupTaskErrorMessage, value); + set => SetProperty(ref _startupTaskErrorMessage, value); } public bool TabIsSelected @@ -340,7 +341,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.TabsPosition = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -360,7 +361,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.UnderlineSelectedTab = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -386,7 +387,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.InactiveTabColorMode = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -400,7 +401,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.ShowTextCopied = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } diff --git a/FluentTerminal.App.ViewModels/Settings/KeyBindingViewModel.cs b/FluentTerminal.App.ViewModels/Settings/KeyBindingViewModel.cs index ea7694e..e21d633 100644 --- a/FluentTerminal.App.ViewModels/Settings/KeyBindingViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/KeyBindingViewModel.cs @@ -1,14 +1,15 @@ using FluentTerminal.App.Services; using FluentTerminal.App.Services.Utilities; -using FluentTerminal.App.ViewModels.Infrastructure; using FluentTerminal.Models; -using GalaSoft.MvvmLight; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; using System; using System.Threading.Tasks; +using System.Windows.Input; namespace FluentTerminal.App.ViewModels.Settings { - public class KeyBindingViewModel : ViewModelBase + public class KeyBindingViewModel : ObservableObject { private readonly IDialogService _dialogService; @@ -17,8 +18,8 @@ namespace FluentTerminal.App.ViewModels.Settings Model = keyBinding; Parent = parent; _dialogService = dialogService; - EditCommand = new AsyncCommand(EditAsync); - DeleteCommand = new AsyncCommand(DeleteAsync); + EditCommand = new AsyncRelayCommand(EditAsync); + DeleteCommand = new AsyncRelayCommand(DeleteAsync); } // Needs to be triggered from the UI thread @@ -36,7 +37,7 @@ namespace FluentTerminal.App.ViewModels.Settings if (Model.Meta != value) { Model.Meta = value; - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -49,7 +50,7 @@ namespace FluentTerminal.App.ViewModels.Settings if (Model.Alt != value) { Model.Alt = value; - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -62,13 +63,13 @@ namespace FluentTerminal.App.ViewModels.Settings if (Model.Ctrl != value) { Model.Ctrl = value; - RaisePropertyChanged(); + OnPropertyChanged(); } } } - public IAsyncCommand DeleteCommand { get; } - public IAsyncCommand EditCommand { get; } + public ICommand DeleteCommand { get; } + public ICommand EditCommand { get; } public int Key { @@ -78,7 +79,7 @@ namespace FluentTerminal.App.ViewModels.Settings if (Model.Key != value) { Model.Key = value; - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -93,7 +94,7 @@ namespace FluentTerminal.App.ViewModels.Settings if (Model.Shift != value) { Model.Shift = value; - RaisePropertyChanged(); + OnPropertyChanged(); } } } diff --git a/FluentTerminal.App.ViewModels/Settings/KeyBindingsPageViewModel.cs b/FluentTerminal.App.ViewModels/Settings/KeyBindingsPageViewModel.cs index 5063714..a82b5a9 100644 --- a/FluentTerminal.App.ViewModels/Settings/KeyBindingsPageViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/KeyBindingsPageViewModel.cs @@ -2,17 +2,18 @@ using FluentTerminal.App.Services.Utilities; using FluentTerminal.Models; using FluentTerminal.Models.Enums; -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; +using System.Windows.Input; namespace FluentTerminal.App.ViewModels.Settings { - public class KeyBindingsPageViewModel : ViewModelBase + public class KeyBindingsPageViewModel : ObservableObject { private readonly IDialogService _dialogService; private readonly ISettingsService _settingsService; @@ -23,15 +24,15 @@ namespace FluentTerminal.App.ViewModels.Settings _settingsService = settingsService; _dialogService = dialogService; _trayProcessCommunicationService = trayProcessCommunicationService; - RestoreDefaultsCommand = new RelayCommand(async () => await RestoreDefaultsAsync().ConfigureAwait(false)); - AddCommand = new RelayCommand(async command => await AddAsync(command).ConfigureAwait(false)); + RestoreDefaultsCommand = new AsyncRelayCommand(RestoreDefaultsAsync); + AddCommand = new AsyncRelayCommand(AddAsync); Initialize(_settingsService.GetCommandKeyBindings()); } - public RelayCommand AddCommand { get; } + public ICommand AddCommand { get; } public ObservableCollection KeyBindings { get; } = new ObservableCollection(); - public RelayCommand RestoreDefaultsCommand { get; } + public ICommand RestoreDefaultsCommand { get; } private Task AddAsync(string command) { diff --git a/FluentTerminal.App.ViewModels/Settings/KeyBindingsViewModel.cs b/FluentTerminal.App.ViewModels/Settings/KeyBindingsViewModel.cs index 34dea9a..828d74a 100644 --- a/FluentTerminal.App.ViewModels/Settings/KeyBindingsViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/KeyBindingsViewModel.cs @@ -1,6 +1,6 @@ using FluentTerminal.App.Services; using FluentTerminal.Models; -using GalaSoft.MvvmLight; +using Microsoft.Toolkit.Mvvm.ComponentModel; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -9,7 +9,7 @@ using System.Threading.Tasks; namespace FluentTerminal.App.ViewModels.Settings { - public class KeyBindingsViewModel : ViewModelBase + public class KeyBindingsViewModel : ObservableObject { private readonly IDialogService _dialogService; private bool _editable; @@ -37,7 +37,7 @@ namespace FluentTerminal.App.ViewModels.Settings public bool Editable { get => _editable; - set => Set(ref _editable, value); + set => SetProperty(ref _editable, value); } public ObservableCollection KeyBindings { get; } = new ObservableCollection(); diff --git a/FluentTerminal.App.ViewModels/Settings/MousePageViewModel.cs b/FluentTerminal.App.ViewModels/Settings/MousePageViewModel.cs index 03bb906..c824c21 100644 --- a/FluentTerminal.App.ViewModels/Settings/MousePageViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/MousePageViewModel.cs @@ -2,13 +2,14 @@ using FluentTerminal.App.Services.Utilities; using FluentTerminal.Models; using FluentTerminal.Models.Enums; -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; using System.Threading.Tasks; +using System.Windows.Input; namespace FluentTerminal.App.ViewModels.Settings { - public class MousePageViewModel : ViewModelBase + public class MousePageViewModel : ObservableObject { private readonly ISettingsService _settingsService; private readonly IDialogService _dialogService; @@ -22,7 +23,7 @@ namespace FluentTerminal.App.ViewModels.Settings _defaultValueProvider = defaultValueProvider; _applicationSettings = _settingsService.GetApplicationSettings(); - RestoreDefaultsCommand = new RelayCommand(async () => await RestoreDefaultsAsync().ConfigureAwait(false)); + RestoreDefaultsCommand = new AsyncRelayCommand(RestoreDefaultsAsync); } public bool CopyOnSelect @@ -34,7 +35,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.CopyOnSelect = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -48,7 +49,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.MouseRightClickAction = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -86,7 +87,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _applicationSettings.MouseMiddleClickAction = value; _settingsService.SaveApplicationSettings(_applicationSettings); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -115,7 +116,7 @@ namespace FluentTerminal.App.ViewModels.Settings set { if (value) MouseMiddleClickAction = MouseAction.CopySelectionOrPaste; } } - public RelayCommand RestoreDefaultsCommand { get; } + public ICommand RestoreDefaultsCommand { get; } // Requires UI thread private async Task RestoreDefaultsAsync() diff --git a/FluentTerminal.App.ViewModels/Settings/ProfilesPageViewModel.cs b/FluentTerminal.App.ViewModels/Settings/ProfilesPageViewModel.cs index b4e86b0..707196f 100644 --- a/FluentTerminal.App.ViewModels/Settings/ProfilesPageViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/ProfilesPageViewModel.cs @@ -1,15 +1,16 @@ using FluentTerminal.App.Services; using FluentTerminal.Models; -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; using System; using System.Collections.ObjectModel; using System.Collections.Generic; using System.Linq; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using System.Windows.Input; namespace FluentTerminal.App.ViewModels.Settings { - public class ProfilesPageViewModel : ViewModelBase + public class ProfilesPageViewModel : ObservableObject { private readonly IDefaultValueProvider _defaultValueProvider; private readonly IDialogService _dialogService; @@ -79,9 +80,9 @@ namespace FluentTerminal.App.ViewModels.Settings } } - public RelayCommand CreateShellProfileCommand { get; } + public ICommand CreateShellProfileCommand { get; } - public RelayCommand CloneCommand { get; } + public ICommand CloneCommand { get; } private void CreateShellProfile() { @@ -122,7 +123,7 @@ namespace FluentTerminal.App.ViewModels.Settings public ShellProfileViewModel SelectedShellProfile { get => _selectedShellProfile; - set => Set(ref _selectedShellProfile, value); + set => SetProperty(ref _selectedShellProfile, value); } public ObservableCollection ShellProfiles { get; } = new ObservableCollection(); diff --git a/FluentTerminal.App.ViewModels/Settings/SshProfilesPageViewModel.cs b/FluentTerminal.App.ViewModels/Settings/SshProfilesPageViewModel.cs index f3778d8..d26b86f 100644 --- a/FluentTerminal.App.ViewModels/Settings/SshProfilesPageViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/SshProfilesPageViewModel.cs @@ -1,15 +1,16 @@ using FluentTerminal.App.Services; using FluentTerminal.Models; -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; using System; using System.Collections.ObjectModel; using System.Collections.Generic; using System.Linq; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using System.Windows.Input; namespace FluentTerminal.App.ViewModels.Settings { - public class SshProfilesPageViewModel: ViewModelBase + public class SshProfilesPageViewModel: ObservableObject { private readonly IDialogService _dialogService; private readonly ISettingsService _settingsService; @@ -63,9 +64,9 @@ namespace FluentTerminal.App.ViewModels.Settings } } - public RelayCommand CreateSshProfileCommand { get; } + public ICommand CreateSshProfileCommand { get; } - public RelayCommand CloneCommand { get; } + public ICommand CloneCommand { get; } public void CreateSshProfile() { @@ -112,7 +113,7 @@ namespace FluentTerminal.App.ViewModels.Settings public SshProfileViewModel SelectedSshProfile { get => _selectedShellProfile; - set => Set(ref _selectedShellProfile, value); + set => SetProperty(ref _selectedShellProfile, value); } public ObservableCollection SshProfiles { get; } = new ObservableCollection(); diff --git a/FluentTerminal.App.ViewModels/Settings/TerminalPageViewModel.cs b/FluentTerminal.App.ViewModels/Settings/TerminalPageViewModel.cs index d345075..7b801bc 100644 --- a/FluentTerminal.App.ViewModels/Settings/TerminalPageViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/TerminalPageViewModel.cs @@ -3,15 +3,16 @@ using FluentTerminal.App.Services.Utilities; using FluentTerminal.App.ViewModels.Utilities; using FluentTerminal.Models; using FluentTerminal.Models.Enums; -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using System.Windows.Input; namespace FluentTerminal.App.ViewModels.Settings { - public class TerminalPageViewModel : ViewModelBase + public class TerminalPageViewModel : ObservableObject { private readonly TerminalOptions _terminalOptions; private readonly ISettingsService _settingsService; @@ -63,7 +64,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _terminalOptions.CursorBlink = value; _settingsService.SaveTerminalOptions(_terminalOptions); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -77,7 +78,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _terminalOptions.UseAcrylicBackground = value; _settingsService.SaveTerminalOptions(_terminalOptions); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -91,7 +92,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _terminalOptions.FontFamily = value; _settingsService.SaveTerminalOptions(_terminalOptions); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -105,7 +106,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _terminalOptions.FontWeight = value; _settingsService.SaveTerminalOptions(_terminalOptions); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -119,7 +120,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _terminalOptions.BackgroundOpacity = value; _settingsService.SaveTerminalOptions(_terminalOptions); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -133,7 +134,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _terminalOptions.Padding = value; _settingsService.SaveTerminalOptions(_terminalOptions); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -153,12 +154,12 @@ namespace FluentTerminal.App.ViewModels.Settings { _terminalOptions.ScrollBackLimit = intValue; _settingsService.SaveTerminalOptions(_terminalOptions); - RaisePropertyChanged(); + OnPropertyChanged(); } } else { - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -173,7 +174,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _terminalOptions.WordSeparator = value; _settingsService.SaveTerminalOptions(_terminalOptions); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -189,14 +190,14 @@ namespace FluentTerminal.App.ViewModels.Settings { _terminalOptions.FontSize = value; _settingsService.SaveTerminalOptions(_terminalOptions); - RaisePropertyChanged(); + OnPropertyChanged(); } } } public IEnumerable Sizes { get; } - public RelayCommand RestoreDefaultsCommand { get; } + public ICommand RestoreDefaultsCommand { get; } private CursorStyle CursorStyle { @@ -207,7 +208,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _terminalOptions.CursorStyle = value; _settingsService.SaveTerminalOptions(_terminalOptions); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -221,7 +222,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _terminalOptions.ScrollBarStyle = value; _settingsService.SaveTerminalOptions(_terminalOptions); - RaisePropertyChanged(); + OnPropertyChanged(); } } } @@ -255,7 +256,7 @@ namespace FluentTerminal.App.ViewModels.Settings _dialogService = dialogService; _defaultValueProvider = defaultValueProvider; - RestoreDefaultsCommand = new RelayCommand(async () => await RestoreDefaultsAsync().ConfigureAwait(false)); + RestoreDefaultsCommand = new AsyncRelayCommand(RestoreDefaultsAsync); Fonts = systemFontService.GetSystemFontFamilies().OrderBy(s => s.Name); Sizes = Enumerable.Range(2, 72); diff --git a/FluentTerminal.App.ViewModels/Settings/ThemesPageViewModel.cs b/FluentTerminal.App.ViewModels/Settings/ThemesPageViewModel.cs index b3b46e1..4d92c68 100644 --- a/FluentTerminal.App.ViewModels/Settings/ThemesPageViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/ThemesPageViewModel.cs @@ -1,18 +1,20 @@ using FluentTerminal.App.Services; using FluentTerminal.App.Services.Utilities; -using FluentTerminal.App.ViewModels.Infrastructure; using FluentTerminal.Models; -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; using System; using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; using FluentTerminal.Models.Messages; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using Microsoft.Toolkit.Mvvm.Messaging; +using System.Windows.Input; namespace FluentTerminal.App.ViewModels.Settings { - public class ThemesPageViewModel : ViewModelBase + public class ThemesPageViewModel : ObservableObject, + IRecipient { private readonly IDefaultValueProvider _defaultValueProvider; private readonly IDialogService _dialogService; @@ -42,11 +44,9 @@ namespace FluentTerminal.App.ViewModels.Settings _imageFileSystemService = imageFileSystemService; CreateThemeCommand = new RelayCommand(CreateTheme); - ImportThemeCommand = new AsyncCommand(ImportThemeAsync); + ImportThemeCommand = new AsyncRelayCommand(ImportThemeAsync); CloneCommand = new RelayCommand(CloneTheme); - MessengerInstance.Register(this, OnTerminalOptionsChanged); - BackgroundOpacity = _settingsService.GetTerminalOptions().BackgroundOpacity; var activeThemeId = _settingsService.GetCurrentThemeId(); @@ -66,14 +66,14 @@ namespace FluentTerminal.App.ViewModels.Settings SelectedTheme = Themes.First(t => t.IsActive); } - public RelayCommand CreateThemeCommand { get; } - public IAsyncCommand ImportThemeCommand { get; } - public RelayCommand CloneCommand { get; set; } + public ICommand CreateThemeCommand { get; } + public ICommand ImportThemeCommand { get; } + public ICommand CloneCommand { get; set; } public double BackgroundOpacity { get => _backgroundOpacity; - set => Set(ref _backgroundOpacity, value); + set => SetProperty(ref _backgroundOpacity, value); } public ThemeViewModel SelectedTheme @@ -87,7 +87,7 @@ namespace FluentTerminal.App.ViewModels.Settings _selectedTheme.BackgroundImageChanged -= OnSelectedThemeBackgroundImageChanged; } - Set(ref _selectedTheme, value); + SetProperty(ref _selectedTheme, value); SelectedThemeChanged?.Invoke(this, _selectedTheme); if (value != null) @@ -218,7 +218,7 @@ namespace FluentTerminal.App.ViewModels.Settings } } - private void OnTerminalOptionsChanged(TerminalOptionsChangedMessage message) + public void Receive(TerminalOptionsChangedMessage message) { BackgroundOpacity = message.TerminalOptions.BackgroundOpacity; } diff --git a/FluentTerminal.App.ViewModels/SettingsViewModel.cs b/FluentTerminal.App.ViewModels/SettingsViewModel.cs index df5a9db..668e66b 100644 --- a/FluentTerminal.App.ViewModels/SettingsViewModel.cs +++ b/FluentTerminal.App.ViewModels/SettingsViewModel.cs @@ -1,11 +1,11 @@ using FluentTerminal.App.Services; using FluentTerminal.App.ViewModels.Settings; -using GalaSoft.MvvmLight; +using Microsoft.Toolkit.Mvvm.ComponentModel; using System; namespace FluentTerminal.App.ViewModels { - public class SettingsViewModel : ViewModelBase + public class SettingsViewModel : ObservableObject { public SettingsViewModel(ISettingsService settingsService, IDefaultValueProvider defaultValueProvider, IDialogService dialogService, ITrayProcessCommunicationService trayProcessCommunicationService, IThemeParserFactory themeParserFactory, ISystemFontService systemFontService, diff --git a/FluentTerminal.App.ViewModels/ShellProfileViewModel.cs b/FluentTerminal.App.ViewModels/ShellProfileViewModel.cs index 6147133..0fc4ab8 100644 --- a/FluentTerminal.App.ViewModels/ShellProfileViewModel.cs +++ b/FluentTerminal.App.ViewModels/ShellProfileViewModel.cs @@ -1,12 +1,12 @@ using FluentTerminal.App.Services; using FluentTerminal.App.Services.Utilities; -using FluentTerminal.App.ViewModels.Infrastructure; using FluentTerminal.Models; -using GalaSoft.MvvmLight.Command; using System; using System.Linq; using System.Threading.Tasks; using FluentTerminal.App.ViewModels.Profiles; +using System.Windows.Input; +using Microsoft.Toolkit.Mvvm.Input; namespace FluentTerminal.App.ViewModels { @@ -28,7 +28,7 @@ namespace FluentTerminal.App.ViewModels public bool IsDefault { get => _isDefault; - set => Set(ref _isDefault, value); + set => SetProperty(ref _isDefault, value); } #endregion Properties @@ -41,9 +41,9 @@ namespace FluentTerminal.App.ViewModels #region Commands - public RelayCommand SetDefaultCommand { get; } + public ICommand SetDefaultCommand { get; } - public IAsyncCommand RestoreDefaultsCommand { get; } + public ICommand RestoreDefaultsCommand { get; } #endregion Commands @@ -60,7 +60,7 @@ namespace FluentTerminal.App.ViewModels shellProfile); SetDefaultCommand = new RelayCommand(SetDefault); - RestoreDefaultsCommand = new AsyncCommand(RestoreDefaultsAsync); + RestoreDefaultsCommand = new AsyncRelayCommand(RestoreDefaultsAsync); } #endregion Constrcutor diff --git a/FluentTerminal.App.ViewModels/TabThemeViewModel.cs b/FluentTerminal.App.ViewModels/TabThemeViewModel.cs index 6c33539..18bf3a1 100644 --- a/FluentTerminal.App.ViewModels/TabThemeViewModel.cs +++ b/FluentTerminal.App.ViewModels/TabThemeViewModel.cs @@ -1,9 +1,9 @@ using FluentTerminal.Models; -using GalaSoft.MvvmLight; +using Microsoft.Toolkit.Mvvm.ComponentModel; namespace FluentTerminal.App.ViewModels { - public class TabThemeViewModel : ViewModelBase + public class TabThemeViewModel : ObservableObject { private bool _isSelected; @@ -18,7 +18,7 @@ namespace FluentTerminal.App.ViewModels get => _isSelected; set { - if (Set(ref _isSelected, value) && value) + if (SetProperty(ref _isSelected, value) && value) { Terminal.TabTheme = this; } diff --git a/FluentTerminal.App.ViewModels/TerminalViewModel.cs b/FluentTerminal.App.ViewModels/TerminalViewModel.cs index 2c0c8f2..85f5091 100644 --- a/FluentTerminal.App.ViewModels/TerminalViewModel.cs +++ b/FluentTerminal.App.ViewModels/TerminalViewModel.cs @@ -1,10 +1,7 @@ using FluentTerminal.App.Services; using FluentTerminal.App.Services.Utilities; -using FluentTerminal.App.ViewModels.Infrastructure; using FluentTerminal.Models; using FluentTerminal.Models.Enums; -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; using Newtonsoft.Json; using System; using System.Collections.ObjectModel; @@ -15,14 +12,18 @@ using Windows.UI.Core; using FluentTerminal.Models.Messages; using System.Windows.Input; using FluentTerminal.App.ViewModels.Menu; -using Windows.UI.Xaml.Data; -using Windows.UI.Xaml; using System.Collections.Generic; -using System.Runtime.InteropServices; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Messaging; +using Microsoft.Toolkit.Mvvm.Input; namespace FluentTerminal.App.ViewModels { - public class TerminalViewModel : ViewModelBase + public class TerminalViewModel : ObservableObject, + IRecipient, + IRecipient, + IRecipient, + IRecipient { #region Static @@ -126,11 +127,6 @@ namespace FluentTerminal.App.ViewModels IKeyboardCommandService keyboardCommandService, ApplicationSettings applicationSettings, ShellProfile shellProfile, IApplicationView applicationView, IClipboardService clipboardService, string terminalState = null) { - MessengerInstance.Register(this, OnApplicationSettingsChanged); - MessengerInstance.Register(this, OnCurrentThemeChanged); - MessengerInstance.Register(this, OnTerminalOptionsChanged); - MessengerInstance.Register(this, OnKeyBindingsChanged); - SettingsService = settingsService; _terminalOptions = SettingsService.GetTerminalOptions(); @@ -147,19 +143,19 @@ namespace FluentTerminal.App.ViewModels TerminalTheme = shellProfile.TerminalThemeId == Guid.Empty ? SettingsService.GetCurrentTheme() : SettingsService.GetTheme(shellProfile.TerminalThemeId); TabThemes = new ObservableCollection(SettingsService.GetTabThemes().Select(theme => new TabThemeViewModel(theme, this))); - CloseCommand = new AsyncCommand(TryCloseAsync, CanExecuteCommand); + CloseCommand = new AsyncRelayCommand(TryCloseAsync, CanExecuteCommand); CloseLeftTabsCommand = new RelayCommand(CloseLeftTabs, CanExecuteCommand); CloseRightTabsCommand = new RelayCommand(CloseRightTabs, CanExecuteCommand); CloseOtherTabsCommand = new RelayCommand(CloseOtherTabs, CanExecuteCommand); FindNextCommand = new RelayCommand(FindNext, CanExecuteCommand); FindPreviousCommand = new RelayCommand(FindPrevious, CanExecuteCommand); CloseSearchPanelCommand = new RelayCommand(CloseSearchPanel, CanExecuteCommand); - EditTitleCommand = new AsyncCommand(EditTitleAsync, CanExecuteCommand); + EditTitleCommand = new AsyncRelayCommand(EditTitleAsync, CanExecuteCommand); DuplicateTabCommand = new RelayCommand(DuplicateTab, CanExecuteCommand); - ReconnectTabCommand = new AsyncCommand(ReconnectTabAsync, () => CanExecuteCommand() && HasExitedWithError); - CopyCommand = new AsyncCommand(Copy, () => HasSelection); - PasteCommand = new AsyncCommand(Paste); - CopyLinkCommand = new AsyncCommand(() => CopyTextAsync(HoveredUri), () => !string.IsNullOrWhiteSpace(HoveredUri)); + ReconnectTabCommand = new AsyncRelayCommand(ReconnectTabAsync, () => CanExecuteCommand() && HasExitedWithError); + CopyCommand = new AsyncRelayCommand(Copy, () => HasSelection); + PasteCommand = new AsyncRelayCommand(Paste); + CopyLinkCommand = new AsyncRelayCommand(() => CopyTextAsync(HoveredUri), () => !string.IsNullOrWhiteSpace(HoveredUri)); ShowSearchPanelCommand = new RelayCommand(() => ShowSearchPanel = true, () => !ShowSearchPanel); FontSize = _terminalOptions.FontSize; @@ -191,13 +187,13 @@ namespace FluentTerminal.App.ViewModels public MenuViewModel ContextMenu { get => _contextMenu; - set => Set(ref _contextMenu, value); + set => SetProperty(ref _contextMenu, value); } public MenuViewModel TabContextMenu { get => _tabContextMenu; - set => Set(ref _tabContextMenu, value); + set => SetProperty(ref _tabContextMenu, value); } private bool _disposalRequested; @@ -241,27 +237,27 @@ namespace FluentTerminal.App.ViewModels public string XtermBufferState { get; private set; } - public AsyncCommand CloseCommand { get; private set; } + public ICommand CloseCommand { get; private set; } - public RelayCommand CloseRightTabsCommand { get; } + public ICommand CloseRightTabsCommand { get; } - public RelayCommand CloseLeftTabsCommand { get; } + public ICommand CloseLeftTabsCommand { get; } - public RelayCommand CloseOtherTabsCommand { get; } + public ICommand CloseOtherTabsCommand { get; } - public RelayCommand CloseSearchPanelCommand { get; } + public ICommand CloseSearchPanelCommand { get; } public IDialogService DialogService { get; } - public IAsyncCommand EditTitleCommand { get; } + public ICommand EditTitleCommand { get; } - public RelayCommand FindNextCommand { get; } + public ICommand FindNextCommand { get; } - public RelayCommand FindPreviousCommand { get; } + public ICommand FindPreviousCommand { get; } - public RelayCommand DuplicateTabCommand { get; } + public ICommand DuplicateTabCommand { get; } - public AsyncCommand ReconnectTabCommand { get; } + public AsyncRelayCommand ReconnectTabCommand { get; } public ICommand CopyLinkCommand { get; private set; } @@ -278,7 +274,7 @@ namespace FluentTerminal.App.ViewModels get => _isSelected; set { - if (Set(ref _isSelected, value)) + if (SetProperty(ref _isSelected, value)) { if (IsSelected) { @@ -291,9 +287,9 @@ namespace FluentTerminal.App.ViewModels _keyboardCommandService.DeregisterCommandHandler(nameof(Command.Search)); _keyboardCommandService.DeregisterCommandHandler(nameof(Command.CloseSearch)); } - RaisePropertyChanged(nameof(IsUnderlined)); - RaisePropertyChanged(nameof(BackgroundTabTheme)); - RaisePropertyChanged(nameof(ShowCloseButton)); + OnPropertyChanged(nameof(IsUnderlined)); + OnPropertyChanged(nameof(BackgroundTabTheme)); + OnPropertyChanged(nameof(ShowCloseButton)); } } } @@ -301,7 +297,7 @@ namespace FluentTerminal.App.ViewModels public bool HasSelection { get => _hasSelection; - set => Set(ref _hasSelection, value); + set => SetProperty(ref _hasSelection, value); } public string HoveredUri @@ -309,7 +305,7 @@ namespace FluentTerminal.App.ViewModels get => _hoveredUri; set { - if (Set(ref _hoveredUri, value)) + if (SetProperty(ref _hoveredUri, value)) { ContextMenu = BuidContextMenu(); } @@ -321,9 +317,9 @@ namespace FluentTerminal.App.ViewModels get => _isHovered; set { - if (Set(ref _isHovered, value)) + if (SetProperty(ref _isHovered, value)) { - RaisePropertyChanged(nameof(ShowCloseButton)); + OnPropertyChanged(nameof(ShowCloseButton)); } } } @@ -339,7 +335,7 @@ namespace FluentTerminal.App.ViewModels public bool HasNewOutput { get => _hasNewOutput; - set => Set(ref _hasNewOutput, value); + set => SetProperty(ref _hasNewOutput, value); } public bool HasExitedWithError @@ -347,36 +343,36 @@ namespace FluentTerminal.App.ViewModels get => _hasExitedWithError; set { - if (Set(ref _hasExitedWithError, value) && value) + if (SetProperty(ref _hasExitedWithError, value) && value) { HasNewOutput = false; } - ReconnectTabCommand.RaiseCanExecuteChanged(); + ReconnectTabCommand.NotifyCanExecuteChanged(); } } public string SearchText { get => _searchText; - set => Set(ref _searchText, value); + set => SetProperty(ref _searchText, value); } public bool SearchMatchCase { get => _searchMatchCase; - set => Set(ref _searchMatchCase, value); + set => SetProperty(ref _searchMatchCase, value); } public bool SearchWholeWord { get => _searchWholeWord; - set => Set(ref _searchWholeWord, value); + set => SetProperty(ref _searchWholeWord, value); } public bool SearchWithRegex { get => _searchWithRegex; - set => Set(ref _searchWithRegex, value); + set => SetProperty(ref _searchWithRegex, value); } public ISettingsService SettingsService { get; } @@ -386,7 +382,7 @@ namespace FluentTerminal.App.ViewModels public bool ShowSearchPanel { get => _showSearchPanel; - set => Set(ref _showSearchPanel, value); + set => SetProperty(ref _showSearchPanel, value); } public bool SearchHasFocus { get; set; } @@ -396,9 +392,9 @@ namespace FluentTerminal.App.ViewModels get => _tabTheme; set { - Set(ref _tabTheme, value); - RaisePropertyChanged(nameof(IsUnderlined)); - RaisePropertyChanged(nameof(BackgroundTabTheme)); + SetProperty(ref _tabTheme, value); + OnPropertyChanged(nameof(IsUnderlined)); + OnPropertyChanged(nameof(BackgroundTabTheme)); // necessary to update this constantly so that duplicated tabs will also carry over the color ShellProfile.TabThemeId = value.Theme.Id; @@ -414,7 +410,7 @@ namespace FluentTerminal.App.ViewModels public TerminalTheme TerminalTheme { get => _terminalTheme; - set => Set(ref _terminalTheme, value); + set => SetProperty(ref _terminalTheme, value); } public bool Initialized { get; set; } @@ -445,7 +441,7 @@ namespace FluentTerminal.App.ViewModels } } - Set(ref _tabTitle, title); + SetProperty(ref _tabTitle, title); ShellProfile.Name = title; } } @@ -455,7 +451,7 @@ namespace FluentTerminal.App.ViewModels get => _shellTitle; set { - if (Set(ref _shellTitle, value) && !_hasCustomTitle) + if (SetProperty(ref _shellTitle, value) && !_hasCustomTitle) { TabTitle = value; } @@ -475,7 +471,7 @@ namespace FluentTerminal.App.ViewModels public Task CloseAsync() { - MessengerInstance.Unregister(this); + //MessengerInstance.Unregister(this); // todo necessary? return Terminal.CloseAsync(); } @@ -579,18 +575,18 @@ namespace FluentTerminal.App.ViewModels await TerminalView?.ReconnectAsync(); } - private void OnApplicationSettingsChanged(ApplicationSettingsChangedMessage message) + public void Receive(ApplicationSettingsChangedMessage message) { ApplicationSettings = message.ApplicationSettings; ApplicationView.ExecuteOnUiThreadAsync(() => { - RaisePropertyChanged(nameof(IsUnderlined)); - RaisePropertyChanged(nameof(BackgroundTabTheme)); + OnPropertyChanged(nameof(IsUnderlined)); + OnPropertyChanged(nameof(BackgroundTabTheme)); }); } - private void OnCurrentThemeChanged(CurrentThemeChangedMessage message) + public void Receive(CurrentThemeChangedMessage message) { // only change theme if not overwritten by profile if (ShellProfile.TerminalThemeId == Guid.Empty) @@ -605,13 +601,13 @@ namespace FluentTerminal.App.ViewModels } } - private void OnTerminalOptionsChanged(TerminalOptionsChangedMessage message) + public void Receive(TerminalOptionsChangedMessage message) { _terminalOptions = message.TerminalOptions; - ApplicationView.ExecuteOnUiThreadAsync(() => RaisePropertyChanged(nameof(BackgroundOpacity)), CoreDispatcherPriority.Low); + ApplicationView.ExecuteOnUiThreadAsync(() => OnPropertyChanged(nameof(BackgroundOpacity)), CoreDispatcherPriority.Low); } - private void OnKeyBindingsChanged(KeyBindingsChangedMessage message) + public void Receive(KeyBindingsChangedMessage message) { ApplicationView.ExecuteOnUiThreadAsync(() => { diff --git a/FluentTerminal.App.ViewModels/ThemeViewModel.cs b/FluentTerminal.App.ViewModels/ThemeViewModel.cs index b44789d..a641061 100644 --- a/FluentTerminal.App.ViewModels/ThemeViewModel.cs +++ b/FluentTerminal.App.ViewModels/ThemeViewModel.cs @@ -1,9 +1,8 @@ using FluentTerminal.App.Services; using FluentTerminal.App.Services.Utilities; -using FluentTerminal.App.ViewModels.Infrastructure; using FluentTerminal.Models; -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; using Newtonsoft.Json; using System; using System.Threading.Tasks; @@ -11,7 +10,7 @@ using System.Windows.Input; namespace FluentTerminal.App.ViewModels { - public class ThemeViewModel : ViewModelBase + public class ThemeViewModel : ObservableObject { private readonly IDialogService _dialogService; private readonly ISettingsService _settingsService; @@ -95,13 +94,13 @@ namespace FluentTerminal.App.ViewModels BackgroundThemeFile = Model.BackgroundImage; SetActiveCommand = new RelayCommand(SetActive); - DeleteCommand = new AsyncCommand(DeleteAsync, NotPreInstalled); + DeleteCommand = new AsyncRelayCommand(DeleteAsync, NotPreInstalled); EditCommand = new RelayCommand(Edit, NotPreInstalled); - CancelEditCommand = new AsyncCommand(CancelEditAsync); - SaveChangesCommand = new AsyncCommand(SaveChangesAsync); - ExportCommand = new AsyncCommand(Export, NotPreInstalled); - ChooseBackgroundImageCommand = new AsyncCommand(ChooseBackgroundImageAsync, NotPreInstalled); - DeleteBackgroundImageCommand = new AsyncCommand(DeleteBackgroundImageAsync, NotPreInstalled); + CancelEditCommand = new AsyncRelayCommand(CancelEditAsync); + SaveChangesCommand = new AsyncRelayCommand(SaveChangesAsync); + ExportCommand = new AsyncRelayCommand(Export, NotPreInstalled); + ChooseBackgroundImageCommand = new AsyncRelayCommand(ChooseBackgroundImageAsync, NotPreInstalled); + DeleteBackgroundImageCommand = new AsyncRelayCommand(DeleteBackgroundImageAsync, NotPreInstalled); } public event EventHandler Activated; @@ -113,7 +112,7 @@ namespace FluentTerminal.App.ViewModels public string Author { get => _author; - set => Set(ref _author, value); + set => SetProperty(ref _author, value); } public string Background @@ -121,7 +120,7 @@ namespace FluentTerminal.App.ViewModels get => _background; set { - Set(ref _background, value); + SetProperty(ref _background, value); BackgroundChanged?.Invoke(this, value); } } @@ -129,67 +128,67 @@ namespace FluentTerminal.App.ViewModels public double BackgroundOpacity { get => _backgroundOpacity; - set => Set(ref _backgroundOpacity, value); + set => SetProperty(ref _backgroundOpacity, value); } public string Black { get => _black; - set => Set(ref _black, value); + set => SetProperty(ref _black, value); } public string Blue { get => _blue; - set => Set(ref _blue, value); + set => SetProperty(ref _blue, value); } public string BrightBlack { get => _brightBlack; - set => Set(ref _brightBlack, value); + set => SetProperty(ref _brightBlack, value); } public string BrightBlue { get => _brightBlue; - set => Set(ref _brightBlue, value); + set => SetProperty(ref _brightBlue, value); } public string BrightCyan { get => _brightCyan; - set => Set(ref _brightCyan, value); + set => SetProperty(ref _brightCyan, value); } public string BrightGreen { get => _brightGreen; - set => Set(ref _brightGreen, value); + set => SetProperty(ref _brightGreen, value); } public string BrightMagenta { get => _brightMagenta; - set => Set(ref _brightMagenta, value); + set => SetProperty(ref _brightMagenta, value); } public string BrightRed { get => _brightRed; - set => Set(ref _brightRed, value); + set => SetProperty(ref _brightRed, value); } public string BrightWhite { get => _brightWhite; - set => Set(ref _brightWhite, value); + set => SetProperty(ref _brightWhite, value); } public string BrightYellow { get => _brightYellow; - set => Set(ref _brightYellow, value); + set => SetProperty(ref _brightYellow, value); } public ICommand CancelEditCommand { get; } @@ -197,19 +196,19 @@ namespace FluentTerminal.App.ViewModels public string Cursor { get => _cursor; - set => Set(ref _cursor, value); + set => SetProperty(ref _cursor, value); } public string CursorAccent { get => _cursorAccent; - set => Set(ref _cursorAccent, value); + set => SetProperty(ref _cursorAccent, value); } public string Cyan { get => _cyan; - set => Set(ref _cyan, value); + set => SetProperty(ref _cyan, value); } public ICommand DeleteCommand { get; } @@ -219,13 +218,13 @@ namespace FluentTerminal.App.ViewModels public string Foreground { get => _foreground; - set => Set(ref _foreground, value); + set => SetProperty(ref _foreground, value); } public string Green { get => _green; - set => Set(ref _green, value); + set => SetProperty(ref _green, value); } public Guid Id { get; } @@ -233,31 +232,31 @@ namespace FluentTerminal.App.ViewModels public bool InEditMode { get => _inEditMode; - set => Set(ref _inEditMode, value); + set => SetProperty(ref _inEditMode, value); } public bool IsActive { get => _isActive; - set => Set(ref _isActive, value); + set => SetProperty(ref _isActive, value); } public string Magenta { get => _magenta; - set => Set(ref _magenta, value); + set => SetProperty(ref _magenta, value); } public string Name { get => _name; - set => Set(ref _name, value); + set => SetProperty(ref _name, value); } public string Red { get => _red; - set => Set(ref _red, value); + set => SetProperty(ref _red, value); } public ICommand SaveChangesCommand { get; } @@ -265,7 +264,7 @@ namespace FluentTerminal.App.ViewModels public string Selection { get => _selection; - set => Set(ref _selection, value); + set => SetProperty(ref _selection, value); } public ICommand SetActiveCommand { get; } @@ -273,13 +272,13 @@ namespace FluentTerminal.App.ViewModels public string White { get => _white; - set => Set(ref _white, value); + set => SetProperty(ref _white, value); } public string Yellow { get => _yellow; - set => Set(ref _yellow, value); + set => SetProperty(ref _yellow, value); } public ImageFile BackgroundThemeFile @@ -287,7 +286,7 @@ namespace FluentTerminal.App.ViewModels get => _backgroundThemeFile; set { - Set(ref _backgroundThemeFile, value); + SetProperty(ref _backgroundThemeFile, value); BackgroundImageChanged?.Invoke(this, value); } } diff --git a/FluentTerminal.App/App.xaml.cs b/FluentTerminal.App/App.xaml.cs index fe52edb..7a9c5b7 100755 --- a/FluentTerminal.App/App.xaml.cs +++ b/FluentTerminal.App/App.xaml.cs @@ -36,7 +36,7 @@ using IContainer = Autofac.IContainer; using FluentTerminal.App.Services.Utilities; using FluentTerminal.App.ViewModels.Profiles; using FluentTerminal.Models.Messages; -using GalaSoft.MvvmLight.Messaging; +using Microsoft.Toolkit.Mvvm.Messaging; namespace FluentTerminal.App { @@ -114,7 +114,7 @@ namespace FluentTerminal.App _container = builder.Build(); - Messenger.Default.Register(this, OnApplicationSettingsChanged); + WeakReferenceMessenger.Default.Register(this, (r, m) => r.OnApplicationSettingsChanged(m)); _settingsService = _container.Resolve(); _notificationService = _container.Resolve(); diff --git a/FluentTerminal.App/Converters/ColorResourceKeyFallbackConverter.cs b/FluentTerminal.App/Converters/ColorResourceKeyFallbackConverter.cs index bd74bf8..aaa4a33 100644 --- a/FluentTerminal.App/Converters/ColorResourceKeyFallbackConverter.cs +++ b/FluentTerminal.App/Converters/ColorResourceKeyFallbackConverter.cs @@ -1,6 +1,5 @@ using Microsoft.Toolkit.Uwp.Helpers; using System; -using Windows.UI; using Windows.UI.Xaml; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Media; diff --git a/FluentTerminal.App/Converters/MenuViewModelToFlyoutMenuConverter.cs b/FluentTerminal.App/Converters/MenuViewModelToFlyoutMenuConverter.cs index 9d0ab04..4247434 100644 --- a/FluentTerminal.App/Converters/MenuViewModelToFlyoutMenuConverter.cs +++ b/FluentTerminal.App/Converters/MenuViewModelToFlyoutMenuConverter.cs @@ -3,7 +3,6 @@ using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Data; using FluentTerminal.App.ViewModels.Menu; using Windows.UI.Xaml.Controls.Primitives; -using Windows.Foundation.Metadata; namespace FluentTerminal.App.Converters { diff --git a/FluentTerminal.App/Converters/TabThemeSelectedConverter.cs b/FluentTerminal.App/Converters/TabThemeSelectedConverter.cs index 7e3184b..c689b0a 100644 --- a/FluentTerminal.App/Converters/TabThemeSelectedConverter.cs +++ b/FluentTerminal.App/Converters/TabThemeSelectedConverter.cs @@ -1,5 +1,4 @@ using FluentTerminal.App.ViewModels; -using FluentTerminal.Models; using System; using Windows.UI.Xaml.Data; diff --git a/FluentTerminal.App/Dialogs/CreateKeyBindingDialog.xaml.cs b/FluentTerminal.App/Dialogs/CreateKeyBindingDialog.xaml.cs index 7240859..0dc25ae 100644 --- a/FluentTerminal.App/Dialogs/CreateKeyBindingDialog.xaml.cs +++ b/FluentTerminal.App/Dialogs/CreateKeyBindingDialog.xaml.cs @@ -1,15 +1,15 @@ using FluentTerminal.App.Services.Dialogs; using FluentTerminal.App.Services.Utilities; using FluentTerminal.Models; -using GalaSoft.MvvmLight.Command; +using Microsoft.Toolkit.Mvvm.Input; using System; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Threading.Tasks; +using System.Windows.Input; using Windows.System; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; -using FluentTerminal.App.Services; namespace FluentTerminal.App.Dialogs { @@ -25,25 +25,25 @@ namespace FluentTerminal.App.Dialogs public bool Ctrl { get => _ctrl; - set => Set(ref _ctrl, value); + set => SetProperty(ref _ctrl, value); } public bool Shift { get => _shift; - set => Set(ref _shift, value); + set => SetProperty(ref _shift, value); } public bool Alt { get => _alt; - set => Set(ref _alt, value); + set => SetProperty(ref _alt, value); } public bool Meta { get => _meta; - set => Set(ref _meta, value); + set => SetProperty(ref _meta, value); } public int Key @@ -51,7 +51,7 @@ namespace FluentTerminal.App.Dialogs get => _key; set { - Set(ref _key, value); + SetProperty(ref _key, value); } } @@ -66,7 +66,7 @@ namespace FluentTerminal.App.Dialogs this.SecondaryButtonText = I18N.Translate("Cancel"); } - public RelayCommand ResetCommand { get; } + public ICommand ResetCommand { get; } public event PropertyChangedEventHandler PropertyChanged; @@ -125,7 +125,7 @@ namespace FluentTerminal.App.Dialogs ResetButton.Visibility = Visibility.Collapsed; } - private void Set(ref T field, T value, [CallerMemberName]string propertyName = "") + private void SetProperty(ref T field, T value, [CallerMemberName]string propertyName = "") { if (field?.Equals(value) ?? value == null) { diff --git a/FluentTerminal.App/Dialogs/CustomCommandDialog.xaml.cs b/FluentTerminal.App/Dialogs/CustomCommandDialog.xaml.cs index 6220f97..bfec4ff 100644 --- a/FluentTerminal.App/Dialogs/CustomCommandDialog.xaml.cs +++ b/FluentTerminal.App/Dialogs/CustomCommandDialog.xaml.cs @@ -16,7 +16,8 @@ using Windows.Foundation; using Windows.System; using Windows.UI.Xaml.Input; using FluentTerminal.App.ViewModels; -using FluentTerminal.App.ViewModels.Infrastructure; +using System.Windows.Input; +using Microsoft.Toolkit.Mvvm.Input; // The Content Dialog item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 @@ -40,7 +41,7 @@ namespace FluentTerminal.App.Dialogs public CommandProfileProviderViewModel ViewModel { get; private set; } - public IAsyncCommand SaveLinkCommand { get; } + public ICommand SaveLinkCommand { get; } public CustomCommandDialog(ISettingsService settingsService, IApplicationView applicationView, ITrayProcessCommunicationService trayProcessCommunicationService, ICommandHistoryService historyService) @@ -52,7 +53,7 @@ namespace FluentTerminal.App.Dialogs InitializeComponent(); - SaveLinkCommand = new AsyncCommand(SaveLink); + SaveLinkCommand = new AsyncRelayCommand(SaveLink); PrimaryButtonText = I18N.Translate("OK"); SecondaryButtonText = I18N.Translate("Cancel"); diff --git a/FluentTerminal.App/Dialogs/SshInfoDialog.xaml.cs b/FluentTerminal.App/Dialogs/SshInfoDialog.xaml.cs index 921283f..37563fd 100644 --- a/FluentTerminal.App/Dialogs/SshInfoDialog.xaml.cs +++ b/FluentTerminal.App/Dialogs/SshInfoDialog.xaml.cs @@ -12,7 +12,8 @@ using FluentTerminal.App.Services; using FluentTerminal.App.Services.Utilities; using FluentTerminal.App.ViewModels.Profiles; using FluentTerminal.Models; -using FluentTerminal.App.ViewModels.Infrastructure; +using System.Windows.Input; +using Microsoft.Toolkit.Mvvm.Input; namespace FluentTerminal.App.Dialogs { @@ -26,8 +27,8 @@ namespace FluentTerminal.App.Dialogs public SshConnectViewModel ViewModel { get; private set; } - public IAsyncCommand BrowseIdentityFileCommand { get; } - public IAsyncCommand SaveLinkCommand { get; } + public ICommand BrowseIdentityFileCommand { get; } + public ICommand SaveLinkCommand { get; } public SshInfoDialog(ISettingsService settingsService, IApplicationView applicationView, IFileSystemService fileSystemService, ITrayProcessCommunicationService trayProcessCommunicationService) @@ -39,8 +40,8 @@ namespace FluentTerminal.App.Dialogs InitializeComponent(); - BrowseIdentityFileCommand = new AsyncCommand(BrowseIdentityFile); - SaveLinkCommand = new AsyncCommand(SaveLink); + BrowseIdentityFileCommand = new AsyncRelayCommand(BrowseIdentityFile); + SaveLinkCommand = new AsyncRelayCommand(SaveLink); PrimaryButtonText = I18N.Translate("OK"); SecondaryButtonText = I18N.Translate("Cancel"); diff --git a/FluentTerminal.App/FluentTerminal.App.csproj b/FluentTerminal.App/FluentTerminal.App.csproj index f2408ea..20a6a56 100644 --- a/FluentTerminal.App/FluentTerminal.App.csproj +++ b/FluentTerminal.App/FluentTerminal.App.csproj @@ -361,6 +361,9 @@ 6.2.12 + + 7.0.0 + 7.0.0 diff --git a/FluentTerminal.App/Services/CommandHistoryService.cs b/FluentTerminal.App/Services/CommandHistoryService.cs index 0a963bb..27832b0 100644 --- a/FluentTerminal.App/Services/CommandHistoryService.cs +++ b/FluentTerminal.App/Services/CommandHistoryService.cs @@ -6,7 +6,7 @@ using System.Text; using FluentTerminal.App.Services.Implementation; using FluentTerminal.Models; using FluentTerminal.Models.Messages; -using GalaSoft.MvvmLight.Messaging; +using Microsoft.Toolkit.Mvvm.Messaging; using Newtonsoft.Json; namespace FluentTerminal.App.Services @@ -153,7 +153,7 @@ namespace FluentTerminal.App.Services { _historyContainer.WriteValueAsJson(GetHash(executedCommand.Value), executedCommand); - Messenger.Default.Send(new CommandHistoryChangedMessage()); + WeakReferenceMessenger.Default.Send(new CommandHistoryChangedMessage()); } /// @@ -357,7 +357,7 @@ namespace FluentTerminal.App.Services _historyContainer.Clear(); - Messenger.Default.Send(new CommandHistoryChangedMessage()); + WeakReferenceMessenger.Default.Send(new CommandHistoryChangedMessage()); } public void Delete(ExecutedCommand executedCommand) @@ -366,7 +366,7 @@ namespace FluentTerminal.App.Services _historyContainer.Delete(GetHash(executedCommand.Value)); - Messenger.Default.Send(new CommandHistoryChangedMessage()); + WeakReferenceMessenger.Default.Send(new CommandHistoryChangedMessage()); } #endregion Methods diff --git a/FluentTerminal.App/ViewModels/CommandItemViewModel.cs b/FluentTerminal.App/ViewModels/CommandItemViewModel.cs index 0566d0a..4a4c1a7 100644 --- a/FluentTerminal.App/ViewModels/CommandItemViewModel.cs +++ b/FluentTerminal.App/ViewModels/CommandItemViewModel.cs @@ -4,11 +4,11 @@ using System.Linq; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Documents; using FluentTerminal.Models; -using GalaSoft.MvvmLight; +using Microsoft.Toolkit.Mvvm.ComponentModel; namespace FluentTerminal.App.ViewModels { - public class CommandItemViewModel : ViewModelBase + public class CommandItemViewModel : ObservableObject { #region Fields @@ -35,7 +35,7 @@ namespace FluentTerminal.App.ViewModels public bool IsMatch { get => _isMatch; - private set => Set(ref _isMatch, value); + private set => SetProperty(ref _isMatch, value); } private RichTextBlock _richTextBlock; @@ -45,7 +45,7 @@ namespace FluentTerminal.App.ViewModels get => _richTextBlock; private set { - if (Set(ref _richTextBlock, value)) + if (SetProperty(ref _richTextBlock, value)) { IsMatch = value != null; } diff --git a/FluentTerminal.App/ViewModels/CommandProfileProviderViewModel.cs b/FluentTerminal.App/ViewModels/CommandProfileProviderViewModel.cs index ac90cf3..b6aa989 100644 --- a/FluentTerminal.App/ViewModels/CommandProfileProviderViewModel.cs +++ b/FluentTerminal.App/ViewModels/CommandProfileProviderViewModel.cs @@ -89,7 +89,7 @@ namespace FluentTerminal.App.ViewModels public string Command { get => _command; - set => Set(ref _command, value); + set => SetProperty(ref _command, value); } private ObservableCollection _commands; @@ -97,7 +97,7 @@ namespace FluentTerminal.App.ViewModels public ObservableCollection Commands { get => _commands; - private set => Set(ref _commands, value); + private set => SetProperty(ref _commands, value); } #endregion Properties diff --git a/FluentTerminal.App/Views/SettingsPages/GeneralSettings.xaml.cs b/FluentTerminal.App/Views/SettingsPages/GeneralSettings.xaml.cs index e099e03..28bf9e1 100644 --- a/FluentTerminal.App/Views/SettingsPages/GeneralSettings.xaml.cs +++ b/FluentTerminal.App/Views/SettingsPages/GeneralSettings.xaml.cs @@ -1,6 +1,4 @@ -using System; -using FluentTerminal.App.ViewModels.Settings; -using Windows.Storage.Pickers; +using FluentTerminal.App.ViewModels.Settings; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Navigation; diff --git a/FluentTerminal.App/Views/SettingsPages/KeyBindingSettings.xaml.cs b/FluentTerminal.App/Views/SettingsPages/KeyBindingSettings.xaml.cs index 4d15619..1eca146 100644 --- a/FluentTerminal.App/Views/SettingsPages/KeyBindingSettings.xaml.cs +++ b/FluentTerminal.App/Views/SettingsPages/KeyBindingSettings.xaml.cs @@ -1,7 +1,6 @@ using FluentTerminal.App.Services.Utilities; using FluentTerminal.App.ViewModels.Settings; using FluentTerminal.Models.Enums; -using FluentTerminal.Models; using System; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Navigation; diff --git a/FluentTerminal.App/Views/TabBar.xaml.cs b/FluentTerminal.App/Views/TabBar.xaml.cs index 555353a..9d897bb 100644 --- a/FluentTerminal.App/Views/TabBar.xaml.cs +++ b/FluentTerminal.App/Views/TabBar.xaml.cs @@ -2,11 +2,11 @@ using FluentTerminal.App.Services.EventArgs; using FluentTerminal.App.Services.Utilities; using FluentTerminal.App.ViewModels; -using GalaSoft.MvvmLight.Command; using System; using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; +using System.Windows.Input; using Windows.ApplicationModel.DataTransfer; using Windows.Foundation; using Windows.UI.Xaml; @@ -21,7 +21,7 @@ namespace FluentTerminal.App.Views DependencyProperty.Register(nameof(ItemsSource), typeof(ObservableCollection), typeof(TabBar), new PropertyMetadata(null)); public static readonly DependencyProperty MyPropertyProperty = - DependencyProperty.Register(nameof(AddCommand), typeof(RelayCommand), typeof(TabBar), new PropertyMetadata(null)); + DependencyProperty.Register(nameof(AddCommand), typeof(ICommand), typeof(TabBar), new PropertyMetadata(null)); public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register(nameof(SelectedItem), typeof(object), typeof(TabBar), new PropertyMetadata(null)); @@ -53,9 +53,9 @@ namespace FluentTerminal.App.Views ScrollViewer.UnregisterPropertyChangedCallback(ScrollViewer.ScrollableWidthProperty, _scrollableWidthChangedToken); } - public RelayCommand AddCommand + public ICommand AddCommand { - get { return (RelayCommand)GetValue(MyPropertyProperty); } + get { return (ICommand)GetValue(MyPropertyProperty); } set { SetValue(MyPropertyProperty, value); } } diff --git a/FluentTerminal.App/Views/TabBarBackgroundBindingHelper.cs b/FluentTerminal.App/Views/TabBarBackgroundBindingHelper.cs index 228aa2b..0b1b400 100644 --- a/FluentTerminal.App/Views/TabBarBackgroundBindingHelper.cs +++ b/FluentTerminal.App/Views/TabBarBackgroundBindingHelper.cs @@ -1,5 +1,4 @@ -using FluentTerminal.Models; -using FluentTerminal.Models.Enums; +using FluentTerminal.Models.Enums; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Data; diff --git a/FluentTerminal.App/Views/TerminalView.xaml.cs b/FluentTerminal.App/Views/TerminalView.xaml.cs index 2f8c8e9..33ffaf6 100644 --- a/FluentTerminal.App/Views/TerminalView.xaml.cs +++ b/FluentTerminal.App/Views/TerminalView.xaml.cs @@ -4,24 +4,23 @@ using Windows.System; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using FluentTerminal.Models.Messages; -using GalaSoft.MvvmLight.Messaging; using FluentTerminal.Models; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media.Imaging; using Windows.UI; +using Microsoft.Toolkit.Mvvm.Messaging; namespace FluentTerminal.App.Views { // ReSharper disable once RedundantExtendsListEntry - public sealed partial class TerminalView : UserControl + public sealed partial class TerminalView : UserControl, + IRecipient, + IRecipient { private ITerminalView _terminalView; public TerminalView(TerminalViewModel viewModel) { - Messenger.Default.Register(this, OnKeyBindingsChanged); - Messenger.Default.Register(this, OnTerminalOptionsChanged); - ViewModel = viewModel; ViewModel.SearchStarted += OnSearchStarted; ViewModel.Activated += OnActivated; @@ -48,7 +47,7 @@ namespace FluentTerminal.App.Views _terminalView?.Dispose(); _terminalView = null; - Messenger.Default.Unregister(this); + // Messenger.Default.Unregister(this); // todo do we need this? ViewModel.SearchStarted -= OnSearchStarted; ViewModel.Activated -= OnActivated; @@ -77,12 +76,12 @@ namespace FluentTerminal.App.Views _terminalView.FindPreviousAsync(e); } - private void OnKeyBindingsChanged(KeyBindingsChangedMessage message) + public void Receive(KeyBindingsChangedMessage message) { _terminalView.ChangeKeyBindingsAsync(); } - private void OnTerminalOptionsChanged(TerminalOptionsChangedMessage message) + public void Receive(TerminalOptionsChangedMessage message) { _terminalView.ChangeOptionsAsync(message.TerminalOptions); } diff --git a/FluentTerminal.Models/Enums/TabThemeKey.cs b/FluentTerminal.Models/Enums/TabThemeKey.cs index f35a2f8..48e1ef8 100644 --- a/FluentTerminal.Models/Enums/TabThemeKey.cs +++ b/FluentTerminal.Models/Enums/TabThemeKey.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace FluentTerminal.Models.Enums +namespace FluentTerminal.Models.Enums { public enum TabThemeKey { diff --git a/FluentTerminal.Models/ExportedTerminalTheme.cs b/FluentTerminal.Models/ExportedTerminalTheme.cs index 7f73524..379b868 100644 --- a/FluentTerminal.Models/ExportedTerminalTheme.cs +++ b/FluentTerminal.Models/ExportedTerminalTheme.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; namespace FluentTerminal.Models { diff --git a/FluentTerminal.Models/FontInfo.cs b/FluentTerminal.Models/FontInfo.cs index 32a6df1..8d46cb3 100644 --- a/FluentTerminal.Models/FontInfo.cs +++ b/FluentTerminal.Models/FontInfo.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace FluentTerminal.Models +namespace FluentTerminal.Models { public class FontInfo { diff --git a/FluentTerminal.Models/ImageFile.cs b/FluentTerminal.Models/ImageFile.cs index ea1cb3e..a448fb3 100644 --- a/FluentTerminal.Models/ImageFile.cs +++ b/FluentTerminal.Models/ImageFile.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; +using System.Collections.Generic; namespace FluentTerminal.Models { diff --git a/FluentTerminal.Models/Messages/ApplicationSettingsChangedMessage.cs b/FluentTerminal.Models/Messages/ApplicationSettingsChangedMessage.cs index 78701e3..036ea5f 100644 --- a/FluentTerminal.Models/Messages/ApplicationSettingsChangedMessage.cs +++ b/FluentTerminal.Models/Messages/ApplicationSettingsChangedMessage.cs @@ -8,7 +8,7 @@ namespace FluentTerminal.Models.Messages public ApplicationSettingsChangedMessage(ApplicationSettings applicationSettings) { - ApplicationSettings = applicationSettings ?? throw new ArgumentNullException(); + ApplicationSettings = applicationSettings ?? throw new ArgumentNullException(nameof(applicationSettings)); } } } \ No newline at end of file diff --git a/FluentTerminal.Models/TabTheme.cs b/FluentTerminal.Models/TabTheme.cs index dbd1e54..5740036 100644 --- a/FluentTerminal.Models/TabTheme.cs +++ b/FluentTerminal.Models/TabTheme.cs @@ -1,6 +1,4 @@ -using System.ComponentModel; - -namespace FluentTerminal.Models +namespace FluentTerminal.Models { public class TabTheme { diff --git a/FluentTerminal.SystemTray/ProcessUtils.cs b/FluentTerminal.SystemTray/ProcessUtils.cs index a4b024a..50ad119 100644 --- a/FluentTerminal.SystemTray/ProcessUtils.cs +++ b/FluentTerminal.SystemTray/ProcessUtils.cs @@ -1,11 +1,8 @@ using System; -using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Management; -using FluentTerminal.App.Services; - namespace FluentTerminal.SystemTray { public static class ProcessUtils diff --git a/FluentTerminal.SystemTray/Services/TerminalsManager.cs b/FluentTerminal.SystemTray/Services/TerminalsManager.cs index 3e9b99d..624fa05 100644 --- a/FluentTerminal.SystemTray/Services/TerminalsManager.cs +++ b/FluentTerminal.SystemTray/Services/TerminalsManager.cs @@ -14,7 +14,7 @@ using System.Text; using System.Text.RegularExpressions; using Windows.ApplicationModel; using FluentTerminal.Models.Messages; -using GalaSoft.MvvmLight.Messaging; +using Microsoft.Toolkit.Mvvm.Messaging; namespace FluentTerminal.SystemTray.Services { @@ -42,7 +42,7 @@ namespace FluentTerminal.SystemTray.Services public TerminalsManager(ISettingsService settingsService) { _applicationSettings = settingsService.GetApplicationSettings(); - Messenger.Default.Register(this, OnApplicationSettingsChanged); + WeakReferenceMessenger.Default.Register(this, (r, m) => r.OnApplicationSettingsChanged(m)); } private void OnApplicationSettingsChanged(ApplicationSettingsChangedMessage message) diff --git a/FluentTerminal.SystemTray/Services/ToggleWindowService.cs b/FluentTerminal.SystemTray/Services/ToggleWindowService.cs index 72588df..538ccd1 100644 --- a/FluentTerminal.SystemTray/Services/ToggleWindowService.cs +++ b/FluentTerminal.SystemTray/Services/ToggleWindowService.cs @@ -5,12 +5,9 @@ using GlobalHotKey; using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using System.Runtime.InteropServices; using System.Windows.Input; using System.Windows.Threading; -using Windows.ApplicationModel; -using Windows.ApplicationModel.Core; using Windows.System; using static FluentTerminal.SystemTray.Native.WindowApi;