Esempio n. 1
0
        public void HandleUnusedMouseEventsForItem(Rect rect, TreeViewItem item, bool firstItem)
        {
            int       itemControlId  = GetItemControlID(item, this);
            Event     current        = Event.current;
            EventType typeForControl = current.GetTypeForControl(itemControlId);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if (!rect.Contains(Event.current.mousePosition))
                {
                    break;
                }
                if (Event.current.button == 0)
                {
                    GUIUtility.keyboardControl = m_KeyboardControlID;
                    Repaint();
                    if (Event.current.clickCount == 2)
                    {
                        if (itemDoubleClickedCallback != null)
                        {
                            itemDoubleClickedCallback(item.id);
                        }
                    }
                    else
                    {
                        if (dragging == null || dragging.CanStartDrag(item, m_DragSelection, Event.current.mousePosition))
                        {
                            m_DragSelection = GetNewSelection(item, true, false);
                            ((DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), itemControlId)).mouseDownPosition = Event.current.mousePosition;
                        }
                        GUIUtility.hotControl = itemControlId;
                    }
                    current.Use();
                    break;
                }
                if (Event.current.button != 1)
                {
                    break;
                }
                bool keepMultiSelection = true;
                SelectionClick(item, keepMultiSelection);
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl != itemControlId)
                {
                    break;
                }
                GUIUtility.hotControl = 0;
                m_DragSelection.Clear();
                current.Use();
                if (!rect.Contains(current.mousePosition))
                {
                    break;
                }
                float      contentIndent = gui.GetContentIndent(item);
                Rect       rect1         = new Rect(rect.x + contentIndent, rect.y, rect.width - contentIndent, rect.height);
                List <int> selectedIds   = state.selectedIDs;
                if (m_AllowRenameOnMouseUp && selectedIds != null && (selectedIds.Count == 1 && selectedIds[0] == item.id) && (rect1.Contains(current.mousePosition) && !EditorGUIUtilityWrap.HasHolddownKeyModifiers(current)))
                {
                    BeginNameEditing(0.5f);
                    break;
                }
                SelectionClick(item, false);
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl != itemControlId || dragging == null)
                {
                    break;
                }
                DragAndDropDelay dragAndDropDelay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), itemControlId);
                if (dragAndDropDelay.CanStartDrag() && dragging.CanStartDrag(item, m_DragSelection, dragAndDropDelay.mouseDownPosition))
                {
                    dragging.StartDrag(item, m_DragSelection);
                    GUIUtility.hotControl = 0;
                }
                current.Use();
                break;

            default:
                if (typeForControl != EventType.DragUpdated && typeForControl != EventType.DragPerform)
                {
                    if (typeForControl != EventType.ContextClick || !rect.Contains(current.mousePosition) || contextClickItemCallback == null)
                    {
                        break;
                    }
                    contextClickItemCallback(item.id);
                    break;
                }
                if (dragging == null || !dragging.DragElement(item, rect, firstItem))
                {
                    break;
                }
                GUIUtility.hotControl = 0;
                break;
            }
        }
Esempio n. 2
0
        private void HandleMouseWithDragging(int itmeId, int controlId, Rect rect, GridItem item)
        {
            Event     current        = Event.current;
            EventType typeForControl = current.GetTypeForControl(controlId);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if (Event.current.button == 0 && rect.Contains(Event.current.mousePosition))
                {
                    if (current.clickCount == 2)
                    {
                        m_Owner.SetSelection(new int[1]
                        {
                            itmeId
                        }, true);
                        if (m_Owner.ItemDoubleClickAction != null)
                        {
                            m_Owner.ItemDoubleClickAction(item);
                        }
                        m_DragSelection.Clear();
                    }
                    else
                    {
                        m_DragSelection       = GetNewSelection(itmeId, true, false);
                        GUIUtility.hotControl = controlId;
                        ((DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), controlId))
                        .mouseDownPosition = Event.current.mousePosition;
                        m_Owner.ScrollToPosition(GridView.AdjustRectForFraming(rect));
                    }
                    current.Use();
                    break;
                }
                if (Event.current.button != 1 || !rect.Contains(Event.current.mousePosition))
                {
                    break;
                }

                m_Owner.SetSelection(GetNewSelection(itmeId, true, false).ToArray(), false);
                Event.current.Use();
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl != controlId)
                {
                    break;
                }

                if (rect.Contains(current.mousePosition))
                {
                    bool flag;
                    if (ListMode)
                    {
                        rect.x     += 28f;
                        rect.width += 28f;
                        flag        = rect.Contains(current.mousePosition);
                    }
                    else
                    {
                        rect.y      = rect.y + rect.height - GridView.s_Styles.resultsGridLabel.fixedHeight;
                        rect.height = GridView.s_Styles.resultsGridLabel.fixedHeight;
                        flag        = rect.Contains(current.mousePosition);
                    }
                    List <int> selectedInstanceIds = m_Owner.ViewConfig.SelectedItemIdList;
                    if (flag && m_Owner.ViewConfig.AllowRenaming &&
                        (m_Owner.AllowRenameOnMouseUp && selectedInstanceIds.Count == 1) &&
                        (selectedInstanceIds[0] == itmeId &&
                         !EditorGUIUtilityWrap.HasHolddownKeyModifiers(current)))
                    {
                        m_Owner.BeginRename(0.5f);
                    }
                    else
                    {
                        m_Owner.SetSelection(GetNewSelection(itmeId, false, false).ToArray(), false);
                    }
                    GUIUtility.hotControl = 0;
                    current.Use();
                }
                m_DragSelection.Clear();
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl != controlId)
                {
                    break;
                }
                if (((DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), controlId))
                    .CanStartDrag())
                {
                    m_Owner.ViewHandler.StartDrag(itmeId, m_DragSelection);
                    GUIUtility.hotControl = 0;
                }
                current.Use();
                break;

            default:
                if (typeForControl != EventType.DragUpdated && typeForControl != EventType.DragPerform)
                {
                    if (typeForControl != EventType.DragExited)
                    {
                        if (typeForControl != EventType.ContextClick)
                        {
                            break;
                        }

                        if (!rect.Contains(current.mousePosition))
                        {
                            break;
                        }

                        if (m_Owner.GirdItemPopupMenuAction != null)
                        {
                            m_Owner.GirdItemPopupMenuAction(item);
                            current.Use();
                        }
                        break;
                    }
                    m_DragSelection.Clear();
                    break;
                }
                bool perform = current.type == EventType.DragPerform;
                if (rect.Contains(current.mousePosition))
                {
                    DragAndDropVisualMode andDropVisualMode = m_Owner.ViewHandler.DoDrag(itmeId, perform);
                    if (andDropVisualMode != DragAndDropVisualMode.None)
                    {
                        if (perform)
                        {
                            DragAndDrop.AcceptDrag();
                        }
                        m_DropTargetControlID  = controlId;
                        DragAndDrop.visualMode = andDropVisualMode;
                        current.Use();
                    }
                    if (perform)
                    {
                        m_DropTargetControlID = 0;
                    }
                }
                if (!perform)
                {
                    break;
                }
                m_DragSelection.Clear();
                break;
            }
        }