diff --git a/FluentTerminal.App.ViewModels/Settings/ProfilesPageViewModel.cs b/FluentTerminal.App.ViewModels/Settings/ProfilesPageViewModel.cs index 0f85381..26ab885 100644 --- a/FluentTerminal.App.ViewModels/Settings/ProfilesPageViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/ProfilesPageViewModel.cs @@ -32,7 +32,7 @@ namespace FluentTerminal.App.ViewModels.Settings var defaultShellProfileId = _settingsService.GetDefaultShellProfileId(); foreach (var shellProfile in _settingsService.GetShellProfiles()) { - var viewModel = new ShellProfileViewModel(shellProfile, settingsService, dialogService, fileSystemService, applicationView, defaultValueProvider); + var viewModel = new ShellProfileViewModel(shellProfile, settingsService, dialogService, fileSystemService, applicationView, defaultValueProvider, false); viewModel.Deleted += OnShellProfileDeleted; viewModel.SetAsDefault += OnShellProfileSetAsDefault; @@ -112,7 +112,7 @@ namespace FluentTerminal.App.ViewModels.Settings { _settingsService.SaveShellProfile(shellProfile, true); - var viewModel = new ShellProfileViewModel(shellProfile, _settingsService, _dialogService, _fileSystemService, _applicationView, _defaultValueProvider); + var viewModel = new ShellProfileViewModel(shellProfile, _settingsService, _dialogService, _fileSystemService, _applicationView, _defaultValueProvider, true); viewModel.EditCommand.Execute(null); viewModel.SetAsDefault += OnShellProfileSetAsDefault; viewModel.Deleted += OnShellProfileDeleted; diff --git a/FluentTerminal.App.ViewModels/Settings/ThemesPageViewModel.cs b/FluentTerminal.App.ViewModels/Settings/ThemesPageViewModel.cs index 441f26a..d0efee4 100644 --- a/FluentTerminal.App.ViewModels/Settings/ThemesPageViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/ThemesPageViewModel.cs @@ -40,7 +40,7 @@ namespace FluentTerminal.App.ViewModels.Settings var activeThemeId = _settingsService.GetCurrentThemeId(); foreach (var theme in _settingsService.GetThemes()) { - var viewModel = new ThemeViewModel(theme, _settingsService, _dialogService, fileSystemService); + var viewModel = new ThemeViewModel(theme, _settingsService, _dialogService, fileSystemService, false); viewModel.Activated += OnThemeActivated; viewModel.Deleted += OnThemeDeleted; @@ -139,7 +139,8 @@ namespace FluentTerminal.App.ViewModels.Settings { _settingsService.SaveTheme(theme, true); - var viewModel = new ThemeViewModel(theme, _settingsService, _dialogService, _fileSystemService); + var viewModel = new ThemeViewModel(theme, _settingsService, _dialogService, _fileSystemService, true); + viewModel.EditCommand.Execute(null); viewModel.Activated += OnThemeActivated; viewModel.Deleted += OnThemeDeleted; Themes.Add(viewModel); diff --git a/FluentTerminal.App.ViewModels/ShellProfileViewModel.cs b/FluentTerminal.App.ViewModels/ShellProfileViewModel.cs index d9c0c0a..a2c9cbc 100644 --- a/FluentTerminal.App.ViewModels/ShellProfileViewModel.cs +++ b/FluentTerminal.App.ViewModels/ShellProfileViewModel.cs @@ -24,6 +24,7 @@ namespace FluentTerminal.App.ViewModels private string _location; private LineEndingStyle _lineEndingStyle; private string _name; + private bool _isNew; private TabTheme _selectedTabTheme; private TerminalTheme _selectedTerminalTheme; private string _workingDirectory; @@ -31,7 +32,7 @@ namespace FluentTerminal.App.ViewModels private readonly IDefaultValueProvider _defaultValueProvider; private bool _editingLineEndingStyle; - public ShellProfileViewModel(ShellProfile shellProfile, ISettingsService settingsService, IDialogService dialogService, IFileSystemService fileSystemService, IApplicationView applicationView, IDefaultValueProvider defaultValueProvider) + public ShellProfileViewModel(ShellProfile shellProfile, ISettingsService settingsService, IDialogService dialogService, IFileSystemService fileSystemService, IApplicationView applicationView, IDefaultValueProvider defaultValueProvider, Boolean isNew) { Model = shellProfile; _settingsService = settingsService; @@ -39,6 +40,7 @@ namespace FluentTerminal.App.ViewModels _fileSystemService = fileSystemService; _applicationView = applicationView; _defaultValueProvider = defaultValueProvider; + _isNew = isNew; _settingsService.ThemeAdded += OnThemeAdded; _settingsService.ThemeDeleted += OnThemeDeleted; @@ -245,6 +247,7 @@ namespace FluentTerminal.App.ViewModels KeyBindings.Editable = false; InEditMode = false; + _isNew = false; } private async Task RestoreDefaults() @@ -289,27 +292,53 @@ namespace FluentTerminal.App.ViewModels private async Task CancelEdit() { - var result = await _dialogService.ShowMessageDialogAsnyc("Please confirm", "Are you sure you want to discard all changes?", DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); - - if (result == DialogButton.OK) + if (_isNew) { - Arguments = _fallbackProfile.Arguments; - Location = _fallbackProfile.Location; - Name = _fallbackProfile.Name; - WorkingDirectory = _fallbackProfile.WorkingDirectory; - LineEndingStyle = _fallbackProfile.LineEndingTranslation; - SelectedTerminalTheme = TerminalThemes.FirstOrDefault(t => t.Id == _fallbackProfile.TerminalThemeId); - SelectedTabTheme = TabThemes.FirstOrDefault(t => t.Id == _fallbackProfile.TabThemeId); - - - KeyBindings.KeyBindings.Clear(); - foreach (var keyBinding in Model.KeyBindings.Select(x => new KeyBinding(x)).ToList()) + await Delete(); + } + else + { + ShellProfile changedProfile = new ShellProfile { - KeyBindings.Add(keyBinding); - } + Arguments = Arguments, + Location = Location, + Name = Name, + WorkingDirectory = WorkingDirectory, + TabThemeId = SelectedTabTheme.Id, + TerminalThemeId = SelectedTerminalTheme.Id, + LineEndingTranslation = _lineEndingStyle, + KeyBindings = KeyBindings.KeyBindings.Select(x => x.Model).ToList() + }; - KeyBindings.Editable = false; - InEditMode = false; + if (!_fallbackProfile.Equals(changedProfile)) + { + var result = await _dialogService.ShowMessageDialogAsnyc("Please confirm", "Are you sure you want to discard all changes?", DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); + + if (result == DialogButton.OK) + { + Arguments = _fallbackProfile.Arguments; + Location = _fallbackProfile.Location; + Name = _fallbackProfile.Name; + WorkingDirectory = _fallbackProfile.WorkingDirectory; + LineEndingStyle = _fallbackProfile.LineEndingTranslation; + SelectedTerminalTheme = TerminalThemes.FirstOrDefault(t => t.Id == _fallbackProfile.TerminalThemeId); + SelectedTabTheme = TabThemes.FirstOrDefault(t => t.Id == _fallbackProfile.TabThemeId); + + KeyBindings.KeyBindings.Clear(); + foreach (var keyBinding in Model.KeyBindings.Select(x => new KeyBinding(x)).ToList()) + { + KeyBindings.Add(keyBinding); + } + + KeyBindings.Editable = false; + InEditMode = false; + } + } + else + { + KeyBindings.Editable = false; + InEditMode = false; + } } } diff --git a/FluentTerminal.App.ViewModels/ThemeViewModel.cs b/FluentTerminal.App.ViewModels/ThemeViewModel.cs index ffe618f..91fbf99 100644 --- a/FluentTerminal.App.ViewModels/ThemeViewModel.cs +++ b/FluentTerminal.App.ViewModels/ThemeViewModel.cs @@ -29,15 +29,14 @@ namespace FluentTerminal.App.ViewModels private string _cursor; private string _cursorAccent; private string _cyan; - private string _fallBackAuthor; - private TerminalColors _fallBackColors; - private string _fallBackName; + private TerminalTheme _fallbackTheme; private string _foreground; private string _green; private bool _inEditMode; private bool _isActive; private string _magenta; private string _name; + private bool _isNew; private string _red; private string _selection; private string _white; @@ -46,12 +45,13 @@ namespace FluentTerminal.App.ViewModels public event EventHandler BackgroundChanged; - public ThemeViewModel(TerminalTheme theme, ISettingsService settingsService, IDialogService dialogService, IFileSystemService fileSystemService) + public ThemeViewModel(TerminalTheme theme, ISettingsService settingsService, IDialogService dialogService, IFileSystemService fileSystemService, bool isNew) { Model = theme; _settingsService = settingsService; _dialogService = dialogService; _fileSystemService = fileSystemService; + _isNew = isNew; Name = Model.Name; Author = Model.Author; @@ -299,42 +299,89 @@ namespace FluentTerminal.App.ViewModels _settingsService.SaveTheme(Model); InEditMode = false; + _isNew = false; } private async Task CancelEdit() { - var result = await _dialogService.ShowMessageDialogAsnyc("Please confirm", "Are you sure you want to discard all changes?", DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); - - if (result == DialogButton.OK) + if (_isNew) { - Black = _fallBackColors.Black; - Red = _fallBackColors.Red; - Green = _fallBackColors.Green; - Yellow = _fallBackColors.Yellow; - Blue = _fallBackColors.Blue; - Magenta = _fallBackColors.Magenta; - Cyan = _fallBackColors.Cyan; - White = _fallBackColors.White; + await Delete(); + } + else + { + TerminalTheme changedTheme = new TerminalTheme() + { + Name = Name, + Author = Author, + Colors = new TerminalColors() + { + Black = Black, + Red = Red, + Green = Green, + Yellow = Yellow, + Blue = Blue, + Magenta = Magenta, + Cyan = Cyan, + White = White, - BrightBlack = _fallBackColors.BrightBlack; - BrightRed = _fallBackColors.BrightRed; - BrightGreen = _fallBackColors.BrightGreen; - BrightYellow = _fallBackColors.BrightYellow; - BrightBlue = _fallBackColors.BrightBlue; - BrightMagenta = _fallBackColors.BrightMagenta; - BrightCyan = _fallBackColors.BrightCyan; - BrightWhite = _fallBackColors.BrightWhite; + BrightBlack = BrightBlack, + BrightRed = BrightRed, + BrightGreen = BrightGreen, + BrightYellow = BrightYellow, + BrightBlue = BrightBlue, + BrightMagenta = BrightMagenta, + BrightCyan = BrightCyan, + BrightWhite = BrightWhite, - Background = _fallBackColors.Background; - Foreground = _fallBackColors.Foreground; - Cursor = _fallBackColors.Cursor; - CursorAccent = _fallBackColors.CursorAccent; - Selection = _fallBackColors.Selection; + Background = Background, + Foreground = Foreground, + Cursor = Cursor, + CursorAccent = CursorAccent, + Selection = Selection + } + }; - Name = _fallBackName; - Author = _fallBackAuthor; + if (!_fallbackTheme.Equals(changedTheme)) + { + var result = await _dialogService.ShowMessageDialogAsnyc("Please confirm", "Are you sure you want to discard all changes?", DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); - InEditMode = false; + if (result == DialogButton.OK) + { + Black = _fallbackTheme.Colors.Black; + Red = _fallbackTheme.Colors.Red; + Green = _fallbackTheme.Colors.Green; + Yellow = _fallbackTheme.Colors.Yellow; + Blue = _fallbackTheme.Colors.Blue; + Magenta = _fallbackTheme.Colors.Magenta; + Cyan = _fallbackTheme.Colors.Cyan; + White = _fallbackTheme.Colors.White; + + BrightBlack = _fallbackTheme.Colors.BrightBlack; + BrightRed = _fallbackTheme.Colors.BrightRed; + BrightGreen = _fallbackTheme.Colors.BrightGreen; + BrightYellow = _fallbackTheme.Colors.BrightYellow; + BrightBlue = _fallbackTheme.Colors.BrightBlue; + BrightMagenta = _fallbackTheme.Colors.BrightMagenta; + BrightCyan = _fallbackTheme.Colors.BrightCyan; + BrightWhite = _fallbackTheme.Colors.BrightWhite; + + Background = _fallbackTheme.Colors.Background; + Foreground = _fallbackTheme.Colors.Foreground; + Cursor = _fallbackTheme.Colors.Cursor; + CursorAccent = _fallbackTheme.Colors.CursorAccent; + Selection = _fallbackTheme.Colors.Selection; + + Name = _fallbackTheme.Name; + Author = _fallbackTheme.Author; + + InEditMode = false; + } + } + else + { + InEditMode = false; + } } } @@ -355,9 +402,7 @@ namespace FluentTerminal.App.ViewModels private void Edit() { - _fallBackColors = new TerminalColors(Model.Colors); - _fallBackName = Name; - _fallBackAuthor = Author; + _fallbackTheme = new TerminalTheme(Model); InEditMode = true; } diff --git a/FluentTerminal.App/FluentTerminal.App.csproj b/FluentTerminal.App/FluentTerminal.App.csproj index a3ba77f..908294b 100644 --- a/FluentTerminal.App/FluentTerminal.App.csproj +++ b/FluentTerminal.App/FluentTerminal.App.csproj @@ -176,10 +176,12 @@ TabBar.xaml + TerminalColorPicker.xaml + TerminalView.xaml diff --git a/FluentTerminal.App/Styles/Custom.xaml b/FluentTerminal.App/Styles/Custom.xaml index a11be8a..b6590dd 100644 --- a/FluentTerminal.App/Styles/Custom.xaml +++ b/FluentTerminal.App/Styles/Custom.xaml @@ -1,5 +1,9 @@  + 24,0,0,0 + 24,0,24,24 + 0,24,0,0 + - + + + - + - + - @@ -318,4 +340,4 @@ - \ No newline at end of file + diff --git a/FluentTerminal.App/Views/TerminalColorPicker.xaml b/FluentTerminal.App/Views/TerminalColorPicker.xaml index 3f6a67d..e4925a7 100644 --- a/FluentTerminal.App/Views/TerminalColorPicker.xaml +++ b/FluentTerminal.App/Views/TerminalColorPicker.xaml @@ -9,10 +9,10 @@ mc:Ignorable="d">