vcl/inc/jsdialog/jsdialogbuilder.hxx |   24 ++++++--
 vcl/jsdialog/jsdialogbuilder.cxx     |  102 ++++++++++++++++-------------------
 2 files changed, 66 insertions(+), 60 deletions(-)

New commits:
commit 0d8a5a686a2779e65c96d5e881717b22964a5493
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Wed Jan 13 13:16:30 2021 +0100
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Feb 5 05:26:15 2021 +0100

    jsdialog: enqueue messages in order
    
    Change-Id: Ib50cf6e2b57c591d1d3cffbe823162d7a17474cf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109262
    Tested-by: Jenkins
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109907
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx 
b/vcl/inc/jsdialog/jsdialogbuilder.hxx
index 0119f6a5c8c0..4693393bdabb 100644
--- a/vcl/inc/jsdialog/jsdialogbuilder.hxx
+++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx
@@ -27,6 +27,8 @@
 #include <cppuhelper/compbase.hxx>
 #include <boost/property_tree/ptree_fwd.hpp>
 
+#include <deque>
+
 class ToolBox;
 class SfxViewShell;
 class VclMultiLineEdit;
@@ -34,6 +36,16 @@ class IconView;
 
 typedef std::map<OString, weld::Widget*> WidgetMap;
 
+namespace jsdialog
+{
+enum MessageType
+{
+    FullUpdate,
+    WidgetUpdate,
+    Close
+};
+}
+
 class JSDialogNotifyIdle : public Idle
 {
     // used to send message
@@ -44,19 +56,21 @@ class JSDialogNotifyIdle : public Idle
     std::string m_LastNotificationMessage;
     bool m_bForce;
 
+    std::deque<std::pair<jsdialog::MessageType, VclPtr<vcl::Window>>> 
m_aMessageQueue;
+
 public:
     JSDialogNotifyIdle(VclPtr<vcl::Window> aNotifierWindow, 
VclPtr<vcl::Window> aContentWindow,
                        std::string sTypeOfJSON);
 
     void Invoke() override;
-    void ForceUpdate();
-    void sendClose();
-    VclPtr<vcl::Window> getNotifierWindow() { return m_aNotifierWindow; }
-    void updateStatus(VclPtr<vcl::Window> pWindow);
+
+    void forceUpdate();
+    void sendMessage(jsdialog::MessageType eType, VclPtr<vcl::Window> pWindow);
 
 private:
     void send(const boost::property_tree::ptree& rTree);
-    boost::property_tree::ptree dumpStatus() const;
+    boost::property_tree::ptree generateFullUpdate() const;
+    boost::property_tree::ptree generateWidgetUpdate(VclPtr<vcl::Window> 
pWindow) const;
     boost::property_tree::ptree generateCloseMessage() const;
 };
 
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 576f2bba5b3b..ea06e2518d0e 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -17,6 +17,7 @@
 #include <vcl/vclmedit.hxx>
 #include <vcl/treelistentry.hxx>
 #include <cppuhelper/supportsservice.hxx>
+#include <utility>
 
 using namespace weld;
 
@@ -32,7 +33,7 @@ JSDialogNotifyIdle::JSDialogNotifyIdle(VclPtr<vcl::Window> 
aNotifierWindow,
     SetPriority(TaskPriority::POST_PAINT);
 }
 
-void JSDialogNotifyIdle::ForceUpdate() { m_bForce = true; }
+void JSDialogNotifyIdle::forceUpdate() { m_bForce = true; }
 
 void JSDialogNotifyIdle::send(const boost::property_tree::ptree& rTree)
 {
@@ -61,7 +62,12 @@ void JSDialogNotifyIdle::send(const 
boost::property_tree::ptree& rTree)
     }
 }
 
-boost::property_tree::ptree JSDialogNotifyIdle::dumpStatus() const
+void JSDialogNotifyIdle::sendMessage(jsdialog::MessageType eType, 
VclPtr<vcl::Window> pWindow)
+{
+    m_aMessageQueue.push_back(std::make_pair(eType, pWindow));
+}
+
+boost::property_tree::ptree JSDialogNotifyIdle::generateFullUpdate() const
 {
     if (!m_aContentWindow || !m_aNotifierWindow)
         return boost::property_tree::ptree();
@@ -91,54 +97,17 @@ boost::property_tree::ptree 
JSDialogNotifyIdle::dumpStatus() const
     return aTree;
 }
 
