[Libreoffice-commits] core.git: sw/source

Caolán McNamara caolanm at redhat.com
Tue Jul 26 15:22:04 UTC 2016


 sw/source/uibase/dbui/mmconfigitem.cxx |   79 ++++++++++++++++++++++++++++++++-
 sw/source/uibase/inc/mmconfigitem.hxx  |    6 ++
 2 files changed, 82 insertions(+), 3 deletions(-)

New commits:
commit adf874c7cc21aedd29286d2ca860b4fd201f87d2
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Jul 26 14:39:27 2016 +0100

    Resolves: tdf#98984 make MailMerge listen for database change
    
    and update to take the new database set on the document instead of
    retaining the initial database
    
    note that now SetCurrentDBData also throws away the old m_xResultSet to force a
    new one to be fetched
    
    Change-Id: Id50287915064949296ee73211e16bbba46ced229

diff --git a/sw/source/uibase/dbui/mmconfigitem.cxx b/sw/source/uibase/dbui/mmconfigitem.cxx
index 1eed5cd..c5c833c 100644
--- a/sw/source/uibase/dbui/mmconfigitem.cxx
+++ b/sw/source/uibase/dbui/mmconfigitem.cxx
@@ -24,6 +24,7 @@
 #include <osl/diagnose.h>
 #include <com/sun/star/uno/Any.hxx>
 #include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/frame/XDispatch.hpp>
 #include <com/sun/star/sdb/XCompletedConnection.hpp>
 #include <com/sun/star/sdbc/XDataSource.hpp>
 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
@@ -43,6 +44,7 @@
 #include <swunohelper.hxx>
 #include <dbmgr.hxx>
 #include <view.hxx>
+#include <unodispatch.hxx>
 #include <wrtsh.hxx>
 #include <dbui.hrc>
 #include <vector>
@@ -732,8 +734,25 @@ SwMailMergeConfigItem::SwMailMergeConfigItem() :
     m_pTargetView(nullptr)
 {}
 
+void SwMailMergeConfigItem::stopDBChangeListening()
+{
+    if (m_xDBChangedListener.is())
+    {
+        uno::Reference<view::XSelectionSupplier> xSupplier = m_pSourceView->GetUNOObject();
+        xSupplier->removeSelectionChangeListener(m_xDBChangedListener);
+        m_xDBChangedListener.clear();
+    }
+}
+
+void SwMailMergeConfigItem::updateCurrentDBDataFromDocument()
+{
+    const SwDBData& rDBData = m_pSourceView->GetWrtShell().GetDBDesc();
+    SetCurrentDBData(rDBData);
+}
+
 SwMailMergeConfigItem::~SwMailMergeConfigItem()
 {
+    stopDBChangeListening();
 }
 
 void  SwMailMergeConfigItem::Commit()
@@ -857,6 +876,7 @@ void SwMailMergeConfigItem::SetCurrentDBData( const SwDBData& rDBData)
         m_pImpl->m_aDBData = rDBData;
         m_pImpl->m_xConnection.clear();
         m_pImpl->m_xSource = nullptr;
+        m_pImpl->m_xResultSet = nullptr;
         m_pImpl->m_xColumnsSupplier = nullptr;
         m_pImpl->SetModified();
     }
@@ -1613,16 +1633,63 @@ SwView* SwMailMergeConfigItem::GetSourceView()
     return m_pSourceView;
 }
 
+//This implements XSelectionChangeListener and XDispatch because the
+//broadcaster uses this combo to determine if to send the database-changed
+//update. Its probably that listening to statusChanged at some other level is
+//equivalent to this. See the other call to SwXDispatch::GetDBChangeURL for
+//the broadcaster of the event.
+class DBChangeListener : public cppu::WeakImplHelper<css::view::XSelectionChangeListener, css::frame::XDispatch>
+{
+    SwMailMergeConfigItem& m_rParent;
+public:
+    explicit DBChangeListener(SwMailMergeConfigItem& rParent)
+        : m_rParent(rParent)
+    {
+    }
+
+    virtual void SAL_CALL selectionChanged(const EventObject& /*rEvent*/) throw (css::uno::RuntimeException, std::exception) override
+    {
+    }
+
+    virtual void SAL_CALL disposing(const EventObject&) throw (css::uno::RuntimeException, std::exception) override
+    {
+        m_rParent.stopDBChangeListening();
+    }
+
+    virtual void SAL_CALL dispatch(const css::util::URL& rURL, const css::uno::Sequence< css::beans::PropertyValue >& /*rArgs*/)
+        throw (css::uno::RuntimeException,
+               std::exception) override
+    {
+        if (rURL.Complete.equalsAscii(SwXDispatch::GetDBChangeURL()))
+            m_rParent.updateCurrentDBDataFromDocument();
+    }
+
+    virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener >&, const css::util::URL&) throw(css::uno::RuntimeException, std::exception) override
+    {
+    }
+
+    virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >&, const css::util::URL&) throw(css::uno::RuntimeException, std::exception) override
+    {
+    }
+};
+
 void SwMailMergeConfigItem::SetSourceView(SwView* pView)
 {
+    if (m_xDBChangedListener.is())
+    {
+        uno::Reference<view::XSelectionSupplier> xSupplier = m_pSourceView->GetUNOObject();
+        xSupplier->removeSelectionChangeListener(m_xDBChangedListener);
+        m_xDBChangedListener.clear();
+    }
+
     m_pSourceView = pView;
 
-    if (!pView)
+    if (!m_pSourceView)
         return;
 
     std::vector<OUString> aDBNameList;
     std::vector<OUString> aAllDBNames;
-    pView->GetWrtShell().GetAllUsedDB( aDBNameList, &aAllDBNames );
+    m_pSourceView->GetWrtShell().GetAllUsedDB( aDBNameList, &aAllDBNames );
     if(!aDBNameList.empty())
     {
         // if fields are available there is usually no need of an addressblock and greeting
@@ -1656,6 +1723,14 @@ void SwMailMergeConfigItem::SetSourceView(SwView* pView)
 
         m_pImpl->m_bUserSettingWereOverwritten = false;
     }
+
+    if (!m_xDBChangedListener.is())
+    {
+        m_xDBChangedListener.set(new DBChangeListener(*this));
+    }
+
+    uno::Reference<view::XSelectionSupplier> xSupplier = m_pSourceView->GetUNOObject();
+    xSupplier->addSelectionChangeListener(m_xDBChangedListener);
 }
 
 void SwMailMergeConfigItem::SetCurrentAddressBlockIndex( sal_Int32 nSet )
diff --git a/sw/source/uibase/inc/mmconfigitem.hxx b/sw/source/uibase/inc/mmconfigitem.hxx
index b952f77..b16f280 100644
--- a/sw/source/uibase/inc/mmconfigitem.hxx
+++ b/sw/source/uibase/inc/mmconfigitem.hxx
@@ -21,6 +21,7 @@
 
 #include <com/sun/star/uno/Sequence.hxx>
 #include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/view/XSelectionChangeListener.hpp>
 #include <tools/resary.hxx>
 #include <memory>
 #include <set>
@@ -58,6 +59,7 @@ class SW_DLLPUBLIC SwMailMergeConfigItem
     sal_Int32 m_nGreetingMoves;
     OUString m_rAddressBlockFrame;
     std::set<sal_Int32> m_aExcludedRecords;
+    css::uno::Reference<css::view::XSelectionChangeListener> m_xDBChangedListener;
 
     sal_uInt16 m_nStartPrint;
     sal_uInt16 m_nEndPrint;
@@ -253,7 +255,9 @@ public:
     void SetSourceView(SwView* pView);
 
     //helper methods
-    OUString GetAssignedColumn(sal_uInt32 nColumn)const;
+    OUString GetAssignedColumn(sal_uInt32 nColumn) const;
+    void stopDBChangeListening();
+    void updateCurrentDBDataFromDocument();
 };
 
 #endif


More information about the Libreoffice-commits mailing list