void OnPick(MouseDownEvent evt) { // Do not prevent zoom and pan if (evt.button == 2 || (evt.ctrlKey && evt.altKey || (evt.button == (int)MouseButton.RightMouse && evt.altKey))) { return; } var pickedElement = PickElement(evt.mousePosition); if (pickedElement != null) { m_Selection.Select(this, pickedElement); SetInnerSelection(pickedElement); if (evt.clickCount == 2) { var posInViewport = m_PickOverlay.ChangeCoordinatesTo(this, evt.localMousePosition); BuilderInPlaceTextEditingUtilities.OpenEditor(pickedElement, this.ChangeCoordinatesTo(pickedElement, posInViewport)); } } else { ClearInnerSelection(); m_Selection.ClearSelection(this); } if (evt.button == (int)MouseButton.RightMouse) { if (pickedElement != null && m_ContextMenuManipulator != null) { pickedElement.SetProperty(BuilderConstants.ElementLinkedDocumentVisualElementVEPropertyName, pickedElement); m_ContextMenuManipulator.RegisterCallbacksOnTarget(pickedElement); m_ContextMenuManipulator.DisplayContextMenu(evt, pickedElement); evt.StopPropagation(); } } else { evt.StopPropagation(); } }
void OnPick(MouseDownEvent evt) { // Do not prevent zoom and pan if (evt.button == 2 || (evt.ctrlKey && evt.altKey || (evt.button == (int)MouseButton.RightMouse && evt.altKey))) { return; } m_PickedElements.Clear(); var pickedElement = PickElement(evt.mousePosition, m_PickedElements); if (pickedElement != null) { var timeSinceStartup = EditorApplication.timeSinceStartup; var previousMouseRect = new Rect( m_PreviousPickMousePosition.x - BuilderConstants.PickSelectionRepeatRectHalfSize, m_PreviousPickMousePosition.y - BuilderConstants.PickSelectionRepeatRectHalfSize, BuilderConstants.PickSelectionRepeatRectSize, BuilderConstants.PickSelectionRepeatRectSize); if (timeSinceStartup - m_PreviousPickMouseTime > BuilderConstants.PickSelectionRepeatMinTimeDelay && previousMouseRect.Contains(evt.mousePosition)) { m_SameLocationPickCount++; var offset = 0; var index = m_PickedElements.IndexOf(pickedElement); // For compound controls, we don't seem to have the actual field root element // in the pickedElements list. So we get index == -1 here. We need to do // some magic to select the proper parent element from the list then. if (index < 0) { index = m_PickedElements.IndexOf(pickedElement.parent); offset = 1; } var maxIndex = m_PickedElements.Count - 1; var newIndex = index + m_SameLocationPickCount - offset; if (newIndex > maxIndex) { m_SameLocationPickCount = 0; } else { pickedElement = m_PickedElements[newIndex]; } } else { m_SameLocationPickCount = 0; } m_PreviousPickMousePosition = evt.mousePosition; m_PreviousPickMouseTime = EditorApplication.timeSinceStartup; m_Selection.Select(this, pickedElement); SetInnerSelection(pickedElement); if (evt.clickCount == 2) { var posInViewport = m_PickOverlay.ChangeCoordinatesTo(this, evt.localMousePosition); BuilderInPlaceTextEditingUtilities.OpenEditor(pickedElement, this.ChangeCoordinatesTo(pickedElement, posInViewport)); } } else { ClearInnerSelection(); m_Selection.ClearSelection(this); } if (evt.button == (int)MouseButton.RightMouse) { if (pickedElement != null && m_ContextMenuManipulator != null) { pickedElement.SetProperty(BuilderConstants.ElementLinkedDocumentVisualElementVEPropertyName, pickedElement); m_ContextMenuManipulator.RegisterCallbacksOnTarget(pickedElement); m_ContextMenuManipulator.DisplayContextMenu(evt, pickedElement); evt.StopPropagation(); } } else { evt.StopPropagation(); } }