SharpDevelop的AddInTree View 插件

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

AddinTreeViewCommand.cs

ExpandedBlockStart.gif ContractedBlock.gif /**/ /*
InBlock.gif * Created by SharpDevelop.
InBlock.gif * User: Administrator
InBlock.gif * Date: 2004-10-4
InBlock.gif * Time: 4:12
InBlock.gif * 
InBlock.gif * To change this template use Tools | Options | Coding | Edit Standard Headers.
ExpandedBlockEnd.gif 
*/

None.gif
using  System;
None.gif
using  System.Windows.Forms;
None.gif
using  System.CodeDom.Compiler;
None.gif
None.gif
using  ICSharpCode.SharpDevelop.Gui;
None.gif
using  ICSharpCode.SharpDevelop.Gui.Pads;
None.gif
using  ICSharpCode.Core.AddIns;
None.gif
using  ICSharpCode.Core.AddIns.Codons;
None.gif
using  ICSharpCode.SharpDevelop.Services;
None.gif
None.gif
namespace  Addins.AddinTreeView
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Description of MyClass.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class AddinTreeViewCommand: AbstractMenuCommand
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{    
InBlock.gif        
public override void Run()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
using (AddinTreeViewContent viewContent = new AddinTreeViewContent() )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                WorkbenchSingleton.Workbench.ShowView(viewContent);

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }
        
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
public class AddinTreeViewContent: AbstractViewContent
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        AddinTreeViewControl viewControl 
= new AddinTreeViewControl();
InBlock.gif
InBlock.gif        
public override Control Control 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return viewControl;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public override bool IsDirty 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return false;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        IWorkbenchWindow workbenchWindow;
InBlock.gif        
public override IWorkbenchWindow WorkbenchWindow 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return workbenchWindow;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                workbenchWindow 
= value;
InBlock.gif                workbenchWindow.Title 
= "AddInTreeView";
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public AddinTreeViewContent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            TitleName 
= "AddinTree View";
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif
InBlock.gif        
public override bool IsViewOnly 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return true;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
public void SaveFile()dot.gif{}
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public void Undo()dot.gif{}
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public void Redo()dot.gif{}
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public override void Save()dot.gif{}
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public override void Save(string filename)dot.gif{}
InBlock.gif        
public override void Load(string filename)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public override string TabPageText 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return "AddInTree";
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif



AddinTreeViewControl.cs

None.gif using  System;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.Drawing;
None.gif
using  System.Data;
None.gif
using  System.Windows.Forms;
None.gif
None.gif
using  ICSharpCode.SharpDevelop.Gui;
None.gif
using  ICSharpCode.Core.AddIns;
None.gif
using  ICSharpCode.Core.AddIns.Codons;
None.gif
None.gif
namespace  Addins.AddinTreeView
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// AddinTreeViewControl 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class AddinTreeViewControl : System.Windows.Forms.UserControl
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private System.Windows.Forms.ColumnHeader chName;
InBlock.gif        
private System.Windows.Forms.ListView lvAddin;
InBlock.gif        
private System.Windows.Forms.ColumnHeader chInfo;
InBlock.gif        
private System.Windows.Forms.CheckBox cbShowAddinInfo;
InBlock.gif        
private System.Windows.Forms.Splitter splitter2;
InBlock.gif        
private System.Windows.Forms.ListView lvDebug;
InBlock.gif        
private System.Windows.Forms.Splitter splitter1;
InBlock.gif        
private System.Windows.Forms.TreeView tvAddin;
InBlock.gif        
private System.Windows.Forms.ColumnHeader chValue;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 
InBlock.gif        
/// 必需的设计器变量。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private System.ComponentModel.Container components = null;
InBlock.gif
InBlock.gif        
public AddinTreeViewControl()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 该调用是 Windows.Forms 窗体设计器所必需的。
InBlock.gif
            InitializeComponent();
InBlock.gif
InBlock.gif            
// TODO: 在 InitializeComponent 调用后添加任何初始化
InBlock.gif
            InitAddinTreeView();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 
InBlock.gif        
/// 清理所有正在使用的资源。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        protected override void Dispose( bool disposing )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if( disposing )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(components != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    components.Dispose();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
base.Dispose( disposing );
ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
组件设计器生成的代码#region 组件设计器生成的代码
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器 
InBlock.gif        
/// 修改此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.chName = new System.Windows.Forms.ColumnHeader();
InBlock.gif            
this.lvAddin = new System.Windows.Forms.ListView();
InBlock.gif            
this.chValue = new System.Windows.Forms.ColumnHeader();
InBlock.gif            
this.chInfo = new System.Windows.Forms.ColumnHeader();
InBlock.gif            
this.cbShowAddinInfo = new System.Windows.Forms.CheckBox();
InBlock.gif            
this.splitter2 = new System.Windows.Forms.Splitter();
InBlock.gif            
this.lvDebug = new System.Windows.Forms.ListView();
InBlock.gif            
this.splitter1 = new System.Windows.Forms.Splitter();
InBlock.gif            
this.tvAddin = new System.Windows.Forms.TreeView();
InBlock.gif            
this.SuspendLayout();
InBlock.gif            
// 
InBlock.gif            
// chName
InBlock.gif            
// 
InBlock.gif
            this.chName.Text = "属性";
