sw/source/uibase/app/apphdl.cxx | 50 ++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 17 deletions(-)
New commits: commit 9a115a254171d702a56a93c5c7e320de755dc8e8 Author: Justin Luth <justin_l...@sil.org> AuthorDate: Thu Dec 9 19:48:46 2021 +0200 Commit: Justin Luth <jl...@mail.com> CommitDate: Fri Dec 10 07:14:41 2021 +0100 tdf#144680 mailmerge toolbar: enable icons unless no resultset 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 <jl...@mail.com> diff --git a/sw/source/uibase/app/apphdl.cxx b/sw/source/uibase/app/apphdl.cxx index dd2b943f476a..4e68665ead51 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,43 @@ 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) + assert(xConfigItem); + if (!xConfigItem->GetResultSet().is()) + { + // 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.Update(); return; - xConfigItem->SetTargetView(nullptr); - SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); - switch (nWhich) + } + + if (nWhich == FN_MAILMERGE_CREATE_DOCUMENTS) { - 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; + 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;