mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-30 13:51:53 +08:00
enhance: allow drag-drop of item (or folder) anywhere in repo-list (#1459)
Dropping on a non-Group item was not allowed earlier, but now it adds/moves the dragged item into the parent Group (possibly Root) of the drop-target item.
This commit is contained in:
@@ -173,6 +173,25 @@ namespace SourceGit.ViewModels
|
||||
activePage.Popup = new CreateGroup(null);
|
||||
}
|
||||
|
||||
public RepositoryNode FindParentGroup(RepositoryNode node, RepositoryNode group = null)
|
||||
{
|
||||
var collection = (group == null) ? Preferences.Instance.RepositoryNodes : group.SubNodes;
|
||||
if (collection.Contains(node))
|
||||
return group;
|
||||
|
||||
foreach (var item in collection)
|
||||
{
|
||||
if (!item.IsRepository)
|
||||
{
|
||||
var parent = FindParentGroup(node, item);
|
||||
if (parent != null)
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void MoveNode(RepositoryNode from, RepositoryNode to)
|
||||
{
|
||||
Preferences.Instance.MoveNode(from, to, true);
|
||||
|
||||
@@ -215,7 +215,7 @@ namespace SourceGit.Views
|
||||
if (to == null)
|
||||
return;
|
||||
|
||||
e.DragEffects = to.IsRepository ? DragDropEffects.None : DragDropEffects.Move;
|
||||
e.DragEffects = DragDropEffects.Move;
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
@@ -226,12 +226,15 @@ namespace SourceGit.Views
|
||||
return;
|
||||
|
||||
var to = grid.DataContext as ViewModels.RepositoryNode;
|
||||
if (to == null || to.IsRepository)
|
||||
if (to == null)
|
||||
{
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (to.IsRepository)
|
||||
to = ViewModels.Welcome.Instance.FindParentGroup(to);
|
||||
|
||||
if (e.Data.Contains("MovedRepositoryTreeNode") &&
|
||||
e.Data.Get("MovedRepositoryTreeNode") is ViewModels.RepositoryNode moved)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user