Browse files

Merge pull request #42 from linearray/master

Improved FBControl.htm and default API a bit.
  • Loading branch information...
2 parents fc4d029 + 7fc0f17 commit 39910170a969f5ed906c8a4e4d89d51e29e4533a @taxilian taxilian committed Feb 7, 2012
Showing with 64 additions and 58 deletions.
  1. +11 −44 fbgen/src/TemplateAPI.cpp
  2. +39 −5 fbgen/src/TemplateAPI.h
  3. +14 −9 gen_templates/FBControl.htm
View
55 fbgen/src/TemplateAPI.cpp
@@ -12,41 +12,18 @@
#include "@{PLUGIN_ident}API.h"
///////////////////////////////////////////////////////////////////////////////
-/// @@fn @{PLUGIN_ident}API::@{PLUGIN_ident}API(const @{PLUGIN_ident}Ptr& plugin, const FB::BrowserHostPtr host)
+/// @@fn FB::variant @{PLUGIN_ident}API::echo(const FB::variant& msg)
///
-/// @@brief Constructor for your JSAPI object. You should register your methods, properties, and events
-/// that should be accessible to Javascript from here.
-///
-/// @@see FB::JSAPIAuto::registerMethod
-/// @@see FB::JSAPIAuto::registerProperty
-/// @@see FB::JSAPIAuto::registerEvent
+/// @@brief Echos whatever is passed from Javascript.
+/// Go ahead and change it. See what happens!
///////////////////////////////////////////////////////////////////////////////
-@{PLUGIN_ident}API::@{PLUGIN_ident}API(const @{PLUGIN_ident}Ptr& plugin, const FB::BrowserHostPtr& host) : m_plugin(plugin), m_host(host)
+FB::variant @{PLUGIN_ident}API::echo(const FB::variant& msg)
{
- registerMethod("echo", make_method(this, &@{PLUGIN_ident}API::echo));
- registerMethod("testEvent", make_method(this, &@{PLUGIN_ident}API::testEvent));
-
- // Read-write property
- registerProperty("testString",
- make_property(this,
- &@{PLUGIN_ident}API::get_testString,
- &@{PLUGIN_ident}API::set_testString));
-
- // Read-only property
- registerProperty("version",
- make_property(this,
- &@{PLUGIN_ident}API::get_version));
-}
+ static int n(0);
+ fire_echo("So far, you clicked this many times: ", n++);
-///////////////////////////////////////////////////////////////////////////////
-/// @@fn @{PLUGIN_ident}API::~@{PLUGIN_ident}API()
-///
-/// @@brief Destructor. Remember that this object will not be released until
-/// the browser is done with it; this will almost definitely be after
-/// the plugin is released.
-///////////////////////////////////////////////////////////////////////////////
-@{PLUGIN_ident}API::~@{PLUGIN_ident}API()
-{
+ // return "foobar";
+ return msg;
}
///////////////////////////////////////////////////////////////////////////////
@@ -66,13 +43,12 @@
return plugin;
}
-
-
// Read/Write property testString
std::string @{PLUGIN_ident}API::get_testString()
{
return m_testString;
}
+
void @{PLUGIN_ident}API::set_testString(const std::string& val)
{
m_testString = val;
@@ -84,16 +60,7 @@ std::string @{PLUGIN_ident}API::get_version()
return FBSTRING_PLUGIN_VERSION;
}
-// Method echo
-FB::variant @{PLUGIN_ident}API::echo(const FB::variant& msg)
-{
- static int n(0);
- fire_echo(msg, n++);
- return msg;
-}
-
-void @{PLUGIN_ident}API::testEvent(const FB::variant& var)
+void @{PLUGIN_ident}API::testEvent()
{
- fire_fired(var, true, 1);
+ fire_test();
}
-
View
44 fbgen/src/TemplateAPI.h
@@ -17,8 +17,43 @@
class @{PLUGIN_ident}API : public FB::JSAPIAuto
{
public:
- @{PLUGIN_ident}API(const @{PLUGIN_ident}Ptr& plugin, const FB::BrowserHostPtr& host);
- virtual ~@{PLUGIN_ident}API();
+ ////////////////////////////////////////////////////////////////////////////
+ /// @@fn @{PLUGIN_ident}API::@{PLUGIN_ident}API(const @{PLUGIN_ident}Ptr& plugin, const FB::BrowserHostPtr host)
+ ///
+ /// @@brief Constructor for your JSAPI object.
+ /// You should register your methods, properties, and events
+ /// that should be accessible to Javascript from here.
+ ///
+ /// @@see FB::JSAPIAuto::registerMethod
+ /// @@see FB::JSAPIAuto::registerProperty
+ /// @@see FB::JSAPIAuto::registerEvent
+ ////////////////////////////////////////////////////////////////////////////
+ @{PLUGIN_ident}API(const @{PLUGIN_ident}Ptr& plugin, const FB::BrowserHostPtr& host) :
+ m_plugin(plugin), m_host(host)
+ {
+ registerMethod("echo", make_method(this, &@{PLUGIN_ident}API::echo));
+ registerMethod("testEvent", make_method(this, &@{PLUGIN_ident}API::testEvent));
+
+ // Read-write property
+ registerProperty("testString",
+ make_property(this,
+ &@{PLUGIN_ident}API::get_testString,
+ &@{PLUGIN_ident}API::set_testString));
+
+ // Read-only property
+ registerProperty("version",
+ make_property(this,
+ &@{PLUGIN_ident}API::get_version));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ /// @@fn @{PLUGIN_ident}API::~@{PLUGIN_ident}API()
+ ///
+ /// @@brief Destructor. Remember that this object will not be released until
+ /// the browser is done with it; this will almost definitely be after
+ /// the plugin is released.
+ ///////////////////////////////////////////////////////////////////////////////
+ virtual ~@{PLUGIN_ident}API() {};
@{PLUGIN_ident}Ptr getPlugin();
@@ -33,12 +68,11 @@ class @{PLUGIN_ident}API : public FB::JSAPIAuto
FB::variant echo(const FB::variant& msg);
// Event helpers
- FB_JSAPI_EVENT(fired, 3, (const FB::variant&, bool, int));
+ FB_JSAPI_EVENT(test, 0, ());
FB_JSAPI_EVENT(echo, 2, (const FB::variant&, const int));
- FB_JSAPI_EVENT(notify, 0, ());
// Method test-event
- void testEvent(const FB::variant& s);
+ void testEvent();
private:
@{PLUGIN_ident}WeakPtr m_plugin;
View
23 gen_templates/FBControl.htm
@@ -26,8 +26,8 @@
function load()
{
- addEvent(plugin(), 'fired', function(x){
- alert('onfired() from load(): '+x)
+ addEvent(plugin(), 'test', function(){
+ alert("Received a test event from the plugin.")
});
}
@@ -37,19 +37,23 @@
function addTestEvent()
{
- addEvent(plugin(), 'fired', function(x){
- alert('onfired(): '+x)
+ addEvent(plugin(), 'echo', function(txt,count){
+ alert(txt+count);
});
}
function testEvent()
{
- plugin().testEvent('test stuff');
+ plugin().testEvent();
}
function pluginValid()
{
- alert(plugin().valid);
+ if(plugin().valid){
+ alert(plugin().echo("This plugin seems to be working!"));
+ } else {
+ alert("Plugin is not working :(");
+ }
}
</script>
<body onload="load()">
@@ -60,12 +64,13 @@
<param name="onload" value="pluginLoaded" />
</object><br />
@@endforeach
+
+<a href="#" onclick="javascript:pluginValid()">Click me!</a> <br />
-<a href="#" onclick="javascript:addTestEvent()">set event handler</a> <br />
+<a href="#" onclick="javascript:addTestEvent()">Activate click counter</a> <br />
-<a href="#" onclick="javascript:testEvent()">Fire event</a> <br />
+<a href="#" onclick="javascript:testEvent()">Fire a test event</a> <br />
-<a href="#" onclick="javascript:pluginValid()">alert plugin valid</a> <br />
</body>
</html>

0 comments on commit 3991017

Please sign in to comment.