Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
v2.0.3.2
Browse files Browse the repository at this point in the history
Fix copy/paste between diagrams in same model
  • Loading branch information
msawczyn committed Apr 25, 2020
1 parent 2d4a1b0 commit 38a1466
Show file tree
Hide file tree
Showing 25 changed files with 583 additions and 495 deletions.
3 changes: 2 additions & 1 deletion changelog.txt
@@ -1,7 +1,8 @@
2.0.3
- Added ability to hide foreign key property names on association lines
- Fix: Self-associations don't appear when existing class is added to new diagram
- Fix: Self-associations didn't appear when existing class is added to new diagram from the Model Explorer
- Fix: Diagram no longer loses focus after its saved
- Fix: Errors when copy/paste between diagrams in same model

2.0.2
- Added count of elements in model explorer tree
Expand Down
89 changes: 47 additions & 42 deletions src/Dsl/CustomCode/Partials/EFModelDiagram.cs
Expand Up @@ -96,37 +96,40 @@ private bool IsAcceptableDropItem(DiagramDragEventArgs diagramDragEventArgs)

private List<ModelElement> DisplayedElements => NestedChildShapes.Select(nestedShape => nestedShape.ModelElement).ToList();

public ShapeElement AddExistingModelElement(ModelElement element)
public static ShapeElement AddExistingModelElement(EFModelDiagram diagram, ModelElement element)
{
if (NestedChildShapes.All(s => s.ModelElement != element))
if (diagram == null)
return null;

if (diagram.NestedChildShapes.All(s => s.ModelElement != element))
{
using (Transaction t = element.Store.TransactionManager.BeginTransaction())
{
try
{
ForceAddShape = true;
FixUpAllDiagrams.FixUp(this, element);
diagram.ForceAddShape = true;
FixUpAllDiagrams.FixUp(diagram, element);

// find all element links that are attached to our element where the ends are in the diagram but the link isn't already in the diagram
List<ElementLink> elementLinks = element.Store.GetAll<ElementLink>()
.Where(link => link.LinkedElements.Contains(element)
&& link.LinkedElements.All(linkedElement => DisplayedElements.Contains(linkedElement))
&& !DisplayedElements.Contains(link))
&& link.LinkedElements.All(linkedElement => diagram.DisplayedElements.Contains(linkedElement))
&& !diagram.DisplayedElements.Contains(link))
.ToList();

foreach (ElementLink elementLink in elementLinks)
FixUpAllDiagrams.FixUp(this, elementLink);
FixUpAllDiagrams.FixUp(diagram, elementLink);

t.Commit();
}
finally
{
ForceAddShape = false;
diagram.ForceAddShape = false;
}
}
}

return NestedChildShapes.FirstOrDefault(s => s.ModelElement == element);
return diagram.NestedChildShapes.FirstOrDefault(s => s.ModelElement == element);
}

public override void OnDragDrop(DiagramDragEventArgs diagramDragEventArgs)
Expand All @@ -137,56 +140,58 @@ public override void OnDragDrop(DiagramDragEventArgs diagramDragEventArgs)

if (element != null)
{
ShapeElement newShape = AddExistingModelElement(element);
ShapeElement newShape = AddExistingModelElement(this, element);

using (Transaction t = element.Store.TransactionManager.BeginTransaction())
using (Transaction t = element.Store.TransactionManager.BeginTransaction("Moving pasted shapes"))
{
if (newShape is NodeShape nodeShape)
nodeShape.Location = diagramDragEventArgs.MousePosition;

t.Commit();
}
}
else if (IsDropping)
else
{
string[] missingFiles = null;
string[] filenames;

if (diagramDragEventArgs.Data.GetData("Text") is string filename)
filenames = filename.Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);
else if (diagramDragEventArgs.Data.GetData("FileDrop") is string[] filenames1)
filenames = filenames1;
else
if (IsDropping)
{
ErrorDisplay.Show($"Unexpected error dropping files. Please create an issue in Github.");
IsDropping = false;
string[] filenames;

return;
}
if (diagramDragEventArgs.Data.GetData("Text") is string filename)
filenames = filename.Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);
else if (diagramDragEventArgs.Data.GetData("FileDrop") is string[] filenames1)
filenames = filenames1;
else
{
ErrorDisplay.Show($"Unexpected error dropping files. Please create an issue in Github.");
IsDropping = false;

string[] existingFiles = filenames.Where(File.Exists).ToArray();
FileDropHelper.HandleMultiDrop(Store, existingFiles);
missingFiles = filenames.Except(existingFiles).ToArray();
return;
}

