📄 reflectiontree.cs
字号:
// ReflectionTree.cs
// Copyright (C) 2001 Mike Krueger
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Xml;
using System.Collections;
using System.IO;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
using System.Reflection;
using System.Threading;
using System.Resources;
using System.Reflection.Emit;
using SharpDevelop.Gui.Edit;
using SharpDevelop.Internal.Undo;
using SharpDevelop.Gui.Window;
using SharpDevelop.Tool.Data;
namespace SharpDevelop.Gui.Edit.Reflection {
public class ReflectionTree : TreeView, ISdEditable
{
ArrayList assemblies = new ArrayList();
// Hashtable xmlhelp = new Hashtable();
public event EventHandler Changed;
public event EventHandler FileTransaction;
public event ProgressEventHandler FileTransactionProgress;
public event EventHandler FileTransactionComplete;
public ArrayList Assemblies {
get {
return assemblies;
}
}
public PrintDocument PrintDocument {
get {
return null;
}
}
public ISdClipboardHandable ClipboardHandler {
get {
return null;
}
}
public UndoStack UndoStack {
get {
return null;
}
}
public bool WriteProtected {
get {
return false;
}
set {
}
}
void OnFileTransaction()
{
FileTransaction(null, null);
FileTransactionProgress(null, 5);
FileTransactionComplete(null, null);
}
public void LoadFile(string filename)
{
try {
AddAssembly(Assembly.LoadFrom(filename));
} catch (Exception e) {
MessageBox.Show("can't load " + filename+ " invalid format.\n(you can only view .NET assemblies)\n " + e.ToString());
}
}
public void SaveFile(string filename)
{
}
public void AddAssembly(Assembly assembly)
{
assemblies.Add(assembly);
TreeNode node = new ReflectionFolderNode(Path.GetFileNameWithoutExtension(assembly.CodeBase), assembly, ReflectionNodeType.Assembly, 0, 1);
Nodes.Add(node);
PopulateTreeView();
new Thread(new ThreadStart(PopulateTreeView)).Start();
// string helpfile = Path.ChangeExtension(assembly.Location, ".xml");
// Console.WriteLine(helpfile);
// if (File.Exists(helpfile)) {
// XmlDocument xmldocument = new XmlDocument();
// xmldocument.Load(helpfile);
// xmlhelp[assembly.FullName] = xmldocument;
// }
}
public void PopulateTreeView(ReflectionNode parentnode)
{
foreach (ReflectionNode node in parentnode.Nodes) {
if (!node.Populated) {
node.Populate();
}
PopulateTreeView(node);
}
}
public void PopulateTreeView()
{
foreach (ReflectionNode node in Nodes) {
if (!node.Populated)
node.Populate();
PopulateTreeView(node);
}
}
public ReflectionTree()
{
if (Changed != null) {} // only to prevent these pesky compiler warning :) M.K.
Dock = DockStyle.Fill;
ImageList imglist = new ImageList();
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Assembly"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.OpenAssembly"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Library"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.NameSpace"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.SubTypes"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.SuperTypes"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ClosedFolderBitmap"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.OpenFolderBitmap"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Reference"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ClosedReferenceFolder"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.OpenReferenceFolder"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ResourceFileIcon"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Event"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Literal"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Class")); //14
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.InternalClass"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ProtectedClass"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.PrivateClass"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Struct"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.InternalStruct"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ProtectedStruct"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.PrivateStruct"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Interface"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.InternalInterface"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ProtectedInterface"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.PrivateInterface"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Enum"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.InternalEnum"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ProtectedEnum"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.PrivateEnum"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Method"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.InternalMethod"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ProtectedMethod"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.PrivateMethod"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Property"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.InternalProperty"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ProtectedProperty"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.PrivateProperty"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Field"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.InternalField"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ProtectedField"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.PrivateField"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Delegate"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.InternalDelegate"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ProtectedDelegate"));
imglist.Images.Add(Resource.GetBitmap("Icons.16x16.PrivateDelegate"));
this.ImageList = imglist;
LabelEdit = false;
HotTracking = false;
AllowDrop = true;
HideSelection = false;
}
public void GoTo(Type type)
{
foreach (ReflectionNode node in Nodes) {
Assembly assembly = (Assembly)node.Attribute;
if (type.Assembly.FullName == assembly.FullName) {
ReflectionNode curnode = (ReflectionNode)node.GetNodeFromCollection(node.Nodes, Path.GetFileName(assembly.CodeBase));
curnode = (ReflectionNode)curnode.GetNodeFromCollection(curnode.Nodes, Path.GetFileName(assembly.CodeBase));
string typename = type.ToString();
int lastindex = typename.LastIndexOf('.');
TreeNode path = curnode;
string nodename = typename;
if (lastindex != -1) {
string pathname = typename.Substring(0, lastindex);
TreeNode tnode = node.GetNodeFromCollection(node.Nodes, pathname);
if (tnode == null) {
return; // TODO : returns, if the tree isn't up to date.
} else
path = tnode;
nodename = typename.Substring(lastindex + 1);
}
TreeNode foundnode = node.GetNodeFromCollection(path.Nodes, nodename);
foundnode.EnsureVisible();
SelectedNode = foundnode;
return;
}
}
AddAssembly(type.Assembly);
GoTo(type);
}
protected override void OnDoubleClick(EventArgs e)
{
ReflectionNode rn = (ReflectionNode)SelectedNode;
if (rn == null)
return;
switch (rn.Type) {
case ReflectionNodeType.Link: // clicked on link, jump to link.
if (rn.Attribute is Type) {
GoTo((Type)rn.Attribute);
}
break;
case ReflectionNodeType.Reference: // clicked on assembly reference, open assembly
// check if the assembly is open
AssemblyName name = (AssemblyName)rn.Attribute;
foreach (ReflectionNode node in Nodes) {
if (node.Type == ReflectionNodeType.Assembly) {
if (name.FullName == ((Assembly)node.Attribute).FullName) // if yes, return
return;
}
}
AddAssembly(Assembly.Load(name));
break;
}
}
protected override void OnBeforeCollapse(TreeViewCancelEventArgs e)
{
base.OnBeforeCollapse(e);
((ReflectionNode)e.Node).OnCollapse();
}
protected override void OnBeforeExpand(TreeViewCancelEventArgs e)
{
base.OnBeforeExpand(e);
// populate node
ReflectionNode rn = (ReflectionNode)e.Node;
if (!rn.Populated)
rn.Populate();
((ReflectionNode)e.Node).OnExpand();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -