[mapguide-commits] r7022 - trunk/Tools/Maestro/Maestro.Shared.UI

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Mon Sep 17 08:06:25 PDT 2012


Author: jng
Date: 2012-09-17 08:06:24 -0700 (Mon, 17 Sep 2012)
New Revision: 7022

Modified:
   trunk/Tools/Maestro/Maestro.Shared.UI/BusyWaitDialog.cs
   trunk/Tools/Maestro/Maestro.Shared.UI/ProgressDialog.cs
Log:
#2110: Make busy/progress dialogs default to transferring the application's UI culture to the background worker. Otherwise the background worker will be using the current system culture (most likely "en") for fetching any localized strings and things that happen in the background like resource validation will use English validation messages instead of the localized ones.

Modified: trunk/Tools/Maestro/Maestro.Shared.UI/BusyWaitDialog.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Shared.UI/BusyWaitDialog.cs	2012-09-17 14:29:22 UTC (rev 7021)
+++ trunk/Tools/Maestro/Maestro.Shared.UI/BusyWaitDialog.cs	2012-09-17 15:06:24 UTC (rev 7022)
@@ -19,6 +19,8 @@
 #endregion
 using System;
 using System.Drawing;
+using System.Globalization;
+using System.Threading;
 using System.Windows.Forms;
 
 namespace Maestro.Shared.UI
@@ -31,14 +33,16 @@
     public partial class BusyWaitDialog : Form
     {
         private BusyWaitDelegate _action;
+        private CultureInfo _culture;
         
-        internal BusyWaitDialog(BusyWaitDelegate action)
+        internal BusyWaitDialog(BusyWaitDelegate action, CultureInfo culture)
         {
             //
             // The InitializeComponent() call is required for Windows Forms designer support.
             //
             InitializeComponent();
             _action = action;
+            _culture = culture;
         }
         
         protected override void OnLoad(EventArgs e)
@@ -48,15 +52,20 @@
         }
         
         public object ReturnValue { get; private set; }
-        
+
         public static void Run(string message, BusyWaitDelegate action, Action<object> onComplete)
         {
+            Run(message, action, onComplete, true);
+        }
+
+        public static void Run(string message, BusyWaitDelegate action, Action<object> onComplete, bool bPreserveThreadCulture)
+        {
             if (action == null)
                 throw new ArgumentNullException("action"); //NOXLATE
             if (onComplete == null)
                 throw new ArgumentNullException("onComplete"); //NOXLATE
             
-            var frm = new BusyWaitDialog(action);
+            var frm = new BusyWaitDialog(action, bPreserveThreadCulture ? Thread.CurrentThread.CurrentCulture : null);
             frm.lblBusy.Text = message;
             if (frm.ShowDialog() == DialogResult.OK)
             {
@@ -66,6 +75,12 @@
         
         void BgWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
         {
+            if (_culture != null)
+            {
+                Thread.CurrentThread.CurrentCulture =
+                    Thread.CurrentThread.CurrentUICulture =
+                        _culture;
+            }
             e.Result = _action.Invoke();
         }
         

Modified: trunk/Tools/Maestro/Maestro.Shared.UI/ProgressDialog.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Shared.UI/ProgressDialog.cs	2012-09-17 14:29:22 UTC (rev 7021)
+++ trunk/Tools/Maestro/Maestro.Shared.UI/ProgressDialog.cs	2012-09-17 15:06:24 UTC (rev 7022)
@@ -22,7 +22,9 @@
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
+using System.Globalization;
 using System.Text;
+using System.Threading;
 using System.Windows.Forms;
 
 namespace Maestro.Shared.UI
@@ -41,6 +43,7 @@
         private object[] m_args;
         private object m_result;
         private bool m_cancelAborts = false;
+        private CultureInfo m_culture;
 
         private System.Threading.Thread m_worker;
 
@@ -70,11 +73,27 @@
         /// <returns></returns>
         public object RunOperationAsync(Form owner, DoBackgroundWork method, params object[] arguments)
         {
+            return RunOperationAsync(owner, method, true, arguments);
+        }
+
+        /// <summary>
+        /// Runs the operation async.
+        /// </summary>
+        /// <param name="owner">The owner.</param>
+        /// <param name="method">The method.</param>
+        /// <param name="bPreserveThreadCulture">If true, the background thread's culture will be set to the culture of the invoking thread</param>
+        /// <param name="arguments">The arguments.</param>
+        /// <returns></returns>
+        public object RunOperationAsync(Form owner, DoBackgroundWork method, bool bPreserveThreadCulture, params object[] arguments)
+        {
             m_method = method;
             m_args = arguments;
             if (this.Visible)
                 this.Hide();
 
+            if (bPreserveThreadCulture)
+                m_culture = Thread.CurrentThread.CurrentCulture;
+
             if (this.ShowDialog(owner) == DialogResult.OK)
                 return m_result;
             else
@@ -85,6 +104,11 @@
         {
             try
             {
+                if (m_culture != null)
+                {
+                    Thread.CurrentThread.CurrentCulture =
+                        Thread.CurrentThread.CurrentUICulture = m_culture;
+                }
                 m_worker = System.Threading.Thread.CurrentThread;
                 e.Result = m_method(BackgroundWorker, e, m_args);
             }



More information about the mapguide-commits mailing list