void Apply(KeyboardNavigationOperation op, EventBase sourceEvent) { if (Apply(op)) { sourceEvent.StopPropagation(); sourceEvent.PreventDefault(); } }
void Invoke(KeyboardNavigationOperation operation, EventBase evt) { if (operation == KeyboardNavigationOperation.None) { return; } m_Action?.Invoke(operation, evt); }
void Apply(KeyboardNavigationOperation op, EventBase sourceEvent) { if (!Apply(op)) { return; } sourceEvent.StopImmediatePropagation(); sourceEvent.PreventDefault(); }
bool Apply(KeyboardNavigationOperation op) { var selectedIndex = GetSelectedIndex(); void UpdateSelectionDown(int newIndex) { while (newIndex < m_Items.Count) { if (m_Items[newIndex].element.enabledSelf) { ChangeSelectedIndex(newIndex, selectedIndex); break; } ++newIndex; } } void UpdateSelectionUp(int newIndex) { while (newIndex >= 0) { if (m_Items[newIndex].element.enabledSelf) { ChangeSelectedIndex(newIndex, selectedIndex); break; } --newIndex; } } switch (op) { case KeyboardNavigationOperation.Cancel: Hide(true); return(true); case KeyboardNavigationOperation.Submit: var item = m_Items[selectedIndex]; if (selectedIndex >= 0 && item.element.enabledSelf) { item.action?.Invoke(); item.actionUserData?.Invoke(item.element.userData); } Hide(true); return(true); case KeyboardNavigationOperation.Previous: UpdateSelectionUp(selectedIndex < 0 ? m_Items.Count - 1 : selectedIndex - 1); return(true); case KeyboardNavigationOperation.Next: UpdateSelectionDown(selectedIndex + 1); return(true); case KeyboardNavigationOperation.PageUp: case KeyboardNavigationOperation.Begin: UpdateSelectionDown(0); return(true); case KeyboardNavigationOperation.PageDown: case KeyboardNavigationOperation.End: UpdateSelectionUp(m_Items.Count - 1); return(true); } return(false); }
bool Apply(KeyboardNavigationOperation op) { switch (op) { case KeyboardNavigationOperation.None: case KeyboardNavigationOperation.SelectAll: break; case KeyboardNavigationOperation.Cancel: editorWindow.Close(); break; case KeyboardNavigationOperation.Submit: if (m_SelectedIndex < 0) { return(false); } onSelectionChanged?.Invoke(m_Items[m_SelectedIndex].value); editorWindow.Close(); break; case KeyboardNavigationOperation.Previous: { return(SelectPreviousDisplayedItem() || SelectLastDisplayedItem()); } case KeyboardNavigationOperation.Next: { return(SelectNextDisplayedItem() || SelectFirstDisplayedItem()); } case KeyboardNavigationOperation.PageUp: { // ReSharper disable once ConditionIsAlwaysTrueOrFalse return(SelectPreviousDisplayedItem(10) || SelectFirstDisplayedItem() || true); } case KeyboardNavigationOperation.PageDown: { // ReSharper disable once ConditionIsAlwaysTrueOrFalse return(SelectNextDisplayedItem(10) || SelectLastDisplayedItem() || true); } case KeyboardNavigationOperation.Begin: { SelectFirstDisplayedItem(); return(true); } case KeyboardNavigationOperation.End: { SelectLastDisplayedItem(); return(true); } } return(false); }
void Invoke(KeyboardNavigationOperation operation, EventBase evt) { m_Action?.Invoke(operation, evt); }