~registry/codeblocks/trunk

« back to all changes in this revision

Viewing changes to src/sdk/pluginmanager.h

  • Committer: mandrav
  • Date: 2007-02-12 14:55:28 UTC
  • Revision ID: svn-v4:98b59c6a-2706-0410-b7d6-d2fa1a1880c9:trunk:3594
* First part of directories layout re-organization: moved all sdk header files to a new dir named "include".

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef PLUGINMANAGER_H
2
 
#define PLUGINMANAGER_H
3
 
 
4
 
#include <vector>
5
 
#include <map>
6
 
 
7
 
#include <wx/dynarray.h>
8
 
#include "globals.h" // PluginType
9
 
#include "settings.h"
10
 
#include "manager.h"
11
 
 
12
 
//forward decls
13
 
struct PluginInfo;
14
 
class cbPlugin;
15
 
class cbMimePlugin;
16
 
class cbConfigurationPanel;
17
 
class cbProject;
18
 
class wxDynamicLibrary;
19
 
class wxMenuBar;
20
 
class wxMenu;
21
 
class CodeBlocksEvent;
22
 
class TiXmlDocument;
23
 
class FileTreeData;
24
 
 
25
 
// typedefs for plugins' function pointers
26
 
typedef void(*PluginSDKVersionProc)(int*,int*,int*);
27
 
typedef cbPlugin*(*CreatePluginProc)();
28
 
typedef void(*FreePluginProc)(cbPlugin*);
29
 
 
30
 
/** Information about the plugin */
31
 
struct PluginInfo
32
 
{
33
 
    wxString name;
34
 
    wxString title;
35
 
    wxString version;
36
 
    wxString description;
37
 
    wxString author;
38
 
    wxString authorEmail;
39
 
    wxString authorWebsite;
40
 
    wxString thanksTo;
41
 
    wxString license;
42
 
};
43
 
 
44
 
// struct with info about each pluing
45
 
struct PluginElement
46
 
{
47
 
    PluginInfo info; // plugin's info struct
48
 
    wxString fileName; // plugin's filename
49
 
    wxDynamicLibrary* library; // plugin's library
50
 
    FreePluginProc freeProc; // plugin's release function pointer
51
 
    cbPlugin* plugin; // the plugin itself
52
 
};
53
 
 
54
 
WX_DEFINE_ARRAY(PluginElement*, PluginElementsArray);
55
 
WX_DEFINE_ARRAY(cbPlugin*, PluginsArray);
56
 
WX_DEFINE_ARRAY(cbConfigurationPanel*, ConfigurationPanelsArray);
57
 
 
58
 
/**
59
 
 * PluginManager manages plugins.
60
 
 *
61
 
 * There are two plugin types: binary and scripted.
62
 
 *
63
 
 * Binary plugins are dynamically loaded shared libraries (dll/so) which
64
 
 * can do pretty much anything with the SDK.
65
 
 *
66
 
 * Script plugins are more lightweight and are very convenient for
67
 
 * smaller scale/functionality plugins.
68
 
 */
69
 
class DLLIMPORT PluginManager : public Mgr<PluginManager>, public wxEvtHandler
70
 
