Inheritance: System.Windows.Forms.UserControl
Example #1
0
        private ContextMenuItem AddContextMenuItem(string name = "", string func = "", int subitem = 0, bool submenu = false, int position = -1)
        {
            List <ContextMenuItem> CurrentList = GetContextMenuList();

            ContextMenuItem item = new ContextMenuItem(name, func);

            item.Location = new System.Drawing.Point(0, (item.Height - 2) * CurrentList.Count);

            GetCurrentContextMenuPanel().Controls.Add(item);

            if (position == -1)
            {
                // add to bottom
                CurrentList.Add(item);
            }
            else
            {
                // add at position
                CurrentList.Insert(position, item);
                RefreshContextMenuItems();
            }

            item.AddConfigWindowReference(this);
            item.SetSubitem(subitem);
            item.SetSubmenu(submenu);

            return(item);
        }
Example #2
0
        public void SetupGhost(ContextMenuItem item)
        {
            if (GhostItem.Parent != null)
            {
                return;
            }

            GhostItem.UpdateCustomActions();
            GhostItem.ItemName.Text     = item.ItemName.Text;
            GhostItem.ItemFunction.Text = item.ItemFunction.Text;
            GhostItem.Indent            = item.Indent;
            GhostItem.IsEnabled         = false;
        }
Example #3
0
        private void SaveContextMenu(List <object> contextMenu, Panel panel)
        {
            int           currentSubLevel = 0;
            List <object> currentMenu     = contextMenu;
            List <object> prevMenu        = null;

            for (int i = 0; i < panel.Children.Count; i++)
            {
                ContextMenuItem item = (ContextMenuItem)panel.Children[i];
                if (i < panel.Children.Count - 1 && ((ContextMenuItem)panel.Children[i + 1]).Indent > item.Indent)
                {
                    // Submenu
                    currentMenu.Add(item.ItemName.Text);
                }
                else if (item.Indent != 0)
                {
                    // Subitem
                    if (item.Indent > currentSubLevel)
                    {
                        // First subitem
                        currentSubLevel = item.Indent;
                        currentMenu.Add(new List <object>());
                        prevMenu    = currentMenu;
                        currentMenu = currentMenu[currentMenu.Count - 1] as List <object>;
                    }
                    else if (item.Indent < currentSubLevel)
                    {
                        currentSubLevel = item.Indent;
                        currentMenu     = prevMenu;
                    }

                    currentMenu.Add(new { name = item.ItemName.Text, func = item.ItemFunction.Text.Trim() });
                }
                else
                {
                    // Item
                    if (currentSubLevel != 0)
                    {
                        currentSubLevel = 0;
                        currentMenu     = contextMenu;
                    }

                    currentMenu.Add(new { name = item.ItemName.Text, func = item.ItemFunction.Text.Trim() });
                }
            }
        }
Example #4
0
        private void LoadItems(List <object> items, Panel panel, ContextMenuEditorCanvas canvas, ScrollViewer scroll, int indent = 0)
        {
            for (int i = 0; i < items.Count; i++)
            {
                dynamic o = (items[i] as dynamic);

                if (o is List <object> )
                {
                    LoadItems(o, panel, canvas, scroll, indent + 1);
                }
                else
                {
                    ContextMenuItem item = new ContextMenuItem(o is string?o: o.name, o is string? "" : o.func, this, panel, canvas, scroll, indent);
                    panel.Children.Add(item);
                    Items.Add(item);

                    Canvas.SetTop(item, item.MinHeight * (panel.Children.Count - 1));
                }
            }
        }
