public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token) { return(Task.Run(delegate { try { if (pattern.HasLineNumber) { return; } CommandTargetRoute route = new CommandTargetRoute(MainToolbar.LastCommandTarget); var matcher = StringMatcher.GetMatcher(pattern.Pattern, false); foreach (var cmdTuple in allCommands) { token.ThrowIfCancellationRequested(); var cmd = cmdTuple.Item1; var matchString = cmdTuple.Item2; int rank; if (matcher.CalcMatchRank(matchString, out rank)) { searchResultCallback.ReportResult(new CommandResult(cmd, null, route, pattern.Pattern, matchString, rank)); } } } catch (OperationCanceledException) { } })); }
public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token) { if (pattern.HasLineNumber) { return(Task.CompletedTask); } var route = new CommandTargetRoute(IdeApp.CommandService.LastCommandTarget); var matcher = StringMatcher.GetMatcher(pattern.Pattern, false); foreach (var cmd in GetAllCommands()) { if (token.IsCancellationRequested) { break; } var matchString = cmd.DisplayName; if (matcher.CalcMatchRank(matchString, out var rank)) { if ((cmd as ActionCommand)?.RuntimeAddin == currentRuntimeAddin) { rank += 1; // we prefer commands comming from the addin } searchResultCallback.ReportResult(new CommandResult(cmd, null, route, pattern.Pattern, matchString, rank)); } } return(Task.CompletedTask); }
void ICommandBar.Update(object defaultTarget) { if (!Visible) { return; } if (initialCommandTarget != null) { defaultTarget = initialCommandTarget; } CommandTargetRoute targetRoute = new CommandTargetRoute(defaultTarget); foreach (Gtk.Widget item in Children) { if (item is ICommandUserItem) { ((ICommandUserItem)item).Update(targetRoute); } else { item.Show(); } } }
internal SearchResult CheckCommand(Command c, CommandTargetRoute route) { ActionCommand cmd = c as ActionCommand; if (cmd == null || cmd.CommandArray) { return(null); } int rank; string matchString = cmd.Text.Replace("_", ""); if (MatchName(matchString, out rank)) { try { var ci = IdeApp.CommandService.GetCommandInfo(cmd.Id, route); if (ci.Enabled && ci.Visible) { return(new CommandResult(cmd, ci, route, pattern, matchString, rank)); } } catch (Exception ex) { LoggingService.LogError("Failure while checking command: " + cmd.Id, ex); } } return(null); }
void ICommandUserItem.Update (CommandTargetRoute targetRoute) { if (commandManager != null && !isArrayItem) { CommandInfo cinfo = commandManager.GetCommandInfo (commandId, targetRoute); this.initialTarget = targetRoute.InitialTarget; Update (cinfo); } }
public void Update(object activeTarget) { CommandTargetRoute route = new CommandTargetRoute(initialTarget ?? activeTarget); foreach (ToolButtonStatus bs in buttons) { bs.Update(route); } }
//updates commands and populates arrays and dynamic menus static CarbonEventHandlerStatus HandleMenuOpening(IntPtr callRef, IntPtr eventRef, IntPtr user_data) { DestroyOldMenuObjects(); menuOpenDepth++; try { IntPtr menuRef = Carbon.GetEventParameter(eventRef, CarbonEventParameterName.DirectObject, CarbonEventParameterType.MenuRef); //don't update dynamic menus recursively if (!mainMenus.Contains(menuRef) && menuRef != appMenu) { return(CarbonEventHandlerStatus.NotHandled); } // uint cmd = HIToolbox.GetMenuItemCommandID (new HIMenuItem (menuRef, 0)); CommandTargetRoute route = new CommandTargetRoute(); ushort count = HIToolbox.CountMenuItems(menuRef); for (ushort i = 1; i <= count; i++) { HIMenuItem mi = new HIMenuItem(menuRef, i); uint macCmdID = HIToolbox.GetMenuItemCommandID(mi); object cmdID; //link items if (macCmdID == linkCommandId) { if (IsGloballyDisabled) { HIToolbox.DisableMenuItem(mi); } else { HIToolbox.EnableMenuItem(mi); } continue; } //items that map to command objects if (!commands.TryGetValue(macCmdID, out cmdID) || cmdID == null) { continue; } CommandInfo cinfo = manager.GetCommandInfo(cmdID, route); menuIdMap[cmdID] = HIToolbox.GetMenuID(menuRef); UpdateMenuItem(menuRef, menuRef, ref i, ref count, macCmdID, cinfo); } } catch (Exception ex) { System.Console.WriteLine(ex); } return(CarbonEventHandlerStatus.NotHandled); }
public void Update(CommandTargetRoute targetRoute) { CommandInfo cmdInfo = IdeApp.CommandService.GetCommandInfo(cmdId, targetRoute); if (lastDesc != cmdInfo.Description) { string toolTip; if (string.IsNullOrEmpty(cmdInfo.AccelKey)) { toolTip = cmdInfo.Description; } else { toolTip = cmdInfo.Description + " (" + KeyBindingManager.BindingToDisplayLabel(cmdInfo.AccelKey, false) + ")"; } button.TooltipText = toolTip; lastDesc = cmdInfo.Description; } if (cmdInfo.Icon.IsNull && button.Label != cmdInfo.Text) { button.Label = cmdInfo.Text; } if (cmdInfo.Icon != stockId) { stockId = cmdInfo.Icon; button.Image = new Gtk.Image(cmdInfo.Icon, Gtk.IconSize.Menu); } if (cmdInfo.Enabled != button.Sensitive) { button.Sensitive = cmdInfo.Enabled; } if (cmdInfo.Visible != button.Visible) { button.Visible = cmdInfo.Visible; } ToggleButton toggle = button as ToggleButton; if (toggle != null && cmdInfo.Checked != toggle.Active) { toggle.Active = cmdInfo.Checked; } if (button.Image != null) { button.Image.Show(); } }
public void Update (CommandTargetRoute targetRoute) { CommandInfo cmdInfo = IdeApp.CommandService.GetCommandInfo (cmdId, targetRoute); bool hasAccel = string.IsNullOrEmpty (cmdInfo.AccelKey); bool hasIcon = !cmdInfo.Icon.IsNull; string desc = cmdInfo.Description; //If the button only has an icon it's not always clear what it does. In such cases, use the label as a //fallback tooltip. Also do this if there's an accelerator, so the user can see what it is. if (string.IsNullOrEmpty (desc) && (hasIcon || hasAccel)) desc = cmdInfo.Text; if (lastDesc != desc) { string toolTip; if (hasAccel) { toolTip = desc; } else { toolTip = desc + " (" + KeyBindingManager.BindingToDisplayLabel (cmdInfo.AccelKey, false) + ")"; } button.TooltipText = toolTip; lastDesc = desc; } if (!hasIcon && button.Label != cmdInfo.Text) button.Label = cmdInfo.Text; if (cmdInfo.Icon != stockId) { stockId = cmdInfo.Icon; button.Image = new Gtk.Image (cmdInfo.Icon, Gtk.IconSize.Menu); } if (cmdInfo.Enabled != button.Sensitive) button.Sensitive = cmdInfo.Enabled; if (cmdInfo.Visible != button.Visible) button.Visible = cmdInfo.Visible; ToggleButton toggle = button as ToggleButton; if (toggle != null && cmdInfo.Checked != toggle.Active) toggle.Active = cmdInfo.Checked; if (button.Image != null) button.Image.Show (); }
void AllResults(WorkerResult lastResult, WorkerResult newResult, CancellationToken token) { CommandTargetRoute route = new CommandTargetRoute(MainToolbar.LastCommandTarget); newResult.filteredCommands = new List <Command> (); bool startsWithLastFilter = lastResult != null && lastResult.pattern != null && newResult.pattern.StartsWith(lastResult.pattern) && lastResult.filteredCommands != null; IEnumerable <Command> allCommands = startsWithLastFilter ? lastResult.filteredCommands : IdeApp.CommandService.GetCommands(); foreach (Command cmd in allCommands) { token.ThrowIfCancellationRequested(); SearchResult curResult = newResult.CheckCommand(cmd, route); if (curResult != null) { newResult.filteredCommands.Add(cmd); newResult.results.AddResult(curResult); } } }
static bool HasVisibleItems(IntPtr submenu) { var route = new CommandTargetRoute(); ushort count = HIToolbox.CountMenuItems(submenu); for (ushort i = 1; i <= count; i++) { HIMenuItem mi = new HIMenuItem(submenu, i); uint macCmdID = HIToolbox.GetMenuItemCommandID(mi); object cmdID; if (macCmdID == linkCommandId) { return(true); } if (!commands.TryGetValue(macCmdID, out cmdID) || cmdID == null) { continue; } CommandInfo cinfo = manager.GetCommandInfo(cmdID, route); if (cinfo.ArrayInfo != null) { foreach (CommandInfo ci in cinfo.ArrayInfo) { if (ci.Visible) { return(true); } } } else if (cinfo.Visible) { return(true); } } return(false); }
internal void Update() { CommandTargetRoute targetRoute = new CommandTargetRoute(initialCommandTarget); foreach (Gtk.Widget item in Children) { if (item is ICommandUserItem) { ((ICommandUserItem)item).Update(targetRoute); } else if (item is Gtk.MenuItem) { Gtk.MenuItem mitem = (Gtk.MenuItem)item; CommandMenu men = mitem.Submenu as CommandMenu; if (men != null) { men.InitialCommandTarget = initialCommandTarget; } item.Show(); if (item is AutoHideMenuItem) { men.Update(); if (!((AutoHideMenuItem)item).HasVisibleChildren) { item.Hide(); } } } else { item.Show(); } } // After updating the menu, hide the separators which don't actually // separate items. bool prevWasItem = false; Gtk.Widget lastSeparator = null; foreach (Gtk.Widget item in Children) { if (item is Gtk.SeparatorMenuItem) { if (!prevWasItem) { item.Hide(); } else { prevWasItem = false; lastSeparator = item; } } else if (item.Visible) { prevWasItem = true; } } if (!prevWasItem && lastSeparator != null) { lastSeparator.Hide(); } }
public CommandResult(Command cmd, CommandInfo ci, CommandTargetRoute route, string match, string matchedString, int rank) : base(match, matchedString, rank) { this.ci = ci; command = cmd; this.route = route; }
public void Update(CommandTargetRoute targetRoute) { CommandInfo cmdInfo = IdeApp.CommandService.GetCommandInfo(cmdId, targetRoute); bool hasAccel = string.IsNullOrEmpty(cmdInfo.AccelKey); bool hasIcon = !cmdInfo.Icon.IsNull; string desc = cmdInfo.Description; bool displayText = !(displayType == CommandEntryDisplayType.IconHasPriority && hasIcon) && displayType != CommandEntryDisplayType.IconOnly; //If the button only has an icon it's not always clear what it does. In such cases, use the label as a //fallback tooltip. Also do this if there's an accelerator, so the user can see what it is. if (string.IsNullOrEmpty(desc) && (!displayText || hasAccel)) { desc = cmdInfo.Text; } if (lastDesc != desc) { string toolTip; if (hasAccel) { toolTip = desc; } else { toolTip = desc + " (" + KeyBindingManager.BindingToDisplayLabel(cmdInfo.AccelKey, false) + ")"; } button.TooltipText = toolTip; lastDesc = desc; } if (displayText && button.Label != cmdInfo.Text) { button.Label = cmdInfo.Text; } if (displayType != CommandEntryDisplayType.TextOnly && cmdInfo.Icon != stockId) { stockId = cmdInfo.Icon; button.Image = image = new ImageView(cmdInfo.Icon, Gtk.IconSize.Menu); } if (button.Image != null && cmdInfo.Enabled != button.Sensitive) { image.Image = image.Image.WithStyles(cmdInfo.Enabled ? "" : "disabled").WithAlpha(cmdInfo.Enabled ? 1.0 : 0.4); } if (cmdInfo.Enabled != button.Sensitive) { button.Sensitive = cmdInfo.Enabled; } if (cmdInfo.Visible != button.Visible) { button.Visible = cmdInfo.Visible; } ToggleButton toggle = button as ToggleButton; if (toggle != null && cmdInfo.Checked != toggle.Active) { toggle.Active = cmdInfo.Checked; } if (button.Image != null) { button.Image.Show(); } }