Ejemplo n.º 1
0
        protected ContextMenuTag CreateContextMenuTag(string tagText)
        {
            var tag = new ContextMenuTag();

            tag.Tag      = tagText;
            tag.TreeItem = this;
            return(tag);
        }
Ejemplo n.º 2
0
        public static ContextMenuTag CreateCommonMenuItems(
            MSWinForms.ContextMenuStrip Menu,
            MSWinForms.ListView LV,
            Options options = null)
        {
            // Use default options if none were passed
            if (options == null)
                options = new Options();

            // If no menu passed, use the menu associated with the LV
            if (Menu == null)
                Menu = LV.ContextMenuStrip;

            //
            // Create the context
            var Context = new ContextMenuTag()
            {
                lv = LV,
                options = options,
                menu = Menu
            };

            var DynMenus = new List<MSWinForms.ToolStripItem>();

            //
            // Copy/Select All
            if (options.MFlags.HasFlag(MenuFlags.CopyAndSelect))
            {
                // Copy
                Context.CopyItemMenu = new MSWinForms.ToolStripMenuItem()
                {
                    ShortcutKeys = (MSWinForms.Keys.Control | MSWinForms.Keys.C),
                    Text = "Copy"
                };
                Context.CopyItemMenu.Click += new EventHandler(menuCommonLVCopyItem_Click);

                // Select All
                Context.SelectAllMenu = new MSWinForms.ToolStripMenuItem()
                {
                    ShortcutKeys = (MSWinForms.Keys.Control | MSWinForms.Keys.A),
                    Text = "Select all"
                };
                Context.SelectAllMenu.Click += new EventHandler(menuCommonLVSelectAll_Click);

                // DeSelect All
                Context.DeSelectAllMenu = new MSWinForms.ToolStripMenuItem()
                {
                    ShortcutKeys = (MSWinForms.Keys.Control | MSWinForms.Keys.D),
                    Text = "De-Select all"
                };
                Context.DeSelectAllMenu.Click += new EventHandler(menuCommonLVDeSelectAll_Click);

                DynMenus.AddRange(new MSWinForms.ToolStripItem[]
                {
                    Context.CopyItemMenu,
                    Context.SelectAllMenu,
                    Context.DeSelectAllMenu,
                    new MSWinForms.ToolStripSeparator(),
                });
            }

            //
            // Find
            if (options.MFlags.HasFlag(MenuFlags.Find))
            {
                // FindFirst
                Context.FindFirstMenu = new MSWinForms.ToolStripMenuItem()
                {
                    ShortcutKeys = (MSWinForms.Keys.Control | MSWinForms.Keys.F),
                    Text = "Find",
                };
                Context.FindFirstMenu.Click += new EventHandler(menuCommonLVFindFirst_Click);

                // FindNext
                Context.FindNextMenu = new MSWinForms.ToolStripMenuItem()
                {
                    ShortcutKeys = MSWinForms.Keys.F3,
                    Text = "Find Next",
                };
                Context.FindNextMenu.Click += new EventHandler(menuCommonLVFindNext_Click);

                DynMenus.AddRange(new MSWinForms.ToolStripItem[]
                {
                    Context.FindFirstMenu,
                    Context.FindNextMenu,
                    new MSWinForms.ToolStripSeparator(),
                });
            }

            //
            // Delete
            if (options.MFlags.HasFlag(MenuFlags.Delete))
            {
                // Delete
                Context.DeleteMenu = new MSWinForms.ToolStripMenuItem()
                {
                    ShortcutKeys = MSWinForms.Keys.Delete,
                    Text = "Delete"
                };
                Context.DeleteMenu.Click += new EventHandler(menuCommonLVDeleteItem_Click);

                DynMenus.AddRange(new MSWinForms.ToolStripItem[]
                {
                    Context.DeleteMenu,
                    new MSWinForms.ToolStripSeparator()
                });
            }

            //
            // Export
            if (options.MFlags.HasFlag(MenuFlags.Export))
            {
                var ExportToTextFile = new MSWinForms.ToolStripMenuItem()
                {
                    ShortcutKeys = (MSWinForms.Keys.Control | MSWinForms.Keys.S),
                    Text = "Export to text file"
                };
                ExportToTextFile.Click += new EventHandler(menuCommonLVExportToTextFile_Click);

                DynMenus.AddRange(new MSWinForms.ToolStripItem[]
                {
                    ExportToTextFile,
                    new MSWinForms.ToolStripSeparator()
                });
            }

            //
            // Add all the dynamic menu items now
            if (DynMenus.Count > 0)
            {
                if (DynMenus[DynMenus.Count - 1] is MSWinForms.ToolStripSeparator)
                    DynMenus.RemoveAt(DynMenus.Count - 1);

                foreach (var m in DynMenus)
                    Menu.Items.Add(m);
            }

            //
            // Dynamic menu to be created based on column item click?
            if (options.OnGenColItemMenuItem != null && options.OnColItemMenuClick != null)
            {
                Menu.Opening += new CancelEventHandler(menuCommonLV_Opening);
                Menu.Closed  += new MSWinForms.ToolStripDropDownClosedEventHandler(menuCommonLV_Closed);
            }

            //
            // Install column sorter
            if (options.WantColSorting)
                LV.ColumnClick += new MSWinForms.ColumnClickEventHandler(lvCommon_ColumnClick);

            //
            // Associate the context with the tags of the listview and the menu
            Menu.Tag = Context;
            LV.Tag = Context;

            // Associate the menu with the LV
            LV.ContextMenuStrip = Menu;

            return Context;
        }
