* Simplifying view models, step 1: Extracting common terminal configuration into TerminalInfoViewModel.cs. * Simplifying a bit. * SSH view models simplfication. * Refactoring duplicated code. * Refactoring duplicated code. * Renaming a resource file. * Cleanup. * Fixing an issue with TemplateSelectors. * QuickSshDialog created. * Minor fix. * Wiring up QuickSshDialog. * Minor fix. * Fixed an issue with shared resources. * Single-text-box dialog works. * Improving "Quick SSH" look. * Improving data validation workflow to avoid double validations. * Refactoring view models and templates to avoid duplicated code. * Minor fix. * Fixing a bug with mosh. * Cleanup. * Cleanup. * Moving profile view models in a separate folder (namespace). * Few comment lines (short description) added to profile view models. * Removing IDisposable from view-models because event-caused memory leaks will be solved differently. * Implemented quick-ssh shortcuts. * Fixing quick SSH command validation. * Minor change. * Minor change. * Combining "SSH Info" and "Quick SSH" into a single dialog. * Quick SSH profiles. * Fixing a minor bug with custom links. * Fixing remote profiles look and feel. * Minor improvements. * Fixing a minor bug. * Minor changes based on Felix' comments. * Saving executed commands history implemented.
109 lines
3.1 KiB
C#
109 lines
3.1 KiB
C#
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;
|
|
|
|
namespace FluentTerminal.App.ViewModels
|
|
{
|
|
/// <summary>
|
|
/// Extends <see cref="ShellProfileViewModelBase{T}"/>, and implements only "Set as default" logic.
|
|
/// </summary>
|
|
public class ShellProfileViewModel : ShellProfileViewModelBase<CommonProfileProviderViewModel>
|
|
{
|
|
#region Fields
|
|
|
|
private readonly IDefaultValueProvider _defaultValueProvider;
|
|
|
|
#endregion Fields
|
|
|
|
#region Properties
|
|
|
|
private bool _isDefault;
|
|
|
|
public bool IsDefault
|
|
{
|
|
get => _isDefault;
|
|
set => Set(ref _isDefault, value);
|
|
}
|
|
|
|
#endregion Properties
|
|
|
|
#region Events
|
|
|
|
public event EventHandler SetAsDefault;
|
|
|
|
#endregion Events
|
|
|
|
#region Commands
|
|
|
|
public RelayCommand SetDefaultCommand { get; }
|
|
|
|
public IAsyncCommand RestoreDefaultsCommand { get; }
|
|
|
|
#endregion Commands
|
|
|
|
#region Constrcutor
|
|
|
|
public ShellProfileViewModel(ShellProfile shellProfile, ISettingsService settingsService,
|
|
IDialogService dialogService, IFileSystemService fileSystemService, IApplicationView applicationView,
|
|
IDefaultValueProvider defaultValueProvider, bool isNew) : base(shellProfile, settingsService, dialogService,
|
|
isNew)
|
|
{
|
|
_defaultValueProvider = defaultValueProvider;
|
|
|
|
ProfileVm = new CommonProfileProviderViewModel(settingsService, applicationView, fileSystemService,
|
|
shellProfile);
|
|
|
|
SetDefaultCommand = new RelayCommand(SetDefault);
|
|
RestoreDefaultsCommand = new AsyncCommand(RestoreDefaults);
|
|
}
|
|
|
|
#endregion Constrcutor
|
|
|
|
#region Methods
|
|
|
|
private async Task RestoreDefaults()
|
|
{
|
|
if (InEditMode || !ProfileVm.PreInstalled)
|
|
{
|
|
throw new InvalidOperationException();
|
|
}
|
|
|
|
var result = await DialogService.ShowMessageDialogAsnyc(I18N.Translate("PleaseConfirm"),
|
|
I18N.Translate("ConfirmRestoreProfile"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true);
|
|
|
|
if (result == DialogButton.OK)
|
|
{
|
|
var profile = _defaultValueProvider.GetPreinstalledShellProfiles().FirstOrDefault(x => x.Id.Equals(Id));
|
|
|
|
if (profile == null)
|
|
{
|
|
// Should not happen ever, but...
|
|
return;
|
|
}
|
|
|
|
ProfileVm.Model = profile;
|
|
Initialize(profile);
|
|
|
|
SettingsService.SaveShellProfile(profile);
|
|
}
|
|
}
|
|
|
|
protected override bool CanDelete()
|
|
{
|
|
return !ProfileVm.PreInstalled;
|
|
}
|
|
|
|
private void SetDefault()
|
|
{
|
|
SetAsDefault?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
|
|
#endregion Methods
|
|
}
|
|
} |