Is it normal that when I selected a shape, the copy/paste operations are disabled
I suppose copy and pasting of shape is not supported
Is there an easy way to make it work
Thanks!
Mike
Is it normal that when I selected a shape, the copy/paste operations are disabled
I suppose copy and pasting of shape is not supported
Is there an easy way to make it work
Thanks!
Mike
Copy/Paste
AmirAlis
Hi Coconut & Mike
There is indeed a bug in our V1 preventing the simple code for copy/paste of shapes from working.
However, we'd generally recommend that unless you really need to, you implement copy/paste at the underlying model elements level, not the shapes level and I'm glad to say that's currently working fine.
Here's a revision of the code above amended for V1 and to use the underlying model elements
private void OnCopy(object sender, EventArgs args)
{
if (this.CurrentDocumentSelection.Count > 0)
{
List<ModelElement> selectedElements = new List<ModelElement>();
foreach (object selectedObject in this.CurrentDocumentSelection)
{
PresentationElement element = selectedObject as PresentationElement;
if (element != null && element.Subject != null)
{
selectedElements.Add(element.Subject);
}
}
IDataObject data = new DataObject();
Microsoft.VisualStudio.Modeling.Diagrams.Diagram diagram = this.CurrentDocView.CurrentDiagram;
diagram.ElementOperations.Copy(data, selectedElements);
Clipboard.SetDataObject(data, true, 5, 100);
}
}
private
void OnPaste(object sender, EventArgs args){ IDataObject data = Clipboard.GetDataObject();
Microsoft.VisualStudio.Modeling.Diagrams.Diagram diagram = this.CurrentDocView.CurrentDiagram;
if (diagram.ElementOperations.CanMerge(diagram.Subject, data))
{
using (Transaction t = diagram.Store.TransactionManager.BeginTransaction("Paste"))
{
diagram.ElementOperations.Merge(diagram.Subject, data);
t.Commit();
}
}
}
We have a specific workaround for the actual problem with copy/pasting Shapes is anyone needs it, but its a horible bit of reflection code, so I won't post it unless someone actually has a need - please email me if you do.
Fusion54
In the bits i'm using (March SDK), the Microsoft.VisualStudio.Modeling.Diagrams.Diagram class is defined in the Microsoft.VisualStudio.Modeling.Sdk.Diagrams assembly located in c:\Program Files\Visual Studio 2005 SDK\2006.03\VisualStudioIntegration\Common\Assemblies\Microsoft.VisualStudio.Modeling.Sdk.Diagrams.dll
Mike
Pati123
The code is specific to the DSL Tools, which is an diagramming add-on to Visual Studio 2005.
Sorry, it won't work in your case.
Mike
ReneeC
I tried to use the code posted by Mike without success.
.CanMerge always return false when I tried to do a paste. When I looked at the IDataObject object returned from Clipbpard.GetDataObject(), it doesn't look like a model data.
Any thoughts
Joe
Donnieb
I tried to use the code posted by Mike without success.
.CanMerge always return false when I tried to do a paste. When I looked at the IDataObject object returned from Clipbpard.GetDataObject(), it doesn't look like a model data.
Any thoughts
Joe
OPH
Hi Mike,
Yes, that's the expected behavior. We're not planning to enable Copy/Paste by default for V1, although it's not too hard to implement yourself. Hopefully we'll have a V1 code sample that shows this. If you're interested in trying this in the meantime, here are a few pointers:
Copy:
1. Add a handler for StandardCommands.Copy to your command set.
2. Create an IDataObject (System.Windows.Forms.DataObject will do).
3. Call Diagram.ElementOperations.Copy, passing the data object and the collection of selected shapes. This call populates the data object with data about the selected objects.
4. Put the data object on the clipboard.
Paste:
1. Add a handler for StandardCommands.Paste
2. Call Diagram.ElementOperations.CanMerge, passing the clipboard data object and the target parent element (generally the Diagram itself) to see if Paste is allowed.
3. If so, call Diagram.ElementOperations.Merge to perform Paste.
Thanks,
Grayson
Debabrata.debroy
i am using visual studio 2003. i have searched in my machine, not able to find the mentioned dll. is that new in 2005
else any alternate approach to build the logic.
to be more detail...i need to copy normal controls(textbox, label,...) and also third party controls(syncfusion grid and chart).
when the user drags the control i am generating xml (my own) for the particular control. the user can save the stuff and when reopens agains, reading the data from the xml and creating the controls.
Thanks for replying
Praveen
Jassim Rahma
Any particular reason why this is not enabled, since the code is so simple
Mike
swingme
I got the Copy/Paste working with the following code. The only problem is that child classes (domain model) are not copied with the parent class. For example, when I copy class from the class diagram template, the attributes and the operations are not copied with the class. How could I get them copied too
Thanks!
Mike
internal void CopyHandler(object sender, EventArgs e)
{
if (this.SelectionCount > 0)
{
IDataObject data = new DataObject();
Microsoft.VisualStudio.Modeling.Diagrams.Diagram diagram = this.CurrentView.CurrentDiagram;
diagram.ElementOperations.Copy(data, this.CurrentSelection);
Clipboard.SetDataObject(data, false, 100, 50);
}
}
internal void PasteHandler(object sender, EventArgs e)
{
IDataObject data = Clipboard.GetDataObject();
Microsoft.VisualStudio.Modeling.Diagrams.Diagram diagram = this.CurrentView.CurrentDiagram;
if (diagram.ElementOperations.CanMerge(diagram.ModelElement, data))
diagram.ElementOperations.Merge(diagram.ModelElement, data);
}
Rhubarb
Hi Mike,
This looks like a bug in our V1 - We're investigating now and we'll get back to you.
mikebk
Hello Mike,
This is praveen from india.
i am not able to find VisualStudio namespace under Microsoft. Can you help me in this.
Thanks,
Praveen
71M
Hi Mike,
There's a piece of metadata on a domain role named PropagatesCopy which controls whether the element at the other end of a relationship is included in the set of elements to copy. Unfortunately, it appears we always set this to false in the generated code in the current CTP. However, I've confirmed that we are modeling this flag for V1, so you will be able to control the copy behavior through this flag in the future.
Thanks,
Grayson