I want only one folder choose dialog to be opened at any one time.
Once the user selected the folder an event will be fired inform the javaScript of the selected folder.
To open the dialog i included the code from the following gist in my project
DialogManager abstraction for FireBreath
pluginAPI cpp
I maintain a global pointer to the plugin so its functions can be called from any context
Q: is this the best way?
#include "DialogManagerWin.h"
pluginAPI * g_thePlugin;
I set it in the pluginAPI CTOR
g_thePlugin = this;
pluginAPI.h
This goes to pluginAPI
this is the event i want to give the javascript the selected folder
FB_JSAPI_EVENT(folderselected, 1, (const std::string&));
the API to call from javaScript:
calls the code from the gist to open the folder selection in another thread to avoid blocking and causing the browser to freeze.
void pluginAPI::SelectFolder(std::string initialFolderPath)
{
FB::PluginWindow* pluginWindow = pluginAPI::getPlugin()->GetWindow();
DialogManager* dlg_mgr = DialogManager::get();
dlg_mgr->OpenFolderDialog(m_host, pluginWindow, folderSelectorCallback);
return;
}
The callback
this callback will be called once the user selected a folder
void folderSelectorCallback(const std::string& folderSelected)
{
g_thePlugin->fire_folderselected(folderSelected);
return ;
}
First of all, there is a difference between the plugin and the root JSAPI object; you’re maintaining a global pointer to the root JSAPI object.
No, this is not a good idea and you should never do this.
Secondly, what you probably want to do here is not to fire a JSAPI event but actually to just call an asynchronous callback. There are examples of this in FBTestPlugin and a blog post on the subject.
All you need to do is accept a const JSObjectPtr& callback argument to the js function and then pass that into the callback from the dialog abstraction.
If you’re using the abstraction as it is in the gist, it’d look something like this:
Haven’t tested that code exactly, but that should be close.