Ejemplo n.º 3
0
        private static bool DeselectPreviousSearchPos(ContextMenuTag lvCtx)
        {
            bool bDeSelected =
                   !lvCtx.options.FindNextMultiSelect
                && lvCtx.SearchPos != 0
                && (lvCtx.SearchPos - 1) < lvCtx.lv.Items.Count;

            // Deselect previous finding
            if (bDeSelected)
                lvCtx.lv.Items[lvCtx.SearchPos - 1].Selected = false;

            return bDeSelected;
        }
Ejemplo n.º 4
0
        private ContextMenuTag CreateCommonMenuItems(
            ContextMenuStrip Menu,
            ListView LV,
            CtxMenuFlags MFlags = CtxMenuFlags.All)
        {
            // FindFirst
            var FindFirst = new ToolStripMenuItem()
            {
                ShortcutKeys = (Keys.Control | System.Windows.Forms.Keys.F),
                Size         = new System.Drawing.Size(202, 22),
                Text         = "Find",
            };

            FindFirst.Click += new EventHandler(menuCommonLVFindFirst_Click);

            // FindNext
            var FindNext = new ToolStripMenuItem()
            {
                ShortcutKeys = Keys.F3,
                Size         = new System.Drawing.Size(202, 22),
                Text         = "Find Next",
            };

            FindNext.Click += new EventHandler(menuCommonLVFindNext_Click);

            var CopyItem = new ToolStripMenuItem()
            {
                ShortcutKeys = (Keys.Control | Keys.C),
                Size         = new System.Drawing.Size(202, 22),
                Text         = "Copy"
            };

            CopyItem.Click += new EventHandler(menuCommonLVCopyItem_Click);

            var SelectAll = new ToolStripMenuItem()
            {
                ShortcutKeys = (Keys.Control | Keys.A),
                Size         = new System.Drawing.Size(202, 22),
                Text         = "Select all"
            };

            SelectAll.Click += new EventHandler(menuCommonLVSelectAll_Click);

            var ExportToTextFile = new ToolStripMenuItem()
            {
                ShortcutKeys = (Keys.Control | Keys.S),
                Size         = new System.Drawing.Size(202, 22),
                Text         = "Export to text file"
            };

            ExportToTextFile.Click += new EventHandler(menuCommonLVExportToTextFile_Click);

            var Delete = new ToolStripMenuItem()
            {
                ShortcutKeys = Keys.Delete,
                Size         = new System.Drawing.Size(202, 22),
                Text         = "Delete"
            };

            Delete.Click += new EventHandler(menuCommonLVDeleteItem_Click);

            if (MFlags.HasFlag(CtxMenuFlags.Find))
            {
                Menu.Items.AddRange(new ToolStripItem[]
                {
                    new ToolStripSeparator(),
                    FindFirst,
                    FindNext,
                });
            }

            if (MFlags.HasFlag(CtxMenuFlags.Delete))
            {
                Menu.Items.AddRange(new ToolStripItem[]
                {
                    new ToolStripSeparator(),
                    Delete
                });
            }

            if (MFlags.HasFlag(CtxMenuFlags.Export))
            {
                Menu.Items.AddRange(new ToolStripItem[]
                {
                    new ToolStripSeparator(),
                    ExportToTextFile
                });
            }

            Menu.Items.AddRange(new ToolStripItem[]
            {
                new ToolStripSeparator(),
                CopyItem,
                SelectAll,
            });

            // Install column sorter
            LV.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(lvCommon_ColumnClick);

            var Context = new ContextMenuTag()
            {
                lv = LV
            };

            Menu.Tag = Context;
            LV.Tag   = Context;

            LV.ContextMenuStrip = Menu;

            return(Context);
        }
