Skip to content

Commit

Permalink
implemented TiNative::include..
Browse files Browse the repository at this point in the history
  • Loading branch information
marshall committed Nov 12, 2008
1 parent 3dddbf0 commit daa75a1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 25 additions & 1 deletion runtime/native/win32/ti_shell/src/ti_native.cc
@@ -1,22 +1,46 @@
#include "ti_native.h"
#include "ti_web_shell.h"

#include <string>
#include <fstream>

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)
{
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);
}
}
2 changes: 2 additions & 0 deletions runtime/native/win32/ti_shell/src/ti_native.h
Expand Up @@ -2,6 +2,7 @@
#define TI_NATIVE_H_

#include "webkit/glue/cpp_bound_class.h"
#include "webkit/glue/webview.h"

class TIWebShell;

Expand All @@ -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

0 comments on commit daa75a1

Please sign in to comment.