Ejemplo n.º 1
0
        private void MouseEnter(object sender, EventArgs e)
        {
            ToolStripMenuItem     item2 = sender as ToolStripMenuItem;
            ToolStripDropDownMenu menu  = item2.Owner as ToolStripDropDownMenu;

            menu.Show();
        }
Ejemplo n.º 2
0
        private void MouseEnter(object sender, EventArgs e)
        {
            ToolStripMenuItem     item2 = (ToolStripMenuItem)sender;
            ToolStripDropDownMenu menu  = (ToolStripDropDownMenu)item2.Owner;

            menu.Show();
        }
Ejemplo n.º 3
0
    /// <summary>
    /// Shows ToolStripDropDownMenu menu at the cursor or caret position, like it would be a ContextMenuStrip menu.
    /// </summary>
    /// <remarks>
    /// This way is undocumented and possibly will stop working in future .NET versions. I did not find a better way.
    /// </remarks>
    public static void ZShowAsContextMenu(this ToolStripDropDownMenu t, bool caret = false)
    {
        if (!(caret && Api.GetCaretPosInScreen_(out POINT p)))
        {
            Api.GetCursorPos(out p);
        }
        var oi = t.OwnerItem; t.OwnerItem = null;         //to set position

        try { t.Show(p); }
        finally { t.OwnerItem = oi; }
    }
Ejemplo n.º 4
0
        protected override void OnDropDown(EventArgs e)
        {
            base.OnDropDown(e);

            this.DropDownHeight = 1;

            if (popup.Visible)
            {
                return;
            }

            Rectangle rect     = RectangleToScreen(this.ClientRectangle);
            Point     location = new Point(rect.X, rect.Y + this.Size.Height);

            popup.Show(location, ToolStripDropDownDirection.BelowRight);
        }
Ejemplo n.º 5
0
        private void ShowContextMenuStrip()
        {
            if (skipNextOpen)
            {
                // we were called because we're closing the context menu strip
                // when clicking the dropdown button.
                skipNextOpen = false;
                return;
            }

            State = PushButtonState.Pressed;

            if (m_SplitMenu != null)
            {
                m_SplitMenu.Show(this, new Point(0, Height));
            }
            else if (m_SplitMenuStrip != null)
            {
                m_SplitMenuStrip.Show(this, new Point(0, Height), ToolStripDropDownDirection.BelowRight);
            }
        }
Ejemplo n.º 6
0
        private void ShowContextMenu(Point location)
        {
            ToolStripDropDownItem addItem = new ToolStripMenuItem();

            addItem.Name = "addMenu";
            addItem.Text = "Add Element";

            ToolStripMenuItem addSimpleRectItem = new ToolStripMenuItem
            {
                Name = "addSimpleRectItem",
                Text = "SimpleRectangle"
            };

            addSimpleRectItem.MouseDown += (sender, e) => { AddNodeElement(location); };

            addItem.DropDownItems.Add(addSimpleRectItem);
            ToolStripDropDownMenu contextMenu = new ToolStripDropDownMenu();

            contextMenu.Items.Add(addItem);
            contextMenu.Show(this, location);
        }
Ejemplo n.º 7
0
        protected override void OnSelectedIndexChanged(EventArgs e)
        {
            foreach (PlayerListItem i in Items)
            {
                i.Selected = false;
            }
            foreach (PlayerListItem i in SelectedItems)
            {
                i.Selected = true;
            }

            base.OnSelectedIndexChanged(e);
            if (SelectedItem == null)
            {
                return;
            }
            SelectedUsername = ((PlayerListItem)SelectedItem).Item.Username;
            Rectangle r = GetItemRectangle(SelectedIndex);

            dropDown.Show(this, r.Location, ToolStripDropDownDirection.BelowLeft);
            Refresh();
        }
Ejemplo n.º 8
0
        public override GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, GH_CanvasMouseEvent e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Grasshopper.Kernel.Special.GH_ValueListItem firstSelectedItem = this.Owner.FirstSelectedItem;
                if (firstSelectedItem.BoxRight.Contains(e.CanvasLocation))
                {
                    ToolStripDropDownMenu menu = new ToolStripDropDownMenu();
                    menu.AutoClose = true;

                    foreach (ToolStripMenuItem toolStripItem in this.collectionToolStripMenuItems)
                    {
                        menu.Items.Add(toolStripItem);
                    }

                    menu.Show(sender, e.ControlLocation);

                    return(GH_ObjectResponse.Handled);
                }
            }
            return(base.RespondToMouseDown(sender, e));
        }
