CodeLite Plugin Internal(1) – IPlugin interface
所有的CodeLite插件都以动态库的形式(.dll or .so)保存在/plugins下,通过程序初始化时调用Frame::LoadPlugins加载[CodeLite的初始化分析在另外一篇文章中已有详述,请在ide.cbforge.com站内参阅]。插件相关的配置保存在/config/plugins.xml文件。文件为XML格式,每一插件项都保存有以下几项:SerializedObject Name,Plugin Name,Author,Description and Version。关于插件的实现我们会分几篇文章分析,这个第一篇主要关注IPlugin接口的实现。
IPlugin is the interface that defines a plugin for CodeLite. Each plugin must implement the pure virtual methods of this interface. The plugin gains access to CodeLite data by using the m_mgr member.
通过阅读相关代码和以下的IPlugin定义,可以知道 1)每一个插件必须继承自这个接口并实现相关纯虚函数,每个插件也可以实现自己的菜单、工具条等;2)插件和CodeLite打交道的唯一桥梁是m_mgr,这个IManager有很多的方式可以获得系统资源,比如其中包括获得当前被激活的editor等。
class IPlugin : public wxEvtHandler
{
protected:
wxString m_shortName;
wxString m_longName;
IManager *m_mgr;public:
IPlugin(IManager *manager) : m_mgr(manager) {}
virtual ~IPlugin() {}//———————————————–
//The interface
//———————————————–
/**
* @brief return the plugin’s short name
* @return
*/
virtual const wxString &GetShortName() const {
return m_shortName;
}
/**
* @brief return the plugin’s long and more descriptive name
* @return
*/
virtual const wxString &GetLongName() const {
return m_longName;
}/**
* When LiteEditor loads all the plugins, this function is called. If toolbar
* is provided by the plugin, the Plugin Manager will palce it in the appropriate
* place on the toolbar pane.
* \param parent toolbar parent, usually this is the main frame
* \return toolbar or NULL
*/
virtual wxToolBar *CreateToolBar(wxWindow *parent) = 0;/**
* Every plugin can place a sub menu in the ‘Plugins’ Menu at the menu bar
* \param pluginsMenu
*/
virtual void CreatePluginMenu(wxMenu *pluginsMenu) = 0;/**
* \brief Call the plugin "shutdown" function
*/
virtual void UnPlug() = 0;/**
* Override this method to allow the plugin to
* hook the popup menu by adding its entries.
* \param menu menu to hook
* \param type menu type
* \sa MenuType
*/
virtual void HookPopupMenu(wxMenu *menu, MenuType type) {
wxUnusedVar(type);
wxUnusedVar(menu);
};/**
* @brief un hook previosly hooked popup menu
* @param menu the parent of our hooked menu
* @param type the parent’s type
* @sa MenuType
*/
virtual void UnHookPopupMenu(wxMenu *menu, MenuType type) {
wxUnusedVar(type);
wxUnusedVar(menu);
};/**
* @brief load image file from /path/to/install/plugins/resources/
* @param name file name (name+extension)
* @return Bitmap of wxNullBitmap if no match was found
*/
virtual wxBitmap LoadBitmapFile(const wxString &name, wxBitmapType type = wxBITMAP_TYPE_PNG) {
wxBitmap bmp;
#ifdef __WXGTK__
wxString pluginsDir(PLUGINS_DIR, wxConvUTF8);
#else
wxString pluginsDir(m_mgr->GetInstallDirectory() + wxT( "/plugins" ));
#endif
wxString basePath(pluginsDir + wxT("/resources/"));bmp.LoadFile(basePath + name, type);
if (bmp.IsOk()) {
return bmp;
}
return wxNullBitmap;
}
};//Every dll must contain at least this function
typedef IPlugin* (*GET_PLUGIN_CREATE_FUNC)(IManager*); 这个函数指针在插件被加载时使用,cbforge.com待续…
typedef PluginInfo (*GET_PLUGIN_INFO_FUNC)();
typedef int (*GET_PLUGIN_INTERFACE_VERSION_FUNC)();
以下列表也可以看出CodeLite中当前12个插件的继承关系,皆出自IPlugin。
Abbreviation.h (codelite-1.0.2822\abbreviation):class AbbreviationPlugin : public IPlugin
Codeformatter.h (codelite-1.0.2822\codeformatter):class CodeFormatter : public IPlugin
Continuousbuild.h (codelite-1.0.2822\continuousbuild):class ContinuousBuild : public IPlugin
Copyright.h (codelite-1.0.2822\copyright):class Copyright : public IPlugin
Cscope.h (codelite-1.0.2822\cscope):class Cscope : public IPlugin
Externaltools.h (codelite-1.0.2822\externaltools):class ExternalToolsPlugin : public IPlugin
Gizmos.h (codelite-1.0.2822\gizmos):class GizmosPlugin : public IPlugin
Snipwiz.h (codelite-1.0.2822\snipwiz):class SnipWiz : public IPlugin
Subversion.h (codelite-1.0.2822\subversion):class SubversionPlugin : public IPlugin
Symbolview.h (codelite-1.0.2822\symbolview):class SymbolViewPlugin : public IPlugin
Unittestpp.h (codelite-1.0.2822\unittestcpp):class UnitTestPP : public IPlugin
Wxformbuilder.h (codelite-1.0.2822\wxformbuilder):class wxFormBuilder : public IPlugin
转载请保留出处,来源ide.cbforge.com,作者Bryan Wu.
Related posts:
- CodeLite Plugin Internal(2)-Load: 插件加载分析
- Codelite代码分析之 Singleton Pattern Template实现及应用
- CodeLite Initializaion analysis - 初始化流程分析(1)
- Code::Blocks中Plugin的实现原理
- Debugging With CodeLite - CodeLite调试简介
- CodeLite to CodeInsight task 1: Internationalization
- CodeLite代码分析之 – Create New Project流程
- CodeLite IDE介绍
- CodeLite 编译解析(with Compile log)
- wxWidget 类型转换(wxString, wxdatatime)














