Code::Blocks  SVN r11506
pluginmanager.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3  * http://www.gnu.org/licenses/lgpl-3.0.html
4  */
5 
6 #ifndef PLUGINMANAGER_H
7 #define PLUGINMANAGER_H
8 
9 #include <vector>
10 #include <map>
11 #include <set>
12 
13 #include <wx/dynarray.h>
14 #include "globals.h" // PluginType
15 #include "settings.h"
16 #include "manager.h"
17 
18 //forward decls
19 struct PluginInfo;
20 class cbPlugin;
21 class cbCompilerPlugin;
22 class cbMimePlugin;
24 class cbProject;
25 class wxDynamicLibrary;
26 class wxMenuBar;
27 class wxMenu;
28 class CodeBlocksEvent;
29 class TiXmlDocument;
30 class FileTreeData;
31 
32 // typedefs for plugins' function pointers
33 typedef void(*PluginSDKVersionProc)(int*,int*,int*);
34 typedef cbPlugin*(*CreatePluginProc)();
35 typedef void(*FreePluginProc)(cbPlugin*);
36 
38 struct PluginInfo
39 {
49 };
50 
51 // struct with info about each pluing
53 {
54  PluginInfo info; // plugin's info struct
55  wxString fileName; // plugin's filename
56  wxDynamicLibrary* library; // plugin's library
57  FreePluginProc freeProc; // plugin's release function pointer
58  cbPlugin* plugin; // the plugin itself
59 };
60 
61 WX_DEFINE_ARRAY(PluginElement*, PluginElementsArray);
62 WX_DEFINE_ARRAY(cbPlugin*, PluginsArray);
63 WX_DEFINE_ARRAY(cbConfigurationPanel*, ConfigurationPanelsArray);
64 
76 class DLLIMPORT PluginManager : public Mgr<PluginManager>, public wxEvtHandler
77 {
78  public:
79  typedef std::vector<cbCompilerPlugin*> CompilerPlugins;
80 
81  public:
82  friend class Mgr<PluginManager>;
83  friend class Manager; // give Manager access to our private members
84  void CreateMenu(wxMenuBar* menuBar);
85  void ReleaseMenu(wxMenuBar* menuBar);
86 
87  void RegisterPlugin(const wxString& name,
88  CreatePluginProc createProc,
89  FreePluginProc freeProc,
90  PluginSDKVersionProc versionProc);
91 
92  int ScanForPlugins(const wxString& path);
93  bool LoadPlugin(const wxString& pluginName);
94  void LoadAllPlugins();
95  void UnloadAllPlugins();
96  void UnloadPlugin(cbPlugin* plugin);
97  int ExecutePlugin(const wxString& pluginName);
98 
99  bool AttachPlugin(cbPlugin* plugin, bool ignoreSafeMode = false);
100  bool DetachPlugin(cbPlugin* plugin);
101 
102  bool InstallPlugin(const wxString& pluginName, bool forAllUsers = true, bool askForConfirmation = true);
103  bool UninstallPlugin(cbPlugin* plugin, bool removeFiles = true);
104  bool ExportPlugin(cbPlugin* plugin, const wxString& filename);
105 
106  const PluginInfo* GetPluginInfo(const wxString& pluginName);
107  const PluginInfo* GetPluginInfo(cbPlugin* plugin);
108 
109  const PluginElementsArray& GetPlugins() const { return m_Plugins; }
110 
111  PluginElement* FindElementByName(const wxString& pluginName);
112  cbPlugin* FindPluginByName(const wxString& pluginName);
113  cbPlugin* FindPluginByFileName(const wxString& pluginFileName);
114 
115  const CompilerPlugins& GetCompilerPlugins() const { return m_CompilerPlugins; }
116  cbCompilerPlugin* GetFirstCompiler() const;
117 
118  PluginsArray GetToolOffers();
119  PluginsArray GetMimeOffers();
120  PluginsArray GetDebuggerOffers();
121  PluginsArray GetCodeCompletionOffers();
122  PluginsArray GetSmartIndentOffers();
123  PluginsArray GetOffersFor(PluginType type);
124 
125  void AskPluginsForModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data = nullptr);
128  void ResetModuleMenu();
136  void RegisterFindMenuItems(bool before, int count);
138  int GetFindMenuItemCount() const;
140  int GetFindMenuItemFirst() const;
143  void RegisterLastNonPluginMenuItem(int id);
151  int FindSortedMenuItemPosition(wxMenu &popup, const wxString& label) const;
152 
153  cbMimePlugin* GetMIMEHandlerForFile(const wxString& filename);
154  void GetConfigurationPanels(int group, wxWindow* parent, ConfigurationPanelsArray& arrayToFill);
155  void GetProjectConfigurationPanels(wxWindow* parent, cbProject* project, ConfigurationPanelsArray& arrayToFill);
156  int Configure();
157  void SetupLocaleDomain(const wxString& DomainName);
158 
159  void NotifyPlugins(CodeBlocksEvent& event);
160  void NotifyPlugins(CodeBlocksDockEvent& event);
161  void NotifyPlugins(CodeBlocksLayoutEvent& event);
162 
163  static void SetSafeMode(bool on){ s_SafeMode = on; }
164  static bool GetSafeMode(){ return s_SafeMode; }
165  private:
166  PluginManager();
167  ~PluginManager() override;
168 
169  void OnScriptMenu(wxCommandEvent& event);
170  void OnScriptModuleMenu(wxCommandEvent& event);
171 
173  bool ReadManifestFile(const wxString& pluginFilename,
174  const wxString& pluginName = wxEmptyString,
175  PluginInfo* infoOut = nullptr);
176  void ReadExtraFilesFromManifestFile(const wxString& pluginFilename,
177  wxArrayString& extraFiles);
178  bool ExtractFile(const wxString& bundlename,
179  const wxString& src_filename,
180  const wxString& dst_filename,
181  bool isMandatory = true);
182 
183  PluginElementsArray m_Plugins;
187 
188  // this struct fills the following vector each time
189  // RegisterPlugin() is called.
190  // this vector is then used in LoadPlugin() (which triggered
191  // the call to RegisterPlugin()) to actually
192  // load the plugins and then it is cleared.
193  //
194  // This is done to avoid global variables initialization order issues
195  // inside the plugins (yes, it happened to me ;)).
197  {
198  PluginRegistration() : createProc(nullptr), freeProc(nullptr), versionProc(nullptr) {}
200  : name(rhs.name),
201  createProc(rhs.createProc),
202  freeProc(rhs.freeProc),
203  versionProc(rhs.versionProc),
204  info(rhs.info)
205  {}
211  };
212  std::vector<PluginRegistration> m_RegisteredPlugins;
213  CompilerPlugins m_CompilerPlugins;
214 
215  int m_FindMenuItemCount = 0;
216  int m_FindMenuItemFirst = 0;
217  int m_LastNonPluginMenuId = 0;
218 
219  static bool s_SafeMode;
220 
221  DECLARE_EVENT_TABLE()
222 };
223 
224 DLLIMPORT bool cbHasRunningCompilers(const PluginManager *manager);
226 
227 #endif // PLUGINMANAGER_H
static bool GetSafeMode()
wxString authorEmail
Definition: pluginmanager.h:45
Base class for plugins.
Definition: cbplugin.h:84
wxString license
Definition: pluginmanager.h:48
wxString name
Definition: pluginmanager.h:40
wxString fileName
Definition: pluginmanager.h:55
static bool s_SafeMode
WX_DEFINE_ARRAY(PluginElement *, PluginElementsArray)
static void SetSafeMode(bool on)
Information about the plugin.
Definition: pluginmanager.h:38
wxArrayInt CreateMenu(wxMenuBar *mbar)
const PluginElementsArray & GetPlugins() const
Event used to request from the main app to add a window to the docking system.
Definition: sdk_events.h:83
FreePluginProc freeProc
Definition: pluginmanager.h:57
wxString m_CurrentlyLoadingFilename
wxString title
Definition: pluginmanager.h:41
PluginInfo info
Definition: pluginmanager.h:54
bool InstallPlugin(const wxString &pluginName, bool allUsers, bool confirm)
Definition: sc_globals.cpp:77
Base class for mime plugins.
Definition: cbplugin.h:684
std::vector< cbCompilerPlugin * > CompilerPlugins
Definition: pluginmanager.h:79
A generic Code::Blocks event.
Definition: sdk_events.h:20
Base class for compiler plugins.
Definition: cbplugin.h:263
#define DLLIMPORT
Definition: settings.h:16
PluginSDKVersionProc versionProc
CompilerPlugins m_CompilerPlugins
DLLIMPORT bool cbHasRunningCompilers(const PluginManager *manager)
PluginManager manages plugins.
Definition: pluginmanager.h:76
PluginType
Known plugin types.
Definition: globals.h:24
Represents a Code::Blocks project.
Definition: cbproject.h:96
null_pointer_t nullptr
Definition: nullptr.cpp:16
const CompilerPlugins & GetCompilerPlugins() const
ModuleType
The type of module offering a context menu.
Definition: globals.h:38
void(* FreePluginProc)(cbPlugin *)
Definition: pluginmanager.h:35
wxDynamicLibrary * m_pCurrentlyLoadingLib
cbPlugin *(* CreatePluginProc)()
Definition: pluginmanager.h:34
wxString wxEmptyString
wxDynamicLibrary * library
Definition: pluginmanager.h:56
wxString version
Definition: pluginmanager.h:42
Definition: manager.h:183
Base class for plugin configuration panels.
wxString thanksTo
Definition: pluginmanager.h:47
TiXmlDocument * m_pCurrentlyLoadingManifestDoc
int ExecutePlugin(const wxString &pluginName)
Definition: sc_globals.cpp:87
wxString authorWebsite
Definition: pluginmanager.h:46
PluginElementsArray m_Plugins
cbPlugin * plugin
Definition: pluginmanager.h:58
void(* PluginSDKVersionProc)(int *, int *, int *)
Definition: pluginmanager.h:33
SQInteger RegisterPlugin(HSQUIRRELVM v)
Definition: sc_plugin.cpp:212
std::vector< PluginRegistration > m_RegisteredPlugins
DLLIMPORT void cbStopRunningCompilers(PluginManager *manager)
Event used to request from the main app to manage the view layouts.
Definition: sdk_events.h:158
PluginRegistration(const PluginRegistration &rhs)
wxString description
Definition: pluginmanager.h:43
wxString author
Definition: pluginmanager.h:44