Ejemplo n.º 9
0
        protected override void RespondToMouseUp(GH_Canvas canvas, GH_CanvasMouseEvent @event)
        {
            bool flag = true;
            ToolStripDropDownMenu obj = new ToolStripDropDownMenu
            {
                ShowCheckMargin = false,
                ShowImageMargin = false
            };

            bool  isNull;
            Color color = GetValue(out isNull);

            color = isNull ? Color.Transparent : color;
            GH_DocumentObject.Menu_AppendColourPicker(obj, color, ColourChanged);
            obj.Show(canvas, @event.ControlLocation);

            void ColourChanged(GH_ColourPicker sender, GH_ColourPickerEventArgs e)
            {
                SetValue(e.Colour, flag);
                flag = false;
            }
        }
Ejemplo n.º 10
0
        private void ValueMenuItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem item2 = (ToolStripMenuItem)sender;

            if (!item2.Checked)
            {
                item2.Checked = true;
                // Add to Design Space
                ToolStripDropDownMenu menu = (ToolStripDropDownMenu)item2.Owner;
                menu.Show();
                this.ExpireSolution(true);
                return;
            }
            else
            {
                item2.Checked = false;
                // Remove from Design Space
                ToolStripDropDownMenu menu = (ToolStripDropDownMenu)item2.Owner;
                menu.Show();
                this.ExpireSolution(true);
                return;
            }
        }
Ejemplo n.º 11
0
        public override GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, GH_CanvasMouseEvent e)
        {
            if (e.Button == MouseButtons.Left)
            {
                switch (this.Owner.ListMode)
                {
                case GH_ValueListMode.CheckList:
                {
                    int arg_4A_0 = 0;
                    int num      = this.Owner.ListItems.Count - 1;
                    for (int i = arg_4A_0; i <= num; i++)
                    {
                        GuanacoListItem item = this.Owner.ListItems[i];
                        if (item.BoxLeft.Contains(e.CanvasLocation))
                        {
                            this.Owner.ToggleItem(i);
                            return(GH_ObjectResponse.Handled);
                        }
                    }
                    break;
                }

                case GH_ValueListMode.DropDown:
                {
                    GuanacoListItem item2 = this.Owner.FirstSelectedItem;
                    if (item2 != null)
                    {
                        if (item2.BoxRight.Contains(e.CanvasLocation))
                        {
                            List <GuanacoListItem> .Enumerator enumerator;
                            ToolStripDropDownMenu menu       = new ToolStripDropDownMenu();
                            GuanacoListItem       activeItem = this.Owner.FirstSelectedItem;
                            enumerator = this.Owner.ListItems.GetEnumerator();
                            try
                            {
                                enumerator = this.Owner.ListItems.GetEnumerator();
                                while (enumerator.MoveNext())
                                {
                                    GuanacoListItem   existingItem = enumerator.Current;
                                    ToolStripMenuItem menuItem     = new ToolStripMenuItem(existingItem.Name);
                                    menuItem.Click += new EventHandler(this.ValueMenuItem_Click);
                                    if (existingItem == activeItem)
                                    {
                                        menuItem.Checked = true;
                                    }
                                    menuItem.Tag = existingItem;
                                    menu.Items.Add(menuItem);
                                }
                            }
                            finally
                            {
                                enumerator.Dispose();
                            }
                            menu.Show(sender, e.ControlLocation);
                            return(GH_ObjectResponse.Handled);
                        }
                    }
                    break;
                }
                }
            }
            return(base.RespondToMouseDown(sender, e));
        }
