Exemplo n.º 1
0
        static object CreateMenuItemFromDescriptor(MenuItemDescriptor descriptor)
        {
            Codon  codon         = descriptor.Codon;
            string type          = codon.Properties.Contains("type") ? codon.Properties["type"] : "Command";
            bool   createCommand = codon.Properties["loadclasslazy"] == "false";

            switch (type)
            {
            case "Separator":
                return(new MenuSeparator(codon, descriptor.Caller));

            case "CheckBox":
                return(new MenuCheckBox(codon, descriptor.Caller));

            case "Item":
            case "Command":
                return(new MenuCommand(codon, descriptor.Caller, createCommand));

            case "Menu":
                return(new Menu(codon, descriptor.Caller, ConvertSubItems(descriptor.SubItems)));

            case "Builder":
                return(codon.AddIn.CreateObject(codon.Properties["class"]));

            default:
                throw new System.NotSupportedException("unsupported menu item type : " + type);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads the menu items.
        /// </summary>
        private void LoadMenuItems()
        {
            IList <BaseMenuItemDescriptor> fileSubItems = new List <BaseMenuItemDescriptor>
            {
                new MenuItemDescriptor(MenuHeaders.ExitHeader, new DelegateCommandProvider <object>().CreateCommand <ExitCommand>())
            };

            MenuItemDescriptor file = new MenuItemDescriptor(MenuHeaders.FileHeader, null, fileSubItems);

            EventAggregator.GetEvent <MenuItemEvent>().Publish(file);
        }
Exemplo n.º 3
0
        private BarItemLink CreateDynamicLink(MenuItemDescriptor item,
                                              IBarItemFinder finder,
                                              PopupMenu popupMenu,
                                              BarManager manager)
        {
            string cmdId       = string.Empty;
            string groupLabel  = string.Empty;
            bool   beginGroup  = false;
            string labelConfig = string.Empty;

            cmdId = item.Codon.Properties["cmdId"];
            if (!string.IsNullOrEmpty(item.Codon.Properties["beginGroup"]))
            {
                beginGroup = bool.Parse(item.Codon.Properties["beginGroup"]);
            }
            if (!string.IsNullOrEmpty(item.Codon.Properties["label"]))
            {
                labelConfig = item.Codon.Properties["label"];
            }

            IUICommand containerCmd = finder.GetDynamicContainer(cmdId);
            BarSubItem groupItem    = containerCmd.BarItem as BarSubItem;

            popupMenu.BeforePopup += popupMenu_BeforePopup;
            if (labelConfig != string.Empty)
            {
                groupLabel        = StringParser.Parse(labelConfig);
                groupItem.Caption = groupLabel;
            }

            BarItemLink link = null;

            if (containerCmd.IsRunTimeContainer)
            {
                //runtime menus
                link = popupMenu.ItemLinks.Add(groupItem);
            }
            else
            {
                List <BarItem> barItems = finder.GetDynamicBarItems(cmdId);
                if (barItems.Count > 0)
                {
                    link            = popupMenu.ItemLinks.Add(groupItem);
                    link.BeginGroup = beginGroup;
                    foreach (BarItem subItem in barItems)
                    {
                        groupItem.ItemLinks.Add(subItem);
                    }
                }
            }
            return(link);
        }
Exemplo n.º 4
0
        private void LoadCustomCommand(Codon codon, MenuItemDescriptor descriptor)
        {
            string commandId      = codon.Id;
            string builderid      = string.Empty;
            string checkForViewId = string.Empty;
            string controllerId   = string.Empty;

            //builder
            if (string.IsNullOrEmpty(codon.Properties["builderid"]))
            {
                throw new Exception(string.Format("BuiderID not found:codonid ={0},condonname = {1}", codon.Id, codon.Name));
            }
            else
            {
                builderid = codon.Properties["builderid"];
            }

            if (!string.IsNullOrEmpty(codon.Properties["controllerId"]))
            {
                controllerId = codon.Properties["controllerId"];
            }
            //checkForViewId
            if (!string.IsNullOrEmpty(codon.Properties["checkForViewId"]))
            {
                checkForViewId = codon.Properties["checkForViewId"];
            }


            //build item
            IPartBuilder buider = RibbonBuilderManager.GetBuider(builderid);
            object       item   = buider.Build(codon, this._controllerFinder.FindController(string.Empty), codon.Conditions);

            if (!(item is BarItem))
            {
                throw new Exception(string.Format("Builded Custom Command object is not BarItem:id ={0},name = {1}", codon.Id, codon.Name));
            }
            if (string.IsNullOrEmpty(codon.Properties["class"]))
            {
                throw new Exception(string.Format("Action Command Class not defined in Custom Command:id ={0},name = {1}", codon.Id, codon.Name));
            }
            //build action command
            ICommand command = (ICommand)codon.AddIn.CreateObject(codon.Properties["class"]);

            BarItem       barItem = item as BarItem;
            CommandDrawer drawer  = new CommandDrawer();

            drawer.SetItemGlyph(codon, barItem);
            this._barManager.Items.Add(barItem);
            this.AddCustomCommand(commandId, checkForViewId, barItem, command, descriptor.Conditions, controllerId);
        }
Exemplo n.º 5
0
        static void InitializeUIElement(MenuItemDescriptor descriptor, object uiElement)
        {
            Codon codon = descriptor.Codon;

            if (codon.Properties.Contains("initializer"))
            {
                var initializerId = codon.Properties["initializer"];
                var initializers  = AddInTree.BuildDictionaryItems <IUIElementInitializer>("/Workbench/UIElementInitializers", null, false);
                var initializer   = initializers.Where(kvp => kvp.Key == initializerId).Select(kvp => kvp.Value).FirstOrDefault();
                if (initializer != null)
                {
                    initializer.Initialize(uiElement);
                }
            }
        }
Exemplo n.º 6
0
        public PopupMenu CreateMenu(string moduleID,
                                    string viewID,
                                    RibbonControl ribbon,
                                    IBarItemFinder finder)
        {
            PopupMenu popupMenu = new PopupMenu();

            popupMenu.Manager = ribbon.Manager;
            popupMenu.Ribbon  = ribbon;

            MenuItemDescriptor menuinfo = this.LoadMenuInfoFromTree(moduleID, viewID);

            if (menuinfo == null)
            {
                return(null);
            }

            bool needSplitor = false;

            foreach (MenuItemDescriptor item in menuinfo.SubItems)
            {
                // string cmdId = string.Empty;

                string cmdType = "normal";
                if (string.IsNullOrEmpty(item.Codon.Properties["cmdId"]))
                {
                    throw new Exception("Context menu config error,not found cmdId:" + item.Codon.Id + " in " + moduleID);
                }
                if (!string.IsNullOrEmpty(item.Codon.Properties["type"]))
                {
                    cmdType = item.Codon.Properties["type"];
                }
                if (cmdType == "normal")
                {
                    this.CreateNormalLink(item, finder, popupMenu, moduleID);
                }
                else if (cmdType == "dynamicGroup")
                {
                    this.CreateDynamicLink(item, finder, popupMenu, ribbon.Manager);
                }
                else
                {
                    throw new Exception("Invalid Command Type:" + cmdType + " in " + moduleID);
                }
            }

            return(popupMenu);
        }
Exemplo n.º 7
0
        static object CreateMenuItemFromDescriptor(MenuCreateContext context, MenuItemDescriptor descriptor)
        {
            Codon  codon         = descriptor.Codon;
            string type          = codon.Properties.Contains("type") ? codon.Properties["type"] : "Command";
            bool   createCommand = codon.Properties["loadclasslazy"] == "false";

            switch (type)
            {
            case "Separator":
                return(new ConditionalSeparator(codon, descriptor.Caller, false));

            case "CheckBox":
                return("CheckBox");

            //return new MenuCheckBox(codon, descriptor.Caller);
            case "Item":
            case "Command":
                return(new MenuCommand(context.InputBindingOwner, codon, descriptor.Caller, createCommand, context.ActivationMethod));

            case "Menu":
                var item = new CoreMenuItem(codon, descriptor.Caller)
                {
                    ItemsSource = new object[1],
                    SetEnabled  = true
                };
                var subItems = CreateUnexpandedMenuItems(context, descriptor.SubItems);
                item.SubmenuOpened += (sender, args) => {
                    item.ItemsSource = ExpandMenuBuilders(subItems, true);
                    args.Handled     = true;
                };
                if (context.ImmediatelyExpandMenuBuildersForShortcuts)
                {
                    ExpandMenuBuilders(subItems, false);
                }
                return(item);

            case "Builder":
                IMenuItemBuilder builder = codon.AddIn.CreateObject(codon.Properties["class"]) as IMenuItemBuilder;
                if (builder == null)
                {
                    throw new NotSupportedException("Menu item builder " + codon.Properties["class"] + " does not implement IMenuItemBuilder");
                }
                return(new MenuItemBuilderPlaceholder(builder, descriptor.Codon, descriptor.Caller));

            default:
                throw new NotSupportedException("unsupported menu item type : " + type);
            }
        }
Exemplo n.º 8
0
		static object CreateMenuItemFromDescriptor(MenuItemDescriptor descriptor)
		{
			Codon codon = descriptor.Codon;
			string type = codon.Properties.Contains("type") ? codon.Properties["type"] : "Command";
			bool createCommand = codon.Properties["loadclasslazy"] == "false";
			
			switch (type) {
				case "Separator":
					return new MenuSeparator(codon, descriptor.Caller);
				case "CheckBox":
					return new MenuCheckBox(codon, descriptor.Caller);
				case "Item":
				case "Command":
					return new MenuCommand(codon, descriptor.Caller, createCommand);
				case "Menu":
					return new Menu(codon, descriptor.Caller, ConvertSubItems(descriptor.SubItems));
				case "Builder":
					return codon.AddIn.CreateObject(codon.Properties["class"]);
				default:
					throw new System.NotSupportedException("unsupported menu item type : " + type);
			}
		}
Exemplo n.º 9
0
        static object CreateMenuItemFromDescriptor(MenuItemDescriptor descriptor)
        {
            Codon  codon         = descriptor.Codon;
            string type          = codon.Properties.Contains("type") ? codon.Properties["type"] : "Command";
            bool   createCommand = codon.Properties["loadclasslazy"] == "false";

            switch (type)
            {
            case "Separator":
                return(new ContextMenuSeparator(codon, descriptor.Caller, descriptor.Conditions));

            case "Item":
            case "Command":
                return(new ContextMenuCommand(codon, descriptor.Caller, createCommand, descriptor.Conditions));

            case "Menu":
                return(new FrameWork.Menu(codon, descriptor.Caller, ConvertSubItems(descriptor.SubItems), descriptor.Conditions));

            default:
                throw new System.NotSupportedException("unsupported menu item type : " + type);
            }
        }
Exemplo n.º 10
0
		static object CreateMenuItemFromDescriptor(MenuCreateContext context, MenuItemDescriptor descriptor)
		{
			Codon codon = descriptor.Codon;
			string type = codon.Properties.Contains("type") ? codon.Properties["type"] : "Command";
			
			switch (type) {
				case "Separator":
					return new ConditionalSeparator(codon, descriptor.Parameter, false, descriptor.Conditions);
				case "CheckBox":
					return new MenuCheckBox(context.InputBindingOwner, codon, descriptor.Parameter, descriptor.Conditions);
				case "Item":
				case "Command":
					return new MenuCommand(context.InputBindingOwner, codon, descriptor.Parameter, context.ActivationMethod, descriptor.Conditions);
				case "Menu":
					var item = new CoreMenuItem(codon, descriptor.Parameter, descriptor.Conditions) {
						ItemsSource = new object[1],
						SetEnabled = true
					};
					var subItems = CreateUnexpandedMenuItems(context, descriptor.SubItems);
					item.SubmenuOpened += (sender, args) => {
						item.ItemsSource = ExpandMenuBuilders(subItems, true);
						args.Handled = true;
					};
					if (context.ImmediatelyExpandMenuBuildersForShortcuts)
						ExpandMenuBuilders(subItems, false);
					return item;
				case "Builder":
					IMenuItemBuilder builder = codon.AddIn.CreateObject(codon.Properties["class"]) as IMenuItemBuilder;
					if (builder == null)
						throw new NotSupportedException("Menu item builder " + codon.Properties["class"] + " does not implement IMenuItemBuilder");
					return new MenuItemBuilderPlaceholder(builder, descriptor.Codon, descriptor.Parameter);
				default:
					throw new NotSupportedException("unsupported menu item type : " + type);
			}
		}
Exemplo n.º 11
0
        private static object CreateMenuItemFromDescriptor(MenuItemDescriptor descriptor)
        {
            Codon  codon         = descriptor.Codon;
            string text          = codon.Properties.Contains("type") ? codon.Properties["type"] : "Command";
            bool   createCommand = codon.Properties["loadclasslazy"] == "false";
            string key;

            switch (key = text)
            {
            case "RibbonPageCategory":
            {
                return(new MenuRibbonPageCategory(codon, descriptor.Caller, MenuService.ConvertSubItems(descriptor.SubItems)));
            }

            case "RibbonPage":
            {
                return(new MenuRibbonPage(codon, descriptor.Caller, MenuService.ConvertSubItems(descriptor.SubItems)));
            }

            case "RibbonPageGroup":
            {
                return(new MenuRibbonPageGroup(codon, descriptor.Caller, MenuService.ConvertSubItems(descriptor.SubItems)));
            }

            case "SubItemCommand":
            {
                return(new MenuSubItemCommand(codon, descriptor.Caller, MenuService.ConvertSubItems(descriptor.SubItems)));
            }

            case "ButtonGroupCommand":
            {
                return(new MenuButtonGroupCommand(codon, descriptor.Caller, MenuService.ConvertSubItems(descriptor.SubItems)));
            }

            case "ContextMenuCommand":
            {
                return(new ContextMenuCommand(codon, descriptor.Caller, MenuService.ConvertSubItems(descriptor.SubItems)));
            }

            case "RadioCommand":
            case "CheckCommand":
            {
                return(new MenuCheckCommand(codon, descriptor.Caller, createCommand));
            }

            case "Command":
            case "ButtonCommand":
            {
                return(new MenuButtonCommand(codon, descriptor.Caller, createCommand));
            }

            case "CheckBoxCommand":
            {
                return(new MenuCheckBoxCommand(codon, descriptor.Caller, createCommand));
            }

            case "ComboBoxCommand":
            {
                return(new MenuComboBoxCommand(codon, descriptor.Caller, createCommand));
            }

            case "SpinCommand":
            {
                return(new MenuSpinCommand(codon, descriptor.Caller, createCommand));
            }

            case "TextCommand":
            {
                return(new MenuTextCommand(codon, descriptor.Caller, createCommand));
            }

            case "MenuTrackBarCommand":
            {
                return(new MenuTrackBarCommand(codon, descriptor.Caller, createCommand));
            }

            case "Builder":
            {
                return(codon.AddIn.CreateObject(codon.Properties["class"]));
            }
            }
            throw new System.NotSupportedException("unsupported menu item type : " + text);
        }
Exemplo n.º 12
0
        private IEnumerable GetItems(object datavalue)
        {
            MenuItemDescriptor descriptor = datavalue as MenuItemDescriptor;
               UnusedReferencesSearchResult searchResults = workflow.SearchResults;

            if(descriptor == null)
               {
               List<MenuItemDescriptor> descriptors = new List<MenuItemDescriptor>();
               Assert.CheckNotNull(searchResults, "searchResults");
               Assert.CheckNotNull(searchResults.Projects, "searchResults.Projects");
               foreach (IProject project in searchResults.Projects)
               {

                   MenuItemDescriptor item = new MenuItemDescriptor(project);
                   item.Tag = project;
                   item.Text = project.Name;
                   item.Icon = ProjectModelIconManager.Instance.GetProjectModelElementImage(project);
                   descriptors.Add(item);

               }
               return descriptors;
               }
               else
               {
               if (descriptor.Tag is IProject)
               {
                   List<MenuItemDescriptor> descriptors = new List<MenuItemDescriptor>();
                   foreach (IModuleReference moduleReference in searchResults[(IProject)descriptor.Tag])
                   {
                       MenuItemDescriptor item = new MenuItemDescriptor(moduleReference);
                       item.Tag = moduleReference;
                       item.Text = moduleReference.Name;
                       item.Icon = ProjectModelIconManager.Instance.GetProjectModelElementImage(moduleReference);
                       descriptors.Add(item);

                   }
                   return descriptors;
               }
               else
               return EmptyArray<object>.Instance;
               }
        }
Exemplo n.º 13
0
        static object CreateMenuItemFromDescriptor(MenuItemDescriptor descriptor, string addinTreePath, ICommandRegister register)
        {
            Codon codon = descriptor.Codon;

            string cmdPath   = addinTreePath + "/" + codon.Id;
            string builderid = string.Empty;

            if (codon.Properties.Contains("builderid"))
            {
                builderid = codon.Properties["builderid"];
            }
            else if (codon.Properties.Contains("cmdId"))
            {
                string cmdId = codon.Properties["cmdId"];
                return(register.GetBarItem(cmdId));
            }
            else
            {
                throw new Exception(string.Format("BuiderID not found:codonid ={0},condonname = {1}", codon.Id, codon.Name));
            }
            if (builderid == string.Empty)
            {
                throw new Exception(string.Format("BuiderID is empty:codonid ={0},condonname = {1}", codon.Id, codon.Name));
            }

            IPartBuilder builder = RibbonBuilderManager.GetBuider(builderid);
            object       obj     = builder.Build(codon, descriptor.Caller, descriptor.Conditions);;

            try
            {
                if (obj is BarButtonItemEx)
                {
                    BarItem cmdBar = obj as BarItem;

                    string formats = "<MenuItem id ={0} checkForViewId =\"\" source =\"Ribbon\" cmdPath =\"{1}\"/>";
                    System.Diagnostics.Debug.WriteLine(string.Format(formats, codon.Id, cmdPath));
                    if (register != null)
                    {
                        //ICommand command = (ICommand)codon.AddIn.CreateObject(codon.Properties["class"]);
                        //command.Owner = register.owner;
                        ICommand command = cmdBar.Tag as ICommand;
                        if (command != null)
                        {
                            if (string.IsNullOrEmpty(codon.Properties["groupName"]))
                            {
                                bool registerSuc = register.RegisterCommand(cmdBar, cmdPath, command, descriptor.Conditions);
                            }
                            else
                            {
                                string groupName   = codon.Properties["groupName"];
                                bool   registerSuc = register.RegisterCommand(cmdBar, codon.Id, cmdPath, command, groupName);
                            }
                        }
                        //Debug.WriteLine("Register =" + registerSuc.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(obj);
        }
Exemplo n.º 14
0
 //------------------------------------------------------------------------------------------------------------------------
 public override void UI_NotificationContextMenu_HandleClick(string[] ids, MenuItemDescriptor desc)
 {
     UI_ShowMessageBox(UI.InformationType.None, "MenuClicked", "Menu item was clicked");
 }