public interface IApplicationObject { void Alert( string msg ); // 產生一條信息 void ShowInStatusBar( string msg ); // 將指定的信息顯示在狀態欄 IDocumentObject QueryCurrentDocument(); // 獲取當前使用的文檔對象 IDocumentObject[] QueryDocuments(); // 獲取所有的文檔對象 // 設置事件處理器 void SetDelegate( Delegates whichOne , EventHandler targer ); } // 目前只需要這一個事件 public enum Delegates { Delegate_ActiveDocumentChanged , } |
/// /// 編輯器對象必須實現這個接口 /// public interface IDocumentObject { // 這些屬性是 RichTextBox 控件的相應的屬性映射 string SelectionText { get ; set ; } Color SelectionColor { get ; set ; } Font SelectionFont { get ; set ; } int SelectionStart { get ; set ; } int SelectionLength { get ; set ; } string SelectionRTF { get ; set ; } bool HasChanges { get ; } void Select( int start , int length ); void AppendText( string str ); void SaveFile( string fileName ); void SaveFile(); void OpenFile( string fileName ); void CloseFile(); } |
/// /// 本程序的插件必須實現這個接口 /// public interface IPlugin { ConnectionResult Connect( IApplicationObject app ); void OnDestory(); void OnLoad(); void Run(); } /// /// 表示插件與主程序連接的結果 /// public enum ConnectionResult { Connection_Suclearcase/" target="_blank" >ccess , Connection_Failed } |
/// /// 用來指定一個插件的相關信息 /// public class PluginInfoAttribute : System.Attribute { /// /// Deprecated. Do not use. /// public PluginInfoAttribute() {} public PluginInfoAttribute( string name , string version , string author , string webpage , bool loadWhenStart ) { // 細節已略去 } public string Name { get { return _Name; } } public string Version { get { return _Version; } } public string Author { get { return _Author; } } public string Webpage { get { return _Webpage; } } public bool LoadWhenStart { get { return _LoadWhenStart; } } /// /// 用來存儲一些有用的信息 /// public object Tag { get { return _Tag; } set { _Tag = value ; } } /// /// 用來存儲序號 /// public int Index { get { return _Index; } set { _Index = value ; } } private string _Name = ""; private string _Version = ""; private string _Author = ""; private string _Webpage = ""; private object _Tag = null ; private int _Index = 0; // 暫時不會用 private bool _LoadWhenStart = true ; } |
/// /// My Pluging 1( Just for test ) /// [ PluginInfo("My Pluging 1( Just for test )" ,"1.0" , "Jack H Hansen" , "http://blog.csdn.net/matrix2003b" , true ) ] public class MyPlugin1 : IPlugin { public MyPlugin1() { } #region IPlugin 成員 // 細節已略去 #endregion private IApplicationObject _App; private IDocumentObject _CurDoc; } |
private bool IsValidPlugin( Type t ) { bool ret = false ; Type[] interfaces = t.GetInterfaces(); foreach ( Type theInterface in interfaces ) { if ( theInterface.FullName == "CSPluginKernel.IPlugin" ) { ret = true ; break ; } } return ret; } |
plugins.Add( pluginAssembly.CreateInstance( plugingType.FullName ) ); |