InBlock.gif            
this.chName.Width = 217;
InBlock.gif            
// 
InBlock.gif            
// lvAddin
InBlock.gif            
// 
ExpandedSubBlockStart.gifContractedSubBlock.gif
            this.lvAddin.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] dot.gif{
InBlock.gif                                                                                      
this.chName,
ExpandedSubBlockEnd.gif                                                                                      
this.chValue}
);
InBlock.gif            
this.lvAddin.Dock = System.Windows.Forms.DockStyle.Fill;
InBlock.gif            
this.lvAddin.FullRowSelect = true;
InBlock.gif            
this.lvAddin.GridLines = true;
InBlock.gif            
this.lvAddin.HoverSelection = true;
InBlock.gif            
this.lvAddin.Location = new System.Drawing.Point(44324);
InBlock.gif            
this.lvAddin.MultiSelect = false;
InBlock.gif            
this.lvAddin.Name = "lvAddin";
InBlock.gif            
this.lvAddin.Size = new System.Drawing.Size(661509);
InBlock.gif            
this.lvAddin.TabIndex = 13;
InBlock.gif            
this.lvAddin.View = System.Windows.Forms.View.Details;
InBlock.gif            
// 
InBlock.gif            
// chValue
InBlock.gif            
// 
InBlock.gif
            this.chValue.Text = "";
InBlock.gif            
this.chValue.Width = 668;
InBlock.gif            
// 
InBlock.gif            
// chInfo
InBlock.gif            
// 
InBlock.gif
            this.chInfo.Text = "Info";
InBlock.gif            
this.chInfo.Width = 673;
InBlock.gif            
// 
InBlock.gif            
// cbShowAddinInfo
InBlock.gif            
// 
InBlock.gif
            this.cbShowAddinInfo.Dock = System.Windows.Forms.DockStyle.Top;
InBlock.gif            
this.cbShowAddinInfo.Location = new System.Drawing.Point(4430);
InBlock.gif            
this.cbShowAddinInfo.Name = "cbShowAddinInfo";
InBlock.gif            
this.cbShowAddinInfo.Size = new System.Drawing.Size(66124);
InBlock.gif            
this.cbShowAddinInfo.TabIndex = 12;
InBlock.gif            
this.cbShowAddinInfo.Text = "显示Codon隶属的Addin信息";
InBlock.gif            
// 
InBlock.gif            
// splitter2
InBlock.gif            
// 
InBlock.gif
            this.splitter2.Dock = System.Windows.Forms.DockStyle.Bottom;
InBlock.gif            
this.splitter2.Location = new System.Drawing.Point(443533);
InBlock.gif            
this.splitter2.Name = "splitter2";
InBlock.gif            
this.splitter2.Size = new System.Drawing.Size(6613);
InBlock.gif            
this.splitter2.TabIndex = 11;
InBlock.gif            
this.splitter2.TabStop = false;
InBlock.gif            
this.splitter2.Visible = false;
InBlock.gif            
// 
InBlock.gif            
// lvDebug
InBlock.gif            
// 
ExpandedSubBlockStart.gifContractedSubBlock.gif
            this.lvDebug.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] dot.gif{
ExpandedSubBlockEnd.gif                                                                                      
this.chInfo}
);
InBlock.gif            
this.lvDebug.Dock = System.Windows.Forms.DockStyle.Bottom;
InBlock.gif            
this.lvDebug.Location = new System.Drawing.Point(443536);
InBlock.gif            
this.lvDebug.Name = "lvDebug";
InBlock.gif            
this.lvDebug.Size = new System.Drawing.Size(661216);
InBlock.gif            
this.lvDebug.TabIndex = 10;
InBlock.gif            
this.lvDebug.View = System.Windows.Forms.View.Details;
InBlock.gif            
this.lvDebug.Visible = false;
InBlock.gif            
// 
InBlock.gif            
// splitter1
InBlock.gif            
// 
InBlock.gif
            this.splitter1.Location = new System.Drawing.Point(4400);
InBlock.gif            
this.splitter1.Name = "splitter1";
InBlock.gif            
this.splitter1.Size = new System.Drawing.Size(3752);
InBlock.gif            
this.splitter1.TabIndex = 9;
InBlock.gif            
this.splitter1.TabStop = false;
InBlock.gif            
// 
InBlock.gif            
// tvAddin
InBlock.gif            
// 
InBlock.gif
            this.tvAddin.Dock = System.Windows.Forms.DockStyle.Left;
