OSDN Git Service

Documented some of the functions and what they do in ContextMenuManager.
authorDouglas R. Miles <logicmoo@gmail.com>
Thu, 15 Oct 2009 23:41:24 +0000 (23:41 +0000)
committerDouglas R. Miles <logicmoo@gmail.com>
Thu, 15 Oct 2009 23:41:24 +0000 (23:41 +0000)
Also added some cleanup code DeregisterContextAction(s)

git-svn-id: https://radegast.googlecode.com/svn/trunk@350 f7a694da-4d33-11de-9ad6-1127a62b9fcd

Radegast/Core/Contexts/ContextActionsManager.cs
Radegast/Core/Contexts/IContextAction.cs

index 7c8aa8d..63e68d3 100644 (file)
@@ -45,9 +45,11 @@ namespace Radegast
         }\r
 \r
         /// <summary>\r
-        ///             RegisterContextAction(typeof(Object), "Clueless Object!",\r
+        /// Register a Context Action \r
+        ///  <code>           RegisterContextAction(typeof(Object), "Clueless Object!",\r
         ///                   (obj, hand)\r
         ///                   => Console.WriteLine("I am an Object!: {0} {1} {2}", obj, hand, obj.GetType()));\r
+        /// </code>\r
         /// </summary>\r
         /// <param name="libomvType"></param>\r
         /// <param name="label"></param>\r
@@ -62,6 +64,25 @@ namespace Radegast
                                });\r
         }\r
 \r
+        /// <summary>\r
+        /// Deregister a Context Action \r
+        ///  <code></code>DeregisterContextAction(typeof(Object), "Clueless Object!");</code>\r
+        /// </summary>\r
+        /// <param name="libomvType"></param>\r
+        /// <param name="label"></param>\r
+        public void DeregisterContextAction(Type libomvType, String label)\r
+        {\r
+            lock (contextEventHandlers)\r
+            {\r
+                contextEventHandlers.RemoveAll(e =>\r
+                                                   {\r
+                                                       ContextAction ca = e as ContextAction;\r
+                                                       return ca != null && ca.Label == label &&\r
+                                                              libomvType == ca.ContextType;\r
+                                                   });\r
+            }\r
+        }\r
+\r
         public void RegisterContextAction(IContextAction handler)\r
         {\r
             lock (contextEventHandlers)\r
@@ -71,13 +92,35 @@ namespace Radegast
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Register a Context Action \r
+        /// </summary>\r
+        /// <param name="handler"></param>\r
+        public void DeregisterContextAction(IContextAction handler)\r
+        {\r
+            lock (contextEventHandlers)\r
+            {\r
+                contextEventHandlers.Remove(handler);\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Used by UI forms to add new ContextMenu Items to a Menu they are about to Display based on the Object\r
+        /// </summary>\r
+        /// <param name="strip">The form's menu</param>\r
+        /// <param name="o">The target object</param>\r
         public void AddContributions(ToolStripDropDown strip, Object o)\r
         {\r
             SetCurrentItem(strip, o);\r
             AddContributions(strip, o != null ? o.GetType() : null, o);\r
         }\r
 \r
-        public void AddContributions(ToolStripDropDown strip, List<ToolStripMenuItem> itemsIn)\r
+        /// <summary>\r
+        /// Used by AddContributions to add new ContextMenu Items to a Menu they are about to Display\r
+        /// </summary>\r
+        /// <param name="strip">The form's menu</param>\r
+        /// <param name="itemsIn">New Items to Add</param>\r
+        public static void AddContributions_Helper(ToolStripDropDown strip, List<ToolStripMenuItem> itemsIn)\r
         {\r
             if (itemsIn == null || itemsIn.Count == 0) return;\r
             List<ToolStripItem> items = new List<ToolStripItem>();\r
@@ -106,6 +149,13 @@ namespace Radegast
             strip.Closing += ((sender, args) => items.ForEach((o) => strip.Items.Remove(o)));\r
         }\r
 \r
+        /// <summary>\r
+        /// Used by UI forms to add new ContextMenu Items to a Menu they are about to Display\r
+        /// </summary>\r
+        /// <param name="strip">The form's menu</param>        \r
+        /// <param name="type">The type it will target</param>\r
+        /// <param name="obj">the Target ofbject</param>\r
+        /// <param name="controls">Control to search for extra contributions (like buttons)</param>\r
         public void AddContributions(ToolStripDropDown strip, Type type, Object obj, params Control[] controls)\r
         {\r
             SetCurrentItem(strip, obj);\r
@@ -119,7 +169,7 @@ namespace Radegast
                 if (v != null) items.AddRange(v);\r
             }\r
             items.Sort(CompareItems);\r
-            AddContributions(strip, items);\r
+            AddContributions_Helper(strip, items);\r
             if (!instance.advancedDebugging) return;\r
             List<ToolStripMenuItem> item1 = new List<ToolStripMenuItem>();\r
             string newVariable = obj.GetType() == type\r
@@ -136,9 +186,14 @@ namespace Radegast
                 ToolTipText = "" + obj\r
             });\r
 \r
-            AddContributions(strip, item1);\r
+            AddContributions_Helper(strip, item1);\r
         }\r
 \r
