/// <summary> /// Called to determine whether the Paste menu command should be enabled. /// </summary> /// <param name="cmd"></param> protected override void ProcessOnStatusPasteCommand(MenuCommand cmd) { CircuitsDocView docView = this.CurrentModelingDocView as CircuitsDocView; Diagram diagram = docView.CurrentDiagram; cmd.Visible = true; cmd.Enabled = diagram.ElementOperations.CanMerge(diagram, System.Windows.Forms.Clipboard.GetDataObject()); }
internal WrappingForm(CircuitsDocView docView, Control content) : this() { // Insert the DSL diagram into the Panel we've provided for it: DiagramPanel.Controls.Add(content); // Allows access to DSL from the form: this.docView = docView; }
/// <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(); } } } }
/// <summary> /// Called by the shell to ask the editor to create a new view object. /// </summary> protected override DslShell::ModelingDocView CreateDocView(DslShell::ModelingDocData docData, string physicalView, out string editorCaption) { // Create the view type supported by this editor. editorCaption = "blah"; CircuitsDocView dv = new CircuitsDocView(docData, this.ServiceProvider); /*foreach (ComponentModel cm in (docData as CircuitsDocData).ModelingDocStore.Store.ElementDirectory.FindElements<ComponentModel>()) * { * editorCaption += cm.Name; * } */ return(dv); }