diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2020-02-24 18:35:18 +0100 |
---|---|---|
committer | Szymon Kłos <eszkadev@gmail.com> | 2020-05-14 16:38:47 +0200 |
commit | 6a947fe26a651384974052c3c0acb2d88f123d18 (patch) | |
tree | b72d9d33e4b1cae4a4a88138e71bd25efb47f108 | |
parent | 43aa6897526fbc44e13d3295e97dfebbc8430e23 (diff) |
Resend jsdialog on entry change
Change-Id: Ic255b8ba56f5b355a95ddc9a9587e1747b66702a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94071
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
-rw-r--r-- | vcl/inc/jsdialog/jsdialogbuilder.hxx | 27 | ||||
-rw-r--r-- | vcl/jsdialog/jsdialogbuilder.cxx | 51 |
2 files changed, 63 insertions, 15 deletions
diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx b/vcl/inc/jsdialog/jsdialogbuilder.hxx index 9d8c68516320..956c3001fc22 100644 --- a/vcl/inc/jsdialog/jsdialogbuilder.hxx +++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx @@ -8,6 +8,19 @@ #include <vcl/builder.hxx> #include <salvtables.hxx> +class JSDialogSender +{ + VclPtr<vcl::Window> m_aOwnedToplevel; + +public: + JSDialogSender(VclPtr<vcl::Window> aOwnedToplevel) + : m_aOwnedToplevel(aOwnedToplevel) + { + } + + void notifyDialogState(); +}; + class VCL_DLLPUBLIC JSInstanceBuilder : public SalInstanceBuilder { public: @@ -16,16 +29,24 @@ public: bool bTakeOwnership = true) override; virtual std::unique_ptr<weld::Label> weld_label(const OString& id, bool bTakeOwnership = false) override; + virtual std::unique_ptr<weld::Entry> weld_entry(const OString& id, + bool bTakeOwnership = false) override; }; -class VCL_DLLPUBLIC JSLabel : public SalInstanceLabel +class VCL_DLLPUBLIC JSLabel : public SalInstanceLabel, public JSDialogSender { - VclPtr<vcl::Window> m_aOwnedToplevel; - public: JSLabel(VclPtr<vcl::Window> aOwnedToplevel, FixedText* pLabel, SalInstanceBuilder* pBuilder, bool bTakeOwnership); virtual void set_label(const OUString& rText) override; }; +class VCL_DLLPUBLIC JSEntry : public SalInstanceEntry, public JSDialogSender +{ +public: + JSEntry(VclPtr<vcl::Window> aOwnedToplevel, ::Edit* pEntry, SalInstanceBuilder* pBuilder, + bool bTakeOwnership); + virtual void set_text(const OUString& rText) override; +}; + #endif
\ No newline at end of file diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx index 8807c3a35907..fc1c7a0159e9 100644 --- a/vcl/jsdialog/jsdialogbuilder.cxx +++ b/vcl/jsdialog/jsdialogbuilder.cxx @@ -7,6 +7,23 @@ using namespace weld; +void JSDialogSender::notifyDialogState() +{ + if (!m_aOwnedToplevel) + return; + + const vcl::ILibreOfficeKitNotifier* pNotifier = m_aOwnedToplevel->GetLOKNotifier(); + if (pNotifier) + { + 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()); + } +} + JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile) : SalInstanceBuilder(dynamic_cast<SalInstanceWidget*>(pParent) @@ -48,25 +65,35 @@ std::unique_ptr<weld::Label> JSInstanceBuilder::weld_label(const OString& id, bo return std::make_unique<JSLabel>(m_aOwnedToplevel, pLabel, this, bTakeOwnership); } +std::unique_ptr<weld::Entry> JSInstanceBuilder::weld_entry(const OString& id, bool bTakeOwnership) +{ + Edit* pEntry = m_xBuilder->get<Edit>(id); + return pEntry ? std::make_unique<JSEntry>(m_aOwnedToplevel, pEntry, this, bTakeOwnership) + : nullptr; +} + JSLabel::JSLabel(VclPtr<vcl::Window> aOwnedToplevel, FixedText* pLabel, SalInstanceBuilder* pBuilder, bool bTakeOwnership) : SalInstanceLabel(pLabel, pBuilder, bTakeOwnership) - , m_aOwnedToplevel(aOwnedToplevel) + , JSDialogSender(aOwnedToplevel) { } void JSLabel::set_label(const OUString& rText) { SalInstanceLabel::set_label(rText); - - const vcl::ILibreOfficeKitNotifier* pNotifier = m_aOwnedToplevel->GetLOKNotifier(); - if (pNotifier) - { - 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()); - } + notifyDialogState(); }; + +JSEntry::JSEntry(VclPtr<vcl::Window> aOwnedToplevel, ::Edit* pEntry, SalInstanceBuilder* pBuilder, + bool bTakeOwnership) + : SalInstanceEntry(pEntry, pBuilder, bTakeOwnership) + , JSDialogSender(aOwnedToplevel) +{ +} + +void JSEntry::set_text(const OUString& rText) +{ + SalInstanceEntry::set_text(rText); + notifyDialogState(); +} |