Skip to content

Commit 49c0cfd

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

File tree

4 files changed

+20
-44
lines changed

4 files changed

+20
-44
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: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,21 @@ public GotoParentSelector()
1212
InitializeComponent();
1313
}
1414

15-
private void OnListLoaded(object sender, RoutedEventArgs e)
15+
protected override void OnLoaded(RoutedEventArgs e)
1616
{
17-
(sender as ListBox)?.Focus();
17+
base.OnLoaded(e);
18+
ParentList.Focus();
1819
}
1920

2021
private void OnListKeyDown(object sender, KeyEventArgs e)
2122
{
2223
if (e is not { Key: Key.Enter, KeyModifiers: KeyModifiers.None })
2324
return;
2425

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

31-
vm.Sure(commit);
32-
Close();
29+
Close(commit);
3330
e.Handled = true;
3431
}
3532

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

41-
if (DataContext is ViewModels.GotoParentSelector vm)
42-
vm.Sure(commit);
43-
44-
Close();
38+
Close(commit);
4539
e.Handled = true;
4640
}
4741
}

src/Views/Histories.axaml.cs

Lines changed: 14 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,20 @@ 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();
198+
dialog.ParentList.ItemsSource = parents;
199+
200+
var c = await dialog.ShowDialog<Models.Commit>(owner);
201+
if (c != null)
202+
vm.NavigateTo(c.SHA);
203+
}
204+
205+
e.Handled = true;
196206
}
197207

198208
private void OnCommitListLayoutUpdated(object _1, EventArgs _2)

0 commit comments

Comments
 (0)