@@ -14,12 +14,13 @@ namespace BIDSHelper.SSIS
1414 using Microsoft . SqlServer . Dts . Design ;
1515 using Microsoft . SqlServer . Management . UI . Grid ;
1616
17- #if KATMAI || DENALI || SQL2014
17+ #if KATMAI || DENALI || SQL2014
1818 using IDTSInfoEventsXX = Microsoft . SqlServer . Dts . Runtime . Wrapper . IDTSInfoEvents100 ;
19- #else
19+ using System . Reflection ;
20+ #else
2021 using IDTSInfoEventsXX = Microsoft . SqlServer . Dts . Runtime . Wrapper . IDTSInfoEvents90 ;
21- #endif
22-
22+ #endif
23+
2324 public partial class VariablesWindowPlugin : BIDSHelperWindowActivatedPluginBase
2425 {
2526 /// <summary>
@@ -125,6 +126,23 @@ private void HookupVariablesWindow(Window GotFocus)
125126 // If buttons already added, no need to do it again so exit
126127 if ( this . moveCopyButton != null && toolbar . Buttons . Contains ( this . moveCopyButton ) ) return ;
127128
129+ #if DENALI || SQL2014
130+ // When you clock the edit expression ellipsis button in the variables grid, we want to use our own expression editor, not the MS one.
131+ // The following section removes their event handler and adds our own
132+ // Get the type of the variables grid, and get the MouseButtonClicked clicked event info
133+ // Then get the private dlgGridControl1_MouseButtonClicked event handler method, and get an instance delegate
134+ Type gridType = grid . GetType ( ) ;
135+ System . Reflection . EventInfo eventInfo = gridType . GetEvent ( "MouseButtonClicked" ) ;
136+ Type handlerType = eventInfo . EventHandlerType ;
137+ MethodInfo legacyMethod = variablesToolWindowControl . GetType ( ) . GetMethod ( "dlgGridControl1_MouseButtonClicked" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
138+ Delegate del = Delegate . CreateDelegate ( handlerType , variablesToolWindowControl , legacyMethod , false ) ;
139+
140+ // Finally remove the interal MS event handler from the event, and add our own
141+ eventInfo . RemoveEventHandler ( grid , del ) ;
142+ grid . MouseButtonClicked += grid_MouseButtonClicked ;
143+ #endif
144+
145+ // Now build tool bar buttons and add them
128146 ToolBarButton separator = new ToolBarButton ( ) ;
129147 separator . Style = ToolBarButtonStyle . Separator ;
130148 toolbar . Buttons . Add ( separator ) ;
@@ -180,6 +198,16 @@ private void HookupVariablesWindow(Window GotFocus)
180198 }
181199 }
182200
201+ private void grid_MouseButtonClicked ( object sender , MouseButtonClickedEventArgs args )
202+ {
203+ // Fragile, as relies on hardcoded index. We are trying to replicate Microsoft.DataTransformationServices.Design.VariablesToolWindow.dlgGridControl1_MouseButtonClicked method check
204+ if ( args . Button == MouseButtons . Left && args . ColumnIndex == 6 )
205+ {
206+ // Dumbass, the args.RowIndex is a long, but all the grid methods that accept a row index are int!
207+ EditExpressionButtonClick ( ( int ) args . RowIndex , args . ColumnIndex ) ;
208+ }
209+ }
210+
183211 //only way I could find to monitor when row data in the grid changes
184212 void grid_Invalidated ( object sender , InvalidateEventArgs e )
185213 {
@@ -358,16 +386,21 @@ void toolbar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
358386
359387
360388 private void EditExpressionButtonClick ( )
389+ {
390+ int selectedRow ;
391+ int selectedCol ;
392+ grid . GetSelectedCell ( out selectedRow , out selectedCol ) ;
393+
394+ EditExpressionButtonClick ( selectedRow , selectedCol ) ;
395+ }
396+
397+ private void EditExpressionButtonClick ( int selectedRow , int selectedCol )
361398 {
362399 try
363400 {
364401 Package package = GetCurrentPackage ( ) ;
365402 if ( package == null ) return ;
366403
367- int selectedRow ;
368- int selectedCol ;
369- grid . GetSelectedCell ( out selectedRow , out selectedCol ) ;
370-
371404 if ( selectedRow < 0 ) return ;
372405
373406 Variable variable = GetVariableForRow ( selectedRow ) ;
0 commit comments