Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 46f44c9

Browse files
committed
New Selection Extensions Server (PrimarySelectionButOnlyWhenMultipleSelectedExtensionServer) & fix OnlyOneItemSelectedExtensionServer
1 parent 19e600c commit 46f44c9

1 file changed

Lines changed: 34 additions & 22 deletions

File tree

src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/SelectionExtensionServer.cs

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,47 +103,59 @@ public override bool ShouldApplyExtensions(DesignItem extendedItem)
103103
}
104104

105105
/// <summary>
106-
/// Applies an extension to the primary selection if Only One Item is Selected.
106+
/// Applies an extension to the primary selection, but only when multiple Items are selected!
107107
/// </summary>
108-
public class OnlyOneItemSelectedExtensionServer : DefaultExtensionServer
108+
public class PrimarySelectionButOnlyWhenMultipleSelectedExtensionServer : PrimarySelectionExtensionServer
109109
{
110-
DesignItem oldPrimarySelection;
111-
bool oldCntBelowTwo = false;
110+
/// <summary>
111+
/// Is called after the extension server is initialized and the Context property has been set.
112+
/// </summary>
113+
protected override void OnInitialized()
114+
{
115+
base.OnInitialized();
116+
this.Services.Selection.SelectionChanged += OnSelectionChanged;
117+
}
118+
119+
void OnSelectionChanged(object sender, EventArgs e)
120+
{
121+
ReapplyExtensions(this.Services.Selection.SelectedItems);
122+
}
112123

124+
/// <summary>
125+
/// Gets if the item is in the secondary selection.
126+
/// </summary>
127+
public override bool ShouldApplyExtensions(DesignItem extendedItem)
128+
{
129+
return Services.Selection.PrimarySelection == extendedItem && Services.Selection.SelectionCount > 1;
130+
}
131+
}
132+
133+
/// <summary>
134+
/// Applies an extension to the primary selection if Only One Item is Selected.
135+
/// </summary>
136+
public class OnlyOneItemSelectedExtensionServer : PrimarySelectionExtensionServer
137+
{
113138
/// <summary>
114139
/// Is called after the extension server is initialized and the Context property has been set.
115140
/// </summary>
116141
protected override void OnInitialized()
117142
{
118143
base.OnInitialized();
119-
this.Services.Selection.PrimarySelectionChanged += OnPrimarySelectionChanged;
120-
this.Services.Selection.SelectionChanged += OnPrimarySelectionChanged;
144+
this.Services.Selection.SelectionChanged += OnSelectionChanged;
121145
}
122146

123-
void OnPrimarySelectionChanged(object sender, EventArgs e)
147+
void OnSelectionChanged(object sender, EventArgs e)
124148
{
125-
DesignItem newPrimarySelection = this.Services.Selection.PrimarySelection;
126-
127-
if (oldPrimarySelection != newPrimarySelection || oldCntBelowTwo != (this.Services.Selection.SelectedItems.Count < 2))
128-
{
129-
if (oldPrimarySelection == null) {
130-
ReapplyExtensions(new DesignItem[] { newPrimarySelection });
131-
} else if (newPrimarySelection == null) {
132-
ReapplyExtensions(new DesignItem[] { oldPrimarySelection });
133-
} else {
134-
ReapplyExtensions(new DesignItem[] { oldPrimarySelection, newPrimarySelection });
135-
}
136-
oldPrimarySelection = newPrimarySelection;
137-
oldCntBelowTwo = this.Services.Selection.SelectedItems.Count < 2;
138-
}
149+
if (this.Services.Selection.SelectedItems.Count > 1)
150+
ReapplyExtensions(this.Services.Selection.SelectedItems);
139151
}
140152

141153
/// <summary>
142154
/// Gets if the item is the primary selection.
143155
/// </summary>
144156
public override bool ShouldApplyExtensions(DesignItem extendedItem)
145157
{
146-
return (this.Services.Selection.SelectedItems.Count < 2 && this.Services.Selection.PrimarySelection == extendedItem);
158+
return Services.Selection.PrimarySelection == extendedItem && Services.Selection.SelectionCount < 2;
147159
}
148160
}
149161

0 commit comments

Comments
 (0)