protected override bool OnDragDrop(Gdk.DragContext context, int x, int y, uint time)
        {
            ActionPaletteItem dropped = DND.Drop(context, null, time) as ActionPaletteItem;

            if (dropped == null)
            {
                return(false);
            }

            if (dropped.Node.Type != Gtk.UIManagerItemType.Menuitem &&
                dropped.Node.Type != Gtk.UIManagerItemType.Menu &&
                dropped.Node.Type != Gtk.UIManagerItemType.Toolitem &&
                dropped.Node.Type != Gtk.UIManagerItemType.Separator)
            {
                return(false);
            }

            ActionTreeNode newNode = null;

            // Toolitems are copied, not moved

            using (wrapper.UndoManager.AtomicChange)
            {
                if (dropped.Node.ParentNode != null && dropped.Node.Type != Gtk.UIManagerItemType.Toolitem)
                {
                    if (dropIndex < nodes.Count)
                    {
                        // Do nothing if trying to drop the node over the same node
                        ActionTreeNode dropNode = nodes [dropIndex];
                        if (dropNode == dropped.Node)
                        {
                            return(false);
                        }

                        dropped.Node.ParentNode.Children.Remove(dropped.Node);

                        // The drop position may have changed after removing the dropped node,
                        // so get it again.
                        dropIndex = nodes.IndexOf(dropNode);
                        nodes.Insert(dropIndex, dropped.Node);
                    }
                    else
                    {
                        dropped.Node.ParentNode.Children.Remove(dropped.Node);
                        nodes.Add(dropped.Node);
                        dropIndex = nodes.Count - 1;
                    }
                }
                else
                {
                    newNode = new ActionTreeNode(Gtk.UIManagerItemType.Menuitem, null, dropped.Node.Action);
                    nodes.Insert(dropIndex, newNode);
                }
                // Select the dropped node
                ActionMenuItem mi = (ActionMenuItem)menuItems [dropIndex];
                mi.Select();
            }

            return(base.OnDragDrop(context, x, y, time));
        }
예제 #2
0
        protected override bool OnDragMotion(Gdk.DragContext context, int x, int y, uint time)
        {
            ActionPaletteItem dragItem = DND.DragWidget as ActionPaletteItem;

            if (dragItem == null)
            {
                return(false);
            }

            if (actionTree.Children.Count > 0)
            {
                ActionMenuItem item = LocateWidget(x, y);
                if (item != null)
                {
                    Widget wrapper = Widget.Lookup(this);

                    // Show the submenu to allow droping to it, but avoid
                    // droping a submenu inside itself
                    if (item.HasSubmenu && item.Node != dragItem.Node)
                    {
                        item.ShowSubmenu(wrapper.GetDesignArea(), item);
                    }

                    // Look for the index where to insert the new item
                    dropIndex = actionTree.Children.IndexOf(item.Node);
                    int mpos = item.Allocation.X + item.Allocation.Width / 2;
                    if (x > mpos)
                    {
                        dropIndex++;
                    }

                    // Calculate the drop position, used to show the drop bar
                    if (dropIndex == 0)
                    {
                        dropPosition = item.Allocation.X;
                    }
                    else if (dropIndex == menuItems.Count)
                    {
                        dropPosition = item.Allocation.Right;
                    }
                    else
                    {
                        item = (ActionMenuItem)menuItems [dropIndex];
                        ActionMenuItem prevItem = (ActionMenuItem)menuItems [dropIndex - 1];
                        dropPosition = prevItem.Allocation.Right + (item.Allocation.X - prevItem.Allocation.Right) / 2;
                    }
                }
            }
            else
            {
                dropIndex = 0;
            }

            QueueDraw();
            return(base.OnDragMotion(context, x, y, time));
        }
        protected override bool OnDragMotion(Gdk.DragContext context, int x, int y, uint time)
        {
            ActionPaletteItem dragItem = DND.DragWidget as ActionPaletteItem;

            if (dragItem == null)
            {
                return(false);
            }

            x += Allocation.X;
            y += Allocation.Y;

            if (actionTree.Children.Count > 0)
            {
                ActionToolItem item = LocateWidget(x, y);
                if (item != null)
                {
                    // Look for the index where to insert the new item
                    dropIndex = actionTree.Children.IndexOf(item.Node);
                    int spos = (Orientation == Gtk.Orientation.Horizontal) ? x : y;
                    int mpos = GetButtonPos(item) + GetButtonSize(item) / 2;
                    if (spos > mpos)
                    {
                        dropIndex++;
                    }

                    // Calculate the drop position, used to show the drop bar
                    if (dropIndex == 0)
                    {
                        dropPosition = GetButtonPos(item);
                    }
                    else if (dropIndex == toolItems.Count)
                    {
                        dropPosition = GetButtonEndPos(item);
                    }
                    else
                    {
                        item = (ActionToolItem)toolItems [dropIndex];
                        ActionToolItem prevItem = (ActionToolItem)toolItems [dropIndex - 1];
                        dropPosition = GetButtonEndPos(prevItem) + (GetButtonPos(item) - GetButtonEndPos(prevItem)) / 2;
                    }
                }
            }
            else
            {
                dropIndex = 0;
            }

            QueueDraw();
            return(base.OnDragMotion(context, x, y, time));
        }
