[Libreoffice-commits] core.git: include/vcl vcl/jsdialog

Szymon KÅ‚os (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 23 07:09:39 UTC 2020


 include/vcl/jsdialog/jsdialogbuilder.hxx |   17 ++++++++++--
 vcl/jsdialog/jsdialogbuilder.cxx         |   43 +++++++++++++++++++++++--------
 2 files changed, 46 insertions(+), 14 deletions(-)

New commits:
commit 526c4bd5dbe0225a1ff14ff1e7fe32151ab7d29d
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Tue Mar 31 15:42:28 2020 +0200
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Tue Jun 23 09:09:00 2020 +0200

    jsdialog: use Idle timer to send updates
    
    Change-Id: Ib4f18bab1279c622b576dca53169b40c4a2526bc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94482
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96847
    Tested-by: Jenkins

diff --git a/include/vcl/jsdialog/jsdialogbuilder.hxx b/include/vcl/jsdialog/jsdialogbuilder.hxx
index 161d770d613a..62f6d11a2d7a 100644
--- a/include/vcl/jsdialog/jsdialogbuilder.hxx
+++ b/include/vcl/jsdialog/jsdialogbuilder.hxx
@@ -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))
     {
     }
 
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 2ab05b40dd21..d7f35b7d6039 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -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)


More information about the Libreoffice-commits mailing list