if (missingFiles.Any())
{
if (missingFiles.Length > 1)
missingFiles[missingFiles.Length - 1] = "and " + missingFiles[missingFiles.Length - 1];
string[] existingFiles = filenames.Where(File.Exists).ToArray();
FileDropHelper.HandleMultiDrop(Store, existingFiles);
string[] missingFiles = filenames.Except(existingFiles).ToArray();

ErrorDisplay.Show($"Can't find files {string.Join(", ", missingFiles)}");
}
if (missingFiles.Any())
{
if (missingFiles.Length > 1)
missingFiles[missingFiles.Length - 1] = "and " + missingFiles[missingFiles.Length - 1];

IsDropping = false;
}
else
{
try
{
base.OnDragDrop(diagramDragEventArgs);
ErrorDisplay.Show($"Can't find files {string.Join(", ", missingFiles)}");
}

IsDropping = false;
}
catch (ArgumentException)
else
{
// ignore. byproduct of multiple diagrams
try
{
base.OnDragDrop(diagramDragEventArgs);
}
catch (ArgumentException)
{
// ignore. byproduct of multiple diagrams
}
}
}
}
Expand Down
22 changes: 10 additions & 12 deletions src/Dsl/Dsl.csproj
Expand Up @@ -246,6 +246,16 @@
<DesignTime>True</DesignTime>
<DependentUpon>FixUpAllDiagrams.tt</DependentUpon>
</Compile>
<Compile Include="GeneratedCode\MultiplicityValidation.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>MultiplicityValidation.tt</DependentUpon>
</Compile>
<Compile Include="GeneratedCode\PropertiesGrid.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>PropertiesGrid.tt</DependentUpon>
</Compile>
<Compile Include="GeneratedCode\SerializationHelper.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down Expand Up @@ -338,17 +348,6 @@
<DesignTime>True</DesignTime>
<DependentUpon>HelpKeywordHelper.tt</DependentUpon>
</Compile>
<Compile Include="GeneratedCode\MultiplicityValidation.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>MultiplicityValidation.tt</DependentUpon>
</Compile>
<Compile Include="GeneratedCode\PropertiesGrid.cs">
<DependentUpon>PropertiesGrid.tt</DependentUpon>
<SubType>Code</SubType>
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
</Compile>
<Compile Include="GeneratedCode\Shapes.cs">
<DependentUpon>Shapes.tt</DependentUpon>
<SubType>Code</SubType>
Expand Down Expand Up @@ -514,7 +513,6 @@
<Content Include="Resources\UnidirectionTool.bmp" />
<None Include="GeneratedCode\Serializer.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Serializer.cs</LastGenOutput>
</None>
<None Include="GeneratedCode\Shapes.tt">
<Generator>TextTemplatingFileGenerator</Generator>
Expand Down
2 changes: 1 addition & 1 deletion src/Dsl/DslDefinition.dsl
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Dsl xmlns:dm0="http://schemas.microsoft.com/VisualStudio/2008/DslTools/Core" dslVersion="1.0.0.0" Id="9987f227-3d05-49b7-b151-857879f5dfb8" Description="Entity Framework visual editor for EF6, EFCore and beyond." Name="EFModel" DisplayName="Entity Framework Visual Editor" Namespace="Sawczyn.EFDesigner.EFModel" MajorVersion="2" Build="3" Revision="1" ProductName="EFDesigner" CompanyName="Michael Sawczyn" PackageGuid="56bbe1ba-aaee-4883-848f-e3c8656f8db2" PackageNamespace="Sawczyn.EFDesigner.EFModel" xmlns="http://schemas.microsoft.com/VisualStudio/2005/DslTools/DslDefinitionModel">
<Dsl xmlns:dm0="http://schemas.microsoft.com/VisualStudio/2008/DslTools/Core" dslVersion="1.0.0.0" Id="9987f227-3d05-49b7-b151-857879f5dfb8" Description="Entity Framework visual editor for EF6, EFCore and beyond." Name="EFModel" DisplayName="Entity Framework Visual Editor" Namespace="Sawczyn.EFDesigner.EFModel" MajorVersion="2" Build="3" Revision="2" ProductName="EFDesigner" CompanyName="Michael Sawczyn" PackageGuid="56bbe1ba-aaee-4883-848f-e3c8656f8db2" PackageNamespace="Sawczyn.EFDesigner.EFModel" xmlns="http://schemas.microsoft.com/VisualStudio/2005/DslTools/DslDefinitionModel">
<Classes>
<DomainClass Id="95532cb8-3452-4b09-a654-aeb2e2d0b3ad" Description="" Name="ModelRoot" DisplayName="Entity Model" Namespace="Sawczyn.EFDesigner.EFModel">
<CustomTypeDescriptor>
Expand Down

0 comments on commit 38a1466

Please sign in to comment.