Beispiel #1
0
        /// <summary>
        /// Paste command processing
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OnPaste(object sender, EventArgs e)
        {
            Diagram diagram = this.CurrentDocView.CurrentDiagram;

            if (diagram == null && this.SingleSelection != null)
            {
                return;
            }

            System.Windows.Forms.IDataObject data =
                System.Windows.Forms.Clipboard.GetDataObject();
            DesignSurfaceElementOperations op = diagram.ElementOperations;

            if (op.CanMerge(((PresentationElement)this.SingleSelection).ModelElement, data))
            {
                // Find a suitable place to position the new shape.
                PointD place = new PointD(0, 0);
                foreach (object item in this.CurrentSelection)
                {
                    ShapeElement shape = item as ShapeElement;
                    if (shape != null)
                    {
                        place = shape.AbsoluteBoundingBox.Center;
                        break;
                    }
                }
                using (Transaction t = diagram.Store.TransactionManager.BeginTransaction("paste"))
                {
                    // Do the business.
                    op.Merge((PresentationElement)this.SingleSelection, data, PointD.ToPointF(place));
                    t.Commit();
                    System.Windows.Forms.Clipboard.Clear();
                }
            }
        }
        /// <summary>
        /// Called when the user presses CTRL+V or chooses Paste on the diagram.
        /// This method assumes we only want to paste things onto the diagram
        /// - not onto anything contained in the diagram.
        /// The base method pastes in a free space on the diagram.
        /// But if the menu was used to invoke paste, we want to paste in the cursor position.
        /// </summary>
        protected override void ProcessOnMenuPasteCommand()
        {
            // If true, this method assumes we're only pasting on the diagram.
            // Anything selected will be deselected, and paste will be onto diagram.
            const bool pasteOnlyOnDiagram = true;

            CircuitsDocView docView = this.CurrentModelingDocView as CircuitsDocView;

            // Retrieve data from clipboard:
            System.Windows.Forms.IDataObject data = System.Windows.Forms.Clipboard.GetDataObject();

            Diagram diagram = docView.CurrentDiagram;

            if (diagram == null)
            {
                return;
            }

            if (!docView.IsContextMenuShowing)
            {
                // User hit CTRL+V - just use base method.

                // Deselect anything that's selected, otherwise
                // pasted item will be incompatible:
                if (pasteOnlyOnDiagram && !this.IsDiagramSelected())
                {
                    docView.SelectObjects(1, new object[] { diagram }, 0);
                }

                // Paste into a convenient spare space on diagram:
                base.ProcessOnMenuPasteCommand();
            }
            else
            {
                // User right-clicked - paste at mouse position.

                // Utility class:
                DesignSurfaceElementOperations op = diagram.ElementOperations;

                ShapeElement pasteTarget = pasteOnlyOnDiagram ? diagram : this.CurrentSelection.OfType <ShapeElement>().First();

                // Check whether what's in the paste buffer is acceptable on the target.
                if (op.CanMerge(pasteTarget, data))
                {
                    // Although op.Merge would be a no-op if CanMerge failed, we check CanMerge first
                    // so that we don't create an empty transaction (after which Undo would be no-op).
                    using (Transaction t = diagram.Store.TransactionManager.BeginTransaction("paste"))
                    {
                        PointD place = docView.ContextMenuMousePosition;
                        op.Merge(pasteTarget, data, PointD.ToPointF(place));
                        t.Commit();
                    }
                }
            }
        }
        private void ProcessDragDropItem(DiagramDragEventArgs e)
        {
            // Utility class:
            DesignSurfaceElementOperations op = this.ElementOperations;

            ShapeElement pasteTarget = this;

            // Check whether what's in the paste buffer is acceptable on the target.
            if (op.CanMerge(pasteTarget.ModelElement, e.Data))
            {
                // Although op.Merge would be a no-op if CanMerge failed, we check CanMerge first
                // so that we don't create an empty transaction (after which Undo would be no-op).
                using (Transaction t = this.Store.TransactionManager.BeginTransaction("paste"))
                {
                    PointD place = e.MousePosition;
                    op.Merge(pasteTarget, e.Data, PointD.ToPointF(place));
                    t.Commit();
                }
            }
        }
Beispiel #4
0
        ///// <summary>
        ///// Add a command to Paste the content of model elements from the clipboard.
        ///// </summary>
        ///// <param name="commands">List of command to add the paste command to.</param>
        //public void AddPasteCommand(IList<MenuCommand> commands)
        //{
        //    commands.Add(new DynamicStatusMenuCommand(new EventHandler(OnStatusPaste),
        //                                              new EventHandler(OnMenuPaste),
        //                                              StandardCommands.Paste));
        //}

        /// <summary>
        /// Status for the Paste Command
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OnStatusPaste(object sender, EventArgs e)
        {
            bool        flag    = false;
            MenuCommand command = sender as MenuCommand;
            Diagram     diagram = null;

            if (CurrentDocView != null)
            {
                diagram = this.CurrentDocView.CurrentDiagram;
            }
            if (diagram != null && this.SingleSelection != null)
            {
                System.Windows.Forms.IDataObject data = System.Windows.Forms.Clipboard.GetDataObject();
                if (data != null)
                {
                    DesignSurfaceElementOperations op = diagram.ElementOperations;
                    flag = op.CanMerge(((PresentationElement)this.SingleSelection).ModelElement, data);
                }
            }
            command.Visible = command.Enabled = flag;
        }