1 #include <sstream>
2
3 using namespace std;
4
5 #include "ADM_jsIf.h"
6 #include "SpiderMonkeyEngine.h"
7 #include "DIA_coreToolkit.h"
8
dump(SpiderMonkeyEngine * engine,JSFunctionSpec * f)9 static void dump(SpiderMonkeyEngine *engine, JSFunctionSpec *f)
10 {
11 while (f->name)
12 {
13 stringstream stream;
14
15 stream << " " << f->name;
16
17 engine->callEventHandlers(IScriptEngine::Information, NULL, -1, stream.str().c_str());
18 f++;
19 }
20 }
21
jsHelp(JSContext * cx,const char * s)22 void jsHelp(JSContext *cx, const char *s)
23 {
24 SpiderMonkeyEngine *engine = (SpiderMonkeyEngine*)JS_GetContextPrivate(cx);
25 int n = engine->jsHooks.size();
26
27 if (!s)
28 {
29 goto none;
30 }
31
32 for (int i = 0; i < n; i++)
33 {
34 if (!strcasecmp(s, engine->jsHooks[i].name))
35 {
36 const char *t = engine->jsHooks[i].text;
37
38 if(t)
39 {
40 engine->callEventHandlers(IScriptEngine::Information, NULL, -1, t);
41 }
42
43 dump(engine, engine->jsHooks[i].jsFunctions);
44 }
45 }
46
47 none:
48 engine->callEventHandlers(IScriptEngine::Information, NULL, -1, "please use help(\"xxx\") with xx among");
49
50 for (int i = 0; i < n; i++)
51 {
52 stringstream stream;
53
54 stream << " " << engine->jsHooks[i].name;
55
56 engine->callEventHandlers(IScriptEngine::Information, NULL, -1, stream.str().c_str());
57 }
58 }
59
jsPrint(JSContext * cx,const char * s)60 void jsPrint(JSContext *cx, const char *s)
61 {
62 SpiderMonkeyEngine *engine = (SpiderMonkeyEngine*)JS_GetContextPrivate(cx);
63
64 engine->callEventHandlers(IScriptEngine::Information, NULL, -1, s);
65 }
66
jsPopupError(const char * s)67 void jsPopupError(const char *s)
68 {// begin displayError
69
70 GUI_Verbose();
71 GUI_Error_HIG("Error",s);
72 GUI_Quiet();
73
74 }// end displayError
75 /**
76 \fn displayInfo
77 \brief info popup
78 */
79
jsPopupInfo(const char * s)80 void jsPopupInfo(const char *s)
81 {// begin displayInfo
82
83 GUI_Verbose();
84 GUI_Info_HIG(ADM_LOG_IMPORTANT,"Info",s);
85 GUI_Quiet();
86
87 }// end displayInfo
88