@@ -102,6 +102,51 @@ public override bool ShouldApplyExtensions(DesignItem extendedItem)
102102 }
103103 }
104104
105+ /// <summary>
106+ /// Applies an extension to the primary selection if Only One Item is Selected.
107+ /// </summary>
108+ public class OnlyOneItemSelectedExtensionServer : DefaultExtensionServer
109+ {
110+ DesignItem oldPrimarySelection ;
111+ bool oldCntBelowTwo = false ;
112+
113+ /// <summary>
114+ /// Is called after the extension server is initialized and the Context property has been set.
115+ /// </summary>
116+ protected override void OnInitialized ( )
117+ {
118+ base . OnInitialized ( ) ;
119+ this . Services . Selection . PrimarySelectionChanged += OnPrimarySelectionChanged ;
120+ this . Services . Selection . SelectionChanged += OnPrimarySelectionChanged ;
121+ }
122+
123+ void OnPrimarySelectionChanged ( object sender , EventArgs e )
124+ {
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+ }
139+ }
140+
141+ /// <summary>
142+ /// Gets if the item is the primary selection.
143+ /// </summary>
144+ public override bool ShouldApplyExtensions ( DesignItem extendedItem )
145+ {
146+ return ( this . Services . Selection . SelectedItems . Count < 2 && this . Services . Selection . PrimarySelection == extendedItem ) ;
147+ }
148+ }
149+
105150 /// <summary>
106151 /// Applies an extension to the parent of the primary selection.
107152 /// </summary>
0 commit comments