首页 > 学院 > 开发设计 > 正文

x01.TestViewContent:插件测试

2019-11-14 13:48:01
字体:
来源:转载
供稿:网友

开发神器 SharpDevelop 的插件系统,很有学习的必要。

1.首先在 github 上下载源代码,确保编译运行无误。

2.在 AddIns/Misc 下添加 SharpDevelop 插件项目 x01.TestViewContent,然后添加 ICSharpCode.Core 和 ICSharpCode.SharpDevelop 引用,设置这两个引用的 Local Copy 为 false;在项目属性上选编译输出为  “../../../../AddIns/AddIns/Misc/TestViewContent/”,可参考其他插件。设置 TestViewContent.addin 的文件属性 Local copy 为 Always。

3.添加类 TestViewContent.cs, 内容如下:

 1 /** 2  * TestViewContent.cs (c) 2015 by x01 3  */ 4 using System; 5 using System.Windows.Forms; 6 using ICSharpCode.SharpDevelop.Gui; 7  8 namespace x01.TestViewContent 9 {10     /// <summary>11     /// Description of TestViewContent.12     /// </summary>13     public class TestViewContent : AbstractViewContent14     {15         Control control;        16         17         public override Control Control {18             get {19                 return control;20             }21         }22         23         public TestViewContent() : base("Test")24         {25             Panel panel = new Panel();26             panel.Dock = DockStyle.Fill;27             28             TextBox textbox = new TextBox();29             textbox.Text = "Hello world!";30             textbox.Dock = DockStyle.Fill;31             textbox.Multiline = true;32             textbox.Height = 500;33             34             panel.Controls.Add(textbox);35             36             this.control = panel;37         }38     }39 }
TestViewContent

4.添加类 TestCommand.cs,内容如下:

 1 /** 2  * TestCommand.cs (c) 2015 by x01 3  */ 4 using System; 5 using ICSharpCode.SharpDevelop; 6 using ICSharpCode.SharpDevelop.Gui; 7  8 namespace x01.TestViewContent 9 {10     /// <summary>11     /// Description of TestCommand.12     /// </summary>13     public class TestCommand : AbstractMenuCommand14     {15         public override void Run()16         {17             WorkbenchSingleton.Workbench.ShowView(new TestViewContent());18         }19     }20 }
TestCommand

5.修改 TestViewContent.addin 后的内容如下:

 1 <AddIn name        = "x01.TestViewContent" 2        author      = "Administrator" 3        url         = "" 4        description = "TODO: Put description here"> 5      6     <Runtime> 7         <Import assembly = "x01.TestViewContent.dll"/> 8     </Runtime> 9     10     <!-- Extend the SharpDevelop AddIn-Tree like this:11     <Path name = ...>12         <.../>13     </Path>14     -->15     <Path name="/Workspace/Autostart">16         <Class id="TestCommand"17                class="x01.TestViewContent.TestCommand" />18     </Path>19 </AddIn>

关键部分是 15-18行。

6.编译生成该插件项目。OK!这时,你会惊奇的发现,不需重新编译整个 Solution,直接进入 bin 目录运行 SharpDevelop.exe 时,该插件已然可用。效果图如下:


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表