[Libreoffice-commits] core.git: Branch 'feature/jsdialogs' - 3 commits - cui/source cui/uiconfig include/vcl solenv/sanitizers vcl/jsdialog vcl/source

Szymon KÅ‚os (via logerrit) logerrit at kemper.freedesktop.org
Tue Mar 31 14:30:26 UTC 2020


Rebased ref, commits from common ancestor:
commit fcb73c5a54c946b1b87b2a2a340cbce14abe7549
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Tue Mar 31 15:42:28 2020 +0200
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Tue Mar 31 16:11:09 2020 +0200

    jsdialog: use Idle timer to send updates
    
    Change-Id: Ib4f18bab1279c622b576dca53169b40c4a2526bc

diff --git a/include/vcl/jsdialog/jsdialogbuilder.hxx b/include/vcl/jsdialog/jsdialogbuilder.hxx
index d01d878828c2..8b7154d98bf5 100644
--- a/include/vcl/jsdialog/jsdialogbuilder.hxx
+++ b/include/vcl/jsdialog/jsdialogbuilder.hxx
@@ -14,12 +14,25 @@
 
 typedef std::map<OString, weld::Widget*> WidgetMap;
 
+class JSDialogNotifyIdle : public Idle
+{
+    VclPtr<vcl::Window> m_aWindow;
+    std::string m_LastNotificationMessage;
+    vcl::LOKWindowId m_LastLOKWindowId;
+
+public:
+    JSDialogNotifyIdle(VclPtr<vcl::Window> aWindow);
+
+    void Invoke() override;
+};
+
 class VCL_DLLPUBLIC JSDialogSender
 {
-    VclPtr<vcl::Window> m_aOwnedToplevel;
+    std::unique_ptr<JSDialogNotifyIdle> mpIdleNotify;
+
 public:
     JSDialogSender(VclPtr<vcl::Window> aOwnedToplevel)
-    : m_aOwnedToplevel(aOwnedToplevel)
+    : mpIdleNotify(new JSDialogNotifyIdle(aOwnedToplevel))
     {}
 
     void notifyDialogState();
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 7db752b77045..2666881cc382 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -7,23 +7,48 @@
 
 using namespace weld;
 
-void JSDialogSender::notifyDialogState()
+JSDialogNotifyIdle::JSDialogNotifyIdle(VclPtr<vcl::Window> aWindow)
+: Idle("JSDialog notify")
+, m_aWindow(aWindow)
+, m_LastNotificationMessage()
+, m_LastLOKWindowId(0)
 {
-    if (!m_aOwnedToplevel)
-        return;
+    SetPriority(TaskPriority::POST_PAINT);
+}
 
-    const vcl::ILibreOfficeKitNotifier* pNotifier = m_aOwnedToplevel->GetLOKNotifier();
-    if (pNotifier)
+void JSDialogNotifyIdle::Invoke()
+{
+    try
     {
-        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());
+        if (!m_aWindow)
+            return;
+
+        const vcl::ILibreOfficeKitNotifier* pNotifier = m_aWindow->GetLOKNotifier();
+        if (pNotifier)
+        {
+            std::stringstream aStream;
+            boost::property_tree::ptree aTree = m_aWindow->DumpAsPropertyTree();
+            aTree.put("id", m_aWindow->GetLOKWindowId());
+            boost::property_tree::write_json(aStream, aTree);
+            const std::string message = aStream.str();
+            if (message != m_LastNotificationMessage)
+            {
+                m_LastNotificationMessage = message;
+                pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, message.c_str());
+            }
+        }
+    }
+    catch (boost::property_tree::json_parser::json_parser_error& rError)
+    {
+        SAL_WARN("vcl.jsdialog", rError.message());
     }
 }
 