Example #5
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            Panel panel = Tabs.SelectedIndex == 0 ? ContextMenuItems_General : ContextMenuItems_Animation;
            ContextMenuEditorCanvas canvas = Tabs.SelectedIndex == 0 ? ContextMenuItems_GeneralCanvas : ContextMenuItems_AnimationCanvas;
            ScrollViewer            scroll = Tabs.SelectedIndex == 0 ? ContextMenuItems_GeneralScroll : ContextMenuItems_AnimationScroll;

            ContextMenuItem item = new ContextMenuItem("", "", this, panel, canvas, scroll, CurrentItemSelection == null ? 0 : CurrentItemSelection.Indent);

            if (CurrentItemSelection == null)
            {
                panel.Children.Add(item);
                Items.Add(item);

                Canvas.SetTop(item, item.MinHeight * (panel.Children.Count - 1));
            }
            else
            {
                panel.Children.Insert(panel.Children.IndexOf(CurrentItemSelection) + 1, item);
                Items.Insert(Items.IndexOf(CurrentItemSelection) + 1, item);
            }

            CurrentItemSelection?.UnselectItem();
            item.SelectItem(true);
        }
Example #6
0
        private ContextMenuItem AddContextMenuItem(string name = "", string func = "", int subitem = 0, bool submenu = false, int position = -1)
        {
            List<ContextMenuItem> CurrentList = GetContextMenuList();

            ContextMenuItem item = new ContextMenuItem(name, func, vimageConfig);
            item.Location = new System.Drawing.Point(0, (item.Height - 2) * CurrentList.Count);

            GetCurrentContextMenuPanel().Controls.Add(item);

            if (position == -1)
            {
                // add to bottom
                CurrentList.Add(item);
            }
            else
            {
                // add at position
                CurrentList.Insert(position, item);
                RefreshContextMenuItems();
            }

            item.AddConfigWindowReference(this);
            item.SetSubitem(subitem);
            item.SetSubmenu(submenu);

            return item;
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                // start dragging
                if (!Dragging && Parent == ParentPanel && ParentCanvas.MovingItem == null && e.GetPosition(null).X < (Indent + 1) * 30)
                {
                    Dragging = true;
                }

                if (Dragging)
                {
                    // update position
                    double posX = e.GetPosition(ParentCanvas).X - AnchorPoint.X;
                    double posY = e.GetPosition(ParentCanvas).Y - AnchorPoint.Y;
                    int    i    = Math.Max((int)Math.Round((posY + ((MinHeight - 2) / 2)) / (MinHeight - 2)), 0);
                    i = Math.Min(i, ParentPanel.Children.Count);

                    double top = Math.Max(i * (MinHeight - 2), 0);
                    Canvas.SetTop(ParentCanvas.SelectionRect, top - 2);

                    int indent = 0;
                    if (i != 0)
                    {
                        ContextMenuItem itemAbove = (ContextMenuItem)ParentPanel.Children[i - 1];
                        if (posX >= (itemAbove.Indent + 1) * 30)
                        {
                            indent = itemAbove.Indent + 1;
                        }
                        else if (posX >= itemAbove.Indent * 30)
                        {
                            indent = itemAbove.Indent;
                        }
                    }
                    Canvas.SetLeft(ParentCanvas.SelectionRect, indent * 30);

                    Indent = indent;
                    ParentCanvas.InsertAtIndex = i;

                    Canvas.SetTop(this, posY);
                    Canvas.SetLeft(this, posX);

                    // scroll window when dragging past top/bottom
                    if (posY + MinHeight > ScrollViewer.ActualHeight + ScrollViewer.VerticalOffset)
                    {
                        ScrollViewer.ScrollToVerticalOffset(ScrollViewer.VerticalOffset + (posY - (ScrollViewer.ActualHeight + ScrollViewer.VerticalOffset - MinHeight)));
                    }
                    else if (posY < ScrollViewer.VerticalOffset)
                    {
                        ScrollViewer.ScrollToVerticalOffset(ScrollViewer.VerticalOffset - (ScrollViewer.VerticalOffset - posY));
                    }

                    e.Handled = true;
                }
            }
            else if (Dragging)
            {
                Dragging = false;
            }
        }