private void ListBoxItemsMouseClick(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Right) { return; } var loc = ListBoxItems.PointToScreen(new Point(e.X, e.Y)); for (int i = 0; i < ListBoxItems.Items.Count; i++) { var rec = ListBoxItems.GetItemRectangle(i); if (rec.X <= e.X && (rec.X + rec.Width) >= e.X && rec.Y <= e.Y && (rec.Y + rec.Height) >= e.Y) { ItemContextMenu.Items[0].Enabled = true; ItemContextMenu.Items[2].Enabled = true; ItemContextMenu.Items[3].Enabled = true; ItemContextMenu.Items[4].Enabled = true; ListBoxItems.ClearSelected(); ListBoxItems.SetSelected(i, true); ItemContextMenu.Show(loc); return; } } ItemContextMenu.Items[0].Enabled = false; ItemContextMenu.Items[3].Enabled = false; ItemContextMenu.Items[4].Enabled = false; ItemContextMenu.Show(loc); }
private void ResultsList_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { int index = ResultsList.IndexFromPoint(e.X, e.Y); if (index == ListBox.NoMatches) { return; } ResultsList.SelectedIndex = index; string file = m_Symbols.GetFileForSymbol((string)ResultsList.SelectedItem); GoToHeaderMenuItem.Enabled = file != null; ItemContextMenu.Show(ResultsList, e.X, e.Y); } }
private void _invokeOnItemClick(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Right || IsCurrentCellInEditMode) { return; } var hti = HitTest(e.X, e.Y); //if (Rows.Count-1 > hti.RowIndex) //index 5 clicked if (_contextMenuMode == ContextMenuDisplayMode.OnCell && hti.RowIndex != -1 && hti.ColumnIndex != -1) { ClearSelection(); Rows[hti.RowIndex].Selected = true; ItemContextMenu.Show(this, e.Location); } else if (_contextMenuMode == ContextMenuDisplayMode.Anywhere) { ItemContextMenu.Show(this, e.Location); } }
public override void OnGUI(Rect rect) { if (s_Styles == null) { s_Styles = new Styles(); } Event evt = Event.current; Rect contentRect = new Rect(0, 0, 1, CalcSize().y); m_ScrollPosition = GUI.BeginScrollView(rect, m_ScrollPosition, contentRect); { float curY = 0f; for (int i = 0; i <= maxIndex; ++i) { int itemControlID = i + 1000000; Rect itemRect = new Rect(0, curY, rect.width, lineHeight); bool addSeperator = Array.IndexOf(m_SeperatorIndices, i) >= 0; // Add new preset button if (m_ShowAddNewPresetItem && i == m_ItemProvider.Count()) { CreateNewItemButton(itemRect); continue; } if (m_ShowEditWindowForIndex == i) { m_ShowEditWindowForIndex = -1; EditExistingItem(itemRect, i); } // Handle event switch (evt.type) { case EventType.Repaint: bool hover = false; if (m_HoverIndex == i) { if (itemRect.Contains(evt.mousePosition)) { hover = true; } else { m_HoverIndex = -1; } } // Overwrite if if (m_ModifyItemUI != null && m_ModifyItemUI.IsShowing()) { hover = m_ItemProvider.GetItem(i) == m_ModifyItemUI.m_Object; } s_Styles.menuItem.Draw(itemRect, GUIContent.Temp(m_ItemProvider.GetName(i)), hover, false, i == selectedIndex, false); if (addSeperator) { const float margin = 4f; Rect seperatorRect = new Rect(itemRect.x + margin, itemRect.y + itemRect.height + seperatorHeight * 0.5f, itemRect.width - 2 * margin, 1); DrawRect(seperatorRect, (EditorGUIUtility.isProSkin) ? new Color(0.32f, 0.32f, 0.32f, 1.333f) : new Color(0.6f, 0.6f, 0.6f, 1.333f)); // dark : light } // We delete presets on alt-click if (AllowDeleteClick(i)) { EditorGUIUtility.AddCursorRect(itemRect, MouseCursor.ArrowMinus); } break; case EventType.MouseDown: if (evt.button == 0 && itemRect.Contains(evt.mousePosition)) { GUIUtility.hotControl = itemControlID; if (!IsDeleteModiferPressed() && evt.clickCount == 1) { GUIUtility.hotControl = 0; SelectItem(i); editorWindow.Close(); evt.Use(); } } break; case EventType.MouseUp: if (GUIUtility.hotControl == itemControlID) { GUIUtility.hotControl = 0; if (evt.button == 0 && itemRect.Contains(evt.mousePosition)) { if (AllowDeleteClick(i)) { DeleteItem(i); evt.Use(); } } } break; case EventType.ContextClick: if (itemRect.Contains(evt.mousePosition)) { evt.Use(); if (m_ModifyItemUI != null && m_ItemProvider.IsModificationAllowed(i)) { ItemContextMenu.Show(i, this); } } break; case EventType.MouseMove: if (itemRect.Contains(evt.mousePosition)) { if (m_HoverIndex != i) { m_HoverIndex = i; Repaint(); } } else if (m_HoverIndex == i) { m_HoverIndex = -1; Repaint(); } break; } curY += lineHeight; if (addSeperator) { curY += seperatorHeight; } } // end foreach item } GUI.EndScrollView(); }