Code::Blocks
SVN r11506
|
Provides scripting in Code::Blocks. More...
#include <scriptingmanager.h>
Classes | |
struct | MenuBoundScript |
struct | TrustedScriptProps |
Script trusts container struct. More... | |
Public Types | |
typedef std::map< wxString, TrustedScriptProps > | TrustedScripts |
Script trusts container struct. More... | |
Public Member Functions | |
bool | LoadScript (const wxString &filename) |
Loads a script. More... | |
bool | LoadBuffer (const wxString &buffer, const wxString &debugName=_T("CommandLine")) |
Loads a string buffer. More... | |
wxString | LoadBufferRedirectOutput (const wxString &buffer) |
Loads a string buffer and captures its output. More... | |
wxString | GetErrorString (SquirrelError *exception=nullptr, bool clearErrors=true) |
Returns an accumulated error string. More... | |
void | DisplayErrors (SquirrelError *exception=nullptr, bool clearErrors=true) |
Display error dialog. More... | |
void | InjectScriptOutput (const wxString &output) |
Injects script output. More... | |
int | Configure () |
Configure scripting in Code::Blocks. More... | |
bool | RegisterScriptPlugin (const wxString &name, const wxArrayInt &ids) |
Registers a script plugin menu IDs with the callback function. More... | |
bool | RegisterScriptMenu (const wxString &menuPath, const wxString &scriptOrFunc, bool isFunction) |
Script-bound function to register a script with a menu item. More... | |
bool | UnRegisterScriptMenu (const wxString &menuPath) |
Script-bound function to unregister a script's menu item. More... | |
bool | UnRegisterAllScriptMenus () |
Unregister all scripts' menu items. More... | |
bool | IsScriptTrusted (const wxString &script) |
Security function. More... | |
bool | IsCurrentlyRunningScriptTrusted () |
Security function. More... | |
void | TrustScript (const wxString &script, bool permanently) |
Security function to trust a script. More... | |
void | TrustCurrentlyRunningScript (bool permanently) |
Security function to trust a script. More... | |
bool | RemoveTrust (const wxString &script) |
Remove a script trust. More... | |
void | RefreshTrusts () |
Force refresh of script trusts. More... | |
const TrustedScripts & | GetTrustedScripts () |
Access the script trusts container (const). More... | |
ScriptingManager & | operator= (cb_unused const ScriptingManager &rhs) |
Private Types | |
typedef std::map< int, MenuBoundScript > | MenuIDToScript |
typedef std::set< wxString > | IncludeSet |
Private Member Functions | |
ScriptingManager (cb_unused const ScriptingManager &rhs) | |
void | OnScriptMenu (wxCommandEvent &event) |
void | OnScriptPluginMenu (wxCommandEvent &event) |
void | RegisterScriptFunctions () |
ScriptingManager () | |
~ScriptingManager () override | |
Friends | |
class | Mgr< ScriptingManager > |
Additional Inherited Members | |
Static Public Member Functions inherited from Mgr< ScriptingManager > | |
static bool | Valid () |
static ScriptingManager * | Get () |
static void | Free () |
Protected Member Functions inherited from Mgr< ScriptingManager > | |
Mgr () | |
virtual | ~Mgr () |
Provides scripting in Code::Blocks.
The scripting engine used is Squirrel (http:://www.squirrel-lang.org).
Here's an example to load and execute a script:
And here's an example to call a script function:
The templated type denotes the function's return type. Also note that the function name is not unicode (we 're not using Squirrel in unicode mode).
Definition at line 50 of file scriptingmanager.h.
struct ScriptingManager::MenuBoundScript |
Definition at line 239 of file scriptingmanager.h.
Class Members | ||
---|---|---|
bool | isFunc | |
wxString | scriptOrFunc |
struct ScriptingManager::TrustedScriptProps |
Script trusts container struct.
Definition at line 56 of file scriptingmanager.h.
Class Members | ||
---|---|---|
wxUint32 | crc | |
bool | permanent |
|
private |
Definition at line 250 of file scriptingmanager.h.
|
private |
Definition at line 244 of file scriptingmanager.h.
typedef std::map<wxString, TrustedScriptProps> ScriptingManager::TrustedScripts |
Script trusts container struct.
Definition at line 64 of file scriptingmanager.h.
|
private |
|
private |
Definition at line 88 of file scriptingmanager.cpp.
References _T, cbThrow, ScriptBindings::RegisterBindings(), ScriptsPrintFunc(), sq_setprintfunc(), and sqstd_register_stringlib().
|
overrideprivate |
Definition at line 109 of file scriptingmanager.cpp.
References _T, wxString::Format(), Manager::Get(), Manager::GetConfigManager(), wxString::insert(), m_TrustedScripts, and ConfigManager::Write().
int ScriptingManager::Configure | ( | ) |
Configure scripting in Code::Blocks.
Definition at line 268 of file scriptingmanager.cpp.
void ScriptingManager::DisplayErrors | ( | SquirrelError * | exception = nullptr , |
bool | clearErrors = true |
||
) |
Display error dialog.
Displays an error dialog containing exception info and any other script errors. Calls GetErrorString() internally. You should normally call this function inside your catch handler for SquirrelFunction<>() calls.
exception | A pointer to the exception object containing the error. Can be NULL (default). |
clearErrors | If true (default), when this function returns all accumulated error messages are cleared. |
Definition at line 245 of file scriptingmanager.cpp.
References _(), cbMessageBox(), Manager::Get(), GetErrorString(), wxString::IsEmpty(), wxDialog::ShowModal(), wxICON_ERROR, wxID_YES, wxNO_DEFAULT, and wxYES_NO.
Referenced by CompilerCommandGenerator::DoBuildScripts(), WizPageBase::GetNext(), WizPageBase::GetPrev(), ProjectOptionsDlg::IsScriptValid(), Wiz::Launch(), Wiz::OnAttach(), ScriptBindings::XrcDialog::OnButton(), WizPage::OnButton(), CodeBlocksApp::OnInit(), WizPageBase::OnPageChanged(), WizPageBase::OnPageChanging(), CodeBlocksApp::OnRun(), OnScriptMenu(), Wiz::RunCustomWizard(), Wiz::RunFilesWizard(), Wiz::RunProjectWizard(), MainFrame::RunStartupScripts(), and Wiz::RunTargetWizard().
wxString ScriptingManager::GetErrorString | ( | SquirrelError * | exception = nullptr , |
bool | clearErrors = true |
||
) |
Returns an accumulated error string.
Returns an error string for the passed exception (if any) plus any accumulated script engine errors (e.g. from failed function calls).
exception | A pointer to the exception object containing the error. Can be NULL (default). |
clearErrors | If true (default), when this function returns all accumulated error messages are cleared. |
Definition at line 232 of file scriptingmanager.cpp.
References cbC2U(), wxString::Clear(), and s_ScriptErrors.
Referenced by DisplayErrors().
const ScriptingManager::TrustedScripts & ScriptingManager::GetTrustedScripts | ( | ) |
Access the script trusts container (const).
Definition at line 419 of file scriptingmanager.cpp.
References m_TrustedScripts.
Referenced by ScriptingSettingsDlg::FillTrusts().
void ScriptingManager::InjectScriptOutput | ( | const wxString & | output | ) |
Injects script output.
This function is for advanced uses. It's used when some code sets a different print function for the scripting engine. When this happens, ScriptingManager no longer receives engine output. If you do something like that, use this function to "forward" all script output to ScriptingManager.
output | The engine's output to inject. |
Definition at line 263 of file scriptingmanager.cpp.
Referenced by ScriptConsolePrintFunc().
bool ScriptingManager::IsCurrentlyRunningScriptTrusted | ( | ) |
Security function.
Definition at line 358 of file scriptingmanager.cpp.
References IsScriptTrusted(), and m_CurrentlyRunningScriptFile.
bool ScriptingManager::IsScriptTrusted | ( | const wxString & | script | ) |
Security function.
script | The script's full filename. |
Definition at line 342 of file scriptingmanager.cpp.
References _(), _T, cbMessageBox(), wxCrc32::FromFile(), m_TrustedScripts, and wxICON_WARNING.
Referenced by IsCurrentlyRunningScriptTrusted().
bool ScriptingManager::LoadBuffer | ( | const wxString & | buffer, |
const wxString & | debugName = _T("CommandLine") |
||
) |
Loads a string buffer.
buffer | The script buffer to compile and run. |
debugName | A debug name. This will appear in any errors displayed. |
Definition at line 174 of file scriptingmanager.cpp.
References _(), _T, wxString::c_str(), cbC2U(), cbMessageBox(), cbU2C(), wxString::Clear(), F(), wxString::Format(), Manager::Get(), Manager::GetLogManager(), LogManager::LogWarning(), m_IncludeSet, UnixFilename(), wxString::wx_str(), and wxICON_ERROR.
Referenced by CompilerCommandGenerator::DoBuildScripts(), ProjectOptionsDlg::IsScriptValid(), Wiz::Launch(), LoadBufferRedirectOutput(), LoadScript(), and CodeBlocksApp::OnInit().
Loads a string buffer and captures its output.
buffer | The script buffer to compile and run. |
Definition at line 218 of file scriptingmanager.cpp.
References capture, CaptureScriptOutput(), wxString::Clear(), LoadBuffer(), ScriptsPrintFunc(), sq_setprintfunc(), and wxEmptyString.
Referenced by MacrosManager::ReplaceMacros().
bool ScriptingManager::LoadScript | ( | const wxString & | filename | ) |
Loads a script.
filename | The filename of the script to run. |
Definition at line 134 of file scriptingmanager.cpp.
References _T, cbReadFileContents(), wxString::Clear(), LogManager::DebugLog(), Manager::Get(), Manager::GetLogManager(), wxFileName::GetPath(), wxString::IsEmpty(), wxFile::IsOpened(), LoadBuffer(), ConfigManager::LocateDataFile(), m_CurrentlyRunningScriptFile, wxFile::Open(), sdScriptsGlobal, and sdScriptsUser.
Referenced by CompilerGCC::DoRunQueue(), ScriptBindings::Include(), ProjectOptionsDlg::IsScriptValid(), Wiz::OnAttach(), ScriptConsole::OnbtnLoadClick(), CodeBlocksApp::OnInit(), OnScriptMenu(), ScriptBindings::Require(), CompilerGCC::RunSingleFile(), and MainFrame::RunStartupScripts().
|
private |
Definition at line 424 of file scriptingmanager.cpp.
References _(), cbMessageBox(), cbU2C(), DisplayErrors(), Manager::Get(), Manager::GetEditorManager(), ScriptingManager::MenuBoundScript::isFunc, LoadScript(), ConfigManager::LocateDataFile(), m_MenuIDToScript, EditorManager::Open(), ScriptingManager::MenuBoundScript::scriptOrFunc, sdScriptsGlobal, sdScriptsUser, wxGetKeyState(), wxICON_ERROR, and WXK_SHIFT.
Referenced by RegisterScriptMenu().
|
private |
Definition at line 471 of file scriptingmanager.cpp.
References ScriptBindings::ScriptPluginWrapper::OnScriptMenu().
Referenced by RegisterScriptPlugin().
|
inline |
Definition at line 219 of file scriptingmanager.h.
References _T, cbThrow, and ScriptBindings::ScriptPluginWrapper::OnScriptMenu().
void ScriptingManager::RefreshTrusts | ( | ) |
Force refresh of script trusts.
Definition at line 398 of file scriptingmanager.cpp.
References _T, wxString::AfterFirst(), wxString::BeforeFirst(), ScriptingManager::TrustedScriptProps::crc, Manager::Get(), Manager::GetConfigManager(), m_TrustedScripts, ScriptingManager::TrustedScriptProps::permanent, ConfigManager::Read(), and wxString::ToULong().
|
private |
Definition at line 129 of file scriptingmanager.cpp.
bool ScriptingManager::RegisterScriptMenu | ( | const wxString & | menuPath, |
const wxString & | scriptOrFunc, | ||
bool | isFunction | ||
) |
Script-bound function to register a script with a menu item.
menuPath | The full menu path. This can be separated by slashes (/) to create submenus (e.g. "MyScripts/ASubMenu/MyItem"). If the last part of the string ("MyItem" in the example) starts with a dash (-) (e.g. "-MyItem") then a menu separator is prepended before the actual menu item. |
scriptOrFunc | The script's filename or a script's function name. |
isFunction | If true, the scriptOrFunc parameter is considered to be a script filename. If false, it is considered to be a script's function name. |
Definition at line 291 of file scriptingmanager.cpp.
References _(), wxString::c_str(), MenuItemsManager::CreateFromString(), F(), Manager::Get(), Manager::GetAppFrame(), Manager::GetAppWindow(), Manager::GetLogManager(), ScriptingManager::MenuBoundScript::isFunc, LogManager::Log(), m_AttachedToMainWindow, m_MenuIDToScript, m_MenuItemsManager, OnScriptMenu(), ScriptingManager::MenuBoundScript::scriptOrFunc, wxMenuItem::SetHelp(), wxString::wx_str(), and wxNewId().
Referenced by ScriptBindings::RegisterBindings(), and MainFrame::RunStartupScripts().
bool ScriptingManager::RegisterScriptPlugin | ( | const wxString & | name, |
const wxArrayInt & | ids | ||
) |
Registers a script plugin menu IDs with the callback function.
name | The script plugin's name. |
ids | The menu IDs to bind. |
Definition at line 273 of file scriptingmanager.cpp.
References Manager::Get(), Manager::GetAppWindow(), m_AttachedToMainWindow, and OnScriptPluginMenu().
Referenced by ScriptBindings::ScriptPluginWrapper::RegisterPlugin().
bool ScriptingManager::RemoveTrust | ( | const wxString & | script | ) |
Remove a script trust.
Definition at line 386 of file scriptingmanager.cpp.
References m_TrustedScripts.
Referenced by ScriptingSettingsDlg::OnDeleteTrust().
void ScriptingManager::TrustCurrentlyRunningScript | ( | bool | permanently | ) |
Security function to trust a script.
permanently | If true, this script will be trusted on a permanent basis. If false, it will be trusted for this session only. |
Definition at line 381 of file scriptingmanager.cpp.
References m_CurrentlyRunningScriptFile, and TrustScript().
Referenced by ScriptBindings::IOLib::SecurityAllows().
void ScriptingManager::TrustScript | ( | const wxString & | script, |
bool | permanently | ||
) |
Security function to trust a script.
script | The script's full filename. |
permanently | If true, this script will be trusted on a permanent basis. If false, it will be trusted for this session only. |
Definition at line 363 of file scriptingmanager.cpp.
References ScriptingManager::TrustedScriptProps::crc, wxCrc32::FromFile(), m_TrustedScripts, and ScriptingManager::TrustedScriptProps::permanent.
Referenced by TrustCurrentlyRunningScript().
bool ScriptingManager::UnRegisterAllScriptMenus | ( | ) |
Unregister all scripts' menu items.
Definition at line 336 of file scriptingmanager.cpp.
References MenuItemsManager::Clear(), and m_MenuItemsManager.
bool ScriptingManager::UnRegisterScriptMenu | ( | const wxString & | menuPath | ) |
Script-bound function to unregister a script's menu item.
menuPath | The full menu path to unregister. |
Definition at line 329 of file scriptingmanager.cpp.
References _T, LogManager::DebugLog(), Manager::Get(), and Manager::GetLogManager().
|
friend |
Definition at line 52 of file scriptingmanager.h.
|
private |
Definition at line 53 of file scriptingmanager.h.
|
private |
Definition at line 247 of file scriptingmanager.h.
Referenced by RegisterScriptMenu(), and RegisterScriptPlugin().
|
private |
Definition at line 248 of file scriptingmanager.h.
Referenced by IsCurrentlyRunningScriptTrusted(), LoadScript(), and TrustCurrentlyRunningScript().
|
private |
Definition at line 251 of file scriptingmanager.h.
Referenced by LoadBuffer().
|
private |
Definition at line 245 of file scriptingmanager.h.
Referenced by OnScriptMenu(), and RegisterScriptMenu().
|
private |
Definition at line 253 of file scriptingmanager.h.
Referenced by RegisterScriptMenu(), and UnRegisterAllScriptMenus().
|
private |
Definition at line 235 of file scriptingmanager.h.
Referenced by GetTrustedScripts(), IsScriptTrusted(), RefreshTrusts(), RemoveTrust(), TrustScript(), and ~ScriptingManager().