-void JSDialogNotifyIdle::updateStatus(VclPtr<vcl::Window> pWindow)
+boost::property_tree::ptree
+JSDialogNotifyIdle::generateWidgetUpdate(VclPtr<vcl::Window> pWindow) const
 {
-    if (!m_aNotifierWindow)
-        return;
-
-    // will be deprecated soon
-    if (m_aNotifierWindow->IsReallyVisible())
-    {
-        if (const vcl::ILibreOfficeKitNotifier* pNotifier = 
m_aNotifierWindow->GetLOKNotifier())
-        {
-            boost::property_tree::ptree aTree;
-
-            aTree.put("commandName", ".uno:jsdialog");
-            aTree.put("success", "true");
-            {
-                boost::property_tree::ptree aResult;
-                aResult.put("dialog_id", m_aNotifierWindow->GetLOKWindowId());
-                aResult.put("control_id", pWindow->get_id());
-                {
-                    boost::property_tree::ptree aControl;
-                    aControl = pWindow->DumpAsPropertyTree();
-                    aResult.add_child("control", aControl);
-                }
-                aTree.add_child("result", aResult);
-            }
-
-            std::stringstream aStream;
-            boost::property_tree::write_json(aStream, aTree);
-            const std::string message = aStream.str();
-            
pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_UNO_COMMAND_RESULT, 
message.c_str());
-        }
-    }
-
-    // new approach - update also if hidden
-    if (const vcl::ILibreOfficeKitNotifier* pNotifier = 
m_aNotifierWindow->GetLOKNotifier())
-    {
-        boost::property_tree::ptree aTree;
+    boost::property_tree::ptree aTree;
 
-        aTree.put("jsontype", m_sTypeOfJSON);
-        aTree.put("action", "update");
-        aTree.put("id", m_aNotifierWindow->GetLOKWindowId());
-        aTree.add_child("control", pWindow->DumpAsPropertyTree());
+    aTree.put("jsontype", m_sTypeOfJSON);
+    aTree.put("action", "update");
+    aTree.put("id", m_aNotifierWindow->GetLOKWindowId());
+    aTree.add_child("control", pWindow->DumpAsPropertyTree());
 
-        std::stringstream aStream;
-        boost::property_tree::write_json(aStream, aTree);
-        const std::string message = aStream.str();
-        pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, 
message.c_str());
-    }
+    return aTree;
 }
 
 boost::property_tree::ptree JSDialogNotifyIdle::generateCloseMessage() const
@@ -152,25 +121,48 @@ boost::property_tree::ptree 
JSDialogNotifyIdle::generateCloseMessage() const
     return aTree;
 }
 
-void JSDialogNotifyIdle::Invoke() { send(dumpStatus()); }
+void JSDialogNotifyIdle::Invoke()
+{
+    for (auto& rMessage : m_aMessageQueue)
+    {
+        jsdialog::MessageType eType = rMessage.first;
+
+        switch (eType)
+        {
+            case jsdialog::MessageType::FullUpdate:
+                send(generateFullUpdate());
+                break;
+
+            case jsdialog::MessageType::WidgetUpdate:
+                send(generateWidgetUpdate(rMessage.second));
+                break;
 
-void JSDialogNotifyIdle::sendClose() { send(generateCloseMessage()); }
+            case jsdialog::MessageType::Close:
+                send(generateCloseMessage());
+                break;
+        }
+    }
+}
 
 void JSDialogSender::notifyDialogState(bool bForce)
 {
-    if (!mpIdleNotify->getNotifierWindow())
-        return;
-
     if (bForce)
-        mpIdleNotify->ForceUpdate();
+        mpIdleNotify->forceUpdate();
+
+    mpIdleNotify->sendMessage(jsdialog::MessageType::FullUpdate, nullptr);
     mpIdleNotify->Start();
 }
 
-void JSDialogSender::sendClose() { mpIdleNotify->sendClose(); }
+void JSDialogSender::sendClose()
+{
+    mpIdleNotify->sendMessage(jsdialog::MessageType::Close, nullptr);
+    mpIdleNotify->Start();
+}
 
 void JSDialogSender::sendUpdate(VclPtr<vcl::Window> pWindow)
 {
-    mpIdleNotify->updateStatus(pWindow);
+    mpIdleNotify->sendMessage(jsdialog::MessageType::WidgetUpdate, pWindow);
+    mpIdleNotify->Start();
 }
 
 // Drag and drop
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to