Merge branch 'sourcegit-scm:develop' into develop

This commit is contained in:
Chuanyan.Chen 2024-06-05 17:25:25 +08:00 committed by GitHub
commit a9873f1f52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 19 deletions

View file

@ -42,23 +42,15 @@ namespace SourceGit.Models
public void Select(IEnumerable<TModel> items) public void Select(IEnumerable<TModel> items)
{ {
var sets = new HashSet<TModel>();
foreach (var item in items)
sets.Add(item);
using (BatchUpdate()) using (BatchUpdate())
{ {
Clear(); Clear();
int num = _source.Rows.Count; foreach (var selected in items)
for (int i = 0; i < num; ++i)
{ {
var m = _source.Rows[i].Model as TModel; var idx = GetModelIndex(_source.Items, selected, IndexPath.Unselected);
if (m != null && sets.Contains(m)) if (!idx.Equals(IndexPath.Unselected))
{
var idx = _source.Rows.RowIndexToModelIndex(i);
Select(idx); Select(idx);
}
} }
} }
} }
@ -431,6 +423,30 @@ namespace SourceGit.Models
return _childrenGetter?.Invoke(node); return _childrenGetter?.Invoke(node);
} }
private IndexPath GetModelIndex(IEnumerable<TModel> collection, TModel model, IndexPath parent)
{
int i = 0;
foreach (var item in collection)
{
var index = parent.Append(i);
if (item != null && item == model)
return index;
var children = GetChildren(item);
if (children != null)
{
var findInChildren = GetModelIndex(children, model, index);
if (!findInChildren.Equals(IndexPath.Unselected))
return findInChildren;
}
i++;
}
return IndexPath.Unselected;
}
private bool HasChildren(IRow row) private bool HasChildren(IRow row)
{ {
var children = GetChildren(row.Model as TModel); var children = GetChildren(row.Model as TModel);

View file

@ -131,12 +131,12 @@ namespace SourceGit.ViewModels
if (line.Type == Models.TextDiffLineType.Added) if (line.Type == Models.TextDiffLineType.Added)
{ {
var sha = line.Content.Substring("Subproject commit ".Length); var sha = line.Content.Substring("Subproject commit ".Length);
submoduleDiff.New = new Commands.QuerySingleCommit(submoduleRoot, sha).Result(); submoduleDiff.New = new Commands.QuerySingleCommit(submoduleRoot, sha).Result() ?? new Models.Commit() { SHA = sha };
} }
else if (line.Type == Models.TextDiffLineType.Deleted) else if (line.Type == Models.TextDiffLineType.Deleted)
{ {
var sha = line.Content.Substring("Subproject commit ".Length); var sha = line.Content.Substring("Subproject commit ".Length);
submoduleDiff.Old = new Commands.QuerySingleCommit(submoduleRoot, sha).Result(); submoduleDiff.Old = new Commands.QuerySingleCommit(submoduleRoot, sha).Result() ?? new Models.Commit() { SHA = sha };
} }
} }
rs = submoduleDiff; rs = submoduleDiff;

View file

@ -20,8 +20,8 @@
IsHitTestVisible="False" IsHitTestVisible="False"
User="{Binding StartPoint.Author}"/> User="{Binding StartPoint.Author}"/>
<TextBlock Grid.Column="1" Classes="monospace" Text="{Binding StartPoint.Author.Name}" Margin="8,0,0,0"/> <TextBlock Grid.Column="1" Classes="monospace" Text="{Binding StartPoint.Author.Name}" Margin="8,0,0,0"/>
<Border Grid.Column="2" Background="DarkGreen" CornerRadius="4" IsVisible="{Binding StartPoint.IsCurrentHead}"> <Border Grid.Column="2" Background="{DynamicResource Brush.Accent}" CornerRadius="4" IsVisible="{Binding StartPoint.IsCurrentHead}">
<TextBlock Text="HEAD" Classes="monospace" Margin="4,0"/> <TextBlock Text="HEAD" Classes="monospace" Margin="4,0" Foreground="#FFDDDDDD"/>
</Border> </Border>
<TextBlock Grid.Column="3" Classes="monospace" Text="{Binding StartPoint.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Foreground="DarkOrange" Margin="8,0,0,0" TextDecorations="Underline" PointerPressed="OnPressedSHA"/> <TextBlock Grid.Column="3" Classes="monospace" Text="{Binding StartPoint.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Foreground="DarkOrange" Margin="8,0,0,0" TextDecorations="Underline" PointerPressed="OnPressedSHA"/>
<TextBlock Grid.Column="4" Classes="monospace" Text="{Binding StartPoint.CommitterTimeStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/> <TextBlock Grid.Column="4" Classes="monospace" Text="{Binding StartPoint.CommitterTimeStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
@ -44,8 +44,8 @@
IsHitTestVisible="False" IsHitTestVisible="False"
User="{Binding Author}"/> User="{Binding Author}"/>
<TextBlock Grid.Column="1" Classes="monospace" Text="{Binding Author.Name}" Margin="8,0,0,0"/> <TextBlock Grid.Column="1" Classes="monospace" Text="{Binding Author.Name}" Margin="8,0,0,0"/>
<Border Grid.Column="2" Background="DarkGreen" CornerRadius="4" IsVisible="{Binding IsCurrentHead}"> <Border Grid.Column="2" Background="{DynamicResource Brush.Accent}" CornerRadius="4" IsVisible="{Binding IsCurrentHead}">
<TextBlock Text="HEAD" Classes="monospace" Margin="4,0"/> <TextBlock Text="HEAD" Classes="monospace" Margin="4,0" Foreground="#FFDDDDDD"/>
</Border> </Border>
<TextBlock Grid.Column="3" Classes="monospace" Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Foreground="DarkOrange" Margin="8,0,0,0" TextDecorations="Underline" PointerPressed="OnPressedSHA" /> <TextBlock Grid.Column="3" Classes="monospace" Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Foreground="DarkOrange" Margin="8,0,0,0" TextDecorations="Underline" PointerPressed="OnPressedSHA" />
<TextBlock Grid.Column="4" Classes="monospace" Text="{Binding CommitterTimeStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/> <TextBlock Grid.Column="4" Classes="monospace" Text="{Binding CommitterTimeStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
@ -56,8 +56,8 @@
</DataTemplate> </DataTemplate>
<DataTemplate DataType="vm:CompareTargetWorktree"> <DataTemplate DataType="vm:CompareTargetWorktree">
<Border HorizontalAlignment="Center" VerticalAlignment="Center" Background="DarkGreen" CornerRadius="4"> <Border HorizontalAlignment="Center" VerticalAlignment="Center" Background="{DynamicResource Brush.Accent}" CornerRadius="4">
<TextBlock Text="{DynamicResource Text.Worktree}" Classes="monospace" Margin="4,2"/> <TextBlock Text="{DynamicResource Text.Worktree}" Classes="monospace" Margin="4,2" Foreground="#FFDDDDDD"/>
</Border> </Border>
</DataTemplate> </DataTemplate>
</ContentControl.DataTemplates> </ContentControl.DataTemplates>