Exemplo n.º 1
0
        public LandingPageMasterViewModel(IMenuItemBuilder menuItemBuilder)
        {
            if (menuItemBuilder == null)
            {
                throw new ArgumentNullException("menuItemBuilder");
            }
            _menuItemBuilder = menuItemBuilder;

            ItemList = _menuItemBuilder.GetMenuItems();
        }
Exemplo n.º 2
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);
            }
        }
        public static void SetMenuItemConfig(this PrefabInfo info, IMenuItemBuilder config)
        {
            info.m_UIPriority = config.UIOrder;
            info.SetUICategory(config.UICategory);
            if (!config.ThumbnailsPath.IsNullOrWhiteSpace())
            {
                var thumbnails = AssetManager.instance.GetThumbnails(config.GetCodeName(), config.ThumbnailsPath);
                info.m_Atlas     = thumbnails;
                info.m_Thumbnail = thumbnails.name;
            }

            if (!config.InfoTooltipPath.IsNullOrWhiteSpace())
            {
                var infoTips = AssetManager.instance.GetInfoTooltip(config.GetCodeName(), config.InfoTooltipPath);
                info.m_InfoTooltipAtlas     = infoTips;
                info.m_InfoTooltipThumbnail = infoTips.name;
            }
        }
Exemplo n.º 4
0
        static IList CreateToolBarItems(UIElement inputBindingOwner, IEnumerable descriptors)
        {
            ArrayList result = new ArrayList();

            foreach (ToolbarItemDescriptor descriptor in descriptors)
            {
                object           item           = CreateToolBarItemFromDescriptor(inputBindingOwner, descriptor);
                IMenuItemBuilder submenuBuilder = item as IMenuItemBuilder;
                if (submenuBuilder != null)
                {
                    result.AddRange(submenuBuilder.BuildItems(descriptor.Codon, descriptor.Caller));
                }
                else
                {
                    result.Add(item);
                }
            }
            return(result);
        }
Exemplo n.º 5
0
        static IList CreateToolBarItems(IEnumerable descriptors)
        {
            ArrayList result = new ArrayList();

            foreach (ToolbarItemDescriptor descriptor in descriptors)
            {
                object item = CreateToolBarItemFromDescriptor(descriptor);
                if (item is IMenuItemBuilder)
                {
                    IMenuItemBuilder submenuBuilder = (IMenuItemBuilder)item;
                    result.AddRange(submenuBuilder.BuildItems(descriptor.Codon, descriptor.Caller));
                }
                else
                {
                    result.Add(item);
                }
            }
            return(result);
        }
Exemplo n.º 6
0
 static void AddItemsToMenu(ToolStripItemCollection collection, IEnumerable <MenuItemDescriptor> descriptors)
 {
     foreach (MenuItemDescriptor descriptor in descriptors)
     {
         object item = CreateMenuItemFromDescriptor(descriptor);
         if (item is ToolStripItem)
         {
             collection.Add((ToolStripItem)item);
             if (item is IStatusUpdate)
             {
                 ((IStatusUpdate)item).UpdateStatus();
             }
         }
         else
         {
             IMenuItemBuilder submenuBuilder = (IMenuItemBuilder)item;
             collection.AddRange(submenuBuilder.BuildItems(descriptor.Codon, descriptor.Parameter).Cast <ToolStripItem>().ToArray());
         }
     }
 }
Exemplo n.º 7
0
 void CreateDropDownItems()
 {
     DropDownItems.Clear();
     foreach (object item in subItems)
     {
         if (item is ToolStripItem)
         {
             DropDownItems.Add((ToolStripItem)item);
             if (item is IStatusUpdate)
             {
                 ((IStatusUpdate)item).UpdateStatus();
                 ((IStatusUpdate)item).UpdateText();
             }
         }
         else
         {
             IMenuItemBuilder submenuBuilder = (IMenuItemBuilder)item;
             DropDownItems.AddRange(submenuBuilder.BuildItems(codon, caller).Cast <ToolStripItem>().ToArray());
         }
     }
 }
        void CreateDropDownItems()
        {
            // let's assume that if a menuBuilder exists,
            // as in the Search Results panel or the Class
            // Browser toolbar, it will handle this step.
            if (menuBuilder != null)
            {
                return;
            }

            // also, let's prevent a null exception
            // in the event that there are no subitems
            if (subItems == null || subItems.Count == 0)
            {
                return;
            }

            DropDownItems.Clear();
            foreach (object item in subItems)
            {
                if (item is ToolStripItem)
                {
                    DropDownItems.Add((ToolStripItem)item);
                    if (item is IStatusUpdate)
                    {
                        ((IStatusUpdate)item).UpdateStatus();
                        ((IStatusUpdate)item).UpdateText();
                    }
                }
                else
                {
                    IMenuItemBuilder submenuBuilder = (IMenuItemBuilder)item;
                    DropDownItems.AddRange(submenuBuilder.BuildItems(codon, caller).Cast <ToolStripItem>().ToArray());
                }
            }
        }
