diff --git a/runtime/native/win32/ti_shell/src/ti_native.cc b/runtime/native/win32/ti_shell/src/ti_native.cc index d0b2105e..bbc0e3c7 100755 --- a/runtime/native/win32/ti_shell/src/ti_native.cc +++ b/runtime/native/win32/ti_shell/src/ti_native.cc @@ -1,17 +1,22 @@ #include "ti_native.h" #include "ti_web_shell.h" +#include +#include + TiNative::TiNative (TIWebShell *ti_web_shell) { this->ti_web_shell = ti_web_shell; BindMethod("debug", &TiNative::debug); BindMethod("getResourcePath", &TiNative::getResourcePath); + BindMethod("include", &TiNative::include); } void TiNative::debug (const CppArgumentList &args, CppVariant *result) { - printf("[titanium:debug]: %s\n", args[0].ToString().c_str()); + if (args.size() > 0) + printf("[titanium:debug]: %s\n", args[0].ToString().c_str()); } void TiNative::getResourcePath(const CppArgumentList &args, CppVariant *result) @@ -19,4 +24,23 @@ void TiNative::getResourcePath(const CppArgumentList &args, CppVariant *result) std::wstring resourcePath = ti_web_shell->getResourcesPath(); result->Set(WideToUTF8(resourcePath)); +} + +void TiNative::include(const CppArgumentList &args, CppVariant *result) +{ + if (args.size() > 0) { + std::string relativeName = args[0].ToString(); + std::string relativePath = WideToUTF8(ti_web_shell->getResourcesPath()); + relativePath += "\\"; + relativePath += relativeName; + + std::ifstream in(relativePath.c_str()); + std::string s, line; + while(getline(in, line)) { + s += line + "\n"; + } + + WebView *webview = ti_web_shell->getHost()->webview(); + webview->GetMainFrame()->ExecuteJavaScript(s, relativePath); + } } \ No newline at end of file diff --git a/runtime/native/win32/ti_shell/src/ti_native.h b/runtime/native/win32/ti_shell/src/ti_native.h index e8474b61..573a5ae4 100755 --- a/runtime/native/win32/ti_shell/src/ti_native.h +++ b/runtime/native/win32/ti_shell/src/ti_native.h @@ -2,6 +2,7 @@ #define TI_NATIVE_H_ #include "webkit/glue/cpp_bound_class.h" +#include "webkit/glue/webview.h" class TIWebShell; @@ -13,6 +14,7 @@ class TiNative : public CppBoundClass void debug (const CppArgumentList &args, CppVariant *result); void getResourcePath(const CppArgumentList &args, CppVariant *result); + void include (const CppArgumentList &args, CppVariant *result); }; #endif \ No newline at end of file