+        /// <summary>\r
+        /// Used by UI forms to set the Context target (saved in the toplevel strip if it's a RadegastContextMenuStrip)\r
+        /// </summary>\r
+        /// <param name="strip"></param>\r
+        /// <param name="o"></param>\r
         public void SetCurrentItem(ToolStripDropDown strip, object o)\r
         {\r
             RadegastContextMenuStrip rmenu = strip as RadegastContextMenuStrip;\r
@@ -161,22 +216,36 @@ namespace Radegast
             return t + sender;\r
         }\r
 \r
+        /// <summary>\r
+        /// Used by UI forms to add new ContextMenu Items gleaned from Controls\r
+        /// </summary>\r
+        /// <param name="strip">The form's menu</param>        \r
+        /// <param name="type">The type it will target</param>\r
+        /// <param name="obj">the Target ofbject</param>\r
+        /// <param name="controls">Control to search for extra contributions (like buttons)</param>\r
         public void GleanContributions(ToolStripDropDown strip, Type type, Object obj, params Control[] controls)\r
         {\r
             SetCurrentItem(strip, obj);\r
             List<ToolStripMenuItem> items = new List<ToolStripMenuItem>();\r
-            foreach (Control control in controls) GleanContributions(items, type, control, obj);                \r
+            foreach (Control control in controls) GleanContributions_Helper(items, type, control, obj);                \r
             if (obj is Control)\r
             {\r
                 Control control1 = (Control) obj;\r
-                GleanContributions(items, type, control1.Parent, obj);\r
+                GleanContributions_Helper(items, type, control1.Parent, obj);\r
             }\r
             if (items.Count == 0) return;\r
             items.Sort(CompareItems);\r
-            AddContributions(strip, items);\r
+            AddContributions_Helper(strip, items);\r
         }\r
 \r
-        public void GleanContributions(List<ToolStripMenuItem> items, Type type, Control control, Object obj)\r
+        /// <summary>\r
+        /// Used by GleanContributions to add new ContextMenu Items gleaned from Parent control that has buttons on it\r
+        /// </summary>\r
+        /// <param name="items">Collection of Items to be added to</param>        \r
+        /// <param name="type">The type it will target</param>\r
+        /// <param name="control">Parent control that has buttons on it</param>\r
+        /// <param name="obj">Will becvome the button's target when </param>\r
+        static public void GleanContributions_Helper(ICollection<ToolStripMenuItem> items, Type type, Control control, Object obj)\r
         {\r
             if (control == null) return;\r
             if (control is Button)\r
@@ -200,7 +269,7 @@ namespace Radegast
                 return;\r
             }\r
             foreach (object v in control.Controls)\r
-                GleanContributions(items, type, (Control) v, obj);\r
+                GleanContributions_Helper(items, type, (Control) v, obj);\r
         }\r
 \r
         static int CompareItems(ToolStripItem i1, ToolStripItem i2)\r
index 6c44bae..0c20f66 100644 (file)
@@ -37,11 +37,45 @@ namespace Radegast
     public interface IContextAction : IDisposable\r
     {\r
         void IContextAction(RadegastInstance instance);\r
+        /// <summary>\r
+        /// Generate a list of ToolStripMenuItems that might be be embeded into a ContextMenuStrip host\r
+        /// </summary>\r
+        /// <param name="target">the context sensitive item</param>\r
+        /// <param name="type">the dereferenced type</param>\r
+        /// <returns>List of ToolStripMenuItem that will be appeneded to the current menu</returns>\r
         IEnumerable<ToolStripMenuItem> GetToolItems(object target, Type type);\r
+        /// <summary>\r
+        /// Get GUI items that one might include on the form to operate this action\r
+        /// </summary>\r
+        /// <param name="target">the context sensitive item</param>\r
+        /// <param name="type">the dereferenced type</param>\r
+        /// <returns>List of Buttons and Other hostable Controls that make sense to appear on the form when this item is selected</returns>\r
         IEnumerable<Control> GetControls(object target, Type type);\r
+        /// <summary>\r
+        /// If the menu item is Enabled\r
+        /// </summary>\r
+        /// <param name="target">the context sensiive item</param>\r
+        /// <returns>false when the menu Item should be greyed</returns>\r
         bool IsEnabled(object target);\r
+        /// <summary>\r
+        /// The menu Item's text based on target \r
+        /// </summary>\r
+        /// <param name="target">the context sensiive item</param>\r
+        /// <returns>true if the Action is availble - for instance some Avatar might not even be logged in so "follow" would not even show up</returns>\r
         string LabelFor(object target);\r
-        bool Contributes(Object o, Type type);\r
+        /// <summary>\r
+        /// If the context menu is usable to the target\r
+        /// </summary>\r
+        /// <param name="target">the context sensitive item</param>\r
+        /// <param name="type">the dereferenced type</param>\r
+        /// <returns>The name that is displayed in a menu of options</returns>\r
+        bool Contributes(Object target, Type type);\r
+        /// <summary>\r
+        /// The Action code goes here\r
+        /// </summary>\r
+        /// <param name="sender">the Control that originates the event</param>\r
+        /// <param name="e">The EventArgs proprietary to the Controls event.. like MouseEventArgs or KeyEventArgs etc</param>\r
+        /// <param name="target">The Context Item that is realy targeted</param>\r
         void OnInvoke(object sender, EventArgs e, object target);\r
     }\r
 }
\ No newline at end of file