Skip to content

Commit 743be54

Browse files
authored
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.
1 parent d192712 commit 743be54

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/ViewModels/Welcome.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,25 @@ public void AddRootNode()
173173
activePage.Popup = new CreateGroup(null);
174174
}
175175

176+
public RepositoryNode FindParentGroup(RepositoryNode node, RepositoryNode group = null)
177+
{
178+
var collection = (group == null) ? Preferences.Instance.RepositoryNodes : group.SubNodes;
179+
if (collection.Contains(node))
180+
return group;
181+
182+
foreach (var item in collection)
183+
{
184+
if (!item.IsRepository)
185+
{
186+
var parent = FindParentGroup(node, item);
187+
if (parent != null)
188+
return parent;
189+
}
190+
}
191+
192+
return null;
193+
}
194+
176195
public void MoveNode(RepositoryNode from, RepositoryNode to)
177196
{
178197
Preferences.Instance.MoveNode(from, to, true);

src/Views/Welcome.axaml.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private void DragOverTreeNode(object sender, DragEventArgs e)
215215
if (to == null)
216216
return;
217217

218-
e.DragEffects = to.IsRepository ? DragDropEffects.None : DragDropEffects.Move;
218+
e.DragEffects = DragDropEffects.Move;
219219
e.Handled = true;
220220
}
221221
}
@@ -226,12 +226,15 @@ private void DropOnTreeNode(object sender, DragEventArgs e)
226226
return;
227227

228228
var to = grid.DataContext as ViewModels.RepositoryNode;
229-
if (to == null || to.IsRepository)
229+
if (to == null)
230230
{
231231
e.Handled = true;
232232
return;
233233
}
234234

235+
if (to.IsRepository)
236+
to = ViewModels.Welcome.Instance.FindParentGroup(to);
237+
235238
if (e.Data.Contains("MovedRepositoryTreeNode") &&
236239
e.Data.Get("MovedRepositoryTreeNode") is ViewModels.RepositoryNode moved)
237240
{

0 commit comments

Comments
 (0)