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();
            }
        }
 protected virtual void OnDragDestSet()
 {
     if (ForceDragDestSet || Reorderable || RowsDraggable)
     {
         Drag.DestSet(this, DestDefaults.All, DragDropDestEntries, DragAction.Move);
     }
     else
     {
         Drag.DestUnset(this);
     }
 }
        private void GroupsTree_DragMotion(object o, DragMotionArgs args)
        {
            TreePath             path;
            TreeViewDropPosition pos;

            if (BusinessDomain.LoggedUser.UserLevel == UserAccessLevel.Operator ||
                !groupsTree.GetDestRowAtPos(args.X, args.Y, out path, out pos))
            {
                args.RetVal = false;
                return;
            }

            if (Drag.GetSourceWidget(args.Context) == groupsTree)
            {
                TreeIter selectedRow;
                if (groupsTree.Selection.GetSelected(out selectedRow))
                {
                    if (groupsTree.Model.GetValue(selectedRow, 2) == deletedGroup)
                    {
                        args.RetVal = false;
                        return;
                    }
                    TreePath draggedPath = groupsTree.Model.GetPath(selectedRow);
                    if (!draggedPath.Equals(path) && !draggedPath.IsAncestor(path))
                    {
                        TreeIter destRow;
                        groupsTree.Model.GetIter(out destRow, path);
                        if (groupsTree.Model.GetValue(destRow, 2) == deletedGroup)
                        {
                            args.RetVal = false;
                            return;
                        }
                        groupsTree.SetDragDestRow(path, pos);
                    }
                }
            }
            else
            {
                switch (pos)
                {
                case TreeViewDropPosition.Before:
                    groupsTree.SetDragDestRow(path, TreeViewDropPosition.IntoOrBefore);
                    break;

                case TreeViewDropPosition.After:
                    groupsTree.SetDragDestRow(path, TreeViewDropPosition.IntoOrAfter);
                    break;
                }
            }
            Gdk.Drag.Status(args.Context, args.Context.SuggestedAction, args.Time);

            args.RetVal = true;
        }
 protected virtual void OnDragSourceSet()
 {
     if (ForceDragSourceSet || Reorderable || RowsDraggable)
     {
         Drag.SourceSet(this, ModifierType.Button1Mask | ModifierType.Button3Mask,
                        DragDropDestEntries, DragAction.Copy | DragAction.Move);
     }
     else
     {
         Drag.SourceUnset(this);
     }
 }
        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);
        }
Exemple #6
0
 public static Widget GetSourceWidget(this DragContext context)
 {
     return(Drag.GetSourceWidget(context));
 }