diff --git a/Greenshot/Forms/BugReportForm.cs b/Greenshot/Forms/BugReportForm.cs index dd1112acf..77cc8929f 100644 --- a/Greenshot/Forms/BugReportForm.cs +++ b/Greenshot/Forms/BugReportForm.cs @@ -31,7 +31,7 @@ namespace Greenshot.Forms { // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); - WindowDetails.ToForeground(Handle); + BringToFront = true; } public BugReportForm(string bugText) : this() { diff --git a/Greenshot/Forms/CaptureForm.cs b/Greenshot/Forms/CaptureForm.cs index 998b27618..1347e215b 100644 --- a/Greenshot/Forms/CaptureForm.cs +++ b/Greenshot/Forms/CaptureForm.cs @@ -177,7 +177,7 @@ namespace Greenshot.Forms { ResumeLayout(); // Fix missing focus - WindowDetails.ToForeground(Handle); + BringToFront = true; TopMost = true; } diff --git a/GreenshotPlugin/Controls/GreenshotForm.cs b/GreenshotPlugin/Controls/GreenshotForm.cs index a872c83c9..ef15c0d76 100644 --- a/GreenshotPlugin/Controls/GreenshotForm.cs +++ b/GreenshotPlugin/Controls/GreenshotForm.cs @@ -38,11 +38,11 @@ namespace GreenshotPlugin.Controls { protected static CoreConfiguration coreConfiguration; private static IDictionary reflectionCache = new Dictionary(); private IComponentChangeService m_changeService; - private bool isDesignModeLanguageSet = false; - private bool applyLanguageManually = false; - private bool storeFieldsManually = false; - private IDictionary designTimeControls; - private IDictionary designTimeToolStripItems; + private bool _isDesignModeLanguageSet = false; + private bool _applyLanguageManually = false; + private bool _storeFieldsManually = false; + private IDictionary _designTimeControls; + private IDictionary _designTimeToolStripItems; static GreenshotForm() { if (!IsInDesignMode) { @@ -68,29 +68,37 @@ namespace GreenshotPlugin.Controls { protected bool ManualLanguageApply { get { - return applyLanguageManually; + return _applyLanguageManually; } set { - applyLanguageManually = value; + _applyLanguageManually = value; } } protected bool ManualStoreFields { get { - return storeFieldsManually; + return _storeFieldsManually; } set { - storeFieldsManually = value; + _storeFieldsManually = value; } } + /// + /// When this is set, the form will be brought to the foreground as soon as it is shown. + /// + protected bool BringToFront { + get; + set; + } + /// /// Code to initialize the language etc during design time /// protected void InitializeForDesigner() { if (DesignMode) { - designTimeControls = new Dictionary(); - designTimeToolStripItems = new Dictionary(); + _designTimeControls = new Dictionary(); + _designTimeToolStripItems = new Dictionary(); try { ITypeResolutionService typeResService = GetService(typeof(ITypeResolutionService)) as ITypeResolutionService; @@ -119,8 +127,8 @@ namespace GreenshotPlugin.Controls { /// protected override void OnPaint(PaintEventArgs e) { if (DesignMode) { - if (!isDesignModeLanguageSet) { - isDesignModeLanguageSet = true; + if (!_isDesignModeLanguageSet) { + _isDesignModeLanguageSet = true; try { ApplyLanguage(); } catch (Exception) { @@ -135,7 +143,7 @@ namespace GreenshotPlugin.Controls { // And it might not ne needed for a Tool Window, but still for the task manager / switcher it's important Icon = GreenshotResources.getGreenshotIcon(); if (!DesignMode) { - if (!applyLanguageManually) { + if (!_applyLanguageManually) { ApplyLanguage(); } FillFields(); @@ -148,12 +156,23 @@ namespace GreenshotPlugin.Controls { } } + /// + /// Make sure the form is visible, if this is wanted + /// + /// EventArgs + protected override void OnShown(EventArgs e) { + base.OnShown(e); + if (BringToFront) { + WindowDetails.ToForeground(Handle); + } + } + /// /// check if the form was closed with an OK, if so store the values in the GreenshotControls /// /// protected override void OnClosed(EventArgs e) { - if (!DesignMode && !storeFieldsManually) { + if (!DesignMode && !_storeFieldsManually) { if (DialogResult == DialogResult.OK) { LOG.Info("Form was closed with OK: storing field values."); StoreFields(); @@ -233,17 +252,17 @@ namespace GreenshotPlugin.Controls { if (ce.Component != null && ((IComponent)ce.Component).Site != null) { Control control = ce.Component as Control; if (control != null) { - if (!designTimeControls.ContainsKey(control.Name)) { - designTimeControls.Add(control.Name, control); + if (!_designTimeControls.ContainsKey(control.Name)) { + _designTimeControls.Add(control.Name, control); } else { - designTimeControls[control.Name] = control; + _designTimeControls[control.Name] = control; } } else if (ce.Component is ToolStripItem) { ToolStripItem item = ce.Component as ToolStripItem; - if (!designTimeControls.ContainsKey(item.Name)) { - designTimeToolStripItems.Add(item.Name, item); + if (!_designTimeControls.ContainsKey(item.Name)) { + _designTimeToolStripItems.Add(item.Name, item); } else { - designTimeToolStripItems[item.Name] = item; + _designTimeToolStripItems[item.Name] = item; } } } @@ -363,10 +382,10 @@ namespace GreenshotPlugin.Controls { } if (DesignMode) { - foreach (Control designControl in designTimeControls.Values) { + foreach (Control designControl in _designTimeControls.Values) { ApplyLanguage(designControl); } - foreach (ToolStripItem designToolStripItem in designTimeToolStripItems.Values) { + foreach (ToolStripItem designToolStripItem in _designTimeToolStripItems.Values) { ApplyLanguage(designToolStripItem); } } diff --git a/GreenshotPlugin/Controls/OAuthLoginForm.cs b/GreenshotPlugin/Controls/OAuthLoginForm.cs index 59e8f4088..f619927e9 100644 --- a/GreenshotPlugin/Controls/OAuthLoginForm.cs +++ b/GreenshotPlugin/Controls/OAuthLoginForm.cs @@ -60,7 +60,14 @@ namespace GreenshotPlugin.Controls { browser.ScriptErrorsSuppressed = false; browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted); browser.Navigate(new Uri(authorizationLink)); + } + /// + /// Make sure the form is visible + /// + /// EventArgs + protected override void OnShown(EventArgs e) { + base.OnShown(e); WindowDetails.ToForeground(Handle); } diff --git a/GreenshotPlugin/Controls/QualityDialog.cs b/GreenshotPlugin/Controls/QualityDialog.cs index 35b9a53d7..bba47e895 100644 --- a/GreenshotPlugin/Controls/QualityDialog.cs +++ b/GreenshotPlugin/Controls/QualityDialog.cs @@ -47,7 +47,7 @@ namespace GreenshotPlugin.Controls { trackBarJpegQuality.Value = Settings.JPGQuality; textBoxJpegQuality.Enabled = OutputFormat.jpg.Equals(outputSettings.Format); textBoxJpegQuality.Text = Settings.JPGQuality.ToString(); - WindowDetails.ToForeground(Handle); + BringToFront = true; } void Button_okClick(object sender, EventArgs e) {