Kaydet (Commit) 55654acd authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

MM: don't try to save the source MM document

Just create in internal copy, if the source document is modified.

Change-Id: I4587b3df5ff0b42c98f1b69fe18b4f11f5c9b8e4
üst 2a6cd03f
......@@ -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();
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment