示例#1
0
        public RDMPSingleControlTabMenu(IActivateItems activator, RDMPSingleControlTab tab, WindowManager windowManager)
        {
            _tab = tab;
            Items.Add("Close Tab", null, (s, e) => tab.Close());
            Items.Add("Close All Tabs", null, (s, e) => windowManager.CloseAllWindows(tab));
            Items.Add("Close All But This", null, (s, e) => windowManager.CloseAllButThis(tab));

            Items.Add("Show", null, (s, e) => tab.HandleUserRequestingEmphasis(activator));

            if (tab is PersistableSingleDatabaseObjectDockContent single)
            {
                var uiFactory = new AtomicCommandUIFactory(activator);
                var builder   = new GoToCommandFactory(activator);

                var gotoMenu = new ToolStripMenuItem(AtomicCommandFactory.GoTo)
                {
                    Enabled = false
                };
                Items.Add(gotoMenu);

                foreach (var cmd in builder.GetCommands(single.DatabaseObject))
                {
                    gotoMenu.DropDownItems.Add(uiFactory.CreateMenuItem(cmd));
                    gotoMenu.Enabled = true;
                }
                RDMPContextMenuStrip.RegisterFetchGoToObjecstCallback(gotoMenu);
            }

            Items.Add("Refresh", FamFamFamIcons.arrow_refresh, (s, e) => _tab.HandleUserRequestingTabRefresh(activator));

            var help = new ToolStripMenuItem("Help", FamFamFamIcons.help, (s, e) => _tab.ShowHelp(activator));

            help.ShortcutKeys = Keys.F1;
            Items.Add(help);
        }
示例#2
0
        public RDMPContextMenuStrip CreateMenu(IActivateItems activator, TreeListView tree, RDMPCollection collection, params IAtomicCommand[] commands)
        {
            var toReturn = new RDMPContextMenuStrip(new RDMPContextMenuStripArgs(activator, tree, collection), collection);

            foreach (IAtomicCommand command in commands)
            {
                toReturn.Items.Add(CreateMenuItem(command));
            }

            return(toReturn);
        }
        void olvCatalogues_CellRightClick(object sender, BrightIdeasSoftware.CellRightClickEventArgs e)
        {
            var ci = olvCatalogues.SelectedObject as CatalogueItem;

            if (ci == null)
            {
                return;
            }

            var menu = new RDMPContextMenuStrip(new RDMPContextMenuStripArgs(Activator), ci);

            menu.Show(Cursor.Position);
        }
