mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-25 21:07:20 -08:00
73 lines
1.8 KiB
C#
73 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SourceGit.ViewModels
|
|
{
|
|
public class MoveRepositoryNode : Popup
|
|
{
|
|
public RepositoryNode Target
|
|
{
|
|
get;
|
|
private set;
|
|
} = null;
|
|
|
|
public List<RepositoryNode> Rows
|
|
{
|
|
get;
|
|
private set;
|
|
} = [];
|
|
|
|
public RepositoryNode Selected
|
|
{
|
|
get => _selected;
|
|
set => SetProperty(ref _selected, value);
|
|
}
|
|
|
|
public MoveRepositoryNode(RepositoryNode target)
|
|
{
|
|
Target = target;
|
|
Rows.Add(new RepositoryNode()
|
|
{
|
|
Name = "ROOT",
|
|
Depth = 0,
|
|
Id = Guid.NewGuid().ToString()
|
|
});
|
|
MakeRows(Preference.Instance.RepositoryNodes, 1);
|
|
|
|
View = new Views.MoveRepositoryNode() { DataContext = this };
|
|
}
|
|
|
|
public override Task<bool> Sure()
|
|
{
|
|
if (_selected != null)
|
|
{
|
|
var node = Preference.Instance.FindNode(_selected.Id);
|
|
Preference.Instance.MoveNode(Target, node, true);
|
|
Welcome.Instance.Refresh();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private void MakeRows(List<RepositoryNode> collection, int depth)
|
|
{
|
|
foreach (var node in collection)
|
|
{
|
|
if (node.IsRepository || node.Id == Target.Id)
|
|
continue;
|
|
|
|
var dump = new RepositoryNode()
|
|
{
|
|
Name = node.Name,
|
|
Depth = depth,
|
|
Id = node.Id
|
|
};
|
|
Rows.Add(dump);
|
|
MakeRows(node.SubNodes, depth + 1);
|
|
}
|
|
}
|
|
|
|
private RepositoryNode _selected = null;
|
|
}
|
|
}
|