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:
Göran W 2025-06-25 10:37:18 +02:00 committed by GitHub
parent d192712f51
commit 743be5491a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 2 deletions

View file

@ -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);

View file

@ -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)
{