{
71
 
    public:
72
 
        friend class Mgr<PluginManager>;
73
 
        friend class Manager; // give Manager access to our private members
74
 
        void CreateMenu(wxMenuBar* menuBar);
75
 
        void ReleaseMenu(wxMenuBar* menuBar);
76
 
 
77
 
        void RegisterPlugin(const wxString& name,
78
 
                            CreatePluginProc createProc,
79
 
                            FreePluginProc freeProc,
80
 
                            PluginSDKVersionProc versionProc);
81
 
 
82
 
        int ScanForPlugins(const wxString& path);
83
 
        bool LoadPlugin(const wxString& pluginName);
84
 
        void LoadAllPlugins();
85
 
        void UnloadAllPlugins();
86
 
        void UnloadPlugin(cbPlugin* plugin);
87
 
        int ExecutePlugin(const wxString& pluginName);
88
 
        int ConfigurePlugin(const wxString& pluginName);
89
 
 
90
 
        bool AttachPlugin(cbPlugin* plugin);
91
 
        bool DetachPlugin(cbPlugin* plugin);
92
 
 
93
 
        bool InstallPlugin(const wxString& pluginName, bool forAllUsers = true, bool askForConfirmation = true);
94
 
        bool UninstallPlugin(cbPlugin* plugin, bool removeFiles = true);
95
 
        bool ExportPlugin(cbPlugin* plugin, const wxString& filename);
96
 
 
97
 
        const PluginInfo* GetPluginInfo(const wxString& pluginName);
98
 
        const PluginInfo* GetPluginInfo(cbPlugin* plugin);
99
 
 
100
 
        PluginElementsArray& GetPlugins(){ return m_Plugins; }
101
 
 
102
 
        PluginElement* FindElementByName(const wxString& pluginName);
103
 
        cbPlugin* FindPluginByName(const wxString& pluginName);
104
 
        cbPlugin* FindPluginByFileName(const wxString& pluginFileName);
105
 
 
106
 
        PluginsArray GetToolOffers();
107
 
        PluginsArray GetMimeOffers();
108
 
        PluginsArray GetCompilerOffers();
109
 
        PluginsArray GetDebuggerOffers();
110
 
        PluginsArray GetCodeCompletionOffers();
111
 
        PluginsArray GetOffersFor(PluginType type);
112
 
        void AskPluginsForModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data = 0);
113
 
        void NotifyPlugins(CodeBlocksEvent& event);
114
 
        cbMimePlugin* GetMIMEHandlerForFile(const wxString& filename);
115
 
        void GetConfigurationPanels(int group, wxWindow* parent, ConfigurationPanelsArray& arrayToFill);
116
 
        void GetProjectConfigurationPanels(wxWindow* parent, cbProject* project, ConfigurationPanelsArray& arrayToFill);
117
 
        int Configure();
118
 
        void SetupLocaleDomain(const wxString& DomainName);
119
 
    private:
120
 
        PluginManager();
121
 
        ~PluginManager();
122
 
 
123
 
                void OnScriptMenu(wxCommandEvent& event);
124
 
                void OnScriptModuleMenu(wxCommandEvent& event);
125
 
 
126
 
        /// @return True if the plugin should be loaded, false if not.
127
 
        bool ReadManifestFile(const wxString& pluginFilename,
128
 
                                const wxString& pluginName = wxEmptyString,
129
 
                                PluginInfo* infoOut = 0);
130
 
        bool ExtractFile(const wxString& bundlename,
131
 
                        const wxString& src_filename,
132
 
                        const wxString& dst_filename);
133
 
 
134
 
        PluginElementsArray m_Plugins;
135
 
        wxString m_CurrentlyLoadingFilename;
136
 
        wxDynamicLibrary* m_pCurrentlyLoadingLib;
137
 
        TiXmlDocument* m_pCurrentlyLoadingManifestDoc;
138
 
 
139
 
        // this struct fills the following vector each time
140
 
        // RegisterPlugin() is called.
141
 
        // this vector is then used in LoadPlugin() (which triggered
142
 
        // the call to RegisterPlugin()) to actually
143
 
        // load the plugins and then it is cleared.
144
 
        //
145
 
        // This is done to avoid global variables initialization order issues
146
 
        // inside the plugins (yes, it happened to me ;)).
147
 
        struct PluginRegistration
148
 
        {
149
 
            PluginRegistration() : createProc(0), freeProc(0), versionProc(0) {}
150
 
            PluginRegistration(const PluginRegistration& rhs)
151
 
                : name(rhs.name),
152
 
                createProc(rhs.createProc),
153
 
                freeProc(rhs.freeProc),
154
 
                versionProc(rhs.versionProc),
155
 
                info(rhs.info)
156
 
            {}
157
 
            wxString name;
158
 
            CreatePluginProc createProc;
159
 
            FreePluginProc freeProc;
160
 
            PluginSDKVersionProc versionProc;
161
 
            PluginInfo info;
162
 
        };
163
 
        std::vector<PluginRegistration> m_RegisteredPlugins;
164
 
 
165
 
                DECLARE_EVENT_TABLE()
166
 
};
167
 
 
168
 
#endif // PLUGINMANAGER_H