mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-21 13:20:30 +08:00
refactor: remove ViewModels.GotoParentSelector since there are no observable datas
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class GotoParentSelector
|
||||
{
|
||||
public List<Models.Commit> Parents
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public GotoParentSelector(Histories owner, List<Models.Commit> parents)
|
||||
{
|
||||
Parents = parents;
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
public void Sure(Models.Commit commit)
|
||||
{
|
||||
_owner.NavigateTo(commit.SHA);
|
||||
}
|
||||
|
||||
private Histories _owner;
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,9 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:m="using:SourceGit.Models"
|
||||
xmlns:v="using:SourceGit.Views"
|
||||
xmlns:vm="using:SourceGit.ViewModels"
|
||||
xmlns:c="using:SourceGit.Converters"
|
||||
mc:Ignorable="d" d:DesignWidth="520" d:DesignHeight="230"
|
||||
x:Class="SourceGit.Views.GotoParentSelector"
|
||||
x:DataType="vm:GotoParentSelector"
|
||||
x:Name="ThisControl"
|
||||
Icon="/App.ico"
|
||||
Title="{DynamicResource Text.GotoParentSelector}"
|
||||
@@ -39,16 +37,15 @@
|
||||
</Grid>
|
||||
|
||||
<ListBox Grid.Row="1"
|
||||
x:Name="ParentList"
|
||||
Focusable="True"
|
||||
Margin="8" Padding="4"
|
||||
ItemsSource="{Binding Parents}"
|
||||
SelectionMode="AlwaysSelected"
|
||||
BorderThickness="0"
|
||||
Background="Transparent"
|
||||
Grid.IsSharedSizeScope="True"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Disabled"
|
||||
Loaded="OnListLoaded"
|
||||
KeyDown="OnListKeyDown">
|
||||
<ListBox.Styles>
|
||||
<Style Selector="ListBoxItem">
|
||||
|
||||
@@ -12,9 +12,10 @@ namespace SourceGit.Views
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void OnListLoaded(object sender, RoutedEventArgs e)
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
{
|
||||
(sender as ListBox)?.Focus();
|
||||
base.OnLoaded(e);
|
||||
ParentList.Focus();
|
||||
}
|
||||
|
||||
private void OnListKeyDown(object sender, KeyEventArgs e)
|
||||
@@ -22,14 +23,10 @@ namespace SourceGit.Views
|
||||
if (e is not { Key: Key.Enter, KeyModifiers: KeyModifiers.None })
|
||||
return;
|
||||
|
||||
if (DataContext is not ViewModels.GotoParentSelector vm)
|
||||
return;
|
||||
|
||||
if (sender is not ListBox { SelectedItem: Models.Commit commit })
|
||||
return;
|
||||
|
||||
vm.Sure(commit);
|
||||
Close();
|
||||
Close(commit);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
@@ -38,10 +35,7 @@ namespace SourceGit.Views
|
||||
if (sender is not Control { DataContext: Models.Commit commit })
|
||||
return;
|
||||
|
||||
if (DataContext is ViewModels.GotoParentSelector vm)
|
||||
vm.Sure(commit);
|
||||
|
||||
Close();
|
||||
Close(commit);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,11 +173,10 @@ namespace SourceGit.Views
|
||||
if (selected[0] is not Models.Commit { Parents.Count: > 0 } commit)
|
||||
return;
|
||||
|
||||
e.Handled = true;
|
||||
|
||||
if (commit.Parents.Count == 1)
|
||||
{
|
||||
vm.NavigateTo(commit.Parents[0]);
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -190,9 +189,20 @@ namespace SourceGit.Views
|
||||
}
|
||||
|
||||
if (parents.Count == 1)
|
||||
{
|
||||
vm.NavigateTo(parents[0].SHA);
|
||||
else if (parents.Count > 1)
|
||||
await App.ShowDialog(new ViewModels.GotoParentSelector(vm, parents));
|
||||
}
|
||||
else if (parents.Count > 1 && TopLevel.GetTopLevel(this) is Window owner)
|
||||
{
|
||||
var dialog = new GotoParentSelector();
|
||||
dialog.ParentList.ItemsSource = parents;
|
||||
|
||||
var c = await dialog.ShowDialog<Models.Commit>(owner);
|
||||
if (c != null)
|
||||
vm.NavigateTo(c.SHA);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnCommitListLayoutUpdated(object _1, EventArgs _2)
|
||||
|
||||
Reference in New Issue
Block a user