tdf#144680 mailmerge toolbar: enable icons unless no resultset
which backports 7.4 commit 9a115a254171d702a56a93c5c7e320de755dc8e8
plus tdf#144680 mailmerge toolbar: disable all icons if no resultset
(7.4 commit 16376cae68f4406ef9440bdcb7b9617de6a6f998)
plus a backport-only paranoid check to ensure that xConfigItem exists.
This fixes a problem introduced in LO 6.3 (backported to 6.1.5)
via commit 60714a814847f6d10f00aa6809a3896a48741e0b
tdf#121606: displaying Mail Merge toolbar shouldn't activate connection
Before 6.1, a user needed to run the mailmerge wizard
(or start the toolbar manually) in order to have
the mailmerge toolbar become available. In either of those cases,
the connection to the database was attempted and thus enabled
or disabled the various buttons based on the status. All good.
In 6.1, the toolbar was started on document load,
as soon as database fields were detected.
Sounds reasonable - good context sensitive UI.
The problem is that databases can often be password protected,
or on slow, remote sites. Thus the 6.3 commit mentioned above,
which disabled most buttons until the connection was established.
Well, having disabled buttons isn't too helpful,
and basically put us back to needing the extra step of
running the mail-merge wizard anyway.
The only problem with leaving them enabled is that we need to
ensure that we don't run the functions with bad results.
So sure - this means that a user thinks they can use the
mail-merge, attempt it, and then may find the buttons disable
when it won't work. That is the same as the forward/backwards
buttons though, so no big deal. Plus it is good feedback that
something isn't right (which will rarely ever be true).
The only time the buttons disable is for non-existant resultsets.
[Note that buttons do NOT disable for a wrong password,
or for a remote connection that can't be established.
And that is what we want anyway, so that further attempts
can be made after fixing the underlying problem.]
Change-Id: I3e82d2d3b35d04632650933c768cb0b5c006cb6f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126625
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126633
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
diff --git a/sw/source/uibase/app/apphdl.cxx b/sw/source/uibase/app/apphdl.cxx
index dd2b943..6532ff0 100644
--- a/sw/source/uibase/app/apphdl.cxx
+++ b/sw/source/uibase/app/apphdl.cxx
@@ -210,12 +210,12 @@ void SwModule::StateOther(SfxItemSet &rSet)
// #i51949# hide e-Mail option if e-Mail is not supported
// #i63267# printing might be disabled
// Without attempting to open the database, (in case it is remote or passworded),
// hide everything after determining there are no valid results. tdf#121606
if (!xConfigItem ||
!xConfigItem->GetConnection().is() ||
xConfigItem->GetConnection()->isClosed() ||
!xConfigItem->GetResultSet().is() ||
xConfigItem->GetCurrentDBData().sDataSource.isEmpty() ||
xConfigItem->GetCurrentDBData().sCommand.isEmpty() ||
(xConfigItem->GetConnection().is() && !xConfigItem->GetConnection()->isClosed() && !xConfigItem->GetResultSet().is()) ||
(nWhich == FN_MAILMERGE_PRINT_DOCUMENTS && Application::GetSettings().GetMiscSettings().GetDisablePrinting()) ||
(nWhich == FN_MAILMERGE_EMAIL_DOCUMENTS && !xConfigItem->IsMailAvailable()))
{
@@ -806,27 +806,47 @@ void SwModule::ExecOther(SfxRequest& rReq)
}
break;
case FN_MAILMERGE_CREATE_DOCUMENTS:
{
std::shared_ptr<SwMailMergeConfigItem> xConfigItem = SwDBManager::PerformMailMerge(GetActiveView());
if (xConfigItem && xConfigItem->GetTargetView())
xConfigItem->GetTargetView()->GetViewFrame()->GetFrame().Appear();
}
break;
case FN_MAILMERGE_SAVE_DOCUMENTS:
case FN_MAILMERGE_PRINT_DOCUMENTS:
case FN_MAILMERGE_EMAIL_DOCUMENTS:
{
std::shared_ptr<SwMailMergeConfigItem> xConfigItem = GetActiveView()->GetMailMergeConfigItem();
if(!xConfigItem)
return;
xConfigItem->SetTargetView(nullptr);
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
switch (nWhich)
assert(xConfigItem);
if (!xConfigItem || !xConfigItem->GetResultSet().is())
{
case FN_MAILMERGE_SAVE_DOCUMENTS: pFact->ExecuteMMResultSaveDialog(rReq.GetFrameWeld()); break;
case FN_MAILMERGE_PRINT_DOCUMENTS: pFact->ExecuteMMResultPrintDialog(rReq.GetFrameWeld()); break;
case FN_MAILMERGE_EMAIL_DOCUMENTS: pFact->ExecuteMMResultEmailDialog(rReq.GetFrameWeld()); break;
// The connection has been attempted, but failed or no results found,
// so invalidate the toolbar buttons in case they need to be disabled.
SfxBindings& rBindings
= GetActiveView()->GetWrtShell().GetView().GetViewFrame()->GetBindings();
rBindings.Invalidate(FN_MAILMERGE_CREATE_DOCUMENTS);
rBindings.Invalidate(FN_MAILMERGE_SAVE_DOCUMENTS);
rBindings.Invalidate(FN_MAILMERGE_PRINT_DOCUMENTS);
rBindings.Invalidate(FN_MAILMERGE_EMAIL_DOCUMENTS);
rBindings.Invalidate(FN_MAILMERGE_FIRST_ENTRY);
rBindings.Invalidate(FN_MAILMERGE_PREV_ENTRY);
rBindings.Invalidate(FN_MAILMERGE_NEXT_ENTRY);
rBindings.Invalidate(FN_MAILMERGE_LAST_ENTRY);
rBindings.Update();
return;
}
if (nWhich == FN_MAILMERGE_CREATE_DOCUMENTS)
{
xConfigItem = SwDBManager::PerformMailMerge(GetActiveView());
if (xConfigItem && xConfigItem->GetTargetView())
xConfigItem->GetTargetView()->GetViewFrame()->GetFrame().Appear();
}
else
{
xConfigItem->SetTargetView(nullptr);
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
if (nWhich == FN_MAILMERGE_SAVE_DOCUMENTS)
pFact->ExecuteMMResultSaveDialog(rReq.GetFrameWeld());
else if (nWhich == FN_MAILMERGE_PRINT_DOCUMENTS)
pFact->ExecuteMMResultPrintDialog(rReq.GetFrameWeld());
else if (nWhich == FN_MAILMERGE_EMAIL_DOCUMENTS)
pFact->ExecuteMMResultEmailDialog(rReq.GetFrameWeld());
}
}
break;