summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2020-12-03 11:16:08 +0100
committerSzymon Kłos <szymon.klos@collabora.com>2020-12-08 11:22:31 +0100
commit913fa080fa8ed17228dc87fe885ec47df917ade6 (patch)
tree09f575cd673a98e3f761d1b538b011e5448ba7bf
parentf36433c10a4be39bd5e93621ee46766c587ad57c (diff)
jsdialog: send close on dialog response
Change-Id: I730d99cc9aa519f07d6b1c436d749f2c0b044bfd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107151 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107349 Tested-by: Szymon Kłos <szymon.klos@collabora.com>
-rw-r--r--include/tools/json_writer.hxx2
-rw-r--r--tools/source/misc/json_writer.cxx2
-rw-r--r--vcl/inc/jsdialog/jsdialogbuilder.hxx9
-rw-r--r--vcl/jsdialog/jsdialogbuilder.cxx82
4 files changed, 68 insertions, 27 deletions
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)