19 namespace ScriptPluginWrapper {
46 ScriptPlugins::iterator it = s_ScriptPlugins.find(name);
47 if (it == s_ScriptPlugins.end())
49 SquirrelObject& o = it->second;
51 ScriptPluginsMenus::iterator itm = s_ScriptPluginsMenus.find(name);
52 if (itm == s_ScriptPluginsMenus.end())
54 itm = s_ScriptPluginsMenus.insert(s_ScriptPluginsMenus.end(), std::make_pair(name,
MenuItemsManager(
false)));
58 SqPlus::SquirrelFunction<wxArrayString&> f(o,
"GetMenu");
67 catch (SquirrelError e)
75 for (
size_t i = 0; i < arr.
GetCount(); ++i)
83 callback.
object = it->second;
86 ModuleMenuCallbacks::iterator mmcIt = s_MenuCallbacks.find(
id);
87 if (mmcIt == s_MenuCallbacks.end())
88 s_MenuCallbacks.insert(s_MenuCallbacks.end(), std::make_pair(
id, callback));
91 s_MenuCallbacks.erase(mmcIt);
92 s_MenuCallbacks.insert(s_MenuCallbacks.end(), std::make_pair(
id, callback));
108 ScriptPlugins::iterator it;
109 for (it = s_ScriptPlugins.begin(); it != s_ScriptPlugins.end(); ++it)
111 SquirrelObject& o = it->second;
112 SqPlus::SquirrelFunction<wxArrayString&> f(o,
"GetModuleMenu");
121 catch (SquirrelError e)
134 callback.
object = it->second;
136 s_MenuCallbacks.insert(s_MenuCallbacks.end(), std::make_pair(
id, callback));
141 for (
size_t i = 0; i < arr.
GetCount(); ++i)
149 callback.
object = it->second;
151 s_MenuCallbacks.insert(s_MenuCallbacks.end(), std::make_pair(
id, callback));
153 menu->
Append(-1, it->first, sub);
164 ModuleMenuCallbacks::iterator it;
165 it = s_MenuCallbacks.find(
id);
166 if (it != s_MenuCallbacks.end())
169 SqPlus::SquirrelFunction<void> f(callback.
object,
"OnMenuClicked");
170 if (!f.func.IsNull())
176 catch (SquirrelError e)
189 ModuleMenuCallbacks::iterator it;
190 it = s_MenuCallbacks.find(
id);
191 if (it != s_MenuCallbacks.end())
194 SqPlus::SquirrelFunction<void> f(callback.
object,
"OnModuleMenuClicked");
195 if (!f.func.IsNull())
201 catch (SquirrelError e)
216 o.AttachToStackObject(2);
219 if (!o.Exists(
"GetPluginInfo"))
223 SqPlus::SquirrelFunction<PluginInfo&> f(o,
"GetPluginInfo");
228 ScriptPlugins::iterator it = s_ScriptPlugins.
find(s);
229 if (it != s_ScriptPlugins.end())
232 s_ScriptPlugins.erase(it);
237 it = s_ScriptPlugins.insert(s_ScriptPlugins.end(), std::make_pair(s, o));
254 const wxString& name = *SqPlus::GetInstance<wxString,false>(v, 2);
257 ScriptPlugins::iterator it = s_ScriptPlugins.
find(name);
258 if (it != s_ScriptPlugins.end())
261 return sa.Return(it->second);
274 ScriptPlugins::iterator it = s_ScriptPlugins.find(name);
275 if (it != s_ScriptPlugins.end())
278 SquirrelObject& o = it->second;
279 SqPlus::SquirrelFunction<int> f(o,
"Execute");
280 if (!f.func.IsNull())
286 catch (SquirrelError e)
299 "class cbScriptPlugin\n" 301 " info = PluginInfo();\n" 304 " info.name = _T(\"cbScriptPlugin\");\n" 305 " info.title = _T(\"Base script plugin\");\n" 306 " info.version = _T(\"0.1a\");\n" 307 " info.license = _T(\"GPL\");\n" 309 " function GetPluginInfo()\n" 313 " function GetMenu()\n" 315 " return wxArrayString();\n" 317 " function GetModuleMenu(who,data)\n" 319 " return wxArrayString();\n" 321 " function Execute()\n" 323 " LogDebug(info.name + _T(\"::Run() : not implemented\"));\n" 326 " function OnMenuClicked(index)\n" 328 " LogDebug(info.name + _T(\": menu clicked: \") + index);\n" 330 " function OnModuleMenuClicked(index)\n" 332 " LogDebug(info.name + _T(\": module menu clicked: \") + index);\n" 352 SQPRINTFUNCTION oldPrintFunc =
sq_getprintfunc(SquirrelVM::GetVMPtr());
356 SquirrelObject script;
359 script = SquirrelVM::CompileBuffer(s_cbScriptPlugin,
"cbScriptPlugin");
360 SquirrelVM::RunScript(script);
362 catch (SquirrelError e)
ScriptPlugins s_ScriptPlugins
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
SQInteger GetPlugin(HSQUIRRELVM v)
Information about the plugin.
std::map< wxString, SquirrelObject > ScriptPlugins
SQRESULT sq_throwerror(HSQUIRRELVM v, const SQChar *err)
int ExecutePlugin(const wxString &name)
const char * s_cbScriptPlugin
size_t find(const wxString &str, size_t nStart=0) const
ModuleType
The type of module offering a context menu.
DLLIMPORT wxString cbC2U(const char *str)
Return str as a proper unicode-compatible string.
SQPRINTFUNCTION sq_getprintfunc(HSQUIRRELVM v)
LogManager * GetLogManager() const
const wxString & _(const wxString &string)
wxArray< int > wxArrayInt
void Log(const wxString &msg, int i=app_log, Logger::level lv=Logger::info)
void sq_setprintfunc(HSQUIRRELVM v, SQPRINTFUNCTION printfunc)
bool RegisterScriptPlugin(const wxString &name, const wxArrayInt &ids)
Registers a script plugin menu IDs with the callback function.
void Register_ScriptPlugin()
ScriptingManager * GetScriptingManager() const
SQInteger RegisterPlugin(HSQUIRRELVM v)
static wxString Format(const wxString &format,...)
DLLIMPORT int cbMessageBox(const wxString &message, const wxString &caption=wxEmptyString, int style=wxOK, wxWindow *parent=NULL, int x=-1, int y=-1)
wxMessageBox wrapper.