Index: ps/trunk/binaries/data/mods/_test.gui/gui/hotkey.js
===================================================================
--- ps/trunk/binaries/data/mods/_test.gui/gui/hotkey.js
+++ ps/trunk/binaries/data/mods/_test.gui/gui/hotkey.js
@@ -1,14 +0,0 @@
-var state_before;
-var state_after;
-
-function handleInputBeforeGui(ev) {
- if ((ev.type == "hotkeydown" || ev.type == "hotkeyup") && ev.hotkey == "test")
- state_before = Engine.HotkeyIsPressed("test");
- return false;
-}
-
-function handleInputAfterGui(ev) {
- if ((ev.type == "hotkeydown" || ev.type == "hotkeyup") && ev.hotkey == "test")
- state_after = Engine.HotkeyIsPressed("test");
- return false;
-}
Index: ps/trunk/binaries/data/mods/_test.gui/gui/hotkey.xml
===================================================================
--- ps/trunk/binaries/data/mods/_test.gui/gui/hotkey.xml
+++ ps/trunk/binaries/data/mods/_test.gui/gui/hotkey.xml
@@ -1,4 +0,0 @@
-
-
-
-
Index: ps/trunk/binaries/data/mods/_test.gui/gui/hotkey/hotkey.js
===================================================================
--- ps/trunk/binaries/data/mods/_test.gui/gui/hotkey/hotkey.js
+++ ps/trunk/binaries/data/mods/_test.gui/gui/hotkey/hotkey.js
@@ -0,0 +1,14 @@
+var state_before;
+var state_after;
+
+function handleInputBeforeGui(ev) {
+ if ((ev.type == "hotkeydown" || ev.type == "hotkeyup") && ev.hotkey == "test")
+ state_before = Engine.HotkeyIsPressed("test");
+ return false;
+}
+
+function handleInputAfterGui(ev) {
+ if ((ev.type == "hotkeydown" || ev.type == "hotkeyup") && ev.hotkey == "test")
+ state_after = Engine.HotkeyIsPressed("test");
+ return false;
+}
Index: ps/trunk/binaries/data/mods/_test.gui/gui/hotkey/hotkey.xml
===================================================================
--- ps/trunk/binaries/data/mods/_test.gui/gui/hotkey/hotkey.xml
+++ ps/trunk/binaries/data/mods/_test.gui/gui/hotkey/hotkey.xml
@@ -0,0 +1,4 @@
+
+
+
+
Index: ps/trunk/binaries/data/mods/_test.gui/gui/hotkey/page_hotkey.xml
===================================================================
--- ps/trunk/binaries/data/mods/_test.gui/gui/hotkey/page_hotkey.xml
+++ ps/trunk/binaries/data/mods/_test.gui/gui/hotkey/page_hotkey.xml
@@ -0,0 +1,4 @@
+
+
+ hotkey.xml
+
Index: ps/trunk/binaries/data/mods/_test.gui/gui/page_hotkey.xml
===================================================================
--- ps/trunk/binaries/data/mods/_test.gui/gui/page_hotkey.xml
+++ ps/trunk/binaries/data/mods/_test.gui/gui/page_hotkey.xml
@@ -1,4 +0,0 @@
-
-
- hotkey.xml
-
Index: ps/trunk/source/gui/CGUI.cpp
===================================================================
--- ps/trunk/source/gui/CGUI.cpp
+++ ps/trunk/source/gui/CGUI.cpp
@@ -73,7 +73,6 @@
if (m_GlobalHotkeys.count(hotkey) && ev->ev.type == SDL_HOTKEYDOWN)
{
- HotkeyInputHandler(ev);
ret = IN_HANDLED;
JSContext* cx = m_ScriptInterface->GetContext();
Index: ps/trunk/source/gui/tests/test_GuiManager.h
===================================================================
--- ps/trunk/source/gui/tests/test_GuiManager.h
+++ ps/trunk/source/gui/tests/test_GuiManager.h
@@ -55,17 +55,20 @@
void test_hotkeysState()
{
-
// Load up a fake test hotkey when pressing 'a'.
const char* test_hotkey_name = "hotkey.test";
g_ConfigDB.SetValueString(CFG_USER, test_hotkey_name, "A");
LoadHotkeys();
// Load up a test page.
- JS::RootedValue val(g_GUI->GetScriptInterface()->GetContext());
- g_GUI->GetScriptInterface()->Eval("({})", &val);
- std::shared_ptr data = g_GUI->GetScriptInterface()->WriteStructuredClone(JS::NullHandleValue);
- g_GUI->PushPage(L"page_hotkey.xml", data, JS::UndefinedHandleValue);
+ const ScriptInterface& scriptInterface = *(g_GUI->GetScriptInterface());
+ JSContext* cx = scriptInterface.GetContext();
+ JSAutoRequest rq(cx);
+ JS::RootedValue val(cx);
+ scriptInterface.CreateObject(cx, &val);
+
+ std::shared_ptr data = scriptInterface.WriteStructuredClone(JS::NullHandleValue);
+ g_GUI->PushPage(L"hotkey/page_hotkey.xml", data, JS::UndefinedHandleValue);
// Press 'a'.
SDL_Event_ hotkeyNotification;
@@ -79,16 +82,22 @@
while (in_poll_event(&ev))
in_dispatch_event(&ev);
+ const ScriptInterface& pageScriptInterface = *(g_GUI->GetActiveGUI()->GetScriptInterface());
+ JSContext* pcx = pageScriptInterface.GetContext();
+ JSAutoRequest pagerq(pcx);
+ JS::RootedValue global(pcx, pageScriptInterface.GetGlobalObject());
+
// Ensure that our hotkey state was synchronised with the event itself.
bool hotkey_pressed_value = false;
- JS::RootedValue js_hotkey_pressed_value(g_GUI->GetActiveGUI()->GetScriptInterface()->GetContext());
- g_GUI->GetActiveGUI()->GetScriptInterface()->Eval("state_before", &js_hotkey_pressed_value);
- g_GUI->GetActiveGUI()->GetScriptInterface()->FromJSVal(g_GUI->GetActiveGUI()->GetScriptInterface()->GetContext(), js_hotkey_pressed_value, hotkey_pressed_value);
+ JS::RootedValue js_hotkey_pressed_value(pageScriptInterface.GetContext());
+
+ pageScriptInterface.GetProperty(global, "state_before", &js_hotkey_pressed_value);
+ ScriptInterface::FromJSVal(pcx, js_hotkey_pressed_value, hotkey_pressed_value);
TS_ASSERT_EQUALS(hotkey_pressed_value, true);
hotkey_pressed_value = false;
- g_GUI->GetActiveGUI()->GetScriptInterface()->Eval("state_after", &js_hotkey_pressed_value);
- g_GUI->GetActiveGUI()->GetScriptInterface()->FromJSVal(g_GUI->GetActiveGUI()->GetScriptInterface()->GetContext(), js_hotkey_pressed_value, hotkey_pressed_value);
+ pageScriptInterface.GetProperty(global, "state_after", &js_hotkey_pressed_value);
+ ScriptInterface::FromJSVal(pcx, js_hotkey_pressed_value, hotkey_pressed_value);
TS_ASSERT_EQUALS(hotkey_pressed_value, true);
hotkeyNotification.ev.type = SDL_KEYUP;
@@ -97,13 +106,13 @@
in_dispatch_event(&ev);
hotkey_pressed_value = true;
- g_GUI->GetActiveGUI()->GetScriptInterface()->Eval("state_before", &js_hotkey_pressed_value);
- g_GUI->GetActiveGUI()->GetScriptInterface()->FromJSVal(g_GUI->GetActiveGUI()->GetScriptInterface()->GetContext(), js_hotkey_pressed_value, hotkey_pressed_value);
+ pageScriptInterface.GetProperty(global, "state_before", &js_hotkey_pressed_value);
+ ScriptInterface::FromJSVal(pcx, js_hotkey_pressed_value, hotkey_pressed_value);
TS_ASSERT_EQUALS(hotkey_pressed_value, false);
hotkey_pressed_value = true;
- g_GUI->GetActiveGUI()->GetScriptInterface()->Eval("state_after", &js_hotkey_pressed_value);
- g_GUI->GetActiveGUI()->GetScriptInterface()->FromJSVal(g_GUI->GetActiveGUI()->GetScriptInterface()->GetContext(), js_hotkey_pressed_value, hotkey_pressed_value);
+ pageScriptInterface.GetProperty(global, "state_after", &js_hotkey_pressed_value);
+ ScriptInterface::FromJSVal(pcx, js_hotkey_pressed_value, hotkey_pressed_value);
TS_ASSERT_EQUALS(hotkey_pressed_value, false);
}