Exemplo n.º 9
0
        public static ToolStripItem[] CreateToolStripItems(object owner, AddInTreeNode treeNode)
        {
            if (treeNode == null)
            {
                return(new ToolStripItem[0]);
            }
            List <ToolStripItem> collection = new List <ToolStripItem>();

            foreach (ToolbarItemDescriptor descriptor in treeNode.BuildChildItems <ToolbarItemDescriptor>(owner))
            {
                object item = CreateToolbarItemFromDescriptor(descriptor);
                if (item is ToolStripItem)
                {
                    collection.Add((ToolStripItem)item);
                }
                else if (item is IMenuItemBuilder)
                {
                    IMenuItemBuilder submenuBuilder = (IMenuItemBuilder)item;
                    collection.AddRange(submenuBuilder.BuildItems(descriptor.Codon, owner).Cast <ToolStripItem>().ToArray());
                }
            }

            return(collection.ToArray());
        }
Exemplo n.º 10
0
			public MenuItemBuilderPlaceholder(IMenuItemBuilder builder, Codon codon, object caller)
			{
				this.builder = builder;
				this.codon = codon;
				this.caller = caller;
			}
Exemplo n.º 11
0
 public MenuItemBuilderPlaceholder(IMenuItemBuilder builder, Codon codon, object caller)
 {
     this.builder = builder;
     this.codon   = codon;
     this.caller  = caller;
 }
Exemplo n.º 12
0
        private static List <SearchItem> HandleMenuCodon(SearchPathDescriptor descriptor, Codon codon, string path, List <string> pathChain)
        {
            List <SearchItem> result = new List <SearchItem>();

            if (codon.Name != "MenuItem")
            {
                return(result);
            }

            List <string> nextPathChain = new List <string>(pathChain);
            string        nextPath      = string.Format("{0}/{1}", path, codon.Id);

            if (codon.Properties.Contains("type") && codon.Properties["type"] == "Menu")
            {
                nextPathChain.Add(AddNextPathChainString(codon));
                if (AddInTree.ExistsTreeNode(nextPath))
                {
                    AddInTreeNode node = AddInTree.GetTreeNode(nextPath);
                    foreach (Codon innerCodon in node.Codons)
                    {
                        result.AddRange(HandleMenuCodon(descriptor, innerCodon, nextPath, nextPathChain));
                    }
                }
            }

            if (!codon.Properties.Contains("type") || (codon.Properties.Contains("type") && (codon.Properties["type"] == "Item" || codon.Properties["type"] == "Command")))
            {
                HandleItemMenuType(descriptor, codon, nextPath, nextPathChain, result);
            }

            if (codon.Properties.Contains("type") && codon.Properties["type"] == "Builder")
            {
                try
                {
                    IMenuItemBuilder builder = codon.AddIn.CreateObject(codon.Properties["class"]) as IMenuItemBuilder;
                    if (builder == null)
                    {
                        return(result);
                    }
                    ICollection collection = builder.BuildItems(codon, null);
                    foreach (MenuItem menuItem in collection)
                    {
                        SearchItem item = GenerateSearchItem(descriptor, codon, nextPath, nextPathChain);
                        item.Label            = menuItem.Header.ToString();
                        item.Command          = menuItem.Command;
                        item.CommandParameter = menuItem.CommandParameter;
                        item.Shortcut         = menuItem.InputGestureText;

                        if (String.IsNullOrWhiteSpace(item.CommandTypeString) && item.Command == null)
                        {
                            continue;
                        }

                        item.Id = path + "/" + item.Label;
                        result.Add(item);
                    }
                }
                catch (Exception ex)
                {
                    LoggingService.Warn(String.Format("Could not load search item from builder at {0} - {1}", codon.Id, codon.AddIn.FileName), ex);
                }
            }
            return(result);
        }