示例#4
0
        /// <summary>
        /// Creates a menu compatible with object <paramref name="o"/>.  Returns null if no compatible menu exists.
        /// Errors are reported to <see cref="IBasicActivateItems.GlobalErrorCheckNotifier"/> (if set up).
        ///
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public ContextMenuStrip GetMenuIfExists(object o)
        {
            try
            {
                var many = o as ICollection;

                if (many != null)
                {
                    var menu = new ContextMenuStrip();

                    var factory = new AtomicCommandUIFactory(_activator);

                    if (many.Cast <object>().All(d => d is IDisableable))
                    {
                        var mi = factory.CreateMenuItem(new ExecuteCommandDisableOrEnable(_activator, many.Cast <IDisableable>().ToArray()));
                        menu.Items.Add(mi);
                    }

                    if (many.Cast <object>().All(d => d is IDeleteable))
                    {
                        var mi = factory.CreateMenuItem(new ExecuteCommandDelete(_activator, many.Cast <IDeleteable>().ToArray()));
                        mi.ShortcutKeys = Keys.Delete;
                        menu.Items.Add(mi);
                    }
                    MenuBuilt?.Invoke(this, new MenuBuiltEventArgs(menu, o));
                    return(menu);
                }

                if (o != null)
                {
                    //is o masquerading as someone else?
                    IMasqueradeAs masquerader = o as IMasqueradeAs;

                    //if so this is who he is pretending to be
                    object masqueradingAs = null;

                    if (masquerader != null)
                    {
                        masqueradingAs = masquerader.MasqueradingAs(); //yes he is masquerading!
                    }
                    var menu = GetMenuWithCompatibleConstructorIfExists(o);

                    //If no menu takes the object o try checking the object it is masquerading as as a secondary preference
                    if (menu == null && masqueradingAs != null)
                    {
                        menu = GetMenuWithCompatibleConstructorIfExists(masqueradingAs, masquerader);
                    }

                    //found a menu with compatible constructor arguments
                    if (menu != null)
                    {
                        if (!Settings.AllowPinning)
                        {
                            var miPin = menu.Items.OfType <AtomicCommandMenuItem>().SingleOrDefault(mi => mi.Tag is ExecuteCommandPin);

                            if (miPin != null)
                            {
                                miPin.Enabled     = false;
                                miPin.ToolTipText = "Pinning is disabled in this collection";
                            }
                        }

                        MenuBuilt?.Invoke(this, new MenuBuiltEventArgs(menu, o));
                        return(menu);
                    }

                    //no compatible menus so just return default menu
                    var defaultMenu = new RDMPContextMenuStrip(new RDMPContextMenuStripArgs(_activator, Tree, o), o);
                    defaultMenu.AddCommonMenuItems(this);

                    MenuBuilt?.Invoke(this, new MenuBuiltEventArgs(defaultMenu, o));
                    return(defaultMenu);
                }
                else
                {
                    //it's a right click in whitespace (nothing right clicked)

                    AtomicCommandUIFactory factory = new AtomicCommandUIFactory(_activator);

                    if (WhitespaceRightClickMenuCommandsGetter != null)
                    {
                        var menu = factory.CreateMenu(_activator, Tree, _collection, WhitespaceRightClickMenuCommandsGetter(_activator));
                        menu.AddCommonMenuItems(this);
                        return(menu);
                    }
                }

                return(null);
            }
            catch (Exception ex)
            {
                if (_activator?.GlobalErrorCheckNotifier == null)
                {
                    throw;
                }

                _activator.GlobalErrorCheckNotifier.OnCheckPerformed(new CheckEventArgs($"Failed to build menu for {o} of Type {o?.GetType()}", CheckResult.Fail, ex));
                return(null);
            }
        }
示例#5
0
        private ContextMenuStrip GetMenuIfExists(object o)
        {
            var many = o as ICollection;

            if (many != null)
            {
                var menu = new ContextMenuStrip();

                var factory = new AtomicCommandUIFactory(_activator);

                if (many.Cast <object>().All(d => d is IDeleteable))
                {
                    var mi = factory.CreateMenuItem(new ExecuteCommandDelete(_activator, many.Cast <IDeleteable>().ToList()));
                    mi.ShortcutKeys = Keys.Delete;
                    menu.Items.Add(mi);
                }

                return(menu);
            }

            if (o != null)
            {
                //is o masquerading as someone else?
                IMasqueradeAs masquerader = o as IMasqueradeAs;

                //if so this is who he is pretending to be
                object masqueradingAs = null;

                if (masquerader != null)
                {
                    masqueradingAs = masquerader.MasqueradingAs(); //yes he is masquerading!
                }
                var menu = GetMenuWithCompatibleConstructorIfExists(o);

                //If no menu takes the object o try checking the object it is masquerading as as a secondary preference
                if (menu == null && masqueradingAs != null)
                {
                    menu = GetMenuWithCompatibleConstructorIfExists(masqueradingAs, masquerader);
                }

                //found a menu with compatible constructor arguments
                if (menu != null)
                {
                    if (!Settings.AllowPinning)
                    {
                        var miPin = menu.Items.OfType <AtomicCommandMenuItem>().SingleOrDefault(mi => mi.Tag is ExecuteCommandPin);

                        if (miPin != null)
                        {
                            miPin.Enabled     = false;
                            miPin.ToolTipText = "Pinning is disabled in this collection";
                        }
                    }

                    return(menu);
                }

                //no compatible menus so just return default menu
                var defaultMenu = new RDMPContextMenuStrip(new RDMPContextMenuStripArgs(_activator, Tree, o), o);
                defaultMenu.AddCommonMenuItems(this);
                return(defaultMenu);
            }
            else
            {
                //it's a right click in whitespace (nothing right clicked)

                AtomicCommandUIFactory factory = new AtomicCommandUIFactory(_activator);

                if (WhitespaceRightClickMenuCommandsGetter != null)
                {
                    var menu = factory.CreateMenu(_activator, Tree, _collection, WhitespaceRightClickMenuCommandsGetter(_activator));
                    menu.AddCommonMenuItems(this);
                    return(menu);
                }
            }

            return(null);
        }