From 6ed349d4c8d1f31f82f7c9d19da94edca6140d2e Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 10 Sep 2022 18:40:05 +0200 Subject: [PATCH] Sidebar - Put all options under the cogwheel button and right-mouse-menu Sidebar - Hide the cogwheel button when not hoving over category/profile Sidebar - Made it easier to drag profiles into an empty category --- .../SidebarCategoryEditView.axaml | 8 +- .../SidebarCategoryEditViewModel.cs | 10 -- .../ProfileConfigurationEditView.axaml | 27 +++-- .../ProfileConfigurationEditViewModel.cs | 49 +------- .../Screens/Sidebar/SidebarCategoryView.axaml | 111 +++++++++++------- .../Sidebar/SidebarCategoryViewModel.cs | 58 ++++++++- .../SidebarProfileConfigurationView.axaml | 32 +++-- 7 files changed, 165 insertions(+), 130 deletions(-) diff --git a/src/Artemis.UI/Screens/Sidebar/ContentDialogs/SidebarCategoryEditView.axaml b/src/Artemis.UI/Screens/Sidebar/ContentDialogs/SidebarCategoryEditView.axaml index ecc53c82e..351b50f79 100644 --- a/src/Artemis.UI/Screens/Sidebar/ContentDialogs/SidebarCategoryEditView.axaml +++ b/src/Artemis.UI/Screens/Sidebar/ContentDialogs/SidebarCategoryEditView.axaml @@ -2,12 +2,14 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:sidebar="clr-namespace:Artemis.UI.Screens.Sidebar" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" - x:Class="Artemis.UI.Screens.Sidebar.SidebarCategoryEditView"> + x:Class="Artemis.UI.Screens.Sidebar.SidebarCategoryEditView" + x:DataType="sidebar:SidebarCategoryEditViewModel"> - + - + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Sidebar/ContentDialogs/SidebarCategoryEditViewModel.cs b/src/Artemis.UI/Screens/Sidebar/ContentDialogs/SidebarCategoryEditViewModel.cs index 0ea351049..f08a25c5e 100644 --- a/src/Artemis.UI/Screens/Sidebar/ContentDialogs/SidebarCategoryEditViewModel.cs +++ b/src/Artemis.UI/Screens/Sidebar/ContentDialogs/SidebarCategoryEditViewModel.cs @@ -23,13 +23,9 @@ public class SidebarCategoryEditViewModel : ContentDialogViewModelBase _categoryName = _category.Name; Confirm = ReactiveCommand.Create(ExecuteConfirm, ValidationContext.Valid); - Delete = ReactiveCommand.Create(ExecuteDelete); - this.ValidationRule(vm => vm.CategoryName, categoryName => !string.IsNullOrWhiteSpace(categoryName), "You must specify a valid name"); } - public ReactiveCommand Delete { get; set; } - public string? CategoryName { get => _categoryName; @@ -52,10 +48,4 @@ public class SidebarCategoryEditViewModel : ContentDialogViewModelBase ContentDialog?.Hide(ContentDialogResult.Primary); } - - private void ExecuteDelete() - { - if (_category != null) - _profileService.DeleteProfileCategory(_category); - } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditView.axaml b/src/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditView.axaml index 2a62a5741..fed01edac 100644 --- a/src/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditView.axaml +++ b/src/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditView.axaml @@ -76,18 +76,20 @@ - - + + - + - + - - - - + + + + + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditViewModel.cs b/src/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditViewModel.cs index b0f21fef7..ed55d14c3 100644 --- a/src/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditViewModel.cs +++ b/src/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditViewModel.cs @@ -63,7 +63,7 @@ public class ProfileConfigurationEditViewModel : DialogViewModelBase( pluginManagementService.GetFeaturesOfType().Where(m => !m.IsAlwaysAvailable).Select(m => new ProfileModuleViewModel(m)) ); @@ -75,7 +75,6 @@ public class ProfileConfigurationEditViewModel : DialogViewModelBase Import { get; } public ReactiveCommand Delete { get; } public ReactiveCommand Cancel { get; } - - private async Task ExecuteImport() - { - if (!IsNew) - return; - - string[]? result = await _windowService.CreateOpenFileDialog() - .HavingFilter(f => f.WithExtension("json").WithName("Artemis profile")) - .ShowAsync(); - - if (result == null) - return; - - string json = await File.ReadAllTextAsync(result[0]); - ProfileConfigurationExportModel? profileConfigurationExportModel = null; - try - { - profileConfigurationExportModel = JsonConvert.DeserializeObject(json, IProfileService.ExportSettings); - } - catch (JsonException e) - { - _windowService.ShowExceptionDialog("Import profile failed", e); - } - - if (profileConfigurationExportModel == null) - { - await _windowService.ShowConfirmContentDialog("Import profile", "Failed to import this profile, make sure it is a valid Artemis profile.", "Confirm", null); - return; - } - - try - { - ProfileConfiguration profileConfiguration = _profileService.ImportProfile(_profileCategory, profileConfigurationExportModel); - - // Remove the temporary profile configuration - _profileService.RemoveProfileConfiguration(_profileConfiguration); - - Close(profileConfiguration); - } - catch (Exception e) - { - _windowService.ShowExceptionDialog("Import profile failed", e); - } - } - + private async Task ExecuteDelete() { if (IsNew) diff --git a/src/Artemis.UI/Screens/Sidebar/SidebarCategoryView.axaml b/src/Artemis.UI/Screens/Sidebar/SidebarCategoryView.axaml index 774ecabbe..d8d5e44f2 100644 --- a/src/Artemis.UI/Screens/Sidebar/SidebarCategoryView.axaml +++ b/src/Artemis.UI/Screens/Sidebar/SidebarCategoryView.axaml @@ -14,15 +14,58 @@ x:DataType="local:SidebarCategoryViewModel"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + @@ -89,33 +132,13 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - + - + Empty category + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Sidebar/SidebarCategoryViewModel.cs b/src/Artemis.UI/Screens/Sidebar/SidebarCategoryViewModel.cs index 36f373bda..73f5fdc81 100644 --- a/src/Artemis.UI/Screens/Sidebar/SidebarCategoryViewModel.cs +++ b/src/Artemis.UI/Screens/Sidebar/SidebarCategoryViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; using System.Linq; using System.Reactive; using System.Reactive.Disposables; @@ -15,6 +16,7 @@ using Artemis.UI.Shared.Services.Builders; using Artemis.UI.Shared.Services.ProfileEditor; using DynamicData; using DynamicData.Binding; +using Newtonsoft.Json; using ReactiveUI; namespace Artemis.UI.Screens.Sidebar; @@ -53,9 +55,11 @@ public class SidebarCategoryViewModel : ActivatableViewModelBase ToggleCollapsed = ReactiveCommand.Create(ExecuteToggleCollapsed); ToggleSuspended = ReactiveCommand.Create(ExecuteToggleSuspended); AddProfile = ReactiveCommand.CreateFromTask(ExecuteAddProfile); - EditCategory = ReactiveCommand.CreateFromTask(ExecuteEditCategory); + ImportProfile = ReactiveCommand.CreateFromTask(ExecuteImportProfile); MoveUp = ReactiveCommand.Create(ExecuteMoveUp); MoveDown = ReactiveCommand.Create(ExecuteMoveDown); + RenameCategory = ReactiveCommand.CreateFromTask(ExecuteRenameCategory); + DeleteCategory = ReactiveCommand.CreateFromTask(ExecuteDeleteCategory); this.WhenActivated(d => { @@ -84,12 +88,17 @@ public class SidebarCategoryViewModel : ActivatableViewModelBase }); } + + + public ReactiveCommand ImportProfile { get; } + public ReactiveCommand ToggleCollapsed { get; } public ReactiveCommand ToggleSuspended { get; } public ReactiveCommand AddProfile { get; } - public ReactiveCommand EditCategory { get; } public ReactiveCommand MoveUp { get; } public ReactiveCommand MoveDown { get; } + public ReactiveCommand RenameCategory { get; } + public ReactiveCommand DeleteCategory { get; } public ProfileCategory ProfileCategory { get; } public ReadOnlyObservableCollection ProfileConfigurations { get; } @@ -114,13 +123,12 @@ public class SidebarCategoryViewModel : ActivatableViewModelBase _profileService.SaveProfileCategory(oldCategory); } - private async Task ExecuteEditCategory() + private async Task ExecuteRenameCategory() { await _windowService.CreateContentDialog() .WithTitle("Edit category") .WithViewModel(out SidebarCategoryEditViewModel vm, ("category", ProfileCategory)) .HavingPrimaryButton(b => b.WithText("Confirm").WithCommand(vm.Confirm)) - .HavingSecondaryButton(b => b.WithText("Delete").WithCommand(vm.Delete)) .WithCloseButtonText("Cancel") .WithDefaultButton(ContentDialogButton.Primary) .ShowAsync(); @@ -128,6 +136,12 @@ public class SidebarCategoryViewModel : ActivatableViewModelBase _sidebarViewModel.UpdateProfileCategories(); } + private async Task ExecuteDeleteCategory() + { + if (await _windowService.ShowConfirmContentDialog($"Delete {ProfileCategory.Name}", "Do you want to delete this category and all its profiles?")) + _profileService.DeleteProfileCategory(ProfileCategory); + } + private async Task ExecuteAddProfile() { ProfileConfiguration? result = await _windowService.ShowDialogAsync( @@ -140,6 +154,42 @@ public class SidebarCategoryViewModel : ActivatableViewModelBase SelectedProfileConfiguration = viewModel; } } + + private async Task ExecuteImportProfile() + { + string[]? result = await _windowService.CreateOpenFileDialog() + .HavingFilter(f => f.WithExtension("json").WithName("Artemis profile")) + .ShowAsync(); + + if (result == null) + return; + + string json = await File.ReadAllTextAsync(result[0]); + ProfileConfigurationExportModel? profileConfigurationExportModel = null; + try + { + profileConfigurationExportModel = JsonConvert.DeserializeObject(json, IProfileService.ExportSettings); + } + catch (JsonException e) + { + _windowService.ShowExceptionDialog("Import profile failed", e); + } + + if (profileConfigurationExportModel == null) + { + await _windowService.ShowConfirmContentDialog("Import profile", "Failed to import this profile, make sure it is a valid Artemis profile.", "Confirm", null); + return; + } + + try + { + _profileService.ImportProfile(ProfileCategory, profileConfigurationExportModel); + } + catch (Exception e) + { + _windowService.ShowExceptionDialog("Import profile failed", e); + } + } private void ExecuteToggleCollapsed() { diff --git a/src/Artemis.UI/Screens/Sidebar/SidebarProfileConfigurationView.axaml b/src/Artemis.UI/Screens/Sidebar/SidebarProfileConfigurationView.axaml index 2abedf391..23d1a1221 100644 --- a/src/Artemis.UI/Screens/Sidebar/SidebarProfileConfigurationView.axaml +++ b/src/Artemis.UI/Screens/Sidebar/SidebarProfileConfigurationView.axaml @@ -9,13 +9,14 @@ x:Class="Artemis.UI.Screens.Sidebar.SidebarProfileConfigurationView" x:DataType="sidebar:SidebarProfileConfigurationViewModel" Background="Transparent"> - - - + + + + @@ -53,8 +54,24 @@ - - + + + + + + + + -