GitBook 提供支持
2004-10-15 SharpDevelop的AddInTree View 插件
自从SharpDevelop 源码分析的系列文章发出来之后,很多朋友给了不错的评价,在这里先感谢各位朋友的鼓励。另外,评论中有位朋友想看看我在文章中提到的AddInTreeView插件,其实这个是个很简单的小东西,因此单独发在这里了。(好像没有找到那里能上传文件,因此直接贴代码了)

AddinTreeViewCommand.cs

1
/*
2
* Created by SharpDevelop.
3
* User: Administrator
4
* Date: 2004-10-4
5
* Time: 4:12
6
*
7
* To change this template use Tools | Options | Coding | Edit Standard Headers.
8
*/
9
using System;
10
using System.Windows.Forms;
11
using System.CodeDom.Compiler;
12
13
using ICSharpCode.SharpDevelop.Gui;
14
using ICSharpCode.SharpDevelop.Gui.Pads;
15
using ICSharpCode.Core.AddIns;
16
using ICSharpCode.Core.AddIns.Codons;
17
using ICSharpCode.SharpDevelop.Services;
18
19
namespace Addins.AddinTreeView
20
{
21
/// <summary>
22
/// Description of MyClass.
23
/// </summary>
24
public class AddinTreeViewCommand: AbstractMenuCommand
25
{
26
public override void Run()
27
{
28
using (AddinTreeViewContent viewContent = new AddinTreeViewContent() )
29
{
30
WorkbenchSingleton.Workbench.ShowView(viewContent);
31
}
32
}
33
}
34
35
public class AddinTreeViewContent: AbstractViewContent
36
{
37
AddinTreeViewControl viewControl = new AddinTreeViewControl();
38
39
public override Control Control
40
{
41
get
42
{
43
return viewControl;
44
}
45
}
46
47
public override bool IsDirty
48
{
49
get
50
{
51
return false;
52
}
53
set
54
{
55
}
56
}
57
58
IWorkbenchWindow workbenchWindow;
59
public override IWorkbenchWindow WorkbenchWindow
60
{
61
get
62
{
63
return workbenchWindow;
64
}
65
set
66
{
67
workbenchWindow = value;
68
workbenchWindow.Title = "AddInTreeView";
69
}
70
}
71
72
public AddinTreeViewContent()
73
{
74
TitleName = "AddinTree View";
75
}
76
77
public override bool IsViewOnly
78
{
79
get
80
{
81
return true;
82
}
83
}
84
public void SaveFile(){}
85
public void Undo(){}
86
public void Redo(){}
87
public override void Save(){}
88
public override void Save(string filename){}
89
public override void Load(string filename)
90
{
91
}
92
93
public override string TabPageText
94
{
95
get
96
{
97
return "AddInTree";
98
}
99
}
100
101
}
102
}
Copied!

AddinTreeViewControl.cs #

1
using System;
2
using System.Collections;
3
using System.ComponentModel;
4
using System.Drawing;
5
using System.Data;
6
using System.Windows.Forms;
7
8
using ICSharpCode.SharpDevelop.Gui;
9
using ICSharpCode.Core.AddIns;
10
using ICSharpCode.Core.AddIns.Codons;
11
12
namespace Addins.AddinTreeView
13
{
14
/// <summary>
15
/// AddinTreeViewControl 的摘要说明。
16
/// </summary>
17
public class AddinTreeViewControl : System.Windows.Forms.UserControl
18
{
19
private System.Windows.Forms.ColumnHeader chName;
20
private System.Windows.Forms.ListView lvAddin;
21
private System.Windows.Forms.ColumnHeader chInfo;
22
private System.Windows.Forms.CheckBox cbShowAddinInfo;
23
private System.Windows.Forms.Splitter splitter2;
24
private System.Windows.Forms.ListView lvDebug;
25
private System.Windows.Forms.Splitter splitter1;
26
private System.Windows.Forms.TreeView tvAddin;
27
private System.Windows.Forms.ColumnHeader chValue;
28
/// <summary>
29
/// 必需的设计器变量。
30
/// </summary>
31
private System.ComponentModel.Container components = null;
32
33
public AddinTreeViewControl()
34
{
35
// 该调用是 Windows.Forms 窗体设计器所必需的。
36
InitializeComponent();
37
38
// TODO: 在 InitializeComponent 调用后添加任何初始化
39
InitAddinTreeView();
40
}
41
42
/// <summary>
43
/// 清理所有正在使用的资源。
44
/// </summary>
45
protected override void Dispose( bool disposing )
46
{
47
if( disposing )
48
{
49
if(components != null)
50
{
51
components.Dispose();
52
}
53
}
54
base.Dispose( disposing );
55
}
56
57
组件设计器生成的代码
58
59
void InitAddinTreeView()
60
{
61
TreeNode pathNode = tvAddin.Nodes.Add("AddinRoot");
62
63
tvAddin.BeginUpdate();
64
try
65
{
66
foreach ( AddIn addIn in AddInTreeSingleton.AddInTree.AddIns)
67
{
68
foreach ( ICSharpCode.Core.AddIns.AddIn.Extension e in addIn.Extensions)
69
{
70
string [] paths = e.Path.Split('/');
71
pathNode = tvAddin.Nodes[0];
72
73
for ( int i=0; i<paths.Length; i++)
74
{
75
bool foundPath = false;
76
77
if ( paths[i] == "" )
78
{
79
pathNode = tvAddin.Nodes[0];
80
continue;
81
}
82
83
for ( int j=0; j<pathNode.Nodes.Count; j++)
84
{
85
if ( pathNode.Nodes[j].Text == paths[i] )
86
{
87
pathNode = pathNode.Nodes[j];
88
foundPath = true;
89
break;
90
}
91
}
92
93
if ( !foundPath )
94
{
95
pathNode = pathNode.Nodes.Add( paths[i] );
96
pathNode.Tag = new ArrayList();
97
//lvDebug.Items.Add("Add " + e.Path + " ---- " + paths[i]);
98
}
99
}
100
101
(pathNode.Tag as ArrayList).Add(e);
102
}
103
}
104
}
105
finally
106
{
107
tvAddin.EndUpdate();
108
}
109
}
110
111
void AddInfo(string Name, string Value)
112
{
113
lvAddin.Items.Add(Name).SubItems.Add(Value);
114
}
115
116
private void tvAddin_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
117
{
118
lvAddin.Items.Clear();
119
120
if ( e.Node.Tag != null )
121
{
122
foreach (AddIn.Extension et in (e.Node.Tag as ArrayList))
123
{
124
AddInfo("Extension", et.ToString());
125
126
foreach ( ICodon codon in et.CodonCollection)
127
{
128
AddInfo(" ┏ Codon ID", codon.ID);
129
AddInfo(" ┣ Codon Name", codon.Name);
130
AddInfo(" ┗ Codon Class", codon.Class);
131
132
if ( cbShowAddinInfo.Checked )
133
{
134
AddInfo(" ┣ Addin Name", codon.AddIn.Name);
135
AddInfo(" ┗ Addin FileName", codon.AddIn.FileName);
136
137
foreach ( ICSharpCode.Core.AddIns.AddIn.Extension ex in codon.AddIn.Extensions)
138
{
139
AddInfo(" ┣ Addin Extensions", ex.Path);
140
}
141
AddInfo(" ┗━━━━━━━━━", "");
142
}
143
}
144
}
145
}
146
}
147
}
148
}
Copied!
最近更新 1yr ago