Skip to content

Commit 5514c56

Browse files
committed
refactor: more efficient way to update the visibility of tab splitters
1 parent b0c14ab commit 5514c56

File tree

4 files changed

+29
-83
lines changed

4 files changed

+29
-83
lines changed

src/Converters/LauncherPageConverters.cs

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/ViewModels/Launcher.cs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public LauncherPage ActivePage
2323
if (SetProperty(ref _activePage, value))
2424
{
2525
PopupHost.Active = value;
26+
UpdateTabSplitterVisible();
2627
}
2728
}
2829
}
@@ -157,13 +158,12 @@ public void CloseTab(object param)
157158
ActivePage = Pages[removeIdx == Pages.Count - 1 ? removeIdx - 1 : removeIdx + 1];
158159
CloseRepositoryInTab(page);
159160
Pages.RemoveAt(removeIdx);
160-
OnPropertyChanged(nameof(Pages));
161161
}
162162
else if (removeIdx + 1 == activeIdx)
163163
{
164164
CloseRepositoryInTab(page);
165165
Pages.RemoveAt(removeIdx);
166-
OnPropertyChanged(nameof(Pages));
166+
UpdateTabSplitterVisible();
167167
}
168168
else
169169
{
@@ -174,42 +174,25 @@ public void CloseTab(object param)
174174
GC.Collect();
175175
}
176176

177-
public void CloseOtherTabs(object param)
177+
public void CloseOtherTabs()
178178
{
179179
if (Pages.Count == 1)
180180
return;
181181

182-
var page = param as LauncherPage;
183-
if (page == null)
184-
page = _activePage;
185-
186-
ActivePage = page;
187-
182+
var id = ActivePage.Node.Id;
188183
foreach (var one in Pages)
189184
{
190-
if (one.Node.Id != page.Node.Id)
185+
if (one.Node.Id != id)
191186
CloseRepositoryInTab(one);
192187
}
193188

194-
Pages = new AvaloniaList<LauncherPage> { page };
195-
OnPropertyChanged(nameof(Pages));
196-
189+
Pages = new AvaloniaList<LauncherPage> { ActivePage };
197190
GC.Collect();
198191
}
199192

200-
public void CloseRightTabs(object param)
193+
public void CloseRightTabs()
201194
{
202-
LauncherPage page = param as LauncherPage;
203-
if (page == null)
204-
page = _activePage;
205-
206-
var endIdx = Pages.IndexOf(page);
207-
var activeIdx = Pages.IndexOf(_activePage);
208-
if (endIdx < activeIdx)
209-
{
210-
ActivePage = page;
211-
}
212-
195+
var endIdx = Pages.IndexOf(ActivePage);
213196
for (var i = Pages.Count - 1; i > endIdx; i--)
214197
{
215198
CloseRepositoryInTab(Pages[i]);
@@ -275,6 +258,13 @@ private void CloseRepositoryInTab(LauncherPage page)
275258
page.Data = null;
276259
}
277260

261+
private void UpdateTabSplitterVisible()
262+
{
263+
var activePageIdx = ActivePage == null ? -1 : Pages.IndexOf(ActivePage);
264+
for (int i = 0; i < Pages.Count; i++)
265+
Pages[i].IsTabSplitterVisible = (activePageIdx != i && activePageIdx != i + 1);
266+
}
267+
278268
private LauncherPage _activePage = null;
279269
}
280270
}

src/ViewModels/LauncherPage.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ public object Data
1818
set => SetProperty(ref _data, value);
1919
}
2020

21+
public bool IsTabSplitterVisible
22+
{
23+
get => _isTabSplitterVisible;
24+
set => SetProperty(ref _isTabSplitterVisible, value);
25+
}
26+
2127
public AvaloniaList<Models.Notification> Notifications
2228
{
2329
get;
@@ -50,12 +56,11 @@ public void CopyPath()
5056
public void DismissNotification(object param)
5157
{
5258
if (param is Models.Notification notice)
53-
{
5459
Notifications.Remove(notice);
55-
}
5660
}
5761

5862
private RepositoryNode _node = null;
5963
private object _data = null;
64+
private bool _isTabSplitterVisible = true;
6065
}
6166
}

src/Views/Launcher.axaml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,9 @@
125125
CommandParameter="{Binding}"
126126
InputGesture="{OnPlatform Ctrl+W, macOS=⌘+W}"/>
127127
<MenuItem Header="{DynamicResource Text.PageTabBar.Tab.CloseOther}"
128-
Command="{Binding #me.((vm:Launcher)DataContext).CloseOtherTabs}"
129-
CommandParameter="{Binding}"/>
128+
Command="{Binding #me.((vm:Launcher)DataContext).CloseOtherTabs}"/>
130129
<MenuItem Header="{DynamicResource Text.PageTabBar.Tab.CloseRight}"
131-
Command="{Binding #me.((vm:Launcher)DataContext).CloseRightTabs}"
132-
CommandParameter="{Binding}"/>
130+
Command="{Binding #me.((vm:Launcher)DataContext).CloseRightTabs}"/>
133131
<MenuItem Header="-" IsVisible="{Binding Node.IsRepository}"/>
134132
<MenuItem IsVisible="{Binding Node.IsRepository}">
135133
<MenuItem.Header>
@@ -210,15 +208,11 @@
210208
</ToolTip.Tip>
211209
<Path Width="8" Height="8" Data="{StaticResource Icons.Window.Close}"/>
212210
</Button>
213-
<Rectangle Grid.Column="2" Width=".5" Height="20" HorizontalAlignment="Right" VerticalAlignment="Center" Fill="{DynamicResource Brush.FG2}">
214-
<Rectangle.IsVisible>
215-
<MultiBinding Converter="{x:Static c:LauncherPageConverters.ToTabSeperatorVisible}">
216-
<Binding/>
217-
<Binding Path="$parent[ListBox].SelectedItem"/>
218-
<Binding Path="#me.((vm:Launcher)DataContext).Pages"/>
219-
</MultiBinding>
220-
</Rectangle.IsVisible>
221-
</Rectangle>
211+
<Rectangle Grid.Column="2"
212+
Width=".5" Height="20"
213+
HorizontalAlignment="Right" VerticalAlignment="Center"
214+
Fill="{DynamicResource Brush.FG2}"
215+
IsVisible="{Binding IsTabSplitterVisible}"/>
222216
</Grid>
223217
</Border>
224218
</DataTemplate>

0 commit comments

Comments
 (0)