InBlock.gif            
this.tvAddin.FullRowSelect = true;
InBlock.gif            
this.tvAddin.HideSelection = false;
InBlock.gif            
this.tvAddin.ImageIndex = -1;
InBlock.gif            
this.tvAddin.Location = new System.Drawing.Point(00);
InBlock.gif            
this.tvAddin.Name = "tvAddin";
InBlock.gif            
this.tvAddin.SelectedImageIndex = -1;
InBlock.gif            
this.tvAddin.Size = new System.Drawing.Size(440752);
InBlock.gif            
this.tvAddin.TabIndex = 8;
InBlock.gif            
this.tvAddin.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvAddin_AfterSelect);
InBlock.gif            
// 
InBlock.gif            
// AddinTreeViewControl
InBlock.gif            
// 
InBlock.gif
            this.Controls.Add(this.lvAddin);
InBlock.gif            
this.Controls.Add(this.cbShowAddinInfo);
InBlock.gif            
this.Controls.Add(this.splitter2);
InBlock.gif            
this.Controls.Add(this.lvDebug);
InBlock.gif            
this.Controls.Add(this.splitter1);
InBlock.gif            
this.Controls.Add(this.tvAddin);
InBlock.gif            
this.Name = "AddinTreeViewControl";
InBlock.gif            
this.Size = new System.Drawing.Size(1104752);
InBlock.gif            
this.ResumeLayout(false);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif
InBlock.gif        
void InitAddinTreeView()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            TreeNode pathNode 
= tvAddin.Nodes.Add("AddinRoot");
InBlock.gif            
InBlock.gif            tvAddin.BeginUpdate();
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
foreach ( AddIn addIn in AddInTreeSingleton.AddInTree.AddIns)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
foreach ( ICSharpCode.Core.AddIns.AddIn.Extension e in addIn.Extensions)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
string [] paths = e.Path.Split('/');
InBlock.gif                        pathNode 
= tvAddin.Nodes[0];
InBlock.gif                        
InBlock.gif                        
for ( int i=0; i<paths.Length; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{    
InBlock.gif                            
bool foundPath = false;
InBlock.gif                            
InBlock.gif                            
if ( paths[i] == "" ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif                                pathNode 
= tvAddin.Nodes[0];
InBlock.gif                                
continue;
ExpandedSubBlockEnd.gif                            }
                        
InBlock.gif                                    
InBlock.gif                            
for ( int j=0; j<pathNode.Nodes.Count; j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif                                
if ( pathNode.Nodes[j].Text == paths[i] )
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif                                    pathNode 
= pathNode.Nodes[j];
InBlock.gif                                    foundPath 
= true;
InBlock.gif                                    
break;
ExpandedSubBlockEnd.gif                                }

ExpandedSubBlockEnd.gif                            }

InBlock.gif                            
InBlock.gif                            
if ( !foundPath )
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif                                pathNode 
= pathNode.Nodes.Add( paths[i] );
InBlock.gif                                pathNode.Tag 
= new ArrayList();
InBlock.gif                                
//lvDebug.Items.Add("Add " + e.Path + " ---- " + paths[i]);
ExpandedSubBlockEnd.gif
                            }

ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
InBlock.gif                        (pathNode.Tag 
as ArrayList).Add(e);
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                tvAddin.EndUpdate();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
void AddInfo(string Name, string Value)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            lvAddin.Items.Add(Name).SubItems.Add(Value);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void tvAddin_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            lvAddin.Items.Clear();
InBlock.gif            
InBlock.gif            
if ( e.Node.Tag != null )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
foreach (AddIn.Extension et in (e.Node.Tag as ArrayList))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    AddInfo(
"Extension", et.ToString());
InBlock.gif
InBlock.gif                    
foreach ( ICodon codon in et.CodonCollection)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        AddInfo(
"  ┏ Codon ID", codon.ID);
InBlock.gif                        AddInfo(
"  ┣ Codon Name", codon.Name);
InBlock.gif                        AddInfo(
"  ┗ Codon Class", codon.Class);
InBlock.gif                        
InBlock.gif                        
if ( cbShowAddinInfo.Checked )
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            AddInfo(
"      ┣ Addin Name", codon.AddIn.Name);
InBlock.gif                            AddInfo(
"      ┗ Addin FileName", codon.AddIn.FileName);
InBlock.gif                        
InBlock.gif                            
foreach ( ICSharpCode.Core.AddIns.AddIn.Extension ex in codon.AddIn.Extensions)
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif                                AddInfo(
"          ┣ Addin Extensions", ex.Path);
ExpandedSubBlockEnd.gif                            }

InBlock.gif                            AddInfo(
"          ┗━━━━━━━━━""");
ExpandedSubBlockEnd.gif                        }

ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/passos/archive/2004/10/15/52513.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值