ToolbarButtonWrapper: Changed to a static factory style to keep all of the reflection code in ToolbarButtonWrapper. toolbarwrapper_static_factory
[VOID.git] / VOID_Core.cs
blob:a/VOID_Core.cs -> blob:b/VOID_Core.cs
--- a/VOID_Core.cs
+++ b/VOID_Core.cs
@@ -157,7 +157,7 @@
 
 		[AVOID_SaveValue("UseBlizzyToolbar")]
 		protected VOID_SaveValue<bool> _UseToolbarManager;
-		protected bool ToolbarManagerLoaded = false;
+		protected bool ToolbarManagerLoaded;
 		internal ToolbarButtonWrapper ToolbarButton;
 
 		/*
@@ -280,6 +280,7 @@
 			this._skinName = this.defaultSkin;
 
 			this.UseToolbarManager = false;
+			this.ToolbarManagerLoaded = false;
 
 			this.LoadConfig ();
 		}
@@ -445,29 +446,17 @@
 
 		protected void LoadToolbarManager()
 		{
-			Type ToolbarManager = AssemblyLoader.loadedAssemblies
-				.Select(a => a.assembly.GetExportedTypes())
-					.SelectMany(t => t)
-					.FirstOrDefault(t => t.FullName == "Toolbar.ToolbarManager");
-
-			if (ToolbarManager == null)
-			{
-				Tools.PostDebugMessage(string.Format(
-					"{0}: Could not load ToolbarManager.",
-					this.GetType().Name
-				));
-
-				return;
-			}
-
-			this.InitializeToolbarButton();
-
-			this.ToolbarManagerLoaded = true;
+			this.ToolbarManagerLoaded = ToolbarButtonWrapper.ToolbarManagerPresent;
+
+			if (this.ToolbarManagerLoaded)
+			{
+				this.InitializeToolbarButton();
+			}
 		}
 
 		protected void InitializeToolbarButton()
 		{
-			this.ToolbarButton = new ToolbarButtonWrapper(this.GetType().Name, "coreToggle");
+			this.ToolbarButton = ToolbarButtonWrapper.TryWrapToolbarButton(this.GetType().Name, "coreToggle");
 			this.ToolbarButton.Text = this.VoidName;
 			this.ToolbarButton.TexturePath = this.VOIDIconOffPath + "_24x24";
 			if (this is VOID_EditorCore)