[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3' - sw/inc sw/source
Szymon Kłos
szymon.klos at collabora.com
Mon Sep 18 20:37:39 UTC 2017
sw/inc/dbmgr.hxx | 9 +++++++++
sw/source/core/doc/docnew.cxx | 7 +++++++
sw/source/uibase/dbui/dbmgr.cxx | 33 ++++++++++++++++++++++++++++-----
3 files changed, 44 insertions(+), 5 deletions(-)
New commits:
commit e63edbb765169da8d4aca09adfff904891cebe98
Author: Szymon Kłos <szymon.klos at collabora.com>
Date: Sat Sep 16 17:01:08 2017 +0200
tdf#108572 remove connection also if not saved
Change-Id: Iddce37c3ad187f4a5572cb3cc2362535134c28e8
Reviewed-on: https://gerrit.libreoffice.org/42357
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>
(cherry picked from commit 29bd193146b40cf90bda5db04b136987f3c7c94d)
Reviewed-on: https://gerrit.libreoffice.org/42369
Reviewed-by: Andras Timar <andras.timar at collabora.com>
Tested-by: Andras Timar <andras.timar at collabora.com>
diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx
index b80f051a4d55..d32e1843f8f8 100644
--- a/sw/inc/dbmgr.hxx
+++ b/sw/inc/dbmgr.hxx
@@ -261,6 +261,12 @@ friend class SwConnectionDisposedListener_Impl;
/// Store last registrations to revoke or commit
static std::vector<std::pair<SwDocShell*, OUString>> m_aUncommitedRegistrations;
+ /// Not used connections.
+ std::vector<OUString> m_aNotUsedConnections;
+
+ /// Set connection as used.
+ void SetAsUsed(const OUString& rName);
+
/// The document that owns this manager.
SwDoc* m_pDoc;
@@ -487,6 +493,9 @@ public:
/// Accept not commited registrations
void CommitLastRegistrations();
+
+ /// Remove not used connections.
+ void RevokeNotUsedConnections();
};
#endif
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index f665c032ccf1..d20203002e16 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -531,6 +531,13 @@ SwDoc::~SwDoc()
mpDBManager->releaseRevokeListener();
SwDBManager::RevokeDataSource(maDBData.sDataSource);
}
+ else if (!mpDBManager->getEmbeddedName().isEmpty())
+ {
+ // Remove the revoke listener here first, so that we don't remove the data source from the document.
+ mpDBManager->releaseRevokeListener();
+ // Remove connections which was committed but not used.
+ mpDBManager->RevokeNotUsedConnections();
+ }
DELETEZ( mpDBManager );
#endif
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index b959a5d7b5f5..838e0fa0888d 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -2529,6 +2529,7 @@ SwDSParam* SwDBManager::FindDSConnection(const OUString& rDataSource, bool bCre
//prefer merge data if available
if(pImpl->pMergeData && rDataSource == pImpl->pMergeData->sDataSource )
{
+ SetAsUsed(rDataSource);
return pImpl->pMergeData;
}
SwDSParam* pFound = nullptr;
@@ -2536,6 +2537,7 @@ SwDSParam* SwDBManager::FindDSConnection(const OUString& rDataSource, bool bCre
{
if(rDataSource == pParam->sDataSource)
{
+ SetAsUsed(rDataSource);
pFound = pParam.get();
break;
}
@@ -2545,6 +2547,7 @@ SwDSParam* SwDBManager::FindDSConnection(const OUString& rDataSource, bool bCre
SwDBData aData;
aData.sDataSource = rDataSource;
pFound = new SwDSParam(aData);
+ SetAsUsed(rDataSource);
m_DataSourceParams.push_back(std::unique_ptr<SwDSParam>(pFound));
try
{
@@ -3240,12 +3243,32 @@ void SwDBManager::RevokeLastRegistrations()
void SwDBManager::CommitLastRegistrations()
{
- auto predicate = [this](const std::pair<SwDocShell*, OUString>& x)
- { return x.first == this->m_pDoc->GetDocShell(); };
+ for (auto aIt = m_aUncommitedRegistrations.begin(); aIt != m_aUncommitedRegistrations.end();)
+ {
+ if (aIt->first == m_pDoc->GetDocShell())
+ {
+ m_aNotUsedConnections.push_back(aIt->second);
+ aIt = m_aUncommitedRegistrations.erase(aIt);
+ }
+ else
+ aIt++;
+ }
+}
- m_aUncommitedRegistrations.erase(
- std::remove_if(m_aUncommitedRegistrations.begin(), m_aUncommitedRegistrations.end(), predicate),
- m_aUncommitedRegistrations.end());
+void SwDBManager::SetAsUsed(const OUString& rName)
+{
+ auto aFound = std::find(m_aNotUsedConnections.begin(), m_aNotUsedConnections.end(), rName);
+ if (aFound != m_aNotUsedConnections.end())
+ m_aNotUsedConnections.erase(aFound);
+}
+
+void SwDBManager::RevokeNotUsedConnections()
+{
+ for (auto aIt = m_aNotUsedConnections.begin(); aIt != m_aNotUsedConnections.end();)
+ {
+ RevokeDataSource(*aIt);
+ aIt = m_aNotUsedConnections.erase(aIt);
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list