Ejemplo n.º 12
0
        public static ToolStripItem[] RecentMenu(this RecentFiles recent, Action <string> loadFileCallback, string entrySemantic, bool noAutoload = false, bool romLoading = false)
        {
            var items = new List <ToolStripItem>();

            if (recent.Empty)
            {
                var none = new ToolStripMenuItem {
                    Enabled = false, Text = "None"
                };
                items.Add(none);
            }
            else
            {
                foreach (var filename in recent)
                {
                    string caption      = filename;
                    string path         = filename;
                    string physicalPath = filename;
                    bool   crazyStuff   = true;

                    //sentinel for newer format OpenAdvanced type code
                    if (romLoading)
                    {
                        if (filename.StartsWith("*"))
                        {
                            var oa = OpenAdvancedSerializer.ParseWithLegacy(filename);
                            caption = oa.DisplayName;

                            crazyStuff = false;
                            if (oa is OpenAdvanced_OpenRom openRom)
                            {
                                crazyStuff   = true;
                                physicalPath = openRom.Path;
                            }
                        }
                    }

                    // TODO - do TSMI and TSDD need disposing? yuck
                    var item = new ToolStripMenuItem {
                        Text = caption.Replace("&", "&&")
                    };
                    items.Add(item);

                    item.Click += (o, ev) =>
                    {
                        loadFileCallback(path);
                    };

                    var tsdd = new ToolStripDropDownMenu();

                    if (crazyStuff)
                    {
                        //TODO - use standard methods to split filename (hawkfile acquire?)
                        var  hf         = new HawkFile(physicalPath ?? throw new Exception("this will probably never appear but I can't be bothered checking --yoshi"), delayIOAndDearchive: true);
                        bool canExplore = File.Exists(hf.FullPathWithoutMember);

                        if (canExplore)
                        {
                            //make a menuitem to show the last modified timestamp
                            var timestamp     = File.GetLastWriteTime(hf.FullPathWithoutMember);
                            var tsmiTimestamp = new ToolStripLabel {
                                Text = timestamp.ToString()
                            };

                            tsdd.Items.Add(tsmiTimestamp);
                            tsdd.Items.Add(new ToolStripSeparator());

                            if (hf.IsArchive)
                            {
                                //make a menuitem to let you copy the path
                                var tsmiCopyCanonicalPath = new ToolStripMenuItem {
                                    Text = "&Copy Canonical Path"
                                };
                                tsmiCopyCanonicalPath.Click += (o, ev) => { Clipboard.SetText(physicalPath); };
                                tsdd.Items.Add(tsmiCopyCanonicalPath);

                                var tsmiCopyArchivePath = new ToolStripMenuItem {
                                    Text = "Copy Archive Path"
                                };
                                tsmiCopyArchivePath.Click += (o, ev) => { Clipboard.SetText(hf.FullPathWithoutMember); };
                                tsdd.Items.Add(tsmiCopyArchivePath);

                                var tsmiOpenArchive = new ToolStripMenuItem {
                                    Text = "Open &Archive"
                                };
                                tsmiOpenArchive.Click += (o, ev) => { System.Diagnostics.Process.Start(hf.FullPathWithoutMember); };
                                tsdd.Items.Add(tsmiOpenArchive);
                            }
                            else
                            {
                                // make a menuitem to let you copy the path
                                var tsmiCopyPath = new ToolStripMenuItem {
                                    Text = "&Copy Path"
                                };
                                tsmiCopyPath.Click += (o, ev) => { Clipboard.SetText(physicalPath); };
                                tsdd.Items.Add(tsmiCopyPath);
                            }

                            tsdd.Items.Add(new ToolStripSeparator());

                            // make a menuitem to let you explore to it
                            var tsmiExplore = new ToolStripMenuItem {
                                Text = "&Explore"
                            };
                            string explorePath = $"\"{hf.FullPathWithoutMember}\"";
                            tsmiExplore.Click += (o, ev) => { System.Diagnostics.Process.Start("explorer.exe", $"/select, {explorePath}"); };
                            tsdd.Items.Add(tsmiExplore);

                            var tsmiCopyFile = new ToolStripMenuItem {
                                Text = "Copy &File"
                            };
                            var lame = new System.Collections.Specialized.StringCollection
                            {
                                hf.FullPathWithoutMember
                            };

                            tsmiCopyFile.Click += (o, ev) => { Clipboard.SetFileDropList(lame); };
                            tsdd.Items.Add(tsmiCopyFile);

                            var tsmiTest = new ToolStripMenuItem {
                                Text = "&Shell Context Menu"
                            };
                            tsmiTest.Click += (o, ev) =>
                            {
                                var si    = new GongSolutions.Shell.ShellItem(hf.FullPathWithoutMember);
                                var scm   = new GongSolutions.Shell.ShellContextMenu(si);
                                var tsddi = o as ToolStripDropDownItem;
                                tsddi.Owner.Update();
                                scm.ShowContextMenu(tsddi.Owner, new System.Drawing.Point(0, 0));
                            };
                            tsdd.Items.Add(tsmiTest);

                            tsdd.Items.Add(new ToolStripSeparator());
                        }
                        else
                        {
                            //make a menuitem to show the last modified timestamp
                            var tsmiMissingFile = new ToolStripLabel {
                                Text = "-Missing-"
                            };
                            tsdd.Items.Add(tsmiMissingFile);
                            tsdd.Items.Add(new ToolStripSeparator());
                        }
                    }                     //crazystuff

                    //in any case, make a menuitem to let you remove the item
                    var tsmiRemovePath = new ToolStripMenuItem {
                        Text = "&Remove"
                    };
                    tsmiRemovePath.Click += (o, ev) => {
                        recent.Remove(path);
                    };
                    tsdd.Items.Add(tsmiRemovePath);

#if false //experiment of popping open a submenu. doesn't work well.
                    item.MouseDown += (o, mev) =>
                    {
                        if (mev.Button != MouseButtons.Right)
                        {
                            return;
                        }
                        //location of the menu containing this item that was just right-clicked
                        var pos = item.Owner.Bounds.Location;
                        //the offset within that menu of this item
                        pos.Offset(item.Bounds.Location);
                        //the offset of the click
                        pos.Offset(mev.Location);
//						tsdd.OwnerItem = item; //has interesting promise, but breaks things otherwise
                        tsdd.Show(pos);
                    };
#endif

                    //just add it to the submenu for now. seems to work well enough, even though its a bit odd
                    item.MouseDown += (o, mev) =>
                    {
                        if (mev.Button != MouseButtons.Right)
                        {
                            return;
                        }
                        if (item.DropDown != null)
                        {
                            item.DropDown = tsdd;
                        }
                        item.ShowDropDown();
                    };
                }
            }

            items.Add(new ToolStripSeparator());

            var clearItem = new ToolStripMenuItem {
                Text = "&Clear", Enabled = !recent.Frozen
            };
            clearItem.Click += (o, ev) => recent.Clear();
            items.Add(clearItem);

            var freezeItem = new ToolStripMenuItem
            {
                Text  = recent.Frozen ? "&Unfreeze" : "&Freeze",
                Image = recent.Frozen ? Properties.Resources.Unfreeze : Properties.Resources.Freeze
            };
            freezeItem.Click += (o, ev) => recent.Frozen ^= true;
            items.Add(freezeItem);

            if (!noAutoload)
            {
                var auto = new ToolStripMenuItem {
                    Text = $"&Autoload {entrySemantic}", Checked = recent.AutoLoad
                };
                auto.Click += (o, ev) => recent.ToggleAutoLoad();
                items.Add(auto);
            }

            var settingsItem = new ToolStripMenuItem {
                Text = "&Recent Settings..."
            };
            settingsItem.Click += (o, ev) =>
            {
                using var prompt = new InputPrompt
                      {
                          TextInputType = InputPrompt.InputType.Unsigned,
                          Message       = "Number of recent files to track",
                          InitialValue  = recent.MAX_RECENT_FILES.ToString()
                      };
                var result = prompt.ShowDialog();
                if (result == DialogResult.OK)
                {
                    int val = int.Parse(prompt.PromptText);
                    if (val > 0)
                    {
                        recent.MAX_RECENT_FILES = val;
                    }
                }
            };
            items.Add(settingsItem);

            return(items.ToArray());
        }
