CodeLite Plugin Internal(1) – IPlugin interface

icosahedronFeather 所有的CodeLite插件都以动态库的形式(.dll or .so)保存在/plugins下,通过程序初始化时调用Frame::LoadPlugins加载[CodeLite的初始化分析在另外一篇文章中已有详述,请在ide.cbforge.com站内参阅]。插件相关的配置保存在/config/plugins.xml文件。文件为XML格式,每一插件项都保存有以下几项:SerializedObject Name, Name,Author,Description and Version。关于插件的实现我们会分几篇文章分析,这个第一篇主要关注接口的实现。

is the interface that defines a for CodeLite. Each must implement the pure virtual methods of this interface. The gains access to CodeLite data by using the m_mgr member.

通过阅读相关代码和以下的定义,可以知道 1)每一个插件必须继承自这个接口并实现相关纯虚函数,每个插件也可以实现自己的菜单、工具条等;2)插件和CodeLite打交道的唯一桥梁是m_mgr,这个IManager有很多的方式可以获得系统资源,比如其中包括获得当前被激活的editor等。

 

class : public wxEvtHandler
{
protected:
    wxString m_shortName;
    wxString m_longName;
    IManager *m_mgr;

public:
    (IManager *manager) : m_mgr(manager) {}
    virtual ~() {}

    //———————————————–
    //The interface
    //———————————————–
    /**
     * @brief return the ’s short name
     * @return
     */
    virtual const wxString &GetShortName() const {
        return m_shortName;
    }
    /**
     * @brief return the ’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 , the 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 can place a sub menu in the ‘Plugins’ Menu at the menu bar
     * \param pluginsMenu
     */
    virtual void CreatePluginMenu(wxMenu *pluginsMenu) = 0;

    /**
     * \brief Call the "shutdown" function
     */
    virtual void UnPlug() = 0;

    /**
     * Override this method to allow the 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 * (*GET_PLUGIN_CREATE_FUNC)(IManager*); 这个函数指针在插件被加载时使用,cbforge.com待续…
typedef PluginInfo (*GET_PLUGIN_INFO_FUNC)();
typedef int (*GET_PLUGIN_INTERFACE_VERSION_FUNC)();

以下列表也可以看出CodeLite中当前12个插件的继承关系,皆出自

Abbreviation.h (codelite-1.0.2822\abbreviation):class AbbreviationPlugin : public
Codeformatter.h (codelite-1.0.2822\codeformatter):class CodeFormatter : public
Continuousbuild.h (codelite-1.0.2822\continuousbuild):class ContinuousBuild : public
Copyright.h (codelite-1.0.2822\copyright):class Copyright : public
Cscope.h (codelite-1.0.2822\cscope):class Cscope : public
Externaltools.h (codelite-1.0.2822\externaltools):class ExternalToolsPlugin : public
Gizmos.h (codelite-1.0.2822\gizmos):class GizmosPlugin : public
Snipwiz.h (codelite-1.0.2822\snipwiz):class SnipWiz : public
Subversion.h (codelite-1.0.2822\subversion):class SubversionPlugin : public
Symbolview.h (codelite-1.0.2822\symbolview):class SymbolViewPlugin : public
Unittestpp.h (codelite-1.0.2822\unittestcpp):class UnitTestPP : public
Wxformbuilder.h (codelite-1.0.2822\wxformbuilder):class wxFormBuilder : public

转载请保留出处,来源ide.cbforge.com,作者Bryan Wu.

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis

Related posts:

  1. CodeLite Plugin Internal(2)-Load: 插件加载分析
  2. Codelite代码分析之 Singleton Pattern Template实现及应用
  3. CodeLite Initializaion analysis - 初始化流程分析(1)
  4. Code::Blocks中Plugin的实现原理
  5. Debugging With CodeLite - CodeLite调试简介
  6. CodeLite to CodeInsight task 1: Internationalization
  7. CodeLite代码分析之 – Create New Project流程
  8. CodeLite IDE介绍
  9. CodeLite 编译解析(with Compile log)
  10. wxWidget 类型转换(wxString, wxdatatime)

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Contact us

Admin: Bryan Wu