2 // SwfTypeDisplayer.cs:
3 // Display types using System.Windows.Forms
5 // Author: Jonathan Pryor (jonpryor@vt.edu)
7 // (C) 2003 Jonathan Pryor
13 using System.Collections;
15 using System.Diagnostics;
16 using System.Reflection;
18 using System.Text.RegularExpressions;
22 using System.ComponentModel;
23 using System.Windows.Forms;
25 namespace Mono.TypeReflector.Displayers.Swf
27 class ReflectorTreeNode : TreeNode
29 private Node node = null;
31 public ReflectorTreeNode (string text)
36 public ReflectorTreeNode (Node node)
39 base.Text = node.Description;
47 public class SwfTypeDisplayer : TypeDisplayer
49 private static int windows = 0;
51 private const string dummyText = "dummy: you shouldn't see this!";
53 private SwfWindow window = new SwfWindow ();
55 public override int MaxDepth {
59 public override bool RequireTypes {
63 public SwfTypeDisplayer ()
67 window.FileOpenClick += new EventHandler (OnFileOpen);
68 window.FileQuitClick += new EventHandler (OnFileQuit);
70 window.EditCopyClick += new EventHandler (OnEditCopy);
72 window.ViewFormatterDefaultClick += new EventHandler (OnViewFormatterDefault);
73 window.ViewFormatterVBClick += new EventHandler (OnViewFormatterVB);
74 window.ViewFormatterCSharpClick += new EventHandler (OnViewFormatterCSharp);
75 window.ViewFinderExplicitClick += new EventHandler (OnViewFinderExplicit);
76 window.ViewFinderReflectionClick += new EventHandler (OnViewFinderReflection);
78 window.HelpAboutClick += new EventHandler (OnHelpAbout);
80 window.TreeView.BeforeExpand += new TreeViewCancelEventHandler (OnNodeExpand);
83 public override void Run ()
87 Application.Run (window);
90 public override void ShowError (string message)
92 MessageBox.Show (message, "Type Reflector", MessageBoxButtons.OK,
93 MessageBoxIcon.Error);
96 private void ShowTypes ()
98 foreach (Assembly a in Assemblies) {
99 ReflectorTreeNode tn = new ReflectorTreeNode (string.Format ("Assembly: {0}", a.FullName));
101 foreach (string ns in Namespaces (a)) {
102 ReflectorTreeNode nn = new ReflectorTreeNode (string.Format ("Namespace: {0}", ns));
105 foreach (Type type in Types (a, ns))
109 window.TreeView.Nodes.Add (tn);
115 private void AddType (Type type, ReflectorTreeNode parent)
117 ReflectorTreeNode tn = CreateTreeNode (type);
118 tn.Nodes.Add (new ReflectorTreeNode (dummyText));
119 parent.Nodes.Add (tn);
122 private ReflectorTreeNode CreateTreeNode (Type type)
124 Node root = new Node (Formatter, Finder);
125 root.NodeInfo = new NodeInfo (null, type);
126 return new ReflectorTreeNode (root);
129 // System.Windows.Forms Functions...
130 private void OnFileQuit (object o, EventArgs args)
132 Console.WriteLine ("Asked to quit app; windows=" + windows);
135 if (--windows == 0) {
136 Console.WriteLine ("App.Exit");
141 private void OnFileOpen (object o, EventArgs args)
143 OpenFileDialog ofd = new OpenFileDialog ();
144 ofd.CheckFileExists = true;
145 ofd.Multiselect = true;
146 ofd.Title = "Open Assembly";
147 ofd.ValidateNames = true;
149 "Assemblies (*.dll;*.exe)|*.dll;*.exe" +
150 "|Dynamic Link Libraries (*.dll)|*.dll" +
151 "|Executables (*.exe)|*.exe" +
152 "|All Files (*.*)|*.*";
154 if (ofd.ShowDialog() == DialogResult.OK) {
155 OpenAssemblies (ofd.FileNames);
159 private void OpenAssemblies (string[] assemblies)
161 SwfTypeDisplayer d = null;
162 if (base.Assemblies.Count == 0)
165 d = new SwfTypeDisplayer ();
167 d.Formatter = Formatter;
171 TypeLoader tl = TypeReflectorApp.CreateLoader (Options);
172 tl.Assemblies = assemblies;
175 TypeReflectorApp.FindTypes (d, tl, new string[]{"."});
178 catch (Exception e) {
179 ShowError (string.Format ("Unable to load Assembly '{0}': {1}",
180 assemblies, e.ToString()));
184 public void OnEditCopy (object o, EventArgs args)
189 public void OnViewFormatterDefault (object o, EventArgs args)
193 public void OnViewFormatterVB (object o, EventArgs args)
197 public void OnViewFormatterCSharp (object o, EventArgs args)
201 public void OnViewFinderReflection (object o, EventArgs args)
205 public void OnViewFinderExplicit (object o, EventArgs args)
209 public void OnHelpAbout (object o, EventArgs args)
213 "Type Reflector, version x.y. Copyright (C) 2002-2003 Jonathan Pryor",
214 "About Type Reflector",
215 MessageBoxButtons.OK,
216 MessageBoxIcon.Information);
217 TypeReflectorApp.PrintVersion ();
220 private void OnNodeExpand (object sender, TreeViewCancelEventArgs e)
223 Console.WriteLine ("(node-expanded (Action {0}) (Cancel {1}) (Node {2}))",
224 e.Action, e.Cancel, e.Node);
227 if ((e.Node.Nodes.Count > 0) && (e.Node.Nodes[0].Text == dummyText)) {
228 ReflectorTreeNode tn = (ReflectorTreeNode) e.Node;
231 foreach (Node child in tn.Node.GetChildren()) {
232 ReflectorTreeNode cn = new ReflectorTreeNode (child);
233 cn.Nodes.Add (new ReflectorTreeNode (dummyText));
237 if (tn.Nodes.Count == 0)