Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1987)

Side by Side Diff: experimental/visual_studio_plugin/third_party/Microsoft.VisualStudio.Project/DontShowAgainDialog.cs

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /// Copyright (c) Microsoft Corporation. All rights reserved.
2
3 using System;
4 using System.ComponentModel;
5 using System.Diagnostics;
6 using System.Drawing;
7 using System.Globalization;
8 using System.Windows.Forms;
9 using System.Windows.Forms.Design;
10 using Microsoft.VisualStudio.Shell;
11 using Microsoft.VisualStudio.Shell.Interop;
12 using Microsoft.Win32;
13
14 namespace Microsoft.VisualStudio.Project
15 {
16 /// <summary>
17 /// Defines a genric don't show again dilaog.
18 /// </summary>
19 internal partial class DontShowAgainDialog : Form
20 {
21 #region constants
22 /// <summary>
23 /// Defines the General subkey under VS hive for the CurrentUser .
24 /// </summary>
25 private static string GeneralSubKey = "General";
26 #endregion
27
28 #region fields
29 /// <summary>
30 /// Defines the bitmap to be drawn
31 /// </summary>
32 private Bitmap bitmap;
33
34 /// <summary>
35 /// The associated service provider
36 /// </summary>
37 private IServiceProvider serviceProvider;
38
39 /// <summary>
40 /// The help topic associated.
41 /// </summary>
42 private string helpTopic;
43
44 /// <summary>
45 /// The value of the don't show again check box
46 /// </summary>
47 private bool dontShowAgainValue;
48 #endregion
49
50 #region constructors
51 /// <summary>
52 /// Overloaded constructor
53 /// </summary>
54 /// <param name="serviceProvider">The associated service provide r.</param>
55 /// <param name="messageText">Thetext to be shown on the dialog< /param>
56 /// <param name="helpTopic">The associated help topic</param>
57 /// <param name="button">The default button</param>
58 internal DontShowAgainDialog(IServiceProvider serviceProvider, s tring messageText, string helpTopic, DefaultButton button)
59 {
60 if(serviceProvider == null)
61 {
62 throw new ArgumentNullException("serviceProvider ");
63 }
64
65 this.serviceProvider = serviceProvider;
66 this.InitializeComponent();
67
68 if(button == DefaultButton.OK)
69 {
70 this.AcceptButton = this.okButton;
71 }
72 else
73 {
74 this.AcceptButton = this.cancelButton;
75 }
76
77
78 this.SetupComponents(messageText, helpTopic);
79 }
80 #endregion
81
82 #region properties
83 /// <summary>
84 /// The value of the dont' show again checkbox before the dialog is closed.
85 /// </summary>
86 internal bool DontShowAgainValue
87 {
88 get
89 {
90 return this.dontShowAgainValue;
91 }
92 }
93 #endregion
94
95 #region methods
96 /// <summary>
97 /// Shows help for the help topic.
98 /// </summary>
99 protected virtual void ShowHelp()
100 {
101 Microsoft.VisualStudio.VSHelp.Help help = this.servicePr ovider.GetService(typeof(Microsoft.VisualStudio.VSHelp.Help)) as Microsoft.Visua lStudio.VSHelp.Help;
102
103 if(help != null)
104 {
105 help.DisplayTopicFromF1Keyword(this.helpTopic);
106 }
107 }
108
109 /// <summary>
110 /// Launches a DontShowAgainDialog if it is needed.
111 /// </summary>
112 /// <param name="serviceProvider">An associated serviceprovider. </param>
113 /// <param name="messageText">The text the dilaog box will conta in.</param>
114 /// <param name="helpTopic">The associated help topic.</param>
115 /// <param name="button">The default button.</param>
116 /// <param name="registryKey">The registry key that serves for p ersisting the not show again value.</param>
117 /// <returns>A Dialog result.</returns>
118 internal static DialogResult LaunchDontShowAgainDialog(IServiceP rovider serviceProvider, string messageText, string helpTopic, DefaultButton but ton, string registryKey)
119 {
120 if(String.IsNullOrEmpty(registryKey))
121 {
122 throw new ArgumentException(SR.GetString(SR.Para meterCannotBeNullOrEmpty, CultureInfo.CurrentUICulture), "registryKey");
123 }
124
125 DialogResult result = DialogResult.OK;
126
127 bool dontShowAgain = ReadDontShowAgainValue(registryKey) ;
128
129 if(!dontShowAgain)
130 {
131 DontShowAgainDialog dialog = new DontShowAgainDi alog(serviceProvider, messageText, helpTopic, button);
132 result = dialog.ShowDialog();
133
134 // Now write to the registry the value.
135 if(dialog.DontShowAgainValue)
136 {
137 WriteDontShowAgainValue(registryKey, 1);
138 }
139 }
140
141 return result;
142 }
143
144 /// <summary>
145 /// Reads a boolean value specifying whether to show or not show the dialog
146 /// </summary>
147 /// <param name="registryKey">The key containing the value.</par am>
148 /// <returns>The value read. If the value cannot be read false i s returned.</returns>
149 internal static bool ReadDontShowAgainValue(string registryKey)
150 {
151 bool dontShowAgain = false;
152 using(RegistryKey root = VSRegistry.RegistryRoot(__VsLoc alRegistryType.RegType_UserSettings))
153 {
154 if(root != null)
155 {
156 using(RegistryKey key = root.OpenSubKey( GeneralSubKey))
157 {
158 int value = (int)key.GetValue(re gistryKey, 0);
159 dontShowAgain = (value != 0);
160 }
161 }
162 }
163
164 return dontShowAgain;
165 }
166
167 /// <summary>
168 /// Writes a value 1 in the registrykey and as aresult the dont show again dialog will not be launched.
169 /// </summary>
170 /// <param name="registryKey">The key to write to.</param>
171 /// <param name="value">The value to write.</param>
172 internal static void WriteDontShowAgainValue(string registryKey, int value)
173 {
174 using(RegistryKey root = VSRegistry.RegistryRoot(__VsLoc alRegistryType.RegType_UserSettings))
175 {
176 if(root != null)
177 {
178 using(RegistryKey key = root.OpenSubKey( GeneralSubKey, true))
179 {
180 key.SetValue(registryKey, value, RegistryValueKind.DWord);
181 }
182 }
183 }
184 }
185
186 /// <summary>
187 /// Shows the dialog if possible hosted by the IUIService.
188 /// </summary>
189 /// <returns>A DialogResult</returns>
190 internal new DialogResult ShowDialog()
191 {
192 Debug.Assert(this.serviceProvider != null, "The service provider should not be null at this time");
193 IUIService uiService = this.serviceProvider.GetService(t ypeof(IUIService)) as IUIService;
194 if(uiService == null)
195 {
196 return this.ShowDialog();
197 }
198
199 return uiService.ShowDialog(this);
200 }
201
202 /// <summary>
203 /// Defines the event delegate when help is requested.
204 /// </summary>
205 /// <param name="sender"></param>
206 /// <param name="hlpevent"></param>
207 private void OnHelpRequested(object sender, HelpEventArgs hlpeve nt)
208 {
209 if(String.IsNullOrEmpty(this.helpTopic))
210 {
211 return;
212 }
213
214 this.ShowHelp();
215 hlpevent.Handled = true;
216 }
217
218 /// <summary>
219 /// Defines the delegate that responds to the help button clicke d event.
220 /// </summary>
221 /// <param name="sender">The sender of the event.</param>
222 /// <param name="e">An instance of canceleventargs </param>
223 private void OnHelpButtonClicked(object sender, CancelEventArgs e)
224 {
225 if(String.IsNullOrEmpty(this.helpTopic))
226 {
227 return;
228 }
229
230 e.Cancel = true;
231 this.ShowHelp();
232 }
233
234 /// <summary>
235 /// Called when the dialog box is repainted.
236 /// </summary>
237 /// <param name="sender">The sender of the event.</param>
238 /// <param name="e">The associated paint event args.</param>
239 private void OnPaint(object sender, PaintEventArgs e)
240 {
241 e.Graphics.DrawImage(this.bitmap, new Point(7, this.mess ageText.Location.Y));
242 }
243
244
245 /// <summary>
246 /// Sets up the components that are not done through teh Initial ize components.
247 /// </summary>
248 /// <param name="helpTopicParam">The associated help topic</para m>
249 /// <param name="messageTextParam">The message to show on the di laog.</param>
250 private void SetupComponents(string messageTextParam, string hel pTopicParam)
251 {
252 // Compute the Distance to the bottom of the dialog
253 int distanceToBottom = this.Size.Height - this.cancelBut ton.Location.Y;
254
255 // The Y end coordinate of the messageText before it ass igned its value.
256 int deltaY = this.messageText.Location.Y + this.messageT ext.Size.Height;
257
258 // Set the maximum size as the CancelButtonEndX - Messag eTextStartX. This way it wil never pass by the button.
259 this.messageText.MaximumSize = new Size(this.cancelButto n.Location.X + this.cancelButton.Size.Width - this.messageText.Location.X, 0);
260 this.messageText.Text = messageTextParam;
261
262 // How much it has changed?
263 deltaY = this.messageText.Size.Height - deltaY;
264 this.AdjustSizesVertically(deltaY, distanceToBottom);
265
266 if(String.IsNullOrEmpty(helpTopicParam))
267 {
268 this.HelpButton = false;
269 }
270 else
271 {
272 this.helpTopic = helpTopicParam;
273 }
274
275 // Create the system icon that will be drawn on the dial og page.
276 Icon icon = new Icon(SystemIcons.Exclamation, 40, 40);
277
278 // Call ToBitmap to convert it.
279 this.bitmap = icon.ToBitmap();
280
281 this.CenterToScreen();
282 }
283
284 /// <summary>
285 /// Handles the cancel button clicked event.
286 /// </summary>
287 /// <param name="sender">The sender of teh event.</param>
288 /// <param name="e">The event args associated to teh event.</par am>
289 private void OnCancelButtonClicked(object sender, EventArgs e)
290 {
291 this.dontShowAgainValue = this.dontShowAgain.Checked;
292 this.DialogResult = DialogResult.Cancel;
293 }
294
295 /// <summary>
296 /// Handles the cancel button clicked event.
297 /// </summary>
298 /// <param name="sender">The sender of teh event.</param>
299 /// <param name="e">The event args associated to teh event.</par am>
300 private void OnOKButtonClicked(object sender, EventArgs e)
301 {
302 this.dontShowAgainValue = this.dontShowAgain.Checked;
303 this.DialogResult = DialogResult.OK;
304 this.Close();
305 }
306
307 /// <summary>
308 /// Moves controls vertically because of a vertical change in t he messagetext.
309 /// </summary>
310 private void AdjustSizesVertically(int deltaY, int distanceToBot tom)
311 {
312 // Move the checkbox to its new location determined by t he height the label.
313 this.dontShowAgain.Location = new Point(this.dontShowAga in.Location.X, this.dontShowAgain.Location.Y + deltaY);
314
315 // Move the buttons to their new location; The X coordin ate is fixed.
316 int newSizeY = this.cancelButton.Location.Y + deltaY;
317 this.cancelButton.Location = new Point(this.cancelButton .Location.X, newSizeY);
318
319 newSizeY = this.okButton.Location.Y + deltaY;
320 this.okButton.Location = new Point(this.okButton.Locatio n.X, newSizeY);
321
322 // Now resize the dialog itself.
323 this.Size = new Size(this.Size.Width, this.cancelButton. Location.Y + distanceToBottom);
324 }
325 #endregion
326
327 #region nested types
328 /// <summary>
329 /// Defines which button to serve as the default button.
330 /// </summary>
331 internal enum DefaultButton
332 {
333 OK,
334 Cancel,
335 }
336 #endregion
337 }
338 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698