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,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);
|
||||||
|
|
Loading…
Reference in a new issue