|
using System;
using System.Windows.Forms;
using System.Reflection;
using System.Diagnostics;
using Reflector;
using Reflector.Configuration;
using Reflector.Reflection;
using Reflector.Browser;
using Reflector.ComponentModel;
using Reflector.UserInterface;
using System.ComponentModel;
namespace Reflector.VSAddIn
{
/// <summary>
/// Summary description for ReflectorSingleton.
/// </summary>
public class ReflectorSingleton
{
public static void SetApplication(object application)
{
__singleton = new ReflectorSingleton(application);
}
private static ReflectorSingleton __singleton;
public static ReflectorSingleton Instance
{
get
{
if(__singleton == null)
{
throw new ApplicationException("SetApplication must be called to init singleton");
}
return __singleton;
}
}
private ReflectorSingleton(object application)
{
_application = application;
}
private object _application;
public object Application
{
get { return _application; }
}
private Type ApplicationType
{
get { return _application.GetType(); }
}
public Assembly ReflectorAssembly
{
get { return _application.GetType().Assembly; }
}
public IServiceProvider ServiceProvider
{
get { return (IServiceProvider)Application; }
}
public Form ApplicationWindow
{
get
{
object applicationWindow = ApplicationType.GetField("applicationWindow", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Application);
Debug.WriteLine(applicationWindow.GetType(), "applicationWindow");
return (Form)applicationWindow;
}
}
public Form ToolWindow
{
get
{
if(_toolWindow == null)
{
_toolWindow = new Form();
ToolWindowControl.TextChanged += new EventHandler(control_TextChanged);
ToolWindowControl.ControlAdded += new ControlEventHandler(_control_ControlAdded);
ToolWindowControl.Parent.Controls.Remove(ToolWindowControl);
ToolWindowControl.Font = ReflectorSingleton.Instance.ApplicationWindow.Font;
}
return _toolWindow;
}
}
private Form _toolWindow;
private void control_TextChanged(object sender, EventArgs e)
{
_toolWindow.Text = ToolWindowControl.Text;
}
private void _control_ControlAdded(object sender, ControlEventArgs e)
{
Control control = e.Control;
ToolWindowControl.Controls.Remove(control);
control.Dock = System.Windows.Forms.DockStyle.Fill;
control.Name = "ToolWindow";
_toolWindow.Controls.Clear();
_toolWindow.Controls.Add(control);
_toolWindow.Visible = true;
_toolWindow.Activate();
}
public Control ToolWindowControl
{
get { return (Control)ApplicationWindow.GetType().GetField("toolWindow", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(ApplicationWindow); }
}
public IBrowser Browser
{
get { return (IBrowser)ServiceProvider.GetService(typeof(IBrowser)); }
}
public IAssemblyLoader AssemblyLoader
{
get { return ((IAssemblyLoader)ReflectorSingleton.Instance.ServiceProvider.GetService(typeof(IAssemblyLoader)));; }
}
public IAssemblyManager AssemblyManager
{
get { return (IAssemblyManager)ServiceProvider.GetService(typeof(IAssemblyManager)); }
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.