added some development tools
[windows-sources.git] / developer / VSSDK / Samples / Source_Code_Control_Provider / C# / SccProviderToolWindow.cs
blob7b9b08861cfe26172cc1520386a6135dee1c6cb2
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 ***************************************************************************/
11 using System;
12 using System.Collections;
13 using System.ComponentModel;
14 using System.ComponentModel.Design;
15 using System.Drawing;
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
28 /// <summary>
29 /// Summary description for SccProviderToolWindow.
30 /// </summary>
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 Caption = Resources.ResourceManager.GetString("ToolWindowCaption");
41 // set the CommandID for the window ToolBar
42 ToolBar = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.imnuToolWindowToolbarMenu);
44 // set the icon for the frame
45 BitmapResourceID = CommandId.ibmpToolWindowsImages; // bitmap strip resource ID
46 BitmapIndex = CommandId.iconSccProviderToolWindow; // index in the bitmap strip
48 control = new SccProviderToolWindowControl();
49 // Initialize the toolwindow colors to respect the current theme
50 SetDefaultColors();
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)
66 SetDefaultColors();
69 override public IWin32Window Window
71 get
73 return control;
77 /// <include file='doc\WindowPane.uex' path='docs/doc[@for="WindowPane.Dispose1"]' />
78 /// <devdoc>
79 /// Called when this tool window pane is being disposed.
80 /// </devdoc>
81 override protected void Dispose(bool disposing)
83 if (disposing)
85 // Unsubscribe from theme changed events
86 VSColorTheme.ThemeChanged -= VSColorTheme_ThemeChanged;
88 if (control != null)
90 try
92 if (control is IDisposable)
93 control.Dispose();
95 catch (Exception e)
97 System.Diagnostics.Debug.Fail(string.Format("Failed to dispose {0} controls.\n{1}", GetType().FullName, e.Message));
99 control = null;
102 IVsWindowFrame windowFrame = (IVsWindowFrame)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);
112 /// <summary>
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.
116 ///
117 /// The current behavior change the background color of the control and swaps with the text color
118 /// </summary>
119 public void ToolWindowToolbarCommand()
121 Color defaultBackground = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
122 Color defaultForeground = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowTextColorKey);
124 if (control.BackColor == defaultBackground)
126 // Swap the colors
127 UpdateWindowColors(defaultForeground, defaultBackground);
129 else
131 // Put back the default colors
132 UpdateWindowColors(defaultBackground, defaultForeground);
136 void UpdateWindowColors(Color clrBackground, Color clrForeground)
138 // Update the window background
139 control.BackColor = clrBackground;
140 control.ForeColor = clrForeground;
142 // Also update the label
143 foreach (Control child in control.Controls)
145 child.BackColor = control.BackColor;
146 child.ForeColor = control.ForeColor;