예제 #4
0
        public virtual void ProcessDragBegin(Gdk.DragContext ctx, Gdk.EventMotion evt)
        {
            editOnRelease = false;
            ActionPaletteItem item = new ActionPaletteItem(node);

            if (ctx != null)
            {
                DND.Drag(parentMenu.Widget, ctx, item);
            }
            else
            {
                DND.Drag(parentMenu.Widget, evt, item);
            }
        }
예제 #5
0
        protected override bool OnDragDrop(Gdk.DragContext context, int x, int y, uint time)
        {
            ActionPaletteItem dropped = DND.Drop(context, null, time) as ActionPaletteItem;

            if (dropped == null)
            {
                return(false);
            }

            if (dropped.Node.Type != Gtk.UIManagerItemType.Menuitem &&
                dropped.Node.Type != Gtk.UIManagerItemType.Menu &&
                dropped.Node.Type != Gtk.UIManagerItemType.Toolitem &&
                dropped.Node.Type != Gtk.UIManagerItemType.Separator)
            {
                return(false);
            }

            ActionTreeNode newNode = dropped.Node;

            if (dropped.Node.Type == Gtk.UIManagerItemType.Toolitem)
            {
                newNode      = newNode.Clone();
                newNode.Type = Gtk.UIManagerItemType.Menuitem;
            }

            Widget wrapper = Widget.Lookup(this);

            using (wrapper.UndoManager.AtomicChange) {
                if (dropIndex < actionTree.Children.Count)
                {
                    // Do nothing if trying to drop the node over the same node
                    ActionTreeNode dropNode = actionTree.Children [dropIndex];
                    if (dropNode == dropped.Node)
                    {
                        return(false);
                    }

                    if (newNode.ParentNode != null)
                    {
                        newNode.ParentNode.Children.Remove(newNode);
                    }

                    // The drop position may have changed after removing the dropped node,
                    // so get it again.
                    dropIndex = actionTree.Children.IndexOf(dropNode);
                    actionTree.Children.Insert(dropIndex, newNode);
                }
                else
                {
                    if (newNode.ParentNode != null)
                    {
                        newNode.ParentNode.Children.Remove(newNode);
                    }
                    actionTree.Children.Add(newNode);
                    dropIndex = actionTree.Children.Count - 1;
                }

                // Select the dropped node
                ActionMenuItem mi = (ActionMenuItem)menuItems [dropIndex];
                mi.Select();
            }

            return(base.OnDragDrop(context, x, y, time));
        }