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

Szymon KÅ‚os (via logerrit) logerrit at kemper.freedesktop.org
Fri Jan 15 07:40:05 UTC 2021


 vcl/inc/jsdialog/jsdialogbuilder.hxx |   24 ++++++--
 vcl/jsdialog/jsdialogbuilder.cxx     |   96 +++++++++++++++++------------------
 2 files changed, 67 insertions(+), 53 deletions(-)

New commits:
commit 8760c3036b2bcfb5021f1f4c57493de73f4859c7
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Wed Jan 13 13:16:30 2021 +0100
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Fri Jan 15 08:39:21 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.klos at collabora.com>

diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx b/vcl/inc/jsdialog/jsdialogbuilder.hxx
index ca59aab24924..a1c320c16159 100644
--- a/vcl/inc/jsdialog/jsdialogbuilder.hxx
+++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx
@@ -24,6 +24,8 @@
 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
 #include <cppuhelper/compbase.hxx>
 
+#include <deque>
+
 class ToolBox;
 class ComboBox;
 class VclMultiLineEdit;
@@ -32,6 +34,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
@@ -42,19 +54,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(tools::JsonWriter& aJsonWriter);
-    std::unique_ptr<tools::JsonWriter> dumpStatus() const;
+    std::unique_ptr<tools::JsonWriter> generateFullUpdate() const;
+    std::unique_ptr<tools::JsonWriter> generateWidgetUpdate(VclPtr<vcl::Window> pWindow) const;
     std::unique_ptr<tools::JsonWriter> generateCloseMessage() const;
 };
 
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 81ba11f92fb9..3741457a4186 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -25,6 +25,7 @@
 #include <vcl/toolkit/treelistentry.hxx>
 #include <vcl/jsdialog/executor.hxx>
 #include <cppuhelper/supportsservice.hxx>
+#include <utility>
 
 JSDialogNotifyIdle::JSDialogNotifyIdle(VclPtr<vcl::Window> aNotifierWindow,
                                        VclPtr<vcl::Window> aContentWindow, std::string sTypeOfJSON)
@@ -38,7 +39,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(tools::JsonWriter& aJsonWriter)
 {
@@ -65,7 +66,12 @@ void JSDialogNotifyIdle::send(tools::JsonWriter& aJsonWriter)
     }
 }
 
-std::unique_ptr<tools::JsonWriter> JSDialogNotifyIdle::dumpStatus() const
+void JSDialogNotifyIdle::sendMessage(jsdialog::MessageType eType, VclPtr<vcl::Window> pWindow)
+{
+    m_aMessageQueue.push_back(std::make_pair(eType, pWindow));
+}
+
+std::unique_ptr<tools::JsonWriter> JSDialogNotifyIdle::generateFullUpdate() const
 {
     std::unique_ptr<tools::JsonWriter> aJsonWriter(new tools::JsonWriter());
 
@@ -97,49 +103,20 @@ std::unique_ptr<tools::JsonWriter> JSDialogNotifyIdle::dumpStatus() const
     return aJsonWriter;
 }
 
-void JSDialogNotifyIdle::updateStatus(VclPtr<vcl::Window> pWindow)
+std::unique_ptr<tools::JsonWriter>
+JSDialogNotifyIdle::generateWidgetUpdate(VclPtr<vcl::Window> pWindow) const
 {
-    if (!m_aNotifierWindow)
-        return;
+    std::unique_ptr<tools::JsonWriter> aJsonWriter(new tools::JsonWriter());
 
-    // will be deprecated soon
-    if (m_aNotifierWindow->IsReallyVisible())
+    aJsonWriter->put("jsontype", m_sTypeOfJSON);
+    aJsonWriter->put("action", "update");
+    aJsonWriter->put("id", m_aNotifierWindow->GetLOKWindowId());
     {
-        if (const vcl::ILibreOfficeKitNotifier* pNotifier = m_aNotifierWindow->GetLOKNotifier())
-        {
-            tools::JsonWriter aJsonWriter;
-
-            aJsonWriter.put("commandName", ".uno:jsdialog");
-            aJsonWriter.put("success", "true");
-            {
-                auto aResult = aJsonWriter.startNode("result");
-                aJsonWriter.put("dialog_id", m_aNotifierWindow->GetLOKWindowId());
-                aJsonWriter.put("control_id", pWindow->get_id());
-                {
-                    auto aEntries = aJsonWriter.startNode("control");
-                    pWindow->DumpAsPropertyTree(aJsonWriter);
-                }
-            }
-
-            pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_UNO_COMMAND_RESULT,
-                                                  aJsonWriter.extractData());
-        }
+        auto aEntries = aJsonWriter->startNode("control");
+        pWindow->DumpAsPropertyTree(*aJsonWriter);
     }
 
-    // new approach - update also if hidden
-    if (const vcl::ILibreOfficeKitNotifier* pNotifier = m_aNotifierWindow->GetLOKNotifier())
-    {
-        tools::JsonWriter aJsonWriter;
-
-        aJsonWriter.put("jsontype", m_sTypeOfJSON);
-        aJsonWriter.put("action", "update");
-        aJsonWriter.put("id", m_aNotifierWindow->GetLOKWindowId());
-        {
-            auto aEntries = aJsonWriter.startNode("control");
-            pWindow->DumpAsPropertyTree(aJsonWriter);
-        }
-        pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, aJsonWriter.extractData());
-    }
+    return aJsonWriter;
 }
 
 std::unique_ptr<tools::JsonWriter> JSDialogNotifyIdle::generateCloseMessage() const
@@ -153,25 +130,48 @@ std::unique_ptr<tools::JsonWriter> JSDialogNotifyIdle::generateCloseMessage() co
     return aJsonWriter;
 }
 
-void JSDialogNotifyIdle::Invoke() { send(*dumpStatus()); }
+void JSDialogNotifyIdle::Invoke()
+{
+    for (auto& rMessage : m_aMessageQueue)
+    {
+        jsdialog::MessageType eType = rMessage.first;
 
-void JSDialogNotifyIdle::sendClose() { send(*generateCloseMessage()); }
+        switch (eType)
+        {
+            case jsdialog::MessageType::FullUpdate:
+                send(*generateFullUpdate());
+                break;
+
+            case jsdialog::MessageType::WidgetUpdate:
+                send(*generateWidgetUpdate(rMessage.second));
+                break;
+
+            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();
 }
 
 namespace


More information about the Libreoffice-commits mailing list