private void grid_ItemClicked(MyGuiControlGrid sender, MyGuiControlGrid.EventArgs eventArgs) { if (eventArgs.Button == MySharedButtonsEnum.Secondary) { int slot = eventArgs.ColumnIndex; var toolbar = MyToolbarComponent.CurrentToolbar; MyToolbarItem item = toolbar.GetSlotItem(slot); if (item == null) { return; } //right clicks in multifunctional items should trigger their menus (if they have more than 0 options) if (item is MyToolbarItemActions) { var actionList = (item as MyToolbarItemActions).PossibleActions(ShownToolbar.ToolbarType); if (UseContextMenu && actionList.Count > 0) { m_contextMenu.CreateNewContextMenu(); foreach (var action in actionList) { m_contextMenu.AddItem(action.Name, icon: action.Icon, userData: action.Id); } m_contextMenu.AddItem(MyTexts.Get(MySpaceTexts.BlockAction_RemoveFromToolbar)); m_contextMenu.Enabled = true; m_contextMenuItemIndex = toolbar.SlotToIndex(slot); } else { RemoveToolbarItem(eventArgs.ColumnIndex); } } else { RemoveToolbarItem(eventArgs.ColumnIndex); } } if (m_shownToolbar.IsValidIndex(eventArgs.ColumnIndex)) { m_shownToolbar.ActivateItemAtSlot(eventArgs.ColumnIndex, true); } }
private void UpdateItemAtIndex(MyToolbar toolbar, int index) { Debug.Assert(toolbar == m_shownToolbar); int slot = toolbar.IndexToSlot(index); if (!toolbar.IsValidIndex(index) || !toolbar.IsValidSlot(slot)) { return; } SetGridItemAt(slot, toolbar[index], clear: true); if (toolbar.SelectedSlot == slot) { RefreshSelectedItem(toolbar); } }
private void UpdateItemIcon(MyToolbar toolbar, MyToolbar.IndexArgs args) { if (toolbar.IsValidIndex(args.ItemIndex)) { var slot = toolbar.IndexToSlot(args.ItemIndex); if (slot != -1) { m_toolbarItemsGrid.GetItemAt(slot).Icons = toolbar.GetItemIcons(args.ItemIndex); } } else { for (int i = 0; i < m_toolbarItemsGrid.ColumnsCount; ++i) { m_toolbarItemsGrid.GetItemAt(i).Icons = toolbar.GetItemIcons(toolbar.SlotToIndex(i)); } } }
private void UpdateItemIcon(MyToolbar toolbar, MyToolbar.IndexArgs args) { if (toolbar.IsValidIndex(args.ItemIndex)) { var slot = toolbar.IndexToSlot(args.ItemIndex); if (slot != -1) m_toolbarItemsGrid.GetItemAt(slot).Icon = toolbar.GetItemIcon(args.ItemIndex); } else { for (int i = 0; i < m_toolbarItemsGrid.ColumnsCount; ++i) { m_toolbarItemsGrid.GetItemAt(i).Icon = toolbar.GetItemIcon(toolbar.SlotToIndex(i)); } } }
private void UpdateItemAtIndex(MyToolbar toolbar, int index) { Debug.Assert(toolbar == m_shownToolbar); int slot = toolbar.IndexToSlot(index); if (!toolbar.IsValidIndex(index) || !toolbar.IsValidSlot(slot)) return; SetGridItemAt(slot, toolbar[index]); if (toolbar.SelectedSlot == slot) RefreshSelectedItem(toolbar); }