Skip to content

Commit

Permalink
Merge pull request #1903 from Nexus-Mods/fix/1897-setting-open-page
Browse files Browse the repository at this point in the history
Fix setting open page behaviour
  • Loading branch information
Al12rs authored Aug 20, 2024
2 parents f3b59a4 + d6f18c6 commit bc0174d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,8 +40,8 @@ public NavigationMenuItem()

_contextMenuCommand = ReactiveCommand.Create<OpenPageBehaviorType>(openPageBehaviorType =>
{
NavigationInformation = NavigationInformation.From(openPageBehaviorType);
OnClick(new RoutedEventArgs());
var navigationInformation = NavigationInformation.From(openPageBehaviorType);
NavigationCommand?.Execute(navigationInformation).Subscribe();
});

var contextMenu = new ContextMenu
Expand Down
2 changes: 0 additions & 2 deletions src/NexusMods.App.UI/Pages/Settings/SettingsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpenPageBehaviorType> DefaultOpenPageBehavior => OpenPageBehaviorType.NewPanel;

public override ISettingsPageViewModel CreateViewModel(SettingsPageContext context)
{
return ServiceProvider.GetRequiredService<ISettingsPageViewModel>();
Expand Down
15 changes: 8 additions & 7 deletions src/NexusMods.App.UI/WorkspaceSystem/Panel/PanelViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -226,9 +229,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<PanelTabId>.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 =
Expand All @@ -238,8 +241,6 @@ public void FromData(PanelData data)
},
};
newTabPage.ViewModel.TabId = vm.Id;
updater.Add(vm);
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reactive;
using DynamicData.Kernel;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;

Expand All @@ -7,7 +8,7 @@ namespace NexusMods.App.UI.WorkspaceSystem;
public class PanelTabViewModel : AViewModel<IPanelTabViewModel>, IPanelTabViewModel
{
/// <inheritdoc/>
public PanelTabId Id { get; } = PanelTabId.From(Guid.NewGuid());
public PanelTabId Id { get; }

/// <inheritdoc/>
public IPanelTabHeaderViewModel Header { get; }
Expand All @@ -26,8 +27,9 @@ public class PanelTabViewModel : AViewModel<IPanelTabViewModel>, IPanelTabViewMo

private TabHistory History { get; }

public PanelTabViewModel(IWorkspaceController workspaceController, WorkspaceId workspaceId, PanelId panelId)
public PanelTabViewModel(IWorkspaceController workspaceController, WorkspaceId workspaceId, PanelId panelId, Optional<PanelTabId> tabId = default)
{
Id = tabId.HasValue ? tabId.Value : PanelTabId.From(Guid.NewGuid());
Header = new PanelTabHeaderViewModel(Id);
History = new TabHistory(
openPageFunc: pageData => {
Expand Down

0 comments on commit bc0174d

Please sign in to comment.