diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc index 3d28229a8e1b..b4017a06cc80 100644 --- a/sw/inc/strings.hrc +++ b/sw/inc/strings.hrc @@ -1402,6 +1402,9 @@ #define STR_AUTOMARK_NO NC_("createautomarkdialog|no", "No") #define STR_WRAP_PANEL_CUSTOM_STR NC_("sidebarwrap|customlabel", "Custom") +#define STR_DATASOURCE_NOT_AVAILABLE NC_("STR_DATASOURCE_NOT_AVAILABLE", "Data source is not available. Mail merge wizard will not work properly.") +#define STR_EXCHANGE_DATABASE NC_("STR_EXCHANGE_DATABASE", "Exchange Database") + #endif diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx index 2b7fe95094ec..4232d315478a 100644 --- a/sw/inc/view.hxx +++ b/sw/inc/view.hxx @@ -555,6 +555,8 @@ public: // form control has been activated DECL_LINK( FormControlActivated, LinkParamNone*, void ); + DECL_LINK( ExchangeDatabaseHandler, weld::Button&, void); + // edit links void EditLinkDlg(); void AutoCaption(const sal_uInt16 nType, const SvGlobalName *pOleId = nullptr); @@ -624,6 +626,10 @@ public: std::shared_ptr const & GetMailMergeConfigItem() const; std::shared_ptr EnsureMailMergeConfigItem(const SfxItemSet* pArgs = nullptr); + OUString GetDataSourceName() const; + static bool IsDataSourceAvailable(const OUString sDataSourceName); + void AppendDataSourceInfobar(); + void ExecFormatPaintbrush(SfxRequest const &); void StateFormatPaintbrush(SfxItemSet &); diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx index 97ae1d94010e..fc63c5568e42 100644 --- a/sw/source/uibase/uiview/view.cxx +++ b/sw/source/uibase/uiview/view.cxx @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include #include @@ -66,6 +68,7 @@ #include #include #include +#include #include #include #include @@ -84,6 +87,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -105,6 +112,8 @@ using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::scanner; +using namespace ::com::sun::star::sdb; +using namespace ::com::sun::star::sdbc; #define SWVIEWFLAGS SfxViewShellFlags::HAS_PRINTOPTIONS @@ -203,6 +212,11 @@ IMPL_LINK_NOARG(SwView, FormControlActivated, LinkParamNone*, void) } } +IMPL_LINK_NOARG(SwView, ExchangeDatabaseHandler, weld::Button&, void) +{ + GetDispatcher().Execute(FN_CHANGE_DBFIELD); +} + namespace { uno::Reference getLayoutManager(const SfxViewFrame& rViewFrame) @@ -1629,7 +1643,25 @@ void SwView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) } else { + if (auto pSfxEventHint = dynamic_cast(&rHint)) + { + switch( pSfxEventHint->GetEventId() ) + { + case SfxEventHintId::CreateDoc: + case SfxEventHintId::OpenDoc: + { + OUString sDataSourceName = GetDataSourceName(); + if ( !sDataSourceName.isEmpty() && !IsDataSourceAvailable(sDataSourceName)) + AppendDataSourceInfobar(); + } + break; + default: + break; + } + } + SfxHintId nId = rHint.GetId(); + switch ( nId ) { // sub shells will be destroyed by the @@ -1710,7 +1742,6 @@ void SwView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) GetViewFrame()->GetBindings().Invalidate(aSlotRedLine); } break; - default: break; } } @@ -1873,6 +1904,38 @@ tools::Rectangle SwView::getLOKVisibleArea() const return tools::Rectangle(); } +OUString SwView::GetDataSourceName() const +{ + uno::Reference xFactory(GetDocShell()->GetModel(), uno::UNO_QUERY); + uno::Reference xSettings( + xFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY); + OUString sDataSourceName = ""; + xSettings->getPropertyValue("CurrentDatabaseDataSource") >>= sDataSourceName; + + return sDataSourceName; +} + +bool SwView::IsDataSourceAvailable(const OUString sDataSourceName) +{ + uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() ); + Reference< XDatabaseContext> xDatabaseContext = DatabaseContext::create(xContext); + + return xDatabaseContext->hasByName(sDataSourceName); +} + +void SwView::AppendDataSourceInfobar() +{ + auto pInfoBar = GetViewFrame()->AppendInfoBar("datasource", "", + SwResId(STR_DATASOURCE_NOT_AVAILABLE), + InfobarType::WARNING); + if (!pInfoBar) + return; + + weld::Button& rBtn = pInfoBar->addButton(); + rBtn.set_label(SwResId(STR_EXCHANGE_DATABASE)); + rBtn.connect_clicked(LINK(this, SwView, ExchangeDatabaseHandler)); +} + namespace sw { void InitPrintOptionsFromApplication(SwPrintData & o_rData, bool const bWeb)