desktop/source/lib/init.cxx          |    1 
 include/tools/json_writer.hxx        |    2 
 tools/source/misc/json_writer.cxx    |    2 
 vcl/inc/jsdialog/jsdialogbuilder.hxx |    9 +++
 vcl/jsdialog/jsdialogbuilder.cxx     |   82 ++++++++++++++++++++++++-----------
 5 files changed, 68 insertions(+), 28 deletions(-)

New commits:
commit 84a3f79fffbb32ee5e083cdb4bd58cb6aa20a381
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Thu Dec 3 14:09:43 2020 +0100
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Tue Dec 8 11:22:44 2020 +0100

    jsdialog: don't skip commands
    
    api was extended and now we send no only
    the latest state of a current window (may be skipped),
    but also commands like: close window <ID>.
    Make sure commands will not be skipped when new dialog
    appears.
    
    Change-Id: I17fa0f09d7ef78cbbcbf8786182dfeb92e6021ad
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107165
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107350
    Tested-by: Jenkins

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 66a32dafbc97..e1e8ac652d3f 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1524,7 +1524,6 @@ void CallbackFlushHandler::queue(const int type, const 
char* data)
             case LOK_CALLBACK_TEXT_VIEW_SELECTION:
             case LOK_CALLBACK_VIEW_CURSOR_VISIBLE:
             case LOK_CALLBACK_CALC_FUNCTION_LIST:
-            case LOK_CALLBACK_JSDIALOG:
             {
                 // deleting the duplicate of visible cursor message can cause 
hyperlink popup not to show up on second/or more click on the same place.
                 // If the hyperlink is not empty we can bypass that to show 
the popup
commit 913fa080fa8ed17228dc87fe885ec47df917ade6
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Thu Dec 3 11:16:08 2020 +0100
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Tue Dec 8 11:22:31 2020 +0100

    jsdialog: send close on dialog response
    
    Change-Id: I730d99cc9aa519f07d6b1c436d749f2c0b044bfd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107151
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107349
    Tested-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/include/tools/json_writer.hxx b/include/tools/json_writer.hxx
index 440fedccf45e..2e50670c5b26 100644
--- a/include/tools/json_writer.hxx
+++ b/include/tools/json_writer.hxx
@@ -76,7 +76,7 @@ public:
     std::string extractAsStdString();
 
     /** returns true if the current JSON data matches the string */
-    bool isDataEquals(const std::string&);
+    bool isDataEquals(const std::string&) const;
 
 private:
     void endNode();
diff --git a/tools/source/misc/json_writer.cxx 
b/tools/source/misc/json_writer.cxx
index a0e0280b840e..1246f0578fca 100644
--- a/tools/source/misc/json_writer.cxx
+++ b/tools/source/misc/json_writer.cxx
@@ -422,7 +422,7 @@ std::string JsonWriter::extractAsStdString()
     return ret;
 }
 
-bool JsonWriter::isDataEquals(const std::string& s)
+bool JsonWriter::isDataEquals(const std::string& s) const
 {
     return s.length() == static_cast<size_t>(mPos - mpBuffer)
            && memcmp(s.data(), mpBuffer, s.length()) == 0;
diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx 
b/vcl/inc/jsdialog/jsdialogbuilder.hxx
index ab7c038648d3..d3c6e7b26d48 100644
--- a/vcl/inc/jsdialog/jsdialogbuilder.hxx
+++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx
@@ -23,6 +23,7 @@
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
 #include <cppuhelper/compbase.hxx>
+#include <boost/property_tree/ptree_fwd.hpp>
 
 class ToolBox;
 class ComboBox;
@@ -47,6 +48,12 @@ public:
 
     void Invoke() override;
     void ForceUpdate();
+    void sendClose();
+
+private:
+    void send(std::unique_ptr<tools::JsonWriter> aJsonWriter);
+    std::unique_ptr<tools::JsonWriter> dumpStatus() const;
+    std::unique_ptr<tools::JsonWriter> generateCloseMessage() const;
 };
 
 class JSDialogSender
@@ -61,6 +68,7 @@ public:
     }
 
     void notifyDialogState(bool bForce = false);
+    void sendClose();
 };
 
 class JSDropTarget final
@@ -216,6 +224,7 @@ public:
 
     virtual void collapse(weld::Widget* pEdit, weld::Widget* pButton) override;
     virtual void undo_collapse() override;
