* Update settings window layout with consistent margins Updated the layout of the different views of the settings window so that there is always margin at the bottom. In some cases this was achieved using <StackPanels> for clarity and extensibility, grouping e.g. a title and some radio options together with one unified margin. Also made some small consistency changes to the .xaml files. * Add width to Themes text input * Normalize margins in settings * Add default display values in Terminal settings ... for Arguments and Working Directory * Generalize TemplateSelector for empty strings * Add default display value for profile keybindings * Update margins and fontsize in theme preview * Update 'loading...' message in About ... to "Checking for updates..." and a spinner as suggested by @skipmeister123 * No popup when cancelling profile edit no changes * Delete profile when new and cancelled * Open new and cloned themes in edit mode ... and make it so canceling deletes the theme. * No popup when cancelling theme edit no changes * Add resources for margin definitions * Check for null Author in TerminalTheme * Add resource for header margin definition * Moved createdBy text to code behind
131 lines
4.9 KiB
C#
131 lines
4.9 KiB
C#
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;
|
|
|
|
namespace FluentTerminal.App.ViewModels.Settings
|
|
{
|
|
public class ProfilesPageViewModel : ViewModelBase
|
|
{
|
|
private readonly IDefaultValueProvider _defaultValueProvider;
|
|
private readonly IDialogService _dialogService;
|
|
private readonly ISettingsService _settingsService;
|
|
private readonly IFileSystemService _fileSystemService;
|
|
private ShellProfileViewModel _selectedShellProfile;
|
|
private readonly IApplicationView _applicationView;
|
|
|
|
public ProfilesPageViewModel(ISettingsService settingsService, IDialogService dialogService, IDefaultValueProvider defaultValueProvider, IFileSystemService fileSystemService, IApplicationView applicationView)
|
|
{
|
|
_settingsService = settingsService;
|
|
_dialogService = dialogService;
|
|
_defaultValueProvider = defaultValueProvider;
|
|
_fileSystemService = fileSystemService;
|
|
_applicationView = applicationView;
|
|
|
|
CreateShellProfileCommand = new RelayCommand(CreateShellProfile);
|
|
CloneCommand = new RelayCommand<ShellProfileViewModel>(Clone);
|
|
|
|
var defaultShellProfileId = _settingsService.GetDefaultShellProfileId();
|
|
foreach (var shellProfile in _settingsService.GetShellProfiles())
|
|
{
|
|
var viewModel = new ShellProfileViewModel(shellProfile, settingsService, dialogService, fileSystemService, applicationView, defaultValueProvider, false);
|
|
viewModel.Deleted += OnShellProfileDeleted;
|
|
viewModel.SetAsDefault += OnShellProfileSetAsDefault;
|
|
|
|
if (shellProfile.Id == defaultShellProfileId)
|
|
{
|
|
viewModel.IsDefault = true;
|
|
}
|
|
ShellProfiles.Add(viewModel);
|
|
}
|
|
|
|
SelectedShellProfile = ShellProfiles.First(p => p.IsDefault);
|
|
|
|
}
|
|
|
|
private void OnShellProfileSetAsDefault(object sender, EventArgs e)
|
|
{
|
|
if (sender is ShellProfileViewModel defaultShellProfile)
|
|
{
|
|
_settingsService.SaveDefaultShellProfileId(defaultShellProfile.Id);
|
|
|
|
foreach (var shellProfile in ShellProfiles)
|
|
{
|
|
shellProfile.IsDefault = shellProfile.Id == defaultShellProfile.Id;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnShellProfileDeleted(object sender, EventArgs e)
|
|
{
|
|
if (sender is ShellProfileViewModel shellProfile)
|
|
{
|
|
if (SelectedShellProfile == shellProfile)
|
|
{
|
|
SelectedShellProfile = ShellProfiles.First();
|
|
}
|
|
ShellProfiles.Remove(shellProfile);
|
|
|
|
if (shellProfile.IsDefault)
|
|
{
|
|
ShellProfiles.First().IsDefault = true;
|
|
_settingsService.SaveDefaultShellProfileId(ShellProfiles.First().Id);
|
|
}
|
|
_settingsService.DeleteShellProfile(shellProfile.Id);
|
|
}
|
|
}
|
|
|
|
public RelayCommand CreateShellProfileCommand { get; }
|
|
|
|
public RelayCommand<ShellProfileViewModel> CloneCommand { get; }
|
|
|
|
private void CreateShellProfile()
|
|
{
|
|
var shellProfile = new ShellProfile
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
PreInstalled = false,
|
|
Name = "New profile",
|
|
KeyBindings = new List<KeyBinding>()
|
|
};
|
|
|
|
AddShellProfile(shellProfile);
|
|
}
|
|
|
|
private void Clone(ShellProfileViewModel shellProfile)
|
|
{
|
|
var cloned = new ShellProfile(shellProfile.Model)
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
PreInstalled = false,
|
|
Name = $"Copy of {shellProfile.Name}"
|
|
};
|
|
|
|
AddShellProfile(cloned);
|
|
}
|
|
|
|
private void AddShellProfile(ShellProfile shellProfile)
|
|
{
|
|
_settingsService.SaveShellProfile(shellProfile, true);
|
|
|
|
var viewModel = new ShellProfileViewModel(shellProfile, _settingsService, _dialogService, _fileSystemService, _applicationView, _defaultValueProvider, true);
|
|
viewModel.EditCommand.Execute(null);
|
|
viewModel.SetAsDefault += OnShellProfileSetAsDefault;
|
|
viewModel.Deleted += OnShellProfileDeleted;
|
|
ShellProfiles.Add(viewModel);
|
|
SelectedShellProfile = viewModel;
|
|
}
|
|
|
|
public ShellProfileViewModel SelectedShellProfile
|
|
{
|
|
get => _selectedShellProfile;
|
|
set => Set(ref _selectedShellProfile, value);
|
|
}
|
|
|
|
public ObservableCollection<ShellProfileViewModel> ShellProfiles { get; } = new ObservableCollection<ShellProfileViewModel>();
|
|
}
|
|
} |