Skip to content

Commit 0cf7aa5

Browse files
authored
Fix for Accessibility Bug 586335 (dotnet#511)
Fix for Accessibility Bug 586335 - EntityType shape, Properties and Navigation Properties compartments key handlers.
1 parent 55d3414 commit 0cf7aa5

File tree

4 files changed

+65
-58
lines changed

4 files changed

+65
-58
lines changed

src/EFTools/EntityDesignEntityDesigner/CustomCode/Diagram/EntityTypeElementListCompartment.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -114,30 +114,5 @@ public override string AccessibleHelp
114114
return Resources.AccHelp_EntityTypeNavigationPropertyCompartment;
115115
}
116116
}
117-
118-
internal void CollapseInTransaction()
119-
{
120-
if (IsExpanded)
121-
{
122-
using (var txn = Store.TransactionManager.BeginTransaction())
123-
{
124-
Collapse();
125-
txn.Commit();
126-
}
127-
}
128-
}
129-
130-
131-
internal void ExpandInTransaction()
132-
{
133-
if (!IsExpanded)
134-
{
135-
using (var txn = Store.TransactionManager.BeginTransaction())
136-
{
137-
Expand();
138-
txn.Commit();
139-
}
140-
}
141-
}
142117
}
143118
}

src/EFTools/EntityDesignEntityDesigner/CustomCode/Shapes/EntityTypeShape.cs

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ internal partial class EntityTypeShape
3333
private static Image _complexPropertyBitmap;
3434
private static Image _navigationPropertyBitmap;
3535
private bool _isAdjustedForFillColor;
36-
private EntityChevronButtonField _expandCollapseField;
3736

3837
internal class EntityChevronButtonField : ChevronButtonField
3938
{
@@ -104,6 +103,9 @@ public override void OnInitialize()
104103
bounds.Location = randomized;
105104
AbsoluteBounds = bounds;
106105
EntityDesignerViewModel.EntityShapeLocationSeed++;
106+
107+
// Provide keyboard shortcuts for collapse and expand of this EntityType shape
108+
this.KeyUp += EntityTypeShape_KeyUp;
107109
}
108110

109111
/// <summary>
@@ -446,16 +448,11 @@ protected override void InitializeShapeFields(IList<ShapeField> shapeFields)
446448
// replace default glyphs in header with ones that respond to filler color and scale with the UX
447449
ReplaceField(
448450
shapeFields, "ExpandCollapse",
449-
fieldName =>
450-
{
451-
_expandCollapseField =
452-
new EntityChevronButtonField(fieldName)
453-
{
454-
DefaultSelectable = false,
455-
DefaultFocusable = false
456-
};
457-
return _expandCollapseField;
458-
});
451+
fieldName => new EntityChevronButtonField(fieldName)
452+
{
453+
DefaultSelectable = false,
454+
DefaultFocusable = false
455+
});
459456
ReplaceField(
460457
shapeFields, "IconDecorator",
461458
fieldName => new EntityImageField(fieldName, appearance => appearance.EntityGlyph));
@@ -487,11 +484,11 @@ public override void EnsureCompartments()
487484
SetAccessibilityOnCompartment(NavigationCompartment, false);
488485

489486
// need to add our own handler for KeyUp event in order to disable Insert key for Navigation Compartment
490-
// and provide keyboard shorcuts for expand and collapse.
487+
// and provide keyboard shortcuts for expand and collapse.
491488
NavigationCompartment.KeyUp += NavigationCompartmentKeyUpHandler;
492489

493490
// since Properties compartment contains now two DomainClasses (Scalar and Complex) we need to handle Insert key on our own
494-
// and provide keyboard shorcuts for expand and collapse.
491+
// and provide keyboard shortcuts for expand and collapse.
495492
PropertiesCompartment.KeyUp += PropertiesCompartmentKeyUpHandler;
496493
}
497494

