@@ -48,34 +48,34 @@ public CodeInspectionsToolbar(VBE vbe, IInspector inspector)
4848
4949 public void Initialize ( )
5050 {
51- var toolbar = _vbe . CommandBars . Add ( RubberduckUI . CodeInspections , Temporary : true ) ;
52- _refreshButton = ( CommandBarButton ) toolbar . Controls . Add ( MsoControlType . msoControlButton , Temporary : true ) ;
51+ _toolbar = _vbe . CommandBars . Add ( RubberduckUI . CodeInspections , Temporary : true ) ;
52+ _refreshButton = ( CommandBarButton ) _toolbar . Controls . Add ( MsoControlType . msoControlButton , Temporary : true ) ;
5353 _refreshButton . TooltipText = RubberduckUI . CodeInspections_Run ;
5454
5555 var refreshIcon = Resources . Refresh ;
5656 refreshIcon . MakeTransparent ( Color . Magenta ) ;
5757 Menu . SetButtonImage ( _refreshButton , refreshIcon ) ;
5858
59- _statusButton = ( CommandBarButton ) toolbar . Controls . Add ( MsoControlType . msoControlButton , Temporary : true ) ;
59+ _statusButton = ( CommandBarButton ) _toolbar . Controls . Add ( MsoControlType . msoControlButton , Temporary : true ) ;
6060 _statusButton . Caption = string . Format ( RubberduckUI . CodeInspections_NumberOfIssues , 0 , "s" ) ;
6161 _statusButton . FaceId = 463 ; // Resources.Warning doesn't look good here
6262 _statusButton . Style = MsoButtonStyle . msoButtonIconAndCaption ;
6363
64- _quickFixButton = ( CommandBarButton ) toolbar . Controls . Add ( MsoControlType . msoControlButton , Temporary : true ) ;
64+ _quickFixButton = ( CommandBarButton ) _toolbar . Controls . Add ( MsoControlType . msoControlButton , Temporary : true ) ;
6565 _quickFixButton . Caption = RubberduckUI . Fix ;
6666 _quickFixButton . Style = MsoButtonStyle . msoButtonIconAndCaption ;
6767 _quickFixButton . FaceId = 305 ; // Resources.applycodechanges_6548_321 doesn't look good here
6868 _quickFixButton . Enabled = false ;
6969
70- _navigatePreviousButton = ( CommandBarButton ) toolbar . Controls . Add ( MsoControlType . msoControlButton , Temporary : true ) ;
70+ _navigatePreviousButton = ( CommandBarButton ) _toolbar . Controls . Add ( MsoControlType . msoControlButton , Temporary : true ) ;
7171 _navigatePreviousButton . BeginGroup = true ;
7272 _navigatePreviousButton . Caption = RubberduckUI . Previous ;
7373 _navigatePreviousButton . TooltipText = RubberduckUI . Previous ;
7474 _navigatePreviousButton . Style = MsoButtonStyle . msoButtonIconAndCaption ;
7575 _navigatePreviousButton . FaceId = 41 ; // Resources.112_LeftArrowLong_Blue_16x16_72 makes a gray Block when disabled
7676 _navigatePreviousButton . Enabled = false ;
7777
78- _navigateNextButton = ( CommandBarButton ) toolbar . Controls . Add ( MsoControlType . msoControlButton , Temporary : true ) ;
78+ _navigateNextButton = ( CommandBarButton ) _toolbar . Controls . Add ( MsoControlType . msoControlButton , Temporary : true ) ;
7979 _navigateNextButton . Caption = RubberduckUI . Next ;
8080 _navigateNextButton . TooltipText = RubberduckUI . Next ;
8181 _navigateNextButton . Style = MsoButtonStyle . msoButtonIconAndCaption ;
@@ -174,6 +174,8 @@ private void _quickFixButton_Click(CommandBarButton Ctrl, ref bool CancelDefault
174174 }
175175
176176 private CancellationTokenSource _tokenSource ;
177+ private CommandBar _toolbar ;
178+
177179 private void _refreshButton_Click ( CommandBarButton Ctrl , ref bool CancelDefault )
178180 {
179181 _tokenSource = new CancellationTokenSource ( ) ;
@@ -233,6 +235,14 @@ private void SetQuickFixTooltip()
233235
234236 public void Dispose ( )
235237 {
238+ Dispose ( true ) ;
239+ }
240+
241+ protected virtual void Dispose ( bool disposing )
242+ {
243+ if ( ! disposing ) { return ; }
244+
245+ _toolbar . Delete ( ) ;
236246 }
237247 }
238248}
0 commit comments