private static SearchItem GenerateSearchItem(SearchPathDescriptor descriptor, Codon codon, string path, List<string> nextPathChain) { SearchItem item = new SearchItem(); item.Codon = codon; string commandName = codon.Properties["command"]; if (!string.IsNullOrEmpty(commandName)) item.Command = MenuService.GetRegisteredCommand(codon.AddIn, commandName); item.PathChain.AddRange(nextPathChain); item.Category = descriptor.Category; item.Id = path; return item; }
static bool ButtonCanExecute(SearchItem item) { if (item.Activator == null) { return(false); } if (item.IsVisible == false) { return(false); } if (item.IsEnabled == false) { return(false); } if (item.Command != null && !item.Command.CanExecute(item.CommandParameter)) { return(false); } return(true); }
static void ButtonExecute(SearchItem item) { item.Activator(); }
static bool ButtonCanExecute(SearchItem item) { if (item.Activator == null) return false; if (item.IsVisible == false) return false; if (item.IsEnabled == false) return false; if (item.Command != null && !item.Command.CanExecute(item.CommandParameter)) return false; return true; }
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); }