jsdialog: use Idle timer to send updates
Change-Id: Ib4f18bab1279c622b576dca53169b40c4a2526bc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94482 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96847 Tested-by: Jenkins
This commit is contained in:
@@ -22,13 +22,24 @@
|
||||
class ComboBox;
|
||||
typedef std::map<OString, weld::Widget*> WidgetMap;
|
||||
|
||||
class JSDialogSender
|
||||
class JSDialogNotifyIdle : public Idle
|
||||
{
|
||||
VclPtr<vcl::Window> m_aOwnedToplevel;
|
||||
VclPtr<vcl::Window> m_aWindow;
|
||||
std::string m_LastNotificationMessage;
|
||||
|
||||
public:
|
||||
JSDialogNotifyIdle(VclPtr<vcl::Window> aWindow);
|
||||
|
||||
void Invoke() override;
|
||||
};
|
||||
|
||||
class VCL_DLLPUBLIC JSDialogSender
|
||||
{
|
||||
std::unique_ptr<JSDialogNotifyIdle> mpIdleNotify;
|
||||
|
||||
public:
|
||||
JSDialogSender(VclPtr<vcl::Window> aOwnedToplevel)
|
||||
: m_aOwnedToplevel(aOwnedToplevel)
|
||||
: mpIdleNotify(new JSDialogNotifyIdle(aOwnedToplevel))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -17,23 +17,44 @@
|
||||
#include <vcl/toolkit/combobox.hxx>
|
||||
#include <messagedialog.hxx>
|
||||
|
||||
void JSDialogSender::notifyDialogState()
|
||||
JSDialogNotifyIdle::JSDialogNotifyIdle(VclPtr<vcl::Window> aWindow)
|
||||
: Idle("JSDialog notify")
|
||||
, m_aWindow(aWindow)
|
||||
, m_LastNotificationMessage()
|
||||
{
|
||||
if (!m_aOwnedToplevel)
|
||||
return;
|
||||
SetPriority(TaskPriority::POST_PAINT);
|
||||
}
|
||||
|
||||
const vcl::ILibreOfficeKitNotifier* pNotifier = m_aOwnedToplevel->GetLOKNotifier();
|
||||
if (pNotifier)
|
||||
void JSDialogNotifyIdle::Invoke()
|
||||
{
|
||||
try
|
||||
{
|
||||
std::stringstream aStream;
|
||||
boost::property_tree::ptree aTree = m_aOwnedToplevel->DumpAsPropertyTree();
|
||||
aTree.put("id", m_aOwnedToplevel->GetLOKWindowId());
|
||||
boost::property_tree::write_json(aStream, aTree);
|
||||
const std::string message = aStream.str();
|
||||
pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, message.c_str());
|
||||
if (!m_aWindow)
|
||||
return;
|
||||
|
||||
const vcl::ILibreOfficeKitNotifier* pNotifier = m_aWindow->GetLOKNotifier();
|
||||
if (pNotifier)
|
||||
{
|
||||
std::stringstream aStream;
|
||||
boost::property_tree::ptree aTree = m_aWindow->DumpAsPropertyTree();
|
||||
aTree.put("id", m_aWindow->GetLOKWindowId());
|
||||
boost::property_tree::write_json(aStream, aTree);
|
||||
const std::string message = aStream.str();
|
||||
if (message != m_LastNotificationMessage)
|
||||
{
|
||||
m_LastNotificationMessage = message;
|
||||
pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, message.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (boost::property_tree::json_parser::json_parser_error& rError)
|
||||
{
|
||||
SAL_WARN("vcl", rError.message());
|
||||
}
|
||||
}
|
||||
|
||||
void JSDialogSender::notifyDialogState() { mpIdleNotify->Start(); }
|
||||
|
||||
JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot,
|
||||
const OUString& rUIFile)
|
||||
: SalInstanceBuilder(dynamic_cast<SalInstanceWidget*>(pParent)
|
||||
|
||||
Reference in New Issue
Block a user