diff options
author | Carlos Alberto Cortez <calberto.cortez@gmail.com> | 2011-09-21 13:03:55 +0400 |
---|---|---|
committer | Carlos Alberto Cortez <calberto.cortez@gmail.com> | 2011-09-21 13:17:22 +0400 |
commit | 64c63ded9d8dcca09eeab54d84155f8fa5466587 (patch) | |
tree | a1855869b79bf0865bdb23f7dfff10a821735dc3 /main/src/addins/WindowsPlatform | |
parent | 7d94e5306dd4da17d5f61edda5f739510f290c36 (diff) |
[Windows] Handle focus restoration for the native dialogs.
Since we are not running the native winforms dialogs on the
same thread, we need to handle the focus ourselves by
focusing them when the immediate parent window gets a
FocusInEvent.
Also, add a root for OpenFileDialogHandler and AddFileDialogHandler,
as we need it to focus them asynchronously -since the lack of direct access
to their inner Form objects-.
Diffstat (limited to 'main/src/addins/WindowsPlatform')
3 files changed, 41 insertions, 6 deletions
diff --git a/main/src/addins/WindowsPlatform/Dialogs/AddFileDialogHandler.cs b/main/src/addins/WindowsPlatform/Dialogs/AddFileDialogHandler.cs index fe5442a80f..c450f488a1 100644 --- a/main/src/addins/WindowsPlatform/Dialogs/AddFileDialogHandler.cs +++ b/main/src/addins/WindowsPlatform/Dialogs/AddFileDialogHandler.cs @@ -12,16 +12,27 @@ namespace MonoDevelop.Platform {
class AddFileDialogHandler: IAddFileDialogHandler
{
+ volatile Form rootForm;
+
public bool Run (AddFileDialogData data)
{
var parentWindow = data.TransientFor ?? MessageService.RootWindow;
+ parentWindow.FocusInEvent += OnParentFocusIn;
bool result = SelectFileDialogHandler.RunWinUIMethod (RunDialog, data);
+ parentWindow.FocusInEvent -= OnParentFocusIn;
parentWindow.Present ();
+
return result;
}
+ void OnParentFocusIn (object o, EventArgs args)
+ {
+ if (rootForm != null)
+ rootForm.BeginInvoke (new Action (() => rootForm.Activate ()));
+ }
+
bool RunDialog (AddFileDialogData data)
{
Application.EnableVisualStyles ();
@@ -35,7 +46,8 @@ namespace MonoDevelop.Platform try
{
- if (adlg.ShowDialog () == DialogResult.Cancel)
+ rootForm = new WinFormsRoot ();
+ if (adlg.ShowDialog (rootForm) == DialogResult.Cancel)
result = false;
else
{
diff --git a/main/src/addins/WindowsPlatform/Dialogs/OpenFileDialogHandler.cs b/main/src/addins/WindowsPlatform/Dialogs/OpenFileDialogHandler.cs index ca9c4fc959..90112c798d 100644 --- a/main/src/addins/WindowsPlatform/Dialogs/OpenFileDialogHandler.cs +++ b/main/src/addins/WindowsPlatform/Dialogs/OpenFileDialogHandler.cs @@ -34,17 +34,28 @@ using MonoDevelop.Platform; namespace MonoDevelop.Platform
{
public class OpenFileDialogHandler : IOpenFileDialogHandler
- {
+ {
+ volatile Form rootForm;
+
public bool Run (OpenFileDialogData data)
{
var parentWindow = data.TransientFor ?? MessageService.RootWindow;
+ parentWindow.FocusInEvent += OnParentFocusIn;
bool result = SelectFileDialogHandler.RunWinUIMethod (RunDialog, data);
+ parentWindow.FocusInEvent -= OnParentFocusIn;
parentWindow.Present ();
+
return result;
}
+ void OnParentFocusIn (object o, EventArgs args)
+ {
+ if (rootForm != null)
+ rootForm.BeginInvoke (new Action (() => rootForm.Activate ()));
+ }
+
bool RunDialog (OpenFileDialogData data)
{
Application.EnableVisualStyles ();
@@ -60,8 +71,9 @@ namespace MonoDevelop.Platform SelectFileDialogHandler.SetCommonFormProperties (data, dlg.FileDialog);
using (dlg) {
- if (dlg.ShowDialog () == DialogResult.Cancel) {
- return false;
+ rootForm = new WinFormsRoot ();
+ if (dlg.ShowDialog (rootForm) == DialogResult.Cancel) {
+ return false;
}
FilePath[] paths = new FilePath [fileDlg.FileNames.Length];
diff --git a/main/src/addins/WindowsPlatform/Dialogs/SelectFileDialogHandler.cs b/main/src/addins/WindowsPlatform/Dialogs/SelectFileDialogHandler.cs index 6a69b556b3..899eafa1ce 100644 --- a/main/src/addins/WindowsPlatform/Dialogs/SelectFileDialogHandler.cs +++ b/main/src/addins/WindowsPlatform/Dialogs/SelectFileDialogHandler.cs @@ -12,16 +12,27 @@ namespace MonoDevelop.Platform {
class SelectFileDialogHandler : ISelectFileDialogHandler
{
+ volatile Form rootForm;
+
public bool Run (SelectFileDialogData data)
{
var parentWindow = data.TransientFor ?? MessageService.RootWindow;
+ parentWindow.FocusInEvent += OnParentFocusIn;
bool result = RunWinUIMethod (RunDialog, data);
+ parentWindow.FocusInEvent -= OnParentFocusIn;
parentWindow.Present ();
+
return result;
}
+ void OnParentFocusIn (object o, EventArgs args)
+ {
+ if (rootForm != null)
+ rootForm.BeginInvoke (new Action (() => rootForm.Activate ()));
+ }
+
bool RunDialog (SelectFileDialogData data)
{
Application.EnableVisualStyles ();
@@ -40,8 +51,8 @@ namespace MonoDevelop.Platform SetFolderBrowserProperties (data, dlg as FolderBrowserDialog);
using (dlg) {
- WinFormsRoot root = new WinFormsRoot();
- if (dlg.ShowDialog(root) == DialogResult.Cancel) {
+ rootForm = new WinFormsRoot ();
+ if (dlg.ShowDialog (rootForm) == DialogResult.Cancel) {
return false;
}
|