summaryrefslogtreecommitdiff
path: root/sw/source/ui
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2020-01-06 01:20:13 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2020-01-06 07:36:19 +0100
commit016c69c99e1ab26e6582ca8dea6fa1b4b9e5d109 (patch)
tree50457543bbba357a360e8b74d9ab398749ebab59 /sw/source/ui
parent0b4f8bf571baf2ccd5a8aafdc4deb41867420be3 (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>
Diffstat (limited to 'sw/source/ui')
-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 dfa97a5c1a5b..01b9065cd36e 100644
--- a/sw/source/ui/fldui/flddb.cxx
+++ b/sw/source/ui/fldui/flddb.cxx
@@ -70,13 +70,14 @@ SwFieldDBPage::SwFieldDBPage(weld::Container* pPage, weld::DialogController* pCo
SwFieldDBPage::~SwFieldDBPage()
{
- 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();
+ }
}
// initialise TabPage
@@ -137,9 +138,7 @@ void SwFieldDBPage::Reset(const SfxItemSet*)
}
else
{
- SwWrtShell *pSh = GetWrtShell();
- if(!pSh)
- pSh = ::GetActiveWrtShell();
+ SwWrtShell *pSh = CheckAndGetWrtShell();
if(pSh)
{
SwDBData aTmp(pSh->GetDBData());
@@ -192,9 +191,8 @@ bool SwFieldDBPage::FillItemSet(SfxItemSet* )
aData.sDataSource = m_xDatabaseTLB->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)
@@ -288,9 +286,8 @@ void SwFieldDBPage::TypeHdl(const weld::TreeView* 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 SwFieldTypesEnum nTypeId = static_cast<SwFieldTypesEnum>(m_xTypeLB->get_id(GetTypeSel()).toUInt32());
@@ -483,15 +480,14 @@ IMPL_LINK(SwFieldDBPage, TreeSelectHdl, weld::TreeView&, rBox, void)
IMPL_LINK_NOARG(SwFieldDBPage, AddDBHdl, weld::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_xDatabaseTLB->AddDataSource(sNewDB);
+ OUString sNewDB
+ = SwDBManager::LoadAndRegisterDataSource(GetFrameWeld(), pSh->GetDoc()->GetDocShell());
+ if (!sNewDB.isEmpty())
+ {
+ m_xDatabaseTLB->AddDataSource(sNewDB);
+ }
}
}
@@ -519,7 +515,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_xDatabaseTLB->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 ed499cbe9755..e507fcb86ee0 100644
--- a/sw/source/ui/fldui/flddb.hxx
+++ b/sw/source/ui/fldui/flddb.hxx
@@ -56,6 +56,7 @@ class SwFieldDBPage : public SwFieldPage
void CheckInsert();
using SwFieldPage::SetWrtShell;
+ SwWrtShell* CheckAndGetWrtShell();
protected:
virtual sal_uInt16 GetGroup() override;