Skip to content

Commit d775557

Browse files
committed
refactor: remove ViewModels.GotoParentSelector since there are no observable datas
Signed-off-by: leo <longshuang@msn.cn>
1 parent ac3aba9 commit d775557

File tree

4 files changed

+21
-45
lines changed

4 files changed

+21
-45
lines changed

src/ViewModels/GotoParentSelector.cs

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

src/Views/GotoParentSelector.axaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:m="using:SourceGit.Models"
66
xmlns:v="using:SourceGit.Views"
7-
xmlns:vm="using:SourceGit.ViewModels"
87
xmlns:c="using:SourceGit.Converters"
98
mc:Ignorable="d" d:DesignWidth="520" d:DesignHeight="230"
109
x:Class="SourceGit.Views.GotoParentSelector"
11-
x:DataType="vm:GotoParentSelector"
1210
x:Name="ThisControl"
1311
Icon="/App.ico"
1412
Title="{DynamicResource Text.GotoParentSelector}"
@@ -39,16 +37,15 @@
3937
</Grid>
4038

4139
<ListBox Grid.Row="1"
40+
x:Name="ParentList"
4241
Focusable="True"
4342
Margin="8" Padding="4"
44-
ItemsSource="{Binding Parents}"
4543
SelectionMode="AlwaysSelected"
4644
BorderThickness="0"
4745
Background="Transparent"
4846
Grid.IsSharedSizeScope="True"
4947
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
5048
ScrollViewer.VerticalScrollBarVisibility="Disabled"
51-
Loaded="OnListLoaded"
5249
KeyDown="OnListKeyDown">
5350
<ListBox.Styles>
5451
<Style Selector="ListBoxItem">

src/Views/GotoParentSelector.axaml.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Collections.Generic;
2+
13
using Avalonia.Controls;
24
using Avalonia.Input;
35
using Avalonia.Interactivity;
@@ -6,30 +8,28 @@ namespace SourceGit.Views
68
{
79
public partial class GotoParentSelector : ChromelessWindow
810
{
9-
public GotoParentSelector()
11+
public GotoParentSelector(List<Models.Commit> commits)
1012
{
1113
CloseOnESC = true;
1214
InitializeComponent();
15+
ParentList.ItemsSource = commits;
1316
}
1417

15-
private void OnListLoaded(object sender, RoutedEventArgs e)
18+
protected override void OnLoaded(RoutedEventArgs e)
1619
{
17-
(sender as ListBox)?.Focus();
20+
base.OnLoaded(e);
21+
ParentList.Focus();
1822
}
1923

2024
private void OnListKeyDown(object sender, KeyEventArgs e)
2125
{
2226
if (e is not { Key: Key.Enter, KeyModifiers: KeyModifiers.None })
2327
return;
2428

25-
if (DataContext is not ViewModels.GotoParentSelector vm)
26-
return;
27-
2829
if (sender is not ListBox { SelectedItem: Models.Commit commit })
2930
return;
3031

31-
vm.Sure(commit);
32-
Close();
32+
Close(commit);
3333
e.Handled = true;
3434
}
3535

@@ -38,10 +38,7 @@ private void OnListItemTapped(object sender, TappedEventArgs e)
3838
if (sender is not Control { DataContext: Models.Commit commit })
3939
return;
4040

41-
if (DataContext is ViewModels.GotoParentSelector vm)
42-
vm.Sure(commit);
43-
44-
Close();
41+
Close(commit);
4542
e.Handled = true;
4643
}
4744
}

src/Views/Histories.axaml.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,10 @@ private async void OnGotoParent(object sender, RoutedEventArgs e)
173173
if (selected[0] is not Models.Commit { Parents.Count: > 0 } commit)
174174
return;
175175

176-
e.Handled = true;
177-
178176
if (commit.Parents.Count == 1)
179177
{
180178
vm.NavigateTo(commit.Parents[0]);
179+
e.Handled = true;
181180
return;
182181
}
183182

@@ -190,9 +189,17 @@ private async void OnGotoParent(object sender, RoutedEventArgs e)
190189
}
191190

192191
if (parents.Count == 1)
192+
{
193193
vm.NavigateTo(parents[0].SHA);
194-
else if (parents.Count > 1)
195-
await App.ShowDialog(new ViewModels.GotoParentSelector(vm, parents));
194+
}
195+
else if (parents.Count > 1 && TopLevel.GetTopLevel(this) is Window owner)
196+
{
197+
var dialog = new GotoParentSelector(parents);
198+
var c = await dialog.ShowDialog<Models.Commit>(owner);
199+
vm.NavigateTo(c.SHA);
200+
}
201+
202+
e.Handled = true;
196203
}
197204

198205
private void OnCommitListLayoutUpdated(object _1, EventArgs _2)

0 commit comments

Comments
 (0)