Ejemplo n.º 13
0
        public override GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, GH_CanvasMouseEvent e)
        {
            if (e.Button == MouseButtons.Left)
            {
                switch (Owner.ListMode)
                {
                case GH_ValueListMode.CheckList:
                    int num = Owner.ListItems.Count - 1;
                    for (int index = 0; index <= num; ++index)
                    {
                        if (Owner.ListItems[index].BoxLeft.Contains(e.CanvasLocation))
                        {
                            Owner.ToggleItem(index);
                            return(GH_ObjectResponse.Handled);
                        }
                    }
                    break;

                case GH_ValueListMode.DropDown:
                    GH_ValueListItem firstSelectedItem1 = Owner.FirstSelectedItem;
                    if (firstSelectedItem1 != null && firstSelectedItem1.BoxRight.Contains(e.CanvasLocation))
                    {
                        ToolStripDropDownMenu stripDropDownMenu  = new ToolStripDropDownMenu();
                        GH_ValueListItem      firstSelectedItem2 = Owner.FirstSelectedItem;
                        foreach (GH_ValueListItem listItem in Owner.ListItems)
                        {
                            ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem(listItem.Name);
                            toolStripMenuItem.Click += new EventHandler(ValueMenuItem_Click);
                            if (listItem == firstSelectedItem2)
                            {
                                toolStripMenuItem.Checked = true;
                            }
                            toolStripMenuItem.Tag = (object)listItem;
                            stripDropDownMenu.Items.Add((ToolStripItem)toolStripMenuItem);
                        }
                        stripDropDownMenu.Show((Control)sender, e.ControlLocation);
                        return(GH_ObjectResponse.Handled);
                    }
                    break;

                case GH_ValueListMode.Sequence:
                case GH_ValueListMode.Cycle:
                    using (List <GH_ValueListItem> .Enumerator enumerator = Owner.ListItems.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            GH_ValueListItem current = enumerator.Current;
                            if (current.IsVisible)
                            {
                                if (current.BoxLeft.Contains(e.CanvasLocation))
                                {
                                    Owner.PrevItem();
                                    return(GH_ObjectResponse.Handled);
                                }
                                if (current.BoxRight.Contains(e.CanvasLocation))
                                {
                                    Owner.NextItem();
                                    return(GH_ObjectResponse.Handled);
                                }
                            }
                        }
                        break;
                    }
                }
            }
            return(base.RespondToMouseDown(sender, e));
        }
