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