Ejemplo n.º 5
0
 private void InitializeObject()
 {
     Tag.ResuldChanged += OnResuldChanged;
     m_Menu             = new ContextMenuTag(this);
     AssignImageIndex();
 }
Ejemplo n.º 6
0
        private ContextMenuTag CreateCommonMenuItems(
            ContextMenuStrip Menu,
            ListView LV,
            CtxMenuFlags MFlags = CtxMenuFlags.All)
        {
            // FindFirst
            var FindFirst = new ToolStripMenuItem()
            {
                ShortcutKeys = (Keys.Control | System.Windows.Forms.Keys.F),
                Size = new System.Drawing.Size(202, 22),
                Text = "Find",
            };
            FindFirst.Click += new EventHandler(menuCommonLVFindFirst_Click);

            // FindNext
            var FindNext = new ToolStripMenuItem()
            {
                ShortcutKeys = Keys.F3,
                Size = new System.Drawing.Size(202, 22),
                Text = "Find Next",
            };
            FindNext.Click += new EventHandler(menuCommonLVFindNext_Click);

            var CopyItem = new ToolStripMenuItem()
            {
                ShortcutKeys = (Keys.Control | Keys.C),
                Size = new System.Drawing.Size(202, 22),
                Text = "Copy"
            };
            CopyItem.Click += new EventHandler(menuCommonLVCopyItem_Click);

            var SelectAll = new ToolStripMenuItem()
            {
                ShortcutKeys = (Keys.Control | Keys.A),
                Size = new System.Drawing.Size(202, 22),
                Text = "Select all"
            };
            SelectAll.Click += new EventHandler(menuCommonLVSelectAll_Click);

            var ExportToTextFile = new ToolStripMenuItem()
            {
                ShortcutKeys = (Keys.Control | Keys.S),
                Size = new System.Drawing.Size(202, 22),
                Text = "Export to text file"
            };
            ExportToTextFile.Click += new EventHandler(menuCommonLVExportToTextFile_Click);

            var Delete = new ToolStripMenuItem()
            {
                ShortcutKeys = Keys.Delete,
                Size = new System.Drawing.Size(202, 22),
                Text = "Delete"
            };
            Delete.Click += new EventHandler(menuCommonLVDeleteItem_Click);

            if (MFlags.HasFlag(CtxMenuFlags.Find))
            {
                Menu.Items.AddRange(new ToolStripItem[]
                {
                    new ToolStripSeparator(),
                    FindFirst,
                    FindNext,
                });
            }

            if (MFlags.HasFlag(CtxMenuFlags.Delete))
            {
                Menu.Items.AddRange(new ToolStripItem[]
                {
                    new ToolStripSeparator(),
                    Delete
                });
            }

            if (MFlags.HasFlag(CtxMenuFlags.Export))
            {
                Menu.Items.AddRange(new ToolStripItem[]
                {
                    new ToolStripSeparator(),
                    ExportToTextFile
                });
            }

            Menu.Items.AddRange(new ToolStripItem[]
            {
                new ToolStripSeparator(),
                CopyItem,
                SelectAll,
            });

            // Install column sorter
            LV.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(lvCommon_ColumnClick);

            var Context = new ContextMenuTag()
            {
                lv = LV
            };
            Menu.Tag = Context;
            LV.Tag = Context;

            LV.ContextMenuStrip = Menu;

            return Context;
        }