public int Compare(IToolBar x, IToolBar y) { if (x != null && y != null) { return(CommandComparer.CompareTags(x.Tag, y.Tag)); } return(0); }
private void Invalidate(object menuTag) { IMenuItem menu = m_menus.FirstOrDefault <IMenu>(x => CommandComparer.TagsEqual(x.MenuTag, menuTag)); if (menu != null) { ((RootMenu)menu).Invalidate(); } }
public int Compare(object x, object y) { var menuX = x as RootMenuModel; var menuY = y as RootMenuModel; if (menuX != null && menuY != null) { return(CommandComparer.CompareTags(menuX.MenuTag, menuY.MenuTag)); } return(0); }
public void GetHashcode_Test() { // Arrange var command = new StringCommand("a", "Test Command A", () => { }); // Act var hashCode = new CommandComparer().GetHashCode(command); // Assert Assert.Equal(command.Id.GetHashCode(), hashCode); }
/// <summary> /// Get items for a given toolbar /// </summary> /// <param name="toolBar"></param> /// <returns></returns> public IEnumerable <IToolBarItem> GetToolBarItems(IToolBar toolBar) { if (toolBar == null || toolBar.Tag == null) { return(EmptyEnumerable <IToolBarItem> .Instance); } var items = m_toolBarItems.Where(x => x.IsVisible && CommandComparer.TagsEqual(x.ToolBarTag, toolBar.Tag)).ToList(); items.Sort(ToolBarItemComparer.Instance); return(items); }
private void RebuildMenu(Menu root) { root.ChildCollection.Clear(); foreach (var command in m_commandService.Commands.Where <ICommandItem>(x => CommandComparer.TagsEqual(x.MenuTag, root.MenuTag) && x.IsVisible(Sce.Atf.Applications.CommandVisibility.Menu))) { MenuUtil.BuildSubMenus(command as CommandItem, root); } MenuUtil.InsertGroupSeparators(root); }
public ICommandItem RemoveCommand(object commandTag) { var command = m_commands.FirstOrDefault <ICommandItem>((x) => CommandComparer.TagsEqual(x.CommandTag, commandTag)); if (command != null) { lock (m_commands) { m_commands.Remove(command); } } return(command); }
public void Compare_EqualCommands_DifferInDescription_Test() { // Arrange var command1 = new NumericCommand(2, "One", () => { }); var command2 = new NumericCommand(2, "_", () => { }); // Act var comparer = new CommandComparer(); // Assert var result = comparer.Equals(command1, command2); Assert.True(result); }
public void Compare_NonEqualCommands_DifferInId_Test() { // Arrange var command1 = new NumericCommand(1, "One", () => { }); var command2 = new NumericCommand(0, "One", () => { }); // Act var comparer = new CommandComparer(); // Assert var result = comparer.Equals(command1, command2); Assert.False(result); }
/// <summary> /// Enumerate items for a given toolbar</summary> /// <param name="toolBar">Toolbar</param> /// <returns>Enumeration of IToolBarItem in toolbar</returns> public IEnumerable <IToolBarItem> GetToolBarItems(IToolBar toolBar) { if (toolBar == null || toolBar.Tag == null) { return(EmptyEnumerable <IToolBarItem> .Instance); } var items = m_toolBarItems.Where(x => x.IsVisible && CommandComparer.TagsEqual(x.ToolBarTag, toolBar.Tag)).ToList(); items.Sort(ToolBarItemComparer.Instance); // Maintain separator groups if (items.Any()) { var groupedItems = new List <IToolBarItem>(); var prevItem = items[0] as CommandItem; object prevTag = prevItem != null ? prevItem.GroupTag : null; groupedItems.Add(items[0]); for (int i = 1; i < items.Count; i++) { var thisItem = items[i] as CommandItem; if (thisItem == null) { groupedItems.Add(items[i]); continue; } object groupTag = thisItem.GroupTag; // add a separator if the new command is from a different group if (groupTag != null && prevTag != null && !CommandComparer.TagsEqual(groupTag, prevTag)) { groupedItems.Add(new ToolBarSeparator()); } groupedItems.Add(thisItem); prevTag = groupTag; } items = groupedItems; } return(items); }
public int Compare(IToolBarItem x, IToolBarItem y) { if (x != null && y != null) { var xCommandItem = x as ICommandItem; var yCommandItem = y as ICommandItem; if (xCommandItem != null && yCommandItem != null) { return(CommandComparer.CompareCommands(xCommandItem, yCommandItem)); } return(CommandComparer.CompareTags(x.Tag, y.Tag)); } return(0); }
private void InsertGroupSeparators() { // Create depth first list of commands var commands = new List <Tuple <ICommandItem, MenuModel> >(); GetCommandsInSubtree(this, commands); for (int i = 1; i < commands.Count; i++) { var previous = commands[i - 1]; var current = commands[i]; if (!CommandComparer.TagsEqual(previous.Item1.GroupTag, current.Item1.GroupTag)) { InsertSeparator(previous, current); } } }
public static void InsertGroupSeparators(Menu menu) { // Create depth first list of commands var commands = new List <Tuple <ICommandItem, Menu> >(); GetCommands(menu, commands); for (int i = 1; i < commands.Count; i++) { var previous = commands[i - 1]; var current = commands[i]; if (!CommandComparer.TagsEqual(previous.Item1.GroupTag, current.Item1.GroupTag)) { InsertSeparator(previous, current); } } }
public int CompareTo(ICommand other) => CommandComparer.CompareCommands(this, other);
private IMenu GetMenu(object menuTag) { return(m_toolbars.FirstOrDefault <IMenu>(x => CommandComparer.TagsEqual(x.MenuTag, menuTag))); }