private void HookupVariablesWindow(Window GotFocus) { try { try { if (GotFocus == null) { return; } if (GotFocus.ObjectKind != SSIS_VARIABLES_TOOL_WINDOW_KIND) { return; //if not the variables window } } catch //ObjectKind property blows up on some windows { return; } //they've highlighted the Variables window, so add the extra toolbar buttons //find a package designer window IDesignerHost designer = null; foreach (Window w in this.ApplicationObject.Windows) { try { designer = w.Object as IDesignerHost; if (designer == null) { continue; } ProjectItem pi = w.ProjectItem; if (pi != null && !(pi.Name.ToLower().EndsWith(".dtsx"))) { designer = null; continue; } } catch { continue; } IDesignerToolWindowService service = (IDesignerToolWindowService)designer.GetService(typeof(IDesignerToolWindowService)); if (service == null) { continue; } IDesignerToolWindow toolWindow = service.GetToolWindow(new Guid(SSIS_VARIABLES_TOOL_WINDOW_KIND), 0); if (toolWindow == null) { continue; } variablesToolWindowControl = (UserControl)toolWindow.Client; //actually Microsoft.DataTransformationServices.Design.VariablesToolWindow which is internal serviceProvider = designer; changesvc = (IComponentChangeService)designer.GetService(typeof(IComponentChangeService)); // Get grid and toolbar #if DENALI || SQL2014 // "tableLayoutPanelMain" - "tableLayoutPanelVariable" - "dlgGridControl1" | "toolBarVariable" grid = (DlgGridControl)variablesToolWindowControl.Controls[0].Controls[0].Controls[0]; ToolBar toolbar = (ToolBar)variablesToolWindowControl.Controls[0].Controls[0].Controls[1]; #else grid = (DlgGridControl)variablesToolWindowControl.Controls["dlgGridControl1"]; ToolBar toolbar = (ToolBar)variablesToolWindowControl.Controls["toolBar1"]; #endif // If buttons already added, no need to do it again so exit if (this.moveCopyButton != null && toolbar.Buttons.Contains(this.moveCopyButton)) { return; } ToolBarButton separator = new ToolBarButton(); separator.Style = ToolBarButtonStyle.Separator; toolbar.Buttons.Add(separator); // Move/Copy button this.moveCopyButton = new ToolBarButton(); this.moveCopyButton.Style = ToolBarButtonStyle.PushButton; this.moveCopyButton.ToolTipText = "Move/Copy Variables to New Scope (BIDS Helper)"; toolbar.Buttons.Add(this.moveCopyButton); toolbar.ImageList.Images.Add(BIDSHelper.Resources.Common.Copy); this.moveCopyButton.ImageIndex = toolbar.ImageList.Images.Count - 1; //Edit Variable Expression button this.editExpressionButton = new ToolBarButton(); this.editExpressionButton.Style = ToolBarButtonStyle.PushButton; this.editExpressionButton.ToolTipText = "Edit Variable Expression (BIDS Helper)"; toolbar.Buttons.Add(this.editExpressionButton); toolbar.ImageList.Images.Add(BIDSHelper.Resources.Versioned.EditVariable); this.editExpressionButton.ImageIndex = toolbar.ImageList.Images.Count - 1; toolbar.ButtonClick += new ToolBarButtonClickEventHandler(toolbar_ButtonClick); toolbar.Wrappable = false; grid.SelectionChanged += new SelectionChangedEventHandler(grid_SelectionChanged); grid.Invalidated += new InvalidateEventHandler(grid_Invalidated); SetButtonEnabled(); RefreshHighlights(); return; } } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n\r\n" + ex.StackTrace); } }
private void HookupVariablesWindow(Window GotFocus) { try { try { if (GotFocus == null) { return; } if (GotFocus.ObjectKind != SSIS_VARIABLES_TOOL_WINDOW_KIND) { return; //if not the variables window } } catch //ObjectKind property blows up on some windows { return; } //they've highlighted the Variables window, so add the extra toolbar buttons //find a package designer window IDesignerHost designer = null; foreach (Window w in this.ApplicationObject.Windows) { try { designer = w.Object as IDesignerHost; if (designer == null) { continue; } ProjectItem pi = w.ProjectItem; if (pi != null && !(pi.Name.ToLower().EndsWith(".dtsx"))) { designer = null; continue; } } catch { continue; } IDesignerToolWindowService service = (IDesignerToolWindowService)designer.GetService(typeof(IDesignerToolWindowService)); if (service == null) { continue; } IDesignerToolWindow toolWindow = service.GetToolWindow(new Guid(SSIS_VARIABLES_TOOL_WINDOW_KIND), 0); if (toolWindow == null) { continue; } variablesToolWindowControl = (UserControl)toolWindow.Client; //actually Microsoft.DataTransformationServices.Design.VariablesToolWindow which is internal serviceProvider = designer; changesvc = (IComponentChangeService)designer.GetService(typeof(IComponentChangeService)); // Get grid and toolbar #if DENALI || SQL2014 // "tableLayoutPanelMain" - "tableLayoutPanelVariable" - "dlgGridControl1" | "toolBarVariable" grid = (DlgGridControl)variablesToolWindowControl.Controls[0].Controls[0].Controls[0]; ToolBar toolbar = (ToolBar)variablesToolWindowControl.Controls[0].Controls[0].Controls[1]; #else grid = (DlgGridControl)variablesToolWindowControl.Controls["dlgGridControl1"]; ToolBar toolbar = (ToolBar)variablesToolWindowControl.Controls["toolBar1"]; #endif // If buttons already added, no need to do it again so exit if (this.moveCopyButton != null && toolbar.Buttons.Contains(this.moveCopyButton)) { return; } #if DENALI || SQL2014 // When you click the edit expression ellipsis button in the variables grid, we want to use our own expression editor, not the MS one. // The following section removes their event handler and adds our own // Get the type of the variables grid, and get the MouseButtonClicked clicked event info // Then get the private dlgGridControl1_MouseButtonClicked event handler method, and get an instance delegate Type gridType = grid.GetType(); System.Reflection.EventInfo eventInfo = gridType.GetEvent("MouseButtonClicked"); Type handlerType = eventInfo.EventHandlerType; MethodInfo legacyMethod = variablesToolWindowControl.GetType().GetMethod("dlgGridControl1_MouseButtonClicked", BindingFlags.NonPublic | BindingFlags.Instance); Delegate del = Delegate.CreateDelegate(handlerType, variablesToolWindowControl, legacyMethod, false); // Finally remove the interal MS event handler from the event, and add our own eventInfo.RemoveEventHandler(grid, del); grid.MouseButtonClicked += grid_MouseButtonClicked; #endif // Now build tool bar buttons and add them ToolBarButton separator = new ToolBarButton(); separator.Style = ToolBarButtonStyle.Separator; toolbar.Buttons.Add(separator); // Move/Copy button this.moveCopyButton = new ToolBarButton(); this.moveCopyButton.Style = ToolBarButtonStyle.PushButton; this.moveCopyButton.ToolTipText = "Move/Copy Variables to New Scope (BIDS Helper)"; toolbar.Buttons.Add(this.moveCopyButton); toolbar.ImageList.Images.Add(BIDSHelper.Resources.Common.Copy); this.moveCopyButton.ImageIndex = toolbar.ImageList.Images.Count - 1; // Edit Variable Expression button this.editExpressionButton = new ToolBarButton(); this.editExpressionButton.Style = ToolBarButtonStyle.PushButton; this.editExpressionButton.ToolTipText = "Edit Variable Expression (BIDS Helper)"; toolbar.Buttons.Add(this.editExpressionButton); toolbar.ImageList.Images.Add(BIDSHelper.Resources.Versioned.EditVariable); this.editExpressionButton.ImageIndex = toolbar.ImageList.Images.Count - 1; #if DENALI || SQL2014 // Find References button this.findReferencesButton = new ToolBarButton(); this.findReferencesButton.Style = ToolBarButtonStyle.PushButton; this.findReferencesButton.ToolTipText = "Find Variable References (BIDS Helper)"; toolbar.Buttons.Add(this.findReferencesButton); toolbar.ImageList.Images.Add(BIDSHelper.Resources.Versioned.VariableFindReferences); this.findReferencesButton.ImageIndex = toolbar.ImageList.Images.Count - 1; // Find Unused button this.findUnusedButton = new ToolBarButton(); this.findUnusedButton.Style = ToolBarButtonStyle.PushButton; this.findUnusedButton.ToolTipText = "Find Unused Variables (BIDS Helper)"; toolbar.Buttons.Add(this.findUnusedButton); toolbar.ImageList.Images.Add(BIDSHelper.Resources.Versioned.VariableFindUnused); this.findUnusedButton.ImageIndex = toolbar.ImageList.Images.Count - 1; #endif toolbar.ButtonClick += new ToolBarButtonClickEventHandler(toolbar_ButtonClick); toolbar.Wrappable = false; grid.SelectionChanged += new SelectionChangedEventHandler(grid_SelectionChanged); grid.Invalidated += new InvalidateEventHandler(grid_Invalidated); SetButtonEnabled(); RefreshHighlights(); return; } } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n\r\n" + ex.StackTrace, DefaultMessageBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); } }