Ejemplo n.º 14
0
        public override GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, GH_CanvasMouseEvent e)
        {
            if (e.Button == MouseButtons.Left)
            {
                RectangleF       rectangleF;
                GH_ValueListItem item2 = this.Owner.FirstSelectedItem;
                if (item2 != null)
                {
                    rectangleF = item2.BoxRight;
                    if (rectangleF.Contains(e.CanvasLocation))
                    {
                        ToolStripDropDownMenu menu       = new ToolStripDropDownMenu();
                        GH_ValueListItem      activeItem = this.Owner.FirstSelectedItem;

                        var dict = new Dictionary <string, IList <GH_ValueListItem> >();
                        foreach (GH_ValueListItem listItem in this.Owner.ListItems)
                        {
                            string key = listItem.Name.StartingLetters();
                            if (!dict.ContainsKey(key))
                            {
                                dict[key] = new List <GH_ValueListItem>();
                            }
                            dict[key].Add(listItem);
                        }

                        if (dict.Keys.Count > 1)
                        {
                            foreach (var kvp in dict)
                            {
                                var menuItems = new List <ToolStripMenuItem>(kvp.Value.Count);
                                foreach (GH_ValueListItem listItem in kvp.Value)
                                {
                                    ToolStripMenuItem menuItem = new ToolStripMenuItem(listItem.Name);
                                    menuItem.Click += this.ValueMenuItem_Click;
                                    if (listItem == activeItem)
                                    {
                                        menuItem.Checked = true;
                                    }
                                    menuItem.Tag = listItem;
                                    menuItems.Add(menuItem);
                                }
                                ToolStripMenuItem keyItem = new ToolStripMenuItem(kvp.Key + "...", null, menuItems.ToArray());
                                menu.Items.Add(keyItem);
                            }
                        }
                        else
                        {
                            //Fallback: one category only
                            foreach (GH_ValueListItem listItem in this.Owner.ListItems)
                            {
                                ToolStripMenuItem menuItem = new ToolStripMenuItem(listItem.Name);
                                menuItem.Click += this.ValueMenuItem_Click;
                                if (listItem == activeItem)
                                {
                                    menuItem.Checked = true;
                                }
                                menuItem.Tag = listItem;
                                menu.Items.Add(menuItem);
                            }
                        }
                        menu.Show(sender, e.ControlLocation);
                        return(GH_ObjectResponse.Handled);
                    }
                }
            }
            return(base.RespondToMouseDown(sender, e));
        }