示例#1
0
        private void HandleCommandEventsForTreeView()
        {
            var type = Event.current.type;

            switch (type)
            {
            case EventType.ExecuteCommand:
            case EventType.ValidateCommand:
                var flag      = type == EventType.ExecuteCommand;
                var selection = m_TreeView.GetSelection();
                if (selection.Length == 0 || !m_TreeView.HasFocus())
                {
                    return;
                }
                if (Event.current.commandName == "Delete" || Event.current.commandName == "SoftDelete")
                {
                    Event.current.Use();
                    if (flag)
                    {
                        var askIfSure = Event.current.commandName == "SoftDelete";
                        if (DeleteItemsAction != null)
                        {
                            DeleteItemsAction(askIfSure);
                        }

                        if (DeleteDoneAction != null)
                        {
                            DeleteDoneAction();
                        }

                        m_TreeView.NotifyListenersThatSelectionChanged();
                    }
                    GUIUtility.ExitGUI();
                }
                else if (Event.current.commandName == "Duplicate")
                {
                    if (flag)
                    {
                        if (DuplicateItemsAction != null)
                        {
                            Event.current.Use();
                            DuplicateItemsAction();
                            m_TreeView.NotifyListenersThatSelectionChanged();
                        }
                    }
                    else
                    {
                        Event.current.Use();
                    }
                }
                break;
            }
        }