コード例 #1
0
        /// <summary>
        ///     Handles a mouse up event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseEventArgs"></param>
        private void HandleMouseUp(object sender, MouseEventArgs mouseEventArgs)
        {
            GraphicElement element = ElementForLocation(mouseEventArgs.Location, _movingBox);

            if (element != null)
            {
                element.HandleMouseUp(sender, mouseEventArgs);
            }

            if (_changingArrow != null)
            {
                _changingArrow      = null;
                _chaningArrowAction = ChangeAction.None;
                RefreshControl();
            }

            if (_movingBox != null)
            {
                if (_movingBoxHasMoved)
                {
                    if (element != null)
                    {
                        BaseTreeNode targetNode = CorrespondingNode(element.Model as IModelElement);
                        BaseTreeNode sourceNode = CorrespondingNode(_movingBox.Model as IModelElement);

                        if (targetNode != null && sourceNode != null && sourceNode != targetNode)
                        {
                            targetNode.AcceptDrop(sourceNode);
                            _movingBox.Location = new Point(0, 0);

                            if (Settings.Default.AllowRefactor)
                            {
                                RefactorAndRelocateOperation refactorAndRelocate =
                                    new RefactorAndRelocateOperation(sourceNode.Model as ModelElement);
                                refactorAndRelocate.ExecuteUsingProgressDialog(GuiUtils.MdiWindow, "Refactoring", false);
                            }
                        }
                    }

                    // Register the fact that the element has moved
                    // because
                    if (_movingBox.TypedModel.X != _positionBeforeMove.X ||
                        _movingBox.TypedModel.Y != _positionBeforeMove.Y)
                    {
                        EfsSystem.Instance.Context.HandleChangeEvent(_movingBox.Model as BaseModelElement,
                                                                     Context.ChangeKind.ModelChange);
                    }
                }

                _movingBox         = null;
                _movingBoxHasMoved = false;
            }
        }
コード例 #2
0
        /// <summary>
        ///     Called when the drop operation is performed on a node
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DragDropHandler(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("WindowsForms10PersistentObject", false))
            {
                Point        pt = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
                BaseTreeNode destinationNode = (BaseTreeNode)((BaseTreeView)sender).GetNodeAt(pt);
                object       data            = e.Data.GetData("WindowsForms10PersistentObject");
                BaseTreeNode sourceNode      = data as BaseTreeNode;
                if (sourceNode != null && destinationNode != null)
                {
                    if ((e.KeyState & Ctrl) != 0)
                    {
                        destinationNode.AcceptCopy(sourceNode);
                    }
                    else if ((e.KeyState & Alt) != 0)
                    {
                        destinationNode.AcceptMove(sourceNode);
                    }
                    else
                    {
                        destinationNode.AcceptDrop(sourceNode);
                        if (Refactor && Settings.Default.AllowRefactor)
                        {
                            NameSpace nameSpace = EnclosingFinder <NameSpace> .find(sourceNode.Model, true);

                            if (nameSpace != null)
                            {
                                // Only apply refactoring when dropping Model Element items
                                // This is useless for Requirements, and test related elements
                                RefactorAndRelocateOperation refactorAndRelocate =
                                    new RefactorAndRelocateOperation(sourceNode.Model as ModelElement);
                                refactorAndRelocate.ExecuteUsingProgressDialog(GuiUtils.MdiWindow, "Refactoring", false);
                            }
                        }
                    }
                }
            }
        }