+void JSDialogSender::notifyDialogState()
+{
+    mpIdleNotify->Start();
+}
+
 JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile)
         : SalInstanceBuilder(
             dynamic_cast<SalInstanceWidget*>(pParent) ?
commit 0d8b0194850558d1a01fe0af2e0c1ffe0ab944e1
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Thu Mar 26 11:49:24 2020 +0100
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Tue Mar 31 16:11:08 2020 +0200

    jsdialog: mobile version of spell dialog
    
    Change-Id: I611b09a8ffb6eb1972ba8702a7a76c9e6ab25fb4

diff --git a/cui/source/dialogs/SpellDialog.cxx b/cui/source/dialogs/SpellDialog.cxx
index 68ef370f65e7..b246f1268b2d 100644
--- a/cui/source/dialogs/SpellDialog.cxx
+++ b/cui/source/dialogs/SpellDialog.cxx
@@ -60,6 +60,8 @@
 #include <svtools/langtab.hxx>
 #include <cppuhelper/exc_hlp.hxx>
 #include <sal/log.hxx>
+#include <comphelper/lok.hxx>
+#include <sfx2/lokhelper.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -192,9 +194,23 @@ SpellDialog::SpellDialog(SpellDialogChildWindow* pChildWindow,
     , m_xOptionsPB(m_xBuilder->weld_button("options"))
     , m_xUndoPB(m_xBuilder->weld_button("undo"))
     , m_xClosePB(m_xBuilder->weld_button("close"))
+    , m_xHelpPB(m_xBuilder->weld_button("help"))
     , m_xToolbar(m_xBuilder->weld_toolbar("toolbar"))
     , m_xSentenceEDWeld(new weld::CustomWeld(*m_xBuilder, "sentence", *m_xSentenceED))
+    , m_xMobileError(m_xBuilder->weld_label("mobile-spell-error"))
 {
+    m_xSentenceED->SetMobileErrorLabel(m_xMobileError);
+
+    if (comphelper::LibreOfficeKit::isActive()
+        && comphelper::LibreOfficeKit::isMobile(SfxLokHelper::getView()))
+    {
+        m_xClosePB->hide();
+        m_xHelpPB->hide();
+        m_xOptionsPB->hide();
+        m_xSentenceEDWeld->hide();
+        m_xMobileError->set_visible(true);
+    }
+
     m_xSentenceED->SetSpellDialog(this);
     m_xSentenceED->Init(m_xToolbar.get());
 
@@ -1667,6 +1683,7 @@ bool SentenceEditWindow_Impl::MarkNextError( bool bIgnoreCurrentError, const css
         if (pEECharAttrib)
         {
             ExtractErrorDescription(*pEECharAttrib, aSpellErrorDescription);
+            m_xMobileError->set_label(aSpellErrorDescription.sErrorText);
 
             bGrammarError = aSpellErrorDescription.bIsGrammarError;
             m_nErrorStart = pEECharAttrib->nStart;
diff --git a/cui/source/inc/SpellDialog.hxx b/cui/source/inc/SpellDialog.hxx
index 30d8627084cb..92d4a9ed6391 100644
--- a/cui/source/inc/SpellDialog.hxx
+++ b/cui/source/inc/SpellDialog.hxx
@@ -65,6 +65,7 @@ class SentenceEditWindow_Impl : public weld::CustomWidgetController
 private:
     std::unique_ptr<EditEngine> m_xEditEngine;
     std::unique_ptr<EditView> m_xEdView;
+    std::shared_ptr<weld::Label> m_xMobileError;
 
     std::set<sal_Int32> m_aIgnoreErrorsAt;
     SpellDialog*        m_pSpellDialog;
@@ -155,6 +156,8 @@ public:
     void            MoveErrorEnd(long nOffset);
 
     void            ResetIgnoreErrorsAt()   { m_aIgnoreErrorsAt.clear(); }
+
+    void            SetMobileErrorLabel(std::shared_ptr<weld::Label> xMobileError) { m_xMobileError = xMobileError; }
 };
 
 // class SvxSpellDialog ---------------------------------------------
@@ -206,8 +209,10 @@ private:
     std::unique_ptr<weld::Button> m_xOptionsPB;
     std::unique_ptr<weld::Button> m_xUndoPB;
     std::unique_ptr<weld::Button> m_xClosePB;
+    std::unique_ptr<weld::Button> m_xHelpPB;
     std::unique_ptr<weld::Toolbar> m_xToolbar;
     std::unique_ptr<weld::CustomWeld> m_xSentenceEDWeld;
+    std::shared_ptr<weld::Label> m_xMobileError;
 
     DECL_LINK(ChangeHdl, weld::Button&, void);
     DECL_LINK(DoubleClickChangeHdl, weld::TreeView&, void);
diff --git a/cui/uiconfig/ui/spellingdialog.ui b/cui/uiconfig/ui/spellingdialog.ui
index ccc6a30e7a46..168c00670983 100644
--- a/cui/uiconfig/ui/spellingdialog.ui
+++ b/cui/uiconfig/ui/spellingdialog.ui
@@ -81,6 +81,7 @@
                 <property name="receives_default">True</property>
                 <property name="use_underline">True</property>
                 <property name="use_stock">True</property>
+                <property name="sensitive">False</property>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -425,6 +426,18 @@
                 <property name="top_attach">2</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkLabel" id="mobile-spell-error">
+                <property name="visible">False</property>
+                <property name="can_focus">False</property>
+                <property name="halign">end</property>
+                <property name="toolbar_style">icons</property>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="top_attach">2</property>
+              </packing>
+            </child>
             <child>
               <object class="GtkScrolledWindow">
                 <property name="visible">True</property>
diff --git a/solenv/sanitizers/ui/cui.suppr b/solenv/sanitizers/ui/cui.suppr
index 59f22233ff39..549954c47a90 100644
--- a/solenv/sanitizers/ui/cui.suppr
+++ b/solenv/sanitizers/ui/cui.suppr
@@ -460,6 +460,7 @@ cui/uiconfig/ui/spellingdialog.ui://GtkLabel[@id='explain'] orphan-label
 cui/uiconfig/ui/spellingdialog.ui://GtkLabel[@id='resumeft'] orphan-label
 cui/uiconfig/ui/spellingdialog.ui://GtkLabel[@id='nosuggestionsft'] orphan-label
 cui/uiconfig/ui/spellingdialog.ui://GtkLabel[@id='alttitleft'] orphan-label
+cui/uiconfig/ui/spellingdialog.ui://GtkLabel[@id='mobile-spell-error'] orphan-label
 cui/uiconfig/ui/storedwebconnectiondialog.ui://GtkLabel[@id='label1'] orphan-label
 cui/uiconfig/ui/storedwebconnectiondialog.ui://GtkLabel[@id='website'] orphan-label
 cui/uiconfig/ui/storedwebconnectiondialog.ui://GtkLabel[@id='username'] orphan-label
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index efd46f9adec0..d9786bc4d70b 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -154,6 +154,7 @@ weld::Builder* Application::CreateBuilder(weld::Widget* pParent, const OUString
             rUIFile == "modules/scalc/ui/validationcriteriapage.ui" ||
             rUIFile == "modules/scalc/ui/validationhelptabpage-mobile.ui" ||
             rUIFile == "modules/scalc/ui/erroralerttabpage-mobile.ui" ||
+            rUIFile == "cui/ui/spellingdialog.ui" ||
             rUIFile == "modules/swriter/ui/watermarkdialog.ui")
             bUseJSBuilder = true;
     }
commit 59d72551a6c886ba7004d2f21253d0cd478828c8
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Wed Mar 25 13:04:08 2020 +0100
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Tue Mar 31 16:11:00 2020 +0200

    jsdialog: resend JSON only if changed
    
    Change-Id: I80a0faf7544c66e30576d2342315a1f9f508fc12

diff --git a/include/vcl/jsdialog/jsdialogbuilder.hxx b/include/vcl/jsdialog/jsdialogbuilder.hxx
index de9c383328a1..d01d878828c2 100644
--- a/include/vcl/jsdialog/jsdialogbuilder.hxx
+++ b/include/vcl/jsdialog/jsdialogbuilder.hxx
@@ -64,24 +64,21 @@ public:
     , JSDialogSender(aOwnedToplevel)
     {}
 
-    virtual void show() override
+    virtual void set_visible(bool visible) override
     {
-        BaseInstanceClass::show();
-        notifyDialogState();
-    }
-
-    virtual void hide() override
-    {
-        BaseInstanceClass::hide();
-        notifyDialogState();
+        bool change = visible != BaseInstanceClass::get_visible();
+        BaseInstanceClass::set_visible(visible);
+        if (change)
+            notifyDialogState();
     }
 
     virtual void set_sensitive(bool sensitive) override
     {
         bool change = sensitive != BaseInstanceClass::get_sensitive();
         BaseInstanceClass::set_sensitive(sensitive);
-        if (change)
+        if (change) {
             notifyDialogState();
+        }
     }
 };
 
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index dc84dbe814c2..7db752b77045 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -283,8 +283,10 @@ JSLabel::JSLabel(VclPtr<vcl::Window> aOwnedToplevel, FixedText* pLabel,
 
 void JSLabel::set_label(const OUString& rText)
 {
+    bool change = get_label() != rText;
     SalInstanceLabel::set_label(rText);
-    notifyDialogState();
+    if (change)
+        notifyDialogState();
 };
 
 JSButton::JSButton(VclPtr<vcl::Window> aOwnedToplevel, ::Button* pButton,
@@ -302,8 +304,10 @@ JSEntry::JSEntry(VclPtr<vcl::Window> aOwnedToplevel, ::Edit* pEntry,
 
 void JSEntry::set_text(const OUString& rText)
 {
+    bool change = get_text() != rText;
     SalInstanceEntry::set_text(rText);
-    notifyDialogState();
+    if (change)
+        notifyDialogState();
 }
 
 JSListBox::JSListBox(VclPtr<vcl::Window> aOwnedToplevel, ::ListBox* pListBox,
@@ -430,8 +434,10 @@ JSCheckButton::JSCheckButton(VclPtr<vcl::Window> aOwnedToplevel, ::CheckBox* pCh
 
 void JSCheckButton::set_state(TriState eState)
 {
+    bool change = get_state() != eState;
     SalInstanceCheckButton::set_state(eState);
-    notifyDialogState();
+    if (change)
+        notifyDialogState();
 }
 
 JSTreeView::JSTreeView(VclPtr<vcl::Window> aOwnedToplevel, ::SvTabListBox* pTreeView,


More information about the Libreoffice-commits mailing list