mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
fix: select item in tree not work
This commit is contained in:
parent
ce9a3dad2f
commit
1870dcd468
1 changed files with 27 additions and 11 deletions
|
@ -42,26 +42,18 @@ namespace SourceGit.Models
|
|||
|
||||
public void Select(IEnumerable<TModel> items)
|
||||
{
|
||||
var sets = new HashSet<TModel>();
|
||||
foreach (var item in items)
|
||||
sets.Add(item);
|
||||
|
||||
using (BatchUpdate())
|
||||
{
|
||||
Clear();
|
||||
|
||||
int num = _source.Rows.Count;
|
||||
for (int i = 0; i < num; ++i)
|
||||
foreach (var selected in items)
|
||||
{
|
||||
var m = _source.Rows[i].Model as TModel;
|
||||
if (m != null && sets.Contains(m))
|
||||
{
|
||||
var idx = _source.Rows.RowIndexToModelIndex(i);
|
||||
var idx = GetModelIndex(_source.Items, selected, IndexPath.Unselected);
|
||||
if (!idx.Equals(IndexPath.Unselected))
|
||||
Select(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event EventHandler ITreeDataGridSelectionInteraction.SelectionChanged
|
||||
{
|
||||
|
@ -431,6 +423,30 @@ namespace SourceGit.Models
|
|||
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)
|
||||
{
|
||||
var children = GetChildren(row.Model as TModel);
|
||||
|
|
Loading…
Reference in a new issue