diff options
author | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2015-11-25 17:48:45 +0300 |
---|---|---|
committer | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2015-11-25 17:48:45 +0300 |
commit | b9bd40261ad463772a2740328ca23b6ddd8ef1e7 (patch) | |
tree | 326bd5e9e53ff0b0b4d337405df50e855ca707e1 | |
parent | d769b6402a53cbddfb6c8ee7729267bb1aa2ac73 (diff) |
[Ide] Internalize CommandRouterContainer.
5 files changed, 33 insertions, 20 deletions
diff --git a/main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore.GuiBuilder/CombinedDesignView.cs b/main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore.GuiBuilder/CombinedDesignView.cs index 73752b1ff8..d4107e6ae2 100644 --- a/main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore.GuiBuilder/CombinedDesignView.cs +++ b/main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore.GuiBuilder/CombinedDesignView.cs @@ -60,7 +60,7 @@ namespace MonoDevelop.GtkCore.GuiBuilder content.DirtyChanged += new EventHandler (OnTextDirtyChanged); CommandRouterContainer crc = new CommandRouterContainer (content.Control, content, true); - crc.Show (); + crc.GetNativeWidget<Gtk.Widget> ().Show (); control = crc; IdeApp.Workbench.ActiveDocumentChanged += new EventHandler (OnActiveDocumentChanged); diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandRouterContainer.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandRouterContainer.cs index d6693f379e..a1cdbadd40 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandRouterContainer.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandRouterContainer.cs @@ -34,7 +34,7 @@ namespace MonoDevelop.Components.Commands /// A container which can be used to redirect the command /// route to a different parent /// </summary> - public class CommandRouterContainer: Gtk.HBox, ICommandDelegatorRouter + public class CommandRouterContainer: Control, ICommandDelegatorRouter { bool continueToParent; @@ -47,17 +47,23 @@ namespace MonoDevelop.Components.Commands { this.continueToParent = continueToParent; } + + protected override object CreateNativeWidget () + { + return new Gtk.HBox (); + } - public CommandRouterContainer (Gtk.Widget child, object target, bool continueToParent) : this (continueToParent) + public CommandRouterContainer (Control child, object target, bool continueToParent) : this (continueToParent) { + var hbox = GetNativeWidget<Gtk.HBox> (); if (child != null) - PackStart (child, true, true, 0); + hbox.PackStart (child, true, true, 0); Delegated = target; } public virtual object GetNextCommandTarget () { - return continueToParent ? Parent : null; + return continueToParent ? GetNativeWidget<Gtk.Widget> ().Parent : null; } public virtual object GetDelegatedCommandTarget () diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Control.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Control.cs index 9203e0f316..ca10eae5d9 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Control.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Control.cs @@ -24,6 +24,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; +using System.Collections.Generic; using MonoDevelop.Components.Commands; #if MAC @@ -33,8 +34,9 @@ using MonoDevelop.Components.Mac; namespace MonoDevelop.Components { - public class Control: IDisposable + public class Control : IDisposable { + static Dictionary<object, Control> cache = new Dictionary<object, Control> (); object nativeWidget; protected Control () @@ -44,8 +46,9 @@ namespace MonoDevelop.Components public Control (object widget) { if (widget == null) - throw new ArgumentNullException ("widget"); + throw new ArgumentNullException (nameof (widget)); this.nativeWidget = widget; + cache.Add (nativeWidget, this); } protected virtual object CreateNativeWidget () @@ -58,10 +61,10 @@ namespace MonoDevelop.Components if (nativeWidget == null) { var w = CreateNativeWidget (); if (!(w is T)) - w = ConvertToType (typeof(T), w); + w = ConvertToType (typeof (T), w); if (w is Gtk.Widget) { var gtkWidget = (Gtk.Widget)w; - var c = new CommandRouterContainer (gtkWidget, this, true); + Gtk.HBox c = new CommandRouterContainer (gtkWidget, this, true).GetNativeWidget<Gtk.HBox> (); c.FocusChain = new [] { gtkWidget }; c.Show (); nativeWidget = c; @@ -69,9 +72,9 @@ namespace MonoDevelop.Components GC.SuppressFinalize (this); Dispose (true); }; - } - else + } else nativeWidget = w; + cache.Add (nativeWidget, this); } if (nativeWidget is T) return (T)nativeWidget; @@ -84,16 +87,16 @@ namespace MonoDevelop.Components if (t.IsInstanceOfType (w)) return w; - #if MAC - if (w is NSView && t == typeof(Gtk.Widget)) { +#if MAC + if (w is NSView && t == typeof (Gtk.Widget)) { var ww = GtkMacInterop.NSViewToGtkWidget ((NSView)w); ww.Show (); return ww; } - if (w is Gtk.Widget && t == typeof(NSView)) { + if (w is Gtk.Widget && t == typeof (NSView)) { return new GtkEmbed ((Gtk.Widget)w); } - #endif +#endif throw new NotSupportedException (); } @@ -104,6 +107,9 @@ namespace MonoDevelop.Components public static implicit operator Control (Gtk.Widget d) { + Control cached; + if (cache.TryGetValue (d, out cached)) + return cached; return new Control (d); } @@ -129,16 +135,17 @@ namespace MonoDevelop.Components ((Gtk.Widget)nativeWidget).Destroy (); return; } - #if MAC +#if MAC else if (nativeWidget is NSView) ((NSView)nativeWidget).Dispose (); - #endif +#endif Dispose (true); } protected virtual void Dispose (bool disposing) { + cache.Remove (nativeWidget); } } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DefaultWorkbench.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DefaultWorkbench.cs index d17a460673..2cecc7cf52 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DefaultWorkbench.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DefaultWorkbench.cs @@ -1269,10 +1269,10 @@ namespace MonoDevelop.Ide.Gui if (force || item.Content == null) { PadContent newContent = padCodon.InitializePadContent (window); - PadCommandRouterContainer crc = new PadCommandRouterContainer (window, newContent.Control, newContent, true); + Gtk.Widget crc = new PadCommandRouterContainer (window, newContent.Control, newContent, true); crc.Show (); - PadCommandRouterContainer router = new PadCommandRouterContainer (window, crc, toolbarFrame, false); + Gtk.Widget router = new PadCommandRouterContainer (window, crc, toolbarFrame, false); router.Show (); item.Content = router; } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/GtkNewProjectDialogBackend.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/GtkNewProjectDialogBackend.cs index 16c9af56ab..865e2b8036 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/GtkNewProjectDialogBackend.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/GtkNewProjectDialogBackend.cs @@ -461,7 +461,7 @@ namespace MonoDevelop.Ide.Projects void FocusWidget (Widget widget)
{
var widgetToFocus = widget;
- var commandRouter = widget as CommandRouterContainer;
+ var commandRouter = ((Control)widget as CommandRouterContainer).GetNativeWidget<Gtk.HBox> ();
if ((commandRouter != null) && commandRouter.Children.Any ()) {
widgetToFocus = commandRouter.Children [0];
}
|