@@ -518,13 +515,13 @@ private void PropertiesCompartmentKeyUpHandler(object sender, DiagramKeyEventArg
518515
// Provide keyboard shortcuts for expand and collapse.
519516
if (e.Control && e.KeyCode == Keys.Up)
520517
{
521-
PropertiesCompartment.CollapseInTransaction();
518+
PropertiesCompartment.EnsureExpandedState(false);
522519
e.Handled = true;
523520
}
524521

525522
if (e.Control && e.KeyCode == Keys.Down)
526523
{
527-
PropertiesCompartment.ExpandInTransaction();
524+
PropertiesCompartment.EnsureExpandedState(true);
528525
e.Handled = true;
529526
}
530527
}
@@ -545,13 +542,13 @@ private void NavigationCompartmentKeyUpHandler(object sender, DiagramKeyEventArg
545542

546543
if (e.Control && e.KeyCode == Keys.Up)
547544
{
548-
NavigationCompartment.CollapseInTransaction();
545+
NavigationCompartment.EnsureExpandedState(false);
549546
e.Handled = true;
550547
}
551548

552549
if (e.Control && e.KeyCode == Keys.Down)
553550
{
554-
NavigationCompartment.ExpandInTransaction();
551+
NavigationCompartment.EnsureExpandedState(true);
555552
e.Handled = true;
556553
}
557554
}
@@ -690,28 +687,19 @@ public override string AccessibleHelp
690687
}
691688
}
692689

693-
public override void OnKeyUp(DiagramKeyEventArgs e)
690+
private void EntityTypeShape_KeyUp(object sender, DiagramKeyEventArgs e)
694691
{
695692
if (e.Control && e.KeyCode == Keys.Up)
696693
{
697-
var isExpanded = _expandCollapseField.IsExpanded(this);
698-
if (isExpanded.HasValue && isExpanded.Value)
699-
{
700-
_expandCollapseField.ChangeState(this);
701-
e.Handled = true;
702-
}
694+
this.EnsureExpandedState(false);
695+
e.Handled = true;
703696
}
697+
704698
if (e.Control && e.KeyCode == Keys.Down)
705699
{
706-
var isExpanded = _expandCollapseField.IsExpanded(this);
707-
if (isExpanded.HasValue && !isExpanded.Value)
708-
{
709-
_expandCollapseField.ChangeState(this);
710-
e.Handled = true;
711-
}
700+
this.EnsureExpandedState(true);
701+
e.Handled = true;
712702
}
713-
714-
base.OnKeyUp(e);
715703
}
716704

717705
/// <summary>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2+
3+
namespace Microsoft.Data.Entity.Design.EntityDesigner.CustomCode.Utils
4+
{
5+
using Microsoft.VisualStudio.Modeling.Diagrams;
6+
7+
/// <summary>
8+
/// Helper extension method for NodeShape objects
9+
/// </summary>
10+
internal static class NodeShapeExtensions
11+
{
12+
/// <summary>
13+
/// Ensures that a <see cref="NodeShape"/> has a particular expanded or collapsed state
14+
/// </summary>
15+
/// <param name="nodeShape">the <see cref="NodeShape"/> on which to ensure the state</param>
16+
/// <param name="expanded">if true, ensure that nodeShape is expanded, if false esnure that it is collapsed</param>
17+
public static void EnsureExpandedState(this NodeShape nodeShape, bool expanded)
18+
{
19+
if (expanded)
20+
{
21+
if (!nodeShape.IsExpanded)
22+
{
23+
using (var txn = nodeShape.Store.TransactionManager.BeginTransaction())
24+
{
25+
nodeShape.IsExpanded = true;
26+
txn.Commit();
27+
}
28+
}
29+
}
30+
else
31+
{
32+
if (nodeShape.IsExpanded)
33+
{
34+
using (var txn = nodeShape.Store.TransactionManager.BeginTransaction())
35+
{
36+
nodeShape.IsExpanded = false;
37+
txn.Commit();
38+
}
39+
}
40+
}
41+
}
42+
}
43+
}

src/EFTools/EntityDesignEntityDesigner/EntityDesigner.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), BuildEFTools.cmd))\tools\EntityFramework.settings.targets"/>
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), BuildEFTools.cmd))\tools\EntityFramework.settings.targets" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -182,6 +182,7 @@
182182
<Compile Include="CustomCode\Utils\Constants.cs" />
183183
<Compile Include="CustomCode\Utils\FileUtils.cs" />
184184
<Compile Include="CustomCode\Utils\ModelUtils.cs" />
185+
<Compile Include="CustomCode\Utils\NodeShapeExtensions.cs" />
185186
<Compile Include="CustomCode\Validation\Association.cs" />
186187
<Compile Include="CustomCode\Validation\EntityDesignerViewModel.cs" />
187188
<Compile Include="CustomCode\Validation\EntityType.cs" />

0 commit comments

Comments
 (0)