summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2016-07-26 14:39:27 +0100
committerCaolán McNamara <caolanm@redhat.com>2016-07-26 16:21:44 +0100
commitadf874c7cc21aedd29286d2ca860b4fd201f87d2 (patch)
tree0f1abe4b74f43927150718327dc6bf7d8eacfc7d /sw
parent9710fd565f17278dc5e5ee645b3924544a8c4235 (diff)
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
Diffstat (limited to 'sw')
-rw-r--r--sw/source/uibase/dbui/mmconfigitem.cxx79
-rw-r--r--sw/source/uibase/inc/mmconfigitem.hxx6
2 files changed, 82 insertions, 3 deletions
diff --git a/sw/source/uibase/dbui/mmconfigitem.cxx b/sw/source/uibase/dbui/mmconfigitem.cxx
index 1eed5cdd9845..c5c833cd2c79 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 b952f77edbc4..b16f280141ef 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