[Monodevelop-patches-list] r2513 - in trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets: . Commands
Lluis Sanchez <lluis@ximian.com>
lluis at mono-cvs.ximian.com
Thu May 5 17:29:35 EDT 2005
Author: lluis
Date: 2005-05-05 17:29:34 -0400 (Thu, 05 May 2005)
New Revision: 2513
Modified:
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/ChangeLog
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandManager.cs
Log:
2005-05-06 Lluis Sanchez Gual <lluis at novell.com>
* Commands/CommandManager.cs: Catch and report exceptions thrown
while dispatching commands.
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/ChangeLog
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/ChangeLog 2005-05-04 16:15:17 UTC (rev 2512)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/ChangeLog 2005-05-05 21:29:34 UTC (rev 2513)
@@ -1,3 +1,8 @@
+2005-05-06 Lluis Sanchez Gual <lluis at novell.com>
+
+ * Commands/CommandManager.cs: Catch and report exceptions thrown
+ while dispatching commands.
+
2005-05-04 Alp Toker <alp at atoker.com>
* Commands/CommandToolButton.cs: enable UseUnderline. The Gtk+ docs
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandManager.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandManager.cs 2005-05-04 16:15:17 UTC (rev 2512)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandManager.cs 2005-05-05 21:29:34 UTC (rev 2513)
@@ -41,6 +41,7 @@
Hashtable handlerInfo = new Hashtable ();
ArrayList toolbars = new ArrayList ();
ArrayList globalHandlers = new ArrayList ();
+ ArrayList commandUpdateErrors = new ArrayList ();
Gtk.AccelGroup accelGroup;
@@ -126,50 +127,56 @@
public bool DispatchCommand (object commandId, object dataItem)
{
- ActionCommand cmd = GetActionCommand (commandId);
-
- int globalPos;
- object cmdTarget = GetFirstCommandTarget (out globalPos);
- CommandInfo info = new CommandInfo (cmd);
-
- while (cmdTarget != null)
- {
- HandlerTypeInfo typeInfo = GetTypeHandlerInfo (cmdTarget);
+ try {
+ ActionCommand cmd = GetActionCommand (commandId);
- CommandUpdaterInfo cui = typeInfo.GetCommandUpdater (commandId);
- if (cui != null) {
- if (cmd.CommandArray) {
- // Make sure that the option is still active
- CommandArrayInfo ainfo = new CommandArrayInfo (info);
- cui.Run (cmdTarget, ainfo);
- bool found = false;
- foreach (CommandInfo ci in ainfo) {
- if (Object.Equals (dataItem, ci.DataItem)) {
- found = true;
- break;
+ int globalPos;
+ object cmdTarget = GetFirstCommandTarget (out globalPos);
+ CommandInfo info = new CommandInfo (cmd);
+
+ while (cmdTarget != null)
+ {
+ HandlerTypeInfo typeInfo = GetTypeHandlerInfo (cmdTarget);
+
+ CommandUpdaterInfo cui = typeInfo.GetCommandUpdater (commandId);
+ if (cui != null) {
+ if (cmd.CommandArray) {
+ // Make sure that the option is still active
+ CommandArrayInfo ainfo = new CommandArrayInfo (info);
+ cui.Run (cmdTarget, ainfo);
+ bool found = false;
+ foreach (CommandInfo ci in ainfo) {
+ if (Object.Equals (dataItem, ci.DataItem)) {
+ found = true;
+ break;
+ }
}
+ if (!found) return false;
+ } else {
+ cui.Run (cmdTarget, info);
+ if (!info.Enabled || !info.Visible) return false;
}
- if (!found) return false;
- } else {
- cui.Run (cmdTarget, info);
- if (!info.Enabled || !info.Visible) return false;
}
+
+ CommandHandlerInfo chi = typeInfo.GetCommandHandler (commandId);
+ if (chi != null) {
+ if (cmd.CommandArray)
+ chi.Run (cmdTarget, dataItem);
+ else
+ chi.Run (cmdTarget);
+ UpdateToolbars ();
+ return true;
+ }
+
+ cmdTarget = GetNextCommandTarget (cmdTarget, ref globalPos);
}
-
- CommandHandlerInfo chi = typeInfo.GetCommandHandler (commandId);
- if (chi != null) {
- if (cmd.CommandArray)
- chi.Run (cmdTarget, dataItem);
- else
- chi.Run (cmdTarget);
- UpdateToolbars ();
- return true;
- }
-
- cmdTarget = GetNextCommandTarget (cmdTarget, ref globalPos);
+
+ return cmd.DispatchCommand (dataItem);
}
-
- return cmd.DispatchCommand (dataItem);
+ catch (Exception ex) {
+ ReportError ("Error while executing command: " + commandId, ex);
+ return false;
+ }
}
internal CommandInfo GetCommandInfo (object commandId)
@@ -177,36 +184,46 @@
ActionCommand cmd = GetActionCommand (commandId);
CommandInfo info = new CommandInfo (cmd);
- int globalPos;
- object cmdTarget = GetFirstCommandTarget (out globalPos);
-
- while (cmdTarget != null)
- {
- HandlerTypeInfo typeInfo = GetTypeHandlerInfo (cmdTarget);
- CommandUpdaterInfo cui = typeInfo.GetCommandUpdater (commandId);
+ try {
+ int globalPos;
+ object cmdTarget = GetFirstCommandTarget (out globalPos);
- if (cui != null) {
- if (cmd.CommandArray) {
- info.ArrayInfo = new CommandArrayInfo (info);
- cui.Run (cmdTarget, info.ArrayInfo);
- return info;
+ while (cmdTarget != null)
+ {
+ HandlerTypeInfo typeInfo = GetTypeHandlerInfo (cmdTarget);
+ CommandUpdaterInfo cui = typeInfo.GetCommandUpdater (commandId);
+
+ if (cui != null) {
+ if (cmd.CommandArray) {
+ info.ArrayInfo = new CommandArrayInfo (info);
+ cui.Run (cmdTarget, info.ArrayInfo);
+ return info;
+ }
+ else {
+ cui.Run (cmdTarget, info);
+ return info;
+ }
}
- else {
- cui.Run (cmdTarget, info);
+
+ if (typeInfo.GetCommandHandler (commandId) != null) {
+ info.Enabled = true;
+ info.Visible = true;
return info;
}
+
+ cmdTarget = GetNextCommandTarget (cmdTarget, ref globalPos);
}
- if (typeInfo.GetCommandHandler (commandId) != null) {
- info.Enabled = true;
- info.Visible = true;
- return info;
+ cmd.UpdateCommandInfo (info);
+ }
+ catch (Exception ex) {
+ if (!commandUpdateErrors.Contains (commandId)) {
+ commandUpdateErrors.Add (commandId);
+ ReportError ("Error while updating status of command: " + commandId, ex);
}
-
- cmdTarget = GetNextCommandTarget (cmdTarget, ref globalPos);
+ info.Enabled = false;
+ info.Visible = true;
}
-
- cmd.UpdateCommandInfo (info);
return info;
}
@@ -343,6 +360,19 @@
toolbar.Update ();
}
}
+
+ public void ReportError (string message, Exception ex)
+ {
+ string msg = ex.ToString();
+ msg = msg.Replace ("<","");
+ msg = msg.Replace (">","");
+ msg = "<b>" + message + "</b>\n\nException ocurred: " + msg;
+
+ Gtk.MessageDialog md = new Gtk.MessageDialog (null, Gtk.DialogFlags.Modal, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, msg);
+ md.Run ();
+ md.Destroy ();
+ md.Dispose ();
+ }
}
internal class HandlerTypeInfo
More information about the Monodevelop-patches-list
mailing list