}\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
});\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
}\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
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
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
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
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
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
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