[Monodevelop-patches-list] r1884 - in trunk/MonoDevelop/Core/src/Main/Base: . Services

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Fri Jul 2 04:42:07 EDT 2004


Author: tberman
Date: 2004-07-02 04:42:07 -0400 (Fri, 02 Jul 2004)
New Revision: 1884

Modified:
   trunk/MonoDevelop/Core/src/Main/Base/ChangeLog
   trunk/MonoDevelop/Core/src/Main/Base/Services/MessageService.cs
Log:
fix another dumb threading bug.


Modified: trunk/MonoDevelop/Core/src/Main/Base/ChangeLog
===================================================================
--- trunk/MonoDevelop/Core/src/Main/Base/ChangeLog	2004-07-02 08:03:07 UTC (rev 1883)
+++ trunk/MonoDevelop/Core/src/Main/Base/ChangeLog	2004-07-02 08:42:07 UTC (rev 1884)
@@ -1,5 +1,10 @@
 2004-07-02  Todd Berman  <tberman at off.net>
 
+	* Services/MessageService.cs: Convert most of these to be threadsafe.
+	Need to do AskQuestion, but this fixes a bug, so I will commit now.
+
+2004-07-02  Todd Berman  <tberman at off.net>
+
 	* Commands/FileCommands.cs: Dont use the FileFilters, as there are
 	not functional at the moment.
 	* Services/File/DefaultFileService.cs: don't attempt to load a

Modified: trunk/MonoDevelop/Core/src/Main/Base/Services/MessageService.cs
===================================================================
--- trunk/MonoDevelop/Core/src/Main/Base/Services/MessageService.cs	2004-07-02 08:03:07 UTC (rev 1883)
+++ trunk/MonoDevelop/Core/src/Main/Base/Services/MessageService.cs	2004-07-02 08:42:07 UTC (rev 1884)
@@ -36,36 +36,69 @@
 		{
 			ShowError(null, String.Format(stringParserService.Parse(formatstring), formatitems));
 		}
-		
+
+		private struct ErrorContainer
+		{
+			public Exception ex;
+			public string message;
+
+			public ErrorContainer (Exception e, string msg)
+			{
+				ex = e;
+				message = msg;
+			}
+		}
+
 		public void ShowError(Exception ex, string message)
 		{
+			DispatchService dispatcher = (DispatchService)ServiceManager.GetService (typeof (DispatchService));
+			dispatcher.GuiDispatch (new StatefulMessageHandler (realShowError), new ErrorContainer (ex, message));
+		}
+
+		private void realShowError (object state)
+		{
+			ErrorContainer container = (ErrorContainer)state;
 			string msg = String.Empty;
 			
-			if (message != null) {
-				msg += message;
+			if (container.message != null) {
+				msg += container.message;
 			}
 			
-			if (message != null && ex != null) {
+			if (container.message != null && container.ex != null) {
 				msg += "\n\n";
 			}
 			
-			if (ex != null) {
-				msg += "Exception occurred: " + ex.ToString();
+			if (container.ex != null) {
+				msg += "Exception occurred: " + container.ex.ToString();
 			}
+			Gtk.MessageDialog md = new Gtk.MessageDialog ((Gtk.Window) WorkbenchSingleton.Workbench, Gtk.DialogFlags.Modal | Gtk.DialogFlags.DestroyWithParent, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, container.message);
+			md.Response += new Gtk.ResponseHandler (OnErrorResponse);
+			md.ShowAll ();
+		}
 
-			using (Gtk.MessageDialog md = new Gtk.MessageDialog ((Gtk.Window) WorkbenchSingleton.Workbench, Gtk.DialogFlags.Modal | Gtk.DialogFlags.DestroyWithParent, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, message)) {
-				md.Run ();
-				md.Hide ();
-			}
+		void OnErrorResponse (object o, Gtk.ResponseArgs args)
+		{
+			((Gtk.Dialog)o).Hide ();
 		}
 		
 		public void ShowWarning(string message)
 		{
-			using (Gtk.MessageDialog md = new Gtk.MessageDialog ((Gtk.Window) WorkbenchSingleton.Workbench, Gtk.DialogFlags.Modal | Gtk.DialogFlags.DestroyWithParent, Gtk.MessageType.Warning, Gtk.ButtonsType.Ok, message)) {
-				md.Run ();
-				md.Hide ();
-			}
+			DispatchService dispatcher = (DispatchService)ServiceManager.GetService (typeof (DispatchService));
+			dispatcher.GuiDispatch (new StatefulMessageHandler (realShowWarning), message);
 		}
+
+		private void realShowWarning (object state)
+		{
+			string message = state as string;
+			Gtk.MessageDialog md = new Gtk.MessageDialog ((Gtk.Window) WorkbenchSingleton.Workbench, Gtk.DialogFlags.Modal | Gtk.DialogFlags.DestroyWithParent, Gtk.MessageType.Warning, Gtk.ButtonsType.Ok, message);
+			md.Response += new Gtk.ResponseHandler (OnWarningResponse);
+			md.ShowAll ();
+		}
+
+		void OnWarningResponse (object o, Gtk.ResponseArgs e)
+		{
+			((Gtk.Dialog)o).Hide ();
+		}
 		
 		public void ShowWarningFormatted(string formatstring, params string[] formatitems)
 		{
@@ -123,11 +156,23 @@
 		
 		public void ShowMessage(string message, string caption)
 		{
+			DispatchService dispatcher = (DispatchService)ServiceManager.GetService (typeof (DispatchService));
+			dispatcher.GuiDispatch (new StatefulMessageHandler (realShowMessage), message);
+		}
+
+		void realShowMessage (object state)
+		{
+			string message = state as string;
 			using (Gtk.MessageDialog md = new Gtk.MessageDialog ((Gtk.Window) WorkbenchSingleton.Workbench, Gtk.DialogFlags.Modal | Gtk.DialogFlags.DestroyWithParent, Gtk.MessageType.Info, Gtk.ButtonsType.Ok, message)) {
-				md.Run ();
-				md.Hide ();
+				md.Response += Gtk.ResponseHandler(OnMessageResponse);
+				md.ShowAll ();
 			}
 		}
+
+		void OnMessageResponse (object o, Gtk.ResponseArgs e)
+		{
+			((Gtk.Dialog)o).Hide ();
+		}
 		
 		// call this method to show a dialog and get a response value
 		// returns null if cancel is selected




More information about the Monodevelop-patches-list mailing list