Skip to content

Commit b43df81

Browse files
authored
Add CloseAll and CloseOthers to the tabbed object view (#161)
1 parent 5f62a32 commit b43df81

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Gui/ViewModels/TabViewPageViewModel.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Reactive;
66
using System.Reactive.Linq;
7+
using System.Windows.Input;
78

89
namespace OpenLoco.Gui.ViewModels
910
{
@@ -29,10 +30,18 @@ public void AddDocument(ILocoFileViewModel model)
2930

3031
public ReactiveCommand<ILocoFileViewModel, Unit> RemoveTabCommand { get; }
3132

33+
[Reactive]
34+
public ICommand CloseAllTabsCommand { get; set; }
35+
36+
[Reactive]
37+
public ReactiveCommand<ILocoFileViewModel, Unit> CloseOtherTabsCommand { get; set; }
38+
3239
public TabViewPageViewModel()
3340
{
3441
Documents = [];
3542
RemoveTabCommand = ReactiveCommand.Create<ILocoFileViewModel>(RemoveTab);
43+
CloseAllTabsCommand = ReactiveCommand.Create(CloseAllTabs);
44+
CloseOtherTabsCommand = ReactiveCommand.Create<ILocoFileViewModel>(CloseOtherTabs);
3645
}
3746

3847
public async void ReloadAll()
@@ -47,5 +56,16 @@ void RemoveTab(ILocoFileViewModel tabToRemove)
4756
{
4857
_ = Documents.Remove(tabToRemove);
4958
}
59+
60+
void CloseAllTabs()
61+
{
62+
Documents.Clear();
63+
}
64+
65+
void CloseOtherTabs(ILocoFileViewModel tabToKeep)
66+
{
67+
Documents.Clear();
68+
Documents.Add(tabToKeep);
69+
}
5070
}
5171
}

Gui/Views/MainWindow.axaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,12 @@
823823
<Button BorderThickness="0" FontSize="12" VerticalAlignment="Center" Command="{Binding $parent[TabControl].((vm:TabViewPageViewModel)DataContext).RemoveTabCommand}" CommandParameter="{Binding}">X</Button>
824824
</StackPanel>
825825
</TabItem.Header>
826+
<TabItem.ContextMenu>
827+
<ContextMenu>
828+
<MenuItem Header="Close All Tabs" Command="{Binding $parent[TabControl].((vm:TabViewPageViewModel)DataContext).CloseAllTabsCommand}" />
829+
<MenuItem Header="Close Other Tabs" Command="{Binding $parent[TabControl].((vm:TabViewPageViewModel)DataContext).CloseOtherTabsCommand}" CommandParameter="{Binding}" />
830+
</ContextMenu>
831+
</TabItem.ContextMenu>
826832
</TabItem>
827833
</DataTemplate>
828834
</TabControl.ItemTemplate>

0 commit comments

Comments
 (0)