summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2016-01-27 13:04:04 +0100
committerJan-Marek Glogowski <glogow@fbihome.de>2016-03-24 22:40:55 +0100
commit55654acd1d026491004528371995ce112b33721b (patch)
treef22faea2ce5ec7b2167ec60e91474ec75ba1e9b2
parent2a6cd03fab17e503c9f98e6f4f2e35c43a383f5f (diff)
MM: don't try to save the source MM document
Just create in internal copy, if the source document is modified. Change-Id: I4587b3df5ff0b42c98f1b69fe18b4f11f5c9b8e4
-rw-r--r--sw/source/uibase/dbui/dbmgr.cxx89
1 files changed, 53 insertions, 36 deletions
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 36b6d3caac3c..4ffe66592ad9 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -167,6 +167,13 @@ const sal_Char cActiveConnection[] = "ActiveConnection";
enum class SwDBNextRecord { NEXT, FIRST };
static bool lcl_ToNextRecord( SwDSParam* pParam, const SwDBNextRecord action = SwDBNextRecord::NEXT );
+enum class WorkingDocType { SOURCE, TARGET, COPY };
+static SfxObjectShell* lcl_CreateWorkingDocument(
+ const WorkingDocType aType, const SwWrtShell &rSourceWrtShell,
+ const vcl::Window *pSourceWindow,
+ SwDBManager** const pDBManager,
+ SwView** const pView, SwWrtShell** const pWrtShell, SwDoc** const pDoc );
+
static bool lcl_getCountFromResultSet( sal_Int32& rCount, const uno::Reference<sdbc::XResultSet>& xResultSet )
{
uno::Reference<beans::XPropertySet> xPrSet(xResultSet, uno::UNO_QUERY);
@@ -416,6 +423,35 @@ bool SwDBManager::MergeNew( const SwMergeDescriptor& rMergeDesc, vcl::Window* pP
{
assert( !bInMerge && !pImpl->pMergeData && "merge already activated!" );
+ SfxObjectShellLock xWorkObjSh;
+ SwWrtShell *pWorkShell = nullptr;
+ SwDoc *pWorkDoc = nullptr;
+ SwDBManager *pWorkDocOrigDBManager = nullptr;
+
+ switch( rMergeDesc.nMergeType )
+ {
+ case DBMGR_MERGE_PRINTER:
+ case DBMGR_MERGE_EMAIL:
+ case DBMGR_MERGE_FILE:
+ case DBMGR_MERGE_SHELL:
+ {
+ SwDocShell *pSourceDocSh = rMergeDesc.rSh.GetView().GetDocShell();
+ if( pSourceDocSh->IsModified() )
+ {
+ pWorkDocOrigDBManager = this;
+ xWorkObjSh = lcl_CreateWorkingDocument(
+ WorkingDocType::SOURCE, rMergeDesc.rSh, nullptr,
+ &pWorkDocOrigDBManager, nullptr, &pWorkShell, &pWorkDoc );
+ }
+ // fall through
+ }
+
+ default:
+ if( !xWorkObjSh.Is() )
+ pWorkShell = &rMergeDesc.rSh;
+ break;
+ }
+
SwDBData aData;
aData.nCommandType = sdb::CommandType::TABLE;
uno::Reference<sdbc::XResultSet> xResSet;
@@ -477,7 +513,7 @@ bool SwDBManager::MergeNew( const SwMergeDescriptor& rMergeDesc, vcl::Window* pP
lcl_InitNumberFormatter(*pImpl->pMergeData, xSource);
- rMergeDesc.rSh.ChgDBData(aData);
+ pWorkShell->ChgDBData(aData);
bInMerge = true;
if (IsInitDBFields())
@@ -485,13 +521,13 @@ bool SwDBManager::MergeNew( const SwMergeDescriptor& rMergeDesc, vcl::Window* pP
// with database fields without DB-Name, use DB-Name from Doc
std::vector<OUString> aDBNames;
aDBNames.push_back(OUString());
- SwDBData aInsertData = rMergeDesc.rSh.GetDBData();
+ SwDBData aInsertData = pWorkShell->GetDBData();
OUString sDBName = aInsertData.sDataSource;
sDBName += OUString(DB_DELIM);
sDBName += aInsertData.sCommand;
sDBName += OUString(DB_DELIM);
sDBName += OUString::number(aInsertData.nCommandType);
- rMergeDesc.rSh.ChangeDBFields( aDBNames, sDBName);
+ pWorkShell->ChangeDBFields( aDBNames, sDBName);
SetInitDBFields(false);
}
@@ -499,10 +535,10 @@ bool SwDBManager::MergeNew( const SwMergeDescriptor& rMergeDesc, vcl::Window* pP
switch(rMergeDesc.nMergeType)
{
case DBMGR_MERGE:
- rMergeDesc.rSh.StartAllAction();
- rMergeDesc.rSh.SwViewShell::UpdateFields( true );
- rMergeDesc.rSh.SetModified();
- rMergeDesc.rSh.EndAllAction();
+ pWorkShell->StartAllAction();
+ pWorkShell->SwViewShell::UpdateFields( true );
+ pWorkShell->SetModified();
+ pWorkShell->EndAllAction();
break;
case DBMGR_MERGE_PRINTER:
@@ -510,18 +546,24 @@ bool SwDBManager::MergeNew( const SwMergeDescriptor& rMergeDesc, vcl::Window* pP
case DBMGR_MERGE_FILE:
case DBMGR_MERGE_SHELL:
// save files and send them as e-Mail if required
- bRet = MergeMailFiles(&rMergeDesc.rSh, rMergeDesc, pParent);
+ bRet = MergeMailFiles(pWorkShell, rMergeDesc, pParent);
break;
default:
// insert selected entries
// (was: InsertRecord)
- ImportFromConnection(&rMergeDesc.rSh);
+ ImportFromConnection(pWorkShell);
break;
}
DELETEZ( pImpl->pMergeData );
+ if( xWorkObjSh.Is() )
+ {
+ pWorkDoc->SetDBManager( pWorkDocOrigDBManager );
+ xWorkObjSh->DoClose();
+ }
+
bInMerge = false;
return bRet;
@@ -904,8 +946,6 @@ static void lcl_PreparePrinterOptions(
}
}
-enum class WorkingDocType { SOURCE, TARGET, COPY };
-
static SfxObjectShell* lcl_CreateWorkingDocument(
// input
const WorkingDocType aType, const SwWrtShell &rSourceWrtShell,
@@ -1107,21 +1147,8 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
}
}
- SwDocShell* pSourceDocSh = pSourceShell->GetView().GetDocShell();
-
- uno::Reference<document::XDocumentProperties> xSourceDocProps;
- {
- uno::Reference<document::XDocumentPropertiesSupplier>
- xDPS(pSourceDocSh->GetModel(), uno::UNO_QUERY);
- xSourceDocProps.set(xDPS->getDocumentProperties());
- assert( xSourceDocProps.is() && "DocumentProperties is null" );
- }
+ SwDocShell *pSourceDocSh = pSourceShell->GetView().GetDocShell();
- // Try saving the source document
- SfxDispatcher* pSfxDispatcher = pSourceShell->GetView().GetViewFrame()->GetDispatcher();
- if( !bMT_SHELL && pSourceDocSh->IsModified() )
- pSfxDispatcher->Execute( pSourceDocSh->HasName() ? SID_SAVEDOC : SID_SAVEASDOC, SfxCallMode::SYNCHRON|SfxCallMode::RECORD);
- if( bMT_SHELL || !pSourceDocSh->IsModified() )
{
// setup the output format
std::shared_ptr<const SfxFilter> pStoreToFilter = SwIoSystem::GetFileFilter(
@@ -2819,15 +2846,8 @@ void SwDBManager::ExecuteFormLetter( SwWrtShell& rSh,
{
{
{
- SwWrtShell *pWorkShell;
- SwDoc *pWorkDoc;
- SwDBManager *pWorkDocOrigDBManager = this;
- SfxObjectShellLock xWorkDocSh = lcl_CreateWorkingDocument(
- WorkingDocType::SOURCE, rSh, nullptr,
- &pWorkDocOrigDBManager, nullptr, &pWorkShell, &pWorkDoc );
-
// prepare mail merge descriptor
- SwMergeDescriptor aMergeDesc( pImpl->pMergeDialog->GetMergeType(), *pWorkShell, aDescriptor );
+ SwMergeDescriptor aMergeDesc( pImpl->pMergeDialog->GetMergeType(), rSh, aDescriptor );
aMergeDesc.sSaveToFilter = pImpl->pMergeDialog->GetSaveFilter();
aMergeDesc.bCreateSingleFile = pImpl->pMergeDialog->IsSaveSingleDoc();
aMergeDesc.sPath = pImpl->pMergeDialog->GetTargetURL();
@@ -2837,9 +2857,6 @@ void SwDBManager::ExecuteFormLetter( SwWrtShell& rSh,
}
MergeNew( aMergeDesc );
-
- pWorkDoc->SetDBManager( pWorkDocOrigDBManager );
- xWorkDocSh->DoClose();
}
}
}