2024-09-02 02:05:43 -07:00
|
|
|
|
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;
|
2024-09-02 05:27:12 -07:00
|
|
|
|
Rows.Add(new RepositoryNode()
|
|
|
|
|
{
|
|
|
|
|
Name = "ROOT",
|
|
|
|
|
Depth = 0,
|
|
|
|
|
Id = Guid.NewGuid().ToString()
|
2024-09-02 02:05:43 -07:00
|
|
|
|
});
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|