+    virtual void response(int response) override;
 };
 
 class JSLabel : public JSWidget<SalInstanceLabel, FixedText>
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 3c663bac10e0..08e66eedb6f5 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -40,7 +40,7 @@ JSDialogNotifyIdle::JSDialogNotifyIdle(VclPtr<vcl::Window> 
aNotifierWindow,
 
 void JSDialogNotifyIdle::ForceUpdate() { m_bForce = true; }
 
-void JSDialogNotifyIdle::Invoke()
+void JSDialogNotifyIdle::send(std::unique_ptr<tools::JsonWriter> aJsonWriter)
 {
     if (!m_aNotifierWindow)
         return;
@@ -48,39 +48,63 @@ void JSDialogNotifyIdle::Invoke()
     const vcl::ILibreOfficeKitNotifier* pNotifier = 
m_aNotifierWindow->GetLOKNotifier();
     if (pNotifier)
     {
-        tools::JsonWriter aJsonWriter;
-        m_aContentWindow->DumpAsPropertyTree(aJsonWriter);
-        aJsonWriter.put("id", m_aNotifierWindow->GetLOKWindowId());
-        aJsonWriter.put("jsontype", m_sTypeOfJSON);
+        if (m_bForce || !aJsonWriter->isDataEquals(m_LastNotificationMessage))
+        {
+            m_bForce = false;
+            m_LastNotificationMessage = aJsonWriter->extractAsStdString();
+            pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG,
+                                                  
m_LastNotificationMessage.c_str());
+        }
+    }
+}
+
+std::unique_ptr<tools::JsonWriter> JSDialogNotifyIdle::dumpStatus() const
+{
+    std::unique_ptr<tools::JsonWriter> aJsonWriter(new tools::JsonWriter());
+
+    if (!m_aContentWindow || !m_aNotifierWindow)
+        return aJsonWriter;
 
-        if (m_sTypeOfJSON == "autofilter")
+    m_aContentWindow->DumpAsPropertyTree(*aJsonWriter);
+    aJsonWriter->put("id", m_aNotifierWindow->GetLOKWindowId());
+    aJsonWriter->put("jsontype", m_sTypeOfJSON);
+
+    if (m_sTypeOfJSON == "autofilter")
+    {
+        vcl::Window* pWindow = m_aContentWindow.get();
+        DockingWindow* pDockingWIndow = dynamic_cast<DockingWindow*>(pWindow);
+        while (pWindow && !pDockingWIndow)
         {
-            vcl::Window* pWindow = m_aContentWindow.get();
-            DockingWindow* pDockingWIndow = 
dynamic_cast<DockingWindow*>(pWindow);
-            while (pWindow && !pDockingWIndow)
-            {
-                pWindow = pWindow->GetParent();
-                pDockingWIndow = dynamic_cast<DockingWindow*>(pWindow);
-            }
-
-            if (pDockingWIndow)
-            {
-                Point aPos = pDockingWIndow->GetFloatingPos();
-                aJsonWriter.put("posx", aPos.getX());
-                aJsonWriter.put("posy", aPos.getY());
-            }
+            pWindow = pWindow->GetParent();
+            pDockingWIndow = dynamic_cast<DockingWindow*>(pWindow);
         }
 
-        if (m_bForce || !aJsonWriter.isDataEquals(m_LastNotificationMessage))
+        if (pDockingWIndow)
         {
-            m_bForce = false;
-            m_LastNotificationMessage = aJsonWriter.extractAsStdString();
-            pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG,
-                                                  
m_LastNotificationMessage.c_str());
+            Point aPos = pDockingWIndow->GetFloatingPos();
+            aJsonWriter->put("posx", aPos.getX());
+            aJsonWriter->put("posy", aPos.getY());
         }
     }
+
+    return aJsonWriter;
+}
+
+std::unique_ptr<tools::JsonWriter> JSDialogNotifyIdle::generateCloseMessage() 
const
+{
+    std::unique_ptr<tools::JsonWriter> aJsonWriter(new tools::JsonWriter());
+    if (m_aNotifierWindow)
+        aJsonWriter->put("id", m_aNotifierWindow->GetLOKWindowId());
+    aJsonWriter->put("jsontype", m_sTypeOfJSON);
+    aJsonWriter->put("action", "close");
+
+    return aJsonWriter;
 }
 
+void JSDialogNotifyIdle::Invoke() { send(dumpStatus()); }
+
+void JSDialogNotifyIdle::sendClose() { send(generateCloseMessage()); }
+
 void JSDialogSender::notifyDialogState(bool bForce)
 {
     if (bForce)
@@ -88,6 +112,8 @@ void JSDialogSender::notifyDialogState(bool bForce)
     mpIdleNotify->Start();
 }
 
+void JSDialogSender::sendClose() { mpIdleNotify->sendClose(); }
+
 namespace
 {
 vcl::Window* extract_sal_widget(weld::Widget* pParent)
@@ -611,6 +637,12 @@ void JSDialog::undo_collapse()
     notifyDialogState();
 }
 
+void JSDialog::response(int response)
+{
+    sendClose();
+    SalInstanceDialog::response(response);
+}
+
 JSLabel::JSLabel(VclPtr<vcl::Window> aNotifierWindow, VclPtr<vcl::Window> 
aContentWindow,
                  FixedText* pLabel, SalInstanceBuilder* pBuilder, bool 
bTakeOwnership,
                  std::string sTypeOfJSON)
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to