1 /***************************************************************************
3 Copyright (c) Microsoft Corporation. All rights reserved.
4 THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
5 ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
6 IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
7 PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
9 ***************************************************************************/
12 using System
.Collections
;
13 using System
.ComponentModel
;
14 using System
.ComponentModel
.Design
;
16 using Microsoft
.Win32
;
17 using System
.Runtime
.InteropServices
;
18 using System
.Windows
.Forms
;
19 using Microsoft
.VisualStudio
.Shell
;
20 using Microsoft
.VisualStudio
.Shell
.Interop
;
21 using Microsoft
.VisualStudio
.PlatformUI
;
23 using IServiceProvider
= System
.IServiceProvider
;
24 using IOleServiceProvider
= Microsoft
.VisualStudio
.OLE
.Interop
.IServiceProvider
;
26 namespace Microsoft
.Samples
.VisualStudio
.SourceControlIntegration
.SccProvider
29 /// Summary description for SccProviderToolWindow.
31 [Guid("B0BAC05D-bbbb-42f2-8085-723ca3712763")]
32 public class SccProviderToolWindow
: ToolWindowPane
34 private SccProviderToolWindowControl control
;
36 public SccProviderToolWindow() :base(null)
38 // set the window title
39 this.Caption
= Resources
.ResourceManager
.GetString("ToolWindowCaption");
41 // set the CommandID for the window ToolBar
42 this.ToolBar
= new CommandID(GuidList
.guidSccProviderCmdSet
, CommandId
.imnuToolWindowToolbarMenu
);
44 // set the icon for the frame
45 this.BitmapResourceID
= CommandId
.ibmpToolWindowsImages
; // bitmap strip resource ID
46 this.BitmapIndex
= CommandId
.iconSccProviderToolWindow
; // index in the bitmap strip
48 control
= new SccProviderToolWindowControl();
49 // Initialize the toolwindow colors to respect the current theme
52 // Sign up to theme changes to keep the colors up to date
53 VSColorTheme
.ThemeChanged
+= VSColorTheme_ThemeChanged
;
56 void SetDefaultColors()
58 Color defaultBackground
= VSColorTheme
.GetThemedColor(EnvironmentColors
.ToolWindowBackgroundColorKey
);
59 Color defaultForeground
= VSColorTheme
.GetThemedColor(EnvironmentColors
.ToolWindowTextColorKey
);
61 UpdateWindowColors(defaultBackground
, defaultForeground
);
64 void VSColorTheme_ThemeChanged(ThemeChangedEventArgs e
)
69 override public IWin32Window Window
73 return (IWin32Window
)control
;
77 /// <include file='doc\WindowPane.uex' path='docs/doc[@for="WindowPane.Dispose1"]' />
79 /// Called when this tool window pane is being disposed.
81 override protected void Dispose(bool disposing
)
85 // Unsubscribe from theme changed events
86 VSColorTheme
.ThemeChanged
-= VSColorTheme_ThemeChanged
;
92 if (control
is IDisposable
)
97 System
.Diagnostics
.Debug
.Fail(String
.Format("Failed to dispose {0} controls.\n{1}", this.GetType().FullName
, e
.Message
));
102 IVsWindowFrame windowFrame
= (IVsWindowFrame
)this.Frame
;
103 if (windowFrame
!= null)
105 // Note: don't check for the return code here.
106 windowFrame
.CloseFrame((uint)__FRAMECLOSE
.FRAMECLOSE_SaveIfDirty
);
109 base.Dispose(disposing
);
113 /// This function is only used to "do something noticeable" when the toolbar button is clicked.
114 /// It is called from the package.
115 /// A typical tool window may not need this function.
117 /// The current behavior change the background color of the control and swaps with the text color
119 public void ToolWindowToolbarCommand()
121 Color defaultBackground
= VSColorTheme
.GetThemedColor(EnvironmentColors
.ToolWindowBackgroundColorKey
);
122 Color defaultForeground
= VSColorTheme
.GetThemedColor(EnvironmentColors
.ToolWindowTextColorKey
);
124 if (this.control
.BackColor
== defaultBackground
)
127 UpdateWindowColors(defaultForeground
, defaultBackground
);
131 // Put back the default colors
132 UpdateWindowColors(defaultBackground
, defaultForeground
);
136 void UpdateWindowColors(Color clrBackground
, Color clrForeground
)
138 // Update the window background
139 this.control
.BackColor
= clrBackground
;
140 this.control
.ForeColor
= clrForeground
;
142 // Also update the label
143 foreach (Control child
in this.control
.Controls
)
145 child
.BackColor
= this.control
.BackColor
;
146 child
.ForeColor
= this.control
.ForeColor
;