summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2020-01-06 01:20:13 +0300
committerMiklos Vajna <vmiklos@collabora.com>2020-02-04 09:16:16 +0100
commita8070d38c81c64e9e9cff0ea28fdcffc2763c365 (patch)
tree49e4b60a631e8faafad8ffa4176e535ebf16d3cf /sw
parent4098608ea21d4737fdd640fd57c2417e56426fbb (diff)
tdf#129798: store SwWrtShell when it's available
GetActiveWrtShell may return nullptr when attaching a new component to current frame, e.g. destroying on print preview. OTOH SwWrtShell is passed to SwFieldDBPage::SetWrtShell on creation, so store it to own base class then. Possibly that would be enough, and we could remove all the checks in other methods - but I don't know the code well enough to be sure that SwFieldDlg::PageCreated and SwFieldEditDlg::CreatePage will always set SwWrtShell; to be on the safe side, I kept the checks where SwWrtShell is used, and stored it in those places if not yet stored. Regression after commit 39ba5e3bde93358af1b363da8f850bdc96806cfa. Change-Id: I21f3c8ef24764e98b1bc287db3c6485ce0b3ab48 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86253 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87947 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/ui/fldui/flddb.cxx58
-rw-r--r--sw/source/ui/fldui/flddb.hxx1
2 files changed, 35 insertions, 24 deletions
diff --git a/sw/source/ui/fldui/flddb.cxx b/sw/source/ui/fldui/flddb.cxx
index 3feac5488241..59b59b31607e 100644
--- a/sw/source/ui/fldui/flddb.cxx
+++ b/sw/source/ui/fldui/flddb.cxx
@@ -79,13 +79,14 @@ SwFieldDBPage::~SwFieldDBPage()
void SwFieldDBPage::dispose()
{
- SwWrtShell* pSh = GetWrtShell();
- if (!pSh)
- pSh = ::GetActiveWrtShell();
- // This would cleanup in the case of cancelled dialog
- SwDBManager* pDbManager = pSh->GetDoc()->GetDBManager();
- if (pDbManager)
- pDbManager->RevokeLastRegistrations();
+ // If we have no stored SwWrtShell, it means we didn't do anything useful - no need to revoke.
+ if (SwWrtShell* pSh = GetWrtShell())
+ {
+ // This would cleanup in the case of cancelled dialog
+ SwDBManager* pDbManager = pSh->GetDoc()->GetDBManager();
+ if (pDbManager)
+ pDbManager->RevokeLastRegistrations();
+ }
m_pTypeLB.clear();
m_pDatabaseTLB.clear();
@@ -160,9 +161,7 @@ void SwFieldDBPage::Reset(const SfxItemSet*)
}
else
{
- SwWrtShell *pSh = GetWrtShell();
- if(!pSh)
- pSh = ::GetActiveWrtShell();
+ SwWrtShell *pSh = CheckAndGetWrtShell();
if(pSh)
{
SwDBData aTmp(pSh->GetDBData());
@@ -213,9 +212,8 @@ bool SwFieldDBPage::FillItemSet(SfxItemSet* )
aData.sDataSource = m_pDatabaseTLB->GetDBName(sTableName, sColumnName, &bIsTable);
aData.sCommand = sTableName;
aData.nCommandType = bIsTable ? 0 : 1;
- SwWrtShell *pSh = GetWrtShell();
- if(!pSh)
- pSh = ::GetActiveWrtShell();
+ SwWrtShell *pSh = CheckAndGetWrtShell();
+ assert(pSh);
SwDBManager* pDbManager = pSh->GetDoc()->GetDBManager();
if (pDbManager)
@@ -309,9 +307,8 @@ void SwFieldDBPage::TypeHdl( ListBox const * pBox )
if (nOld == GetTypeSel())
return;
- SwWrtShell *pSh = GetWrtShell();
- if(!pSh)
- pSh = ::GetActiveWrtShell();
+ SwWrtShell *pSh = CheckAndGetWrtShell();
+ assert(pSh);
bool bCond = false, bSetNo = false, bFormat = false, bDBFormat = false;
const sal_uInt16 nTypeId = static_cast<sal_uInt16>(reinterpret_cast<sal_uLong>(m_pTypeLB->GetEntryData(GetTypeSel())));
@@ -499,15 +496,14 @@ IMPL_LINK( SwFieldDBPage, TreeSelectHdl, SvTreeListBox *, pBox, void )
IMPL_LINK_NOARG(SwFieldDBPage, AddDBHdl, Button*, void)
{
- SwWrtShell* pSh = GetWrtShell();
- if (!pSh)
- pSh = ::GetActiveWrtShell();
-
- OUString sNewDB
- = SwDBManager::LoadAndRegisterDataSource(GetFrameWeld(), pSh->GetDoc()->GetDocShell());
- if(!sNewDB.isEmpty())
+ if (SwWrtShell* pSh = CheckAndGetWrtShell())
{
- m_pDatabaseTLB->AddDataSource(sNewDB);
+ OUString sNewDB
+ = SwDBManager::LoadAndRegisterDataSource(GetFrameWeld(), pSh->GetDoc()->GetDocShell());
+ if (!sNewDB.isEmpty())
+ {
+ m_pDatabaseTLB->AddDataSource(sNewDB);
+ }
}
}
@@ -535,7 +531,21 @@ void SwFieldDBPage::ActivateMailMergeAddress()
void SwFieldDBPage::SetWrtShell(SwWrtShell& rSh)
{
+ // We need to remember the shell to be able to call correct SwDBManager
+ SwFieldPage::SetWrtShell(&rSh);
m_pDatabaseTLB->SetWrtShell(rSh);
}
+SwWrtShell* SwFieldDBPage::CheckAndGetWrtShell()
+{
+ SwWrtShell* pSh = GetWrtShell();
+ if (!pSh)
+ {
+ pSh = ::GetActiveWrtShell();
+ if (pSh) // this is not guaranteed: e.g., activating print preview with dialog active
+ SetWrtShell(*pSh);
+ }
+ return pSh;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/ui/fldui/flddb.hxx b/sw/source/ui/fldui/flddb.hxx
index b8121bb2affd..2c3a98578cfe 100644
--- a/sw/source/ui/fldui/flddb.hxx
+++ b/sw/source/ui/fldui/flddb.hxx
@@ -63,6 +63,7 @@ class SwFieldDBPage : public SwFieldPage
void CheckInsert();
using SwFieldPage::SetWrtShell;
+ SwWrtShell* CheckAndGetWrtShell();
protected:
virtual sal_uInt16 GetGroup() override;