Improving the logic to make sure new windows are moved to the front, so the user can't miss them.

This commit is contained in:
Robin 2015-04-17 11:20:30 +02:00
commit 9d7299e5ea
5 changed files with 52 additions and 26 deletions

View file

@ -31,7 +31,7 @@ namespace Greenshot.Forms {
// The InitializeComponent() call is required for Windows Forms designer support. // The InitializeComponent() call is required for Windows Forms designer support.
// //
InitializeComponent(); InitializeComponent();
WindowDetails.ToForeground(Handle); BringToFront = true;
} }
public BugReportForm(string bugText) : this() { public BugReportForm(string bugText) : this() {

View file

@ -177,7 +177,7 @@ namespace Greenshot.Forms {
ResumeLayout(); ResumeLayout();
// Fix missing focus // Fix missing focus
WindowDetails.ToForeground(Handle); BringToFront = true;
TopMost = true; TopMost = true;
} }

View file

@ -38,11 +38,11 @@ namespace GreenshotPlugin.Controls {
protected static CoreConfiguration coreConfiguration; protected static CoreConfiguration coreConfiguration;
private static IDictionary<Type, FieldInfo[]> reflectionCache = new Dictionary<Type, FieldInfo[]>(); private static IDictionary<Type, FieldInfo[]> reflectionCache = new Dictionary<Type, FieldInfo[]>();
private IComponentChangeService m_changeService; private IComponentChangeService m_changeService;
private bool isDesignModeLanguageSet = false; private bool _isDesignModeLanguageSet = false;
private bool applyLanguageManually = false; private bool _applyLanguageManually = false;
private bool storeFieldsManually = false; private bool _storeFieldsManually = false;
private IDictionary<string, Control> designTimeControls; private IDictionary<string, Control> _designTimeControls;
private IDictionary<string, ToolStripItem> designTimeToolStripItems; private IDictionary<string, ToolStripItem> _designTimeToolStripItems;
static GreenshotForm() { static GreenshotForm() {
if (!IsInDesignMode) { if (!IsInDesignMode) {
@ -68,29 +68,37 @@ namespace GreenshotPlugin.Controls {
protected bool ManualLanguageApply { protected bool ManualLanguageApply {
get { get {
return applyLanguageManually; return _applyLanguageManually;
} }
set { set {
applyLanguageManually = value; _applyLanguageManually = value;
} }
} }
protected bool ManualStoreFields { protected bool ManualStoreFields {
get { get {
return storeFieldsManually; return _storeFieldsManually;
} }
set { set {
storeFieldsManually = value; _storeFieldsManually = value;
} }
} }
/// <summary>
/// When this is set, the form will be brought to the foreground as soon as it is shown.
/// </summary>
protected bool BringToFront {
get;
set;
}
/// <summary> /// <summary>
/// Code to initialize the language etc during design time /// Code to initialize the language etc during design time
/// </summary> /// </summary>
protected void InitializeForDesigner() { protected void InitializeForDesigner() {
if (DesignMode) { if (DesignMode) {
designTimeControls = new Dictionary<string, Control>(); _designTimeControls = new Dictionary<string, Control>();
designTimeToolStripItems = new Dictionary<string, ToolStripItem>(); _designTimeToolStripItems = new Dictionary<string, ToolStripItem>();
try { try {
ITypeResolutionService typeResService = GetService(typeof(ITypeResolutionService)) as ITypeResolutionService; ITypeResolutionService typeResService = GetService(typeof(ITypeResolutionService)) as ITypeResolutionService;
@ -119,8 +127,8 @@ namespace GreenshotPlugin.Controls {
/// <param name="e"></param> /// <param name="e"></param>
protected override void OnPaint(PaintEventArgs e) { protected override void OnPaint(PaintEventArgs e) {
if (DesignMode) { if (DesignMode) {
if (!isDesignModeLanguageSet) { if (!_isDesignModeLanguageSet) {
isDesignModeLanguageSet = true; _isDesignModeLanguageSet = true;
try { try {
ApplyLanguage(); ApplyLanguage();
} catch (Exception) { } 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 // And it might not ne needed for a Tool Window, but still for the task manager / switcher it's important
Icon = GreenshotResources.getGreenshotIcon(); Icon = GreenshotResources.getGreenshotIcon();
if (!DesignMode) { if (!DesignMode) {
if (!applyLanguageManually) { if (!_applyLanguageManually) {
ApplyLanguage(); ApplyLanguage();
} }
FillFields(); FillFields();
@ -148,12 +156,23 @@ namespace GreenshotPlugin.Controls {
} }
} }
/// <summary>
/// Make sure the form is visible, if this is wanted
/// </summary>
/// <param name="e">EventArgs</param>
protected override void OnShown(EventArgs e) {
base.OnShown(e);
if (BringToFront) {
WindowDetails.ToForeground(Handle);
}
}
/// <summary> /// <summary>
/// check if the form was closed with an OK, if so store the values in the GreenshotControls /// check if the form was closed with an OK, if so store the values in the GreenshotControls
/// </summary> /// </summary>
/// <param name="e"></param> /// <param name="e"></param>
protected override void OnClosed(EventArgs e) { protected override void OnClosed(EventArgs e) {
if (!DesignMode && !storeFieldsManually) { if (!DesignMode && !_storeFieldsManually) {
if (DialogResult == DialogResult.OK) { if (DialogResult == DialogResult.OK) {
LOG.Info("Form was closed with OK: storing field values."); LOG.Info("Form was closed with OK: storing field values.");
StoreFields(); StoreFields();
@ -233,17 +252,17 @@ namespace GreenshotPlugin.Controls {
if (ce.Component != null && ((IComponent)ce.Component).Site != null) { if (ce.Component != null && ((IComponent)ce.Component).Site != null) {
Control control = ce.Component as Control; Control control = ce.Component as Control;
if (control != null) { if (control != null) {
if (!designTimeControls.ContainsKey(control.Name)) { if (!_designTimeControls.ContainsKey(control.Name)) {
designTimeControls.Add(control.Name, control); _designTimeControls.Add(control.Name, control);
} else { } else {
designTimeControls[control.Name] = control; _designTimeControls[control.Name] = control;
} }
} else if (ce.Component is ToolStripItem) { } else if (ce.Component is ToolStripItem) {
ToolStripItem item = ce.Component as ToolStripItem; ToolStripItem item = ce.Component as ToolStripItem;
if (!designTimeControls.ContainsKey(item.Name)) { if (!_designTimeControls.ContainsKey(item.Name)) {
designTimeToolStripItems.Add(item.Name, item); _designTimeToolStripItems.Add(item.Name, item);
} else { } else {
designTimeToolStripItems[item.Name] = item; _designTimeToolStripItems[item.Name] = item;
} }
} }
} }
@ -363,10 +382,10 @@ namespace GreenshotPlugin.Controls {
} }
if (DesignMode) { if (DesignMode) {
foreach (Control designControl in designTimeControls.Values) { foreach (Control designControl in _designTimeControls.Values) {
ApplyLanguage(designControl); ApplyLanguage(designControl);
} }
foreach (ToolStripItem designToolStripItem in designTimeToolStripItems.Values) { foreach (ToolStripItem designToolStripItem in _designTimeToolStripItems.Values) {
ApplyLanguage(designToolStripItem); ApplyLanguage(designToolStripItem);
} }
} }

View file

@ -60,7 +60,14 @@ namespace GreenshotPlugin.Controls {
browser.ScriptErrorsSuppressed = false; browser.ScriptErrorsSuppressed = false;
browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted); browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
browser.Navigate(new Uri(authorizationLink)); browser.Navigate(new Uri(authorizationLink));
}
/// <summary>
/// Make sure the form is visible
/// </summary>
/// <param name="e">EventArgs</param>
protected override void OnShown(EventArgs e) {
base.OnShown(e);
WindowDetails.ToForeground(Handle); WindowDetails.ToForeground(Handle);
} }

View file

@ -47,7 +47,7 @@ namespace GreenshotPlugin.Controls {
trackBarJpegQuality.Value = Settings.JPGQuality; trackBarJpegQuality.Value = Settings.JPGQuality;
textBoxJpegQuality.Enabled = OutputFormat.jpg.Equals(outputSettings.Format); textBoxJpegQuality.Enabled = OutputFormat.jpg.Equals(outputSettings.Format);
textBoxJpegQuality.Text = Settings.JPGQuality.ToString(); textBoxJpegQuality.Text = Settings.JPGQuality.ToString();
WindowDetails.ToForeground(Handle); BringToFront = true;
} }
void Button_okClick(object sender, EventArgs e) { void Button_okClick(object sender, EventArgs e) {