private void GroupsTree_DragDrop(object o, DragDropArgs args) { Drag.Finish(args.Context, true, true, args.Time); if (grid.Selection.Count == 0) { return; } TreePath path; TreeViewDropPosition pos; groupsPanel.GroupsTree.GetDestRowAtPos(args.X, args.Y, out path, out pos); TreeIter row; groupsPanel.GroupsTree.Model.GetIter(out row, path); G group = (G)groupsPanel.GroupsTree.Model.GetValue(row, 2); using (Message messageDialog = GetMovingToGroupMessage(group.Name)) { messageDialog.Buttons = MessageButtons.YesNo; if (messageDialog.Run() != ResponseType.Yes) { return; } foreach (int selectedIndex in grid.Selection) { object entity = grid.Model [selectedIndex]; IPersistableEntity <T> persistableEntity = entity as IPersistableEntity <T>; if (persistableEntity == null) { continue; } IHirarchicalEntity hirarchicalEntity = entity as IHirarchicalEntity; if (hirarchicalEntity == null) { continue; } if (group.Id == GroupBase <G> .DeletedGroupId) { hirarchicalEntity.Deleted = true; hirarchicalEntity.GroupId = GroupBase <G> .DefaultGroupId; } else { hirarchicalEntity.Deleted = false; hirarchicalEntity.GroupId = group.Id; } persistableEntity.CommitChanges(); } OnEntitiesChanged(groupsPanel.GetSelectedGroupId()); OnEntitiesMovedToAGroup(); } }
private void GroupsTree_DragDrop(object o, DragDropArgs args) { if (Drag.GetSourceWidget(args.Context) != groupsTree) { return; } TreePath path; TreeViewDropPosition pos; groupsTree.GetDestRowAtPos(args.X, args.Y, out path, out pos); TreeIter row; groupsTree.Model.GetIter(out row, path); T group = (T)groupsTree.Model.GetValue(row, 2); int insertionIndex = GetInsertionIndex(pos, ref group); TreeIter selectedRow; if (!groupsTree.Selection.GetSelected(out selectedRow)) { args.RetVal = true; Drag.Finish(args.Context, false, false, args.Time); return; } TreePath draggedPath = groupsTree.Model.GetPath(selectedRow); if (draggedPath.Equals(path) || draggedPath.IsAncestor(path)) { args.RetVal = true; Drag.Finish(args.Context, false, false, args.Time); return; } T draggedGroup = RemoveFromOldPosition(group, selectedRow, ref insertionIndex); MoveGroup(draggedGroup, insertionIndex, group); args.RetVal = true; Drag.Finish(args.Context, true, true, args.Time); TreePath movedPath = LoadGroups(false, draggedGroup); groupsTree.ExpandToPath(movedPath); }