From 70058fc2598fee1fbb28c423d8168483aa1a8b51 Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Mon, 19 Aug 2024 16:50:58 +0200 Subject: [PATCH 1/4] Remove custom page behavior --- src/NexusMods.App.UI/Pages/Settings/SettingsPage.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/NexusMods.App.UI/Pages/Settings/SettingsPage.cs b/src/NexusMods.App.UI/Pages/Settings/SettingsPage.cs index 2d00145560..3082b3ad42 100644 --- a/src/NexusMods.App.UI/Pages/Settings/SettingsPage.cs +++ b/src/NexusMods.App.UI/Pages/Settings/SettingsPage.cs @@ -17,8 +17,6 @@ public SettingsPageFactory(IServiceProvider serviceProvider) : base(serviceProvi public static readonly PageFactoryId StaticId = PageFactoryId.From(Guid.Parse("3DE311A0-0AB0-4191-9CA5-5CE8EA76C393")); public override PageFactoryId Id => StaticId; - public override Optional DefaultOpenPageBehavior => OpenPageBehaviorType.NewPanel; - public override ISettingsPageViewModel CreateViewModel(SettingsPageContext context) { return ServiceProvider.GetRequiredService(); From 63e49002983c8b3b16d1af565cd2f854fa3b8068 Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Mon, 19 Aug 2024 19:27:49 +0200 Subject: [PATCH 2/4] Fix `NavigationMenuItem` unwontedly remembering last custom behavior used --- .../Controls/Navigation/NavigationMenuItem.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/NexusMods.App.UI/Controls/Navigation/NavigationMenuItem.cs b/src/NexusMods.App.UI/Controls/Navigation/NavigationMenuItem.cs index 0478117054..4556c5b9ea 100644 --- a/src/NexusMods.App.UI/Controls/Navigation/NavigationMenuItem.cs +++ b/src/NexusMods.App.UI/Controls/Navigation/NavigationMenuItem.cs @@ -1,7 +1,6 @@ using System.Reactive; using Avalonia; using Avalonia.Controls; -using Avalonia.Interactivity; using DynamicData.Kernel; using NexusMods.App.UI.Resources; using NexusMods.App.UI.WorkspaceSystem; @@ -41,8 +40,8 @@ public NavigationMenuItem() _contextMenuCommand = ReactiveCommand.Create(openPageBehaviorType => { - NavigationInformation = NavigationInformation.From(openPageBehaviorType); - OnClick(new RoutedEventArgs()); + var navigationInformation = NavigationInformation.From(openPageBehaviorType); + NavigationCommand?.Execute(navigationInformation).Subscribe(); }); var contextMenu = new ContextMenu From 61a382ce5b2c3af38856bebcefec40e72bbef941 Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:26:45 +0200 Subject: [PATCH 3/4] Properly restore PageTabId from stored tab data, to correctly restore selected tab --- .../WorkspaceSystem/Panel/PanelViewModel.cs | 6 ++---- .../WorkspaceSystem/PanelTab/PanelTabViewModel.cs | 6 ++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/NexusMods.App.UI/WorkspaceSystem/Panel/PanelViewModel.cs b/src/NexusMods.App.UI/WorkspaceSystem/Panel/PanelViewModel.cs index ae80df429b..8931a915c5 100644 --- a/src/NexusMods.App.UI/WorkspaceSystem/Panel/PanelViewModel.cs +++ b/src/NexusMods.App.UI/WorkspaceSystem/Panel/PanelViewModel.cs @@ -226,9 +226,9 @@ public void FromData(PanelData data) for (uint i = 0; i < data.Tabs.Length; i++) { var tab = data.Tabs[i]; - var newTabPage = _factoryController.Create(tab.PageData, WindowId, WorkspaceId, Id, tabId: Optional.None); + var newTabPage = _factoryController.Create(tab.PageData, WindowId, WorkspaceId, Id, tabId: tab.Id); - var vm = new PanelTabViewModel(_workspaceController, WorkspaceId, Id) + var vm = new PanelTabViewModel(_workspaceController, WorkspaceId, Id, tab.Id) { Contents = newTabPage, Header = @@ -238,8 +238,6 @@ public void FromData(PanelData data) }, }; - newTabPage.ViewModel.TabId = vm.Id; - updater.Add(vm); } }); diff --git a/src/NexusMods.App.UI/WorkspaceSystem/PanelTab/PanelTabViewModel.cs b/src/NexusMods.App.UI/WorkspaceSystem/PanelTab/PanelTabViewModel.cs index 87293a3c45..5031968576 100644 --- a/src/NexusMods.App.UI/WorkspaceSystem/PanelTab/PanelTabViewModel.cs +++ b/src/NexusMods.App.UI/WorkspaceSystem/PanelTab/PanelTabViewModel.cs @@ -1,4 +1,5 @@ using System.Reactive; +using DynamicData.Kernel; using ReactiveUI; using ReactiveUI.Fody.Helpers; @@ -7,7 +8,7 @@ namespace NexusMods.App.UI.WorkspaceSystem; public class PanelTabViewModel : AViewModel, IPanelTabViewModel { /// - public PanelTabId Id { get; } = PanelTabId.From(Guid.NewGuid()); + public PanelTabId Id { get; } /// public IPanelTabHeaderViewModel Header { get; } @@ -26,8 +27,9 @@ public class PanelTabViewModel : AViewModel, IPanelTabViewMo private TabHistory History { get; } - public PanelTabViewModel(IWorkspaceController workspaceController, WorkspaceId workspaceId, PanelId panelId) + public PanelTabViewModel(IWorkspaceController workspaceController, WorkspaceId workspaceId, PanelId panelId, Optional tabId = default) { + Id = tabId.HasValue ? tabId.Value : PanelTabId.From(Guid.NewGuid()); Header = new PanelTabHeaderViewModel(Id); History = new TabHistory( openPageFunc: pageData => { From d6f18c68a13077a3fbfe0241c079afc2326edc19 Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:39:27 +0200 Subject: [PATCH 4/4] Update SelectedTab even while PanelViewModel isn't active, as this needs to be available anyways. --- .../WorkspaceSystem/Panel/PanelViewModel.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/NexusMods.App.UI/WorkspaceSystem/Panel/PanelViewModel.cs b/src/NexusMods.App.UI/WorkspaceSystem/Panel/PanelViewModel.cs index 8931a915c5..5ace5a7280 100644 --- a/src/NexusMods.App.UI/WorkspaceSystem/Panel/PanelViewModel.cs +++ b/src/NexusMods.App.UI/WorkspaceSystem/Panel/PanelViewModel.cs @@ -65,6 +65,11 @@ public PanelViewModel(IWorkspaceController workspaceController, PageFactoryContr .Bind(out _tabs) .Subscribe(); + this.WhenAnyValue(vm => vm.SelectedTabId) + .Select(selectedTabId => Tabs.FirstOrDefault(tab => tab.Id == selectedTabId)) + .WhereNotNull() + .SubscribeWithErrorLogging(selectedTab => SelectedTab = selectedTab); + this.WhenActivated(disposables => { this.WhenAnyValue(vm => vm.LogicalBounds) @@ -129,9 +134,7 @@ public PanelViewModel(IWorkspaceController workspaceController, PageFactoryContr .Connect() .WhenPropertyChanged(item => item.Header.IsSelected) .Where(propertyValue => propertyValue.Value) - .Select(propertyValue => propertyValue.Sender) - .Do(vm => SelectedTab = vm) - .Select(vm => vm.Id) + .Select(propertyValue => propertyValue.Sender.Id) .BindToVM(this, vm => vm.SelectedTabId) .DisposeWith(disposables);