Code::Blocks  SVN r11506
scriptingmanager.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 SCRIPTING_H
7 #define SCRIPTING_H
8 
9 #include <map>
10 #include <set>
11 
12 #ifndef CB_PRECOMP
13  #include "cbexception.h" // cbThrow
14  #include "globals.h" // cbC2U
15 #endif
16 
17 #include "settings.h"
18 #include "manager.h"
19 #include "menuitemsmanager.h"
20 #include <wx/intl.h>
21 
22 struct SquirrelError;
23 
50 class DLLIMPORT ScriptingManager : public Mgr<ScriptingManager>, public wxEvtHandler
51 {
52  friend class Mgr<ScriptingManager>;
54  public:
57  {
58  bool permanent; // store trust in config (permanent trust)
59  wxUint32 crc; // script's contents crc32
60  };
61 
62  // script filename -> props
64  typedef std::map<wxString, TrustedScriptProps> TrustedScripts;
65 
71  bool LoadScript(const wxString& filename);
72 
79  bool LoadBuffer(const wxString& buffer, const wxString& debugName = _T("CommandLine"));
80 
86  wxString LoadBufferRedirectOutput(const wxString& buffer);
87 
97  wxString GetErrorString(SquirrelError* exception = nullptr, bool clearErrors = true);
98 
109  void DisplayErrors(SquirrelError* exception = nullptr, bool clearErrors = true);
110 
119  void InjectScriptOutput(const wxString& output);
120 
125  int Configure();
126 
133  bool RegisterScriptPlugin(const wxString& name, const wxArrayInt& ids);
134 
148  bool RegisterScriptMenu(const wxString& menuPath, const wxString& scriptOrFunc, bool isFunction);
149 
155  bool UnRegisterScriptMenu(const wxString& menuPath);
156 
161  bool UnRegisterAllScriptMenus();
162 
170  bool IsScriptTrusted(const wxString& script);
171 
178  bool IsCurrentlyRunningScriptTrusted();
179 
193  void TrustScript(const wxString& script, bool permanently);
194 
201  void TrustCurrentlyRunningScript(bool permanently);
202 
207  bool RemoveTrust(const wxString& script);
208 
210  void RefreshTrusts();
211 
216  const TrustedScripts& GetTrustedScripts();
217 
218  // needed for SqPlus bindings
219  ScriptingManager& operator=(cb_unused const ScriptingManager& rhs) // prevent assignment operator
220  {
221  cbThrow(_T("Can't assign a ScriptingManager* !!!"));
222  return *this;
223  }
224  private:
225  // needed for SqPlus bindings
226  ScriptingManager(cb_unused const ScriptingManager& rhs); // prevent copy construction
227 
228  void OnScriptMenu(wxCommandEvent& event);
229  void OnScriptPluginMenu(wxCommandEvent& event);
230  void RegisterScriptFunctions();
231 
233  ~ScriptingManager() override;
234 
235  TrustedScripts m_TrustedScripts;
236 
237  // container for script menus
238  // script menuitem_ID -> script_filename
240  {
242  bool isFunc;
243  };
244  typedef std::map<int, MenuBoundScript> MenuIDToScript;
245  MenuIDToScript m_MenuIDToScript;
246 
249 
250  typedef std::set<wxString> IncludeSet;
251  IncludeSet m_IncludeSet;
252 
254 
255  DECLARE_EVENT_TABLE()
256 };
257 
258 typedef char SQChar; // HACK, MUST match with the type as defined for the dedicated platform in squirrel.h
259 void PrintSquirrelToWxString(wxString& msg, const SQChar* s, va_list& vl);
260 
261 #endif // SCRIPTING_H
wxString m_CurrentlyRunningScriptFile
std::map< int, MenuBoundScript > MenuIDToScript
void PrintSquirrelToWxString(wxString &msg, const SQChar *s, va_list &vl)
#define _T(string)
IncludeSet m_IncludeSet
wxCriticalSection cs
MenuItemsManager m_MenuItemsManager
std::map< wxString, TrustedScriptProps > TrustedScripts
Script trusts container struct.
#define DLLIMPORT
Definition: settings.h:16
ScriptingManager & operator=(cb_unused const ScriptingManager &rhs)
std::set< wxString > IncludeSet
Manager for wxMenuItem pointers.
unsigned int wxUint32
Definition: manager.h:183
#define cbThrow(message)
Definition: cbexception.h:42
wxArray< int > wxArrayInt
MenuIDToScript m_MenuIDToScript
Provides scripting in Code::Blocks.
char SQChar
Script trusts container struct.
TrustedScripts m_TrustedScripts