x01.TestViewContent: 插件测试

时间:2023-03-09 18:56:33
x01.TestViewContent: 插件测试

开发神器 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, 内容如下:

 /**
* TestViewContent.cs (c) 2015 by x01
*/
using System;
using System.Windows.Forms;
using ICSharpCode.SharpDevelop.Gui; namespace x01.TestViewContent
{
/// <summary>
/// Description of TestViewContent.
/// </summary>
public class TestViewContent : AbstractViewContent
{
Control control; public override Control Control {
get {
return control;
}
} public TestViewContent() : base("Test")
{
Panel panel = new Panel();
panel.Dock = DockStyle.Fill; TextBox textbox = new TextBox();
textbox.Text = "Hello world!";
textbox.Dock = DockStyle.Fill;
textbox.Multiline = true;
textbox.Height = ; panel.Controls.Add(textbox); this.control = panel;
}
}
}

TestViewContent

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

 /**
* TestCommand.cs (c) 2015 by x01
*/
using System;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui; namespace x01.TestViewContent
{
/// <summary>
/// Description of TestCommand.
/// </summary>
public class TestCommand : AbstractMenuCommand
{
public override void Run()
{
WorkbenchSingleton.Workbench.ShowView(new TestViewContent());
}
}
}

TestCommand

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

 <AddIn name        = "x01.TestViewContent"
author = "Administrator"
url = ""
description = "TODO: Put description here"> <Runtime>
<Import assembly = "x01.TestViewContent.dll"/>
</Runtime> <!-- Extend the SharpDevelop AddIn-Tree like this:
<Path name = ...>
<.../>
</Path>
-->
<Path name="/Workspace/Autostart">
<Class id="TestCommand"
class="x01.TestViewContent.TestCommand" />
</Path>
</AddIn>

关键部分是 15-18行。

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

x01.TestViewContent: 插件测试