diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2021-12-01 17:06:08 +0100 |
---|---|---|
committer | Thorsten Behrens <thorsten.behrens@allotropia.de> | 2021-12-06 08:24:45 +0100 |
commit | 7d3d19ab76ff0acb948431c1792561a466bcd2d9 (patch) | |
tree | b935b5bf7819bd7444e6818473731e4372942030 /sw | |
parent | c0658e3e60daae59058734a13127fb6af38f2e21 (diff) |
tdf#145062 sw: deal with failing insertion of field in SwWrtShell
Change-Id: Ic0c479e97b7a5f6fcc7f7eb454eb77a5c47de9db
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126191
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
(cherry picked from commit e58583e70b3434a158a3902cc7ae81d0b3bdfc49)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126245
Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/editsh.hxx | 2 | ||||
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 2 | ||||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 24 | ||||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter4.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/edit/edfld.cxx | 6 | ||||
-rw-r--r-- | sw/source/ui/dbui/dbinsdlg.cxx | 4 | ||||
-rw-r--r-- | sw/source/uibase/dochdl/swdtflvr.cxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/fldui/fldmgr.cxx | 53 | ||||
-rw-r--r-- | sw/source/uibase/inc/wrtsh.hxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/wrtsh/wrtsh2.cxx | 8 |
10 files changed, 59 insertions, 46 deletions
diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx index f2d8c5300535..dd727b10368d 100644 --- a/sw/inc/editsh.hxx +++ b/sw/inc/editsh.hxx @@ -395,7 +395,7 @@ public: /// Currently there are two variants: signature and classification. bool RemoveParagraphMetadataFieldAtCursor(); - void Insert2(SwField const &, const bool bForceExpandHints); + bool InsertField(SwField const &, const bool bForceExpandHints); void UpdateOneField(SwField &); ///< One single field. diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 54f4ecc7b9a9..943e26ee1aa5 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -2179,7 +2179,7 @@ void SwTiledRenderingTest::testRedlineField() SwDateTimeField aDate(static_cast<SwDateTimeFieldType*>(pWrtShell->GetFieldType(0, SwFieldIds::DateTime))); //aDate->SetDateTime(::DateTime(::DateTime::SYSTEM)); - pWrtShell->Insert(aDate); + pWrtShell->InsertField2(aDate); // Get the redline just created const SwRedlineTable& rTable = pWrtShell->GetDoc()->getIDocumentRedlineAccess().GetRedlineTable(); diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 4973e238a4d0..7a16fcc556ce 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -1023,7 +1023,7 @@ void SwUiWriterTest::testFdo74981() SwDoc* pDoc = createSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); SwInputField aField(static_cast<SwInputFieldType*>(pWrtShell->GetFieldType(0, SwFieldIds::Input)), "foo", "bar", 0, 0); - pWrtShell->Insert(aField); + pWrtShell->InsertField2(aField); { // expect hints @@ -1054,10 +1054,10 @@ void SwUiWriterTest::testTdf98512() SwInputFieldType *const pType(static_cast<SwInputFieldType*>( pWrtShell->GetFieldType(0, SwFieldIds::Input))); SwInputField aField1(pType, "foo", "bar", INP_TXT, 0); - pWrtShell->Insert(aField1); + pWrtShell->InsertField2(aField1); pWrtShell->SttEndDoc(/*bStt=*/true); SwInputField aField2(pType, "baz", "quux", INP_TXT, 0); - pWrtShell->Insert(aField2); + pWrtShell->InsertField2(aField2); pWrtShell->SttEndDoc(/*bStt=*/true); pWrtShell->SetMark(); pWrtShell->SttEndDoc(/*bStt=*/false); @@ -2690,14 +2690,14 @@ void SwUiWriterTest::testTdf77342() pWrtShell->StartOfSection(); //inserting reference field 1 SwGetRefField aField1(pRefType, "", "", REF_FOOTNOTE, sal_uInt16(0), REF_CONTENT); - pWrtShell->Insert(aField1); + pWrtShell->InsertField2(aField1); //inserting second footnote pWrtShell->InsertFootnote(""); pWrtShell->StartOfSection(); pCursor->Move(fnMoveForward); //inserting reference field 2 SwGetRefField aField2(pRefType, "", "", REF_FOOTNOTE, sal_uInt16(1), REF_CONTENT); - pWrtShell->Insert(aField2); + pWrtShell->InsertField2(aField2); //inserting third footnote pWrtShell->InsertFootnote(""); pWrtShell->StartOfSection(); @@ -2705,7 +2705,7 @@ void SwUiWriterTest::testTdf77342() pCursor->Move(fnMoveForward); //inserting reference field 3 SwGetRefField aField3(pRefType, "", "", REF_FOOTNOTE, sal_uInt16(2), REF_CONTENT); - pWrtShell->Insert(aField3); + pWrtShell->InsertField2(aField3); //updating the fields IDocumentFieldsAccess& rField(pDoc->getIDocumentFieldsAccess()); rField.UpdateExpFields(nullptr, true); @@ -2926,38 +2926,38 @@ void SwUiWriterTest::testTdf63553() //inserting sequence field 1 SwSetExpFieldType* pSeqType = static_cast<SwSetExpFieldType*>(pWrtShell->GetFieldType(SwFieldIds::SetExp, "Illustration")); SwSetExpField aSetField1(pSeqType, "", SVX_NUM_ARABIC); - pWrtShell->Insert(aSetField1); + pWrtShell->InsertField2(aSetField1); SwGetRefFieldType* pRefType = static_cast<SwGetRefFieldType*>(pWrtShell->GetFieldType(0, SwFieldIds::GetRef)); //moving cursor to the starting of document pWrtShell->StartOfSection(); //inserting reference field 1 SwGetRefField aGetField1(pRefType, "Illustration", "", REF_SEQUENCEFLD, sal_uInt16(0), REF_CONTENT); - pWrtShell->Insert(aGetField1); + pWrtShell->InsertField2(aGetField1); //now we have ref1-seq1 //moving the cursor pCursor->Move(fnMoveForward); //inserting sequence field 2 SwSetExpField aSetField2(pSeqType, "", SVX_NUM_ARABIC); - pWrtShell->Insert(aSetField2); + pWrtShell->InsertField2(aSetField2); //moving the cursor pWrtShell->StartOfSection(); pCursor->Move(fnMoveForward); //inserting reference field 2 SwGetRefField aGetField2(pRefType, "Illustration", "", REF_SEQUENCEFLD, sal_uInt16(1), REF_CONTENT); - pWrtShell->Insert(aGetField2); + pWrtShell->InsertField2(aGetField2); //now we have ref1-ref2-seq1-seq2 //moving the cursor pCursor->Move(fnMoveForward); pCursor->Move(fnMoveForward); //inserting sequence field 3 SwSetExpField aSetField3(pSeqType, "", SVX_NUM_ARABIC); - pWrtShell->Insert(aSetField3); + pWrtShell->InsertField2(aSetField3); pWrtShell->StartOfSection(); pCursor->Move(fnMoveForward); pCursor->Move(fnMoveForward); //inserting reference field 3 SwGetRefField aGetField3(pRefType, "Illustration", "", REF_SEQUENCEFLD, sal_uInt16(2), REF_CONTENT); - pWrtShell->Insert(aGetField3); + pWrtShell->InsertField2(aGetField3); //now after insertion we have ref1-ref2-ref3-seq1-seq2-seq3 //updating the fields IDocumentFieldsAccess& rField(pDoc->getIDocumentFieldsAccess()); diff --git a/sw/qa/extras/uiwriter/uiwriter4.cxx b/sw/qa/extras/uiwriter/uiwriter4.cxx index ac0938d28624..54a78055ca94 100644 --- a/sw/qa/extras/uiwriter/uiwriter4.cxx +++ b/sw/qa/extras/uiwriter/uiwriter4.cxx @@ -2688,7 +2688,7 @@ void SwUiWriterTest4::testTdf115013() // Insert the field into document SwDBField aField(pFieldType); - pWrtShell->Insert(aField); + pWrtShell->InsertField2(aField); } // Save it as DOCX & load it again reload("Office Open XML Text", "mm-field.docx"); diff --git a/sw/source/core/edit/edfld.cxx b/sw/source/core/edit/edfld.cxx index eda748efd303..a812fa1f3e0f 100644 --- a/sw/source/core/edit/edfld.cxx +++ b/sw/source/core/edit/edfld.cxx @@ -139,7 +139,7 @@ void SwEditShell::FieldToText( SwFieldType const * pType ) } /// add a field at the cursor position -void SwEditShell::Insert2(SwField const & rField, const bool bForceExpandHints) +bool SwEditShell::InsertField(SwField const & rField, const bool bForceExpandHints) { CurrShell aCurr( this ); StartAllAction(); @@ -149,13 +149,15 @@ void SwEditShell::Insert2(SwField const & rField, const bool bForceExpandHints) ? SetAttrMode::FORCEHINTEXPAND : SetAttrMode::DEFAULT; + bool bSuccess(false); for(const SwPaM& rPaM : GetCursor()->GetRingContainer()) // for each PaM { - const bool bSuccess(GetDoc()->getIDocumentContentOperations().InsertPoolItem(rPaM, aField, nInsertFlags)); + bSuccess |= GetDoc()->getIDocumentContentOperations().InsertPoolItem(rPaM, aField, nInsertFlags); OSL_ENSURE( bSuccess, "Doc->Insert(Field) failed"); } EndAllAction(); + return bSuccess; } /// Are the PaMs positioned on fields? diff --git a/sw/source/ui/dbui/dbinsdlg.cxx b/sw/source/ui/dbui/dbinsdlg.cxx index c057865aa1d2..c35980fd30cc 100644 --- a/sw/source/ui/dbui/dbinsdlg.cxx +++ b/sw/source/ui/dbui/dbinsdlg.cxx @@ -1276,7 +1276,7 @@ void SwInsertDBColAutoPilot::DataToDoc( const Sequence<Any>& rSelection, } pField->SetInitialized(); - rSh.Insert( *pField ); + rSh.InsertField2( *pField ); } break; @@ -1340,7 +1340,7 @@ void SwInsertDBColAutoPilot::DataToDoc( const Sequence<Any>& rSelection, break; if( m_xRbAsField->get_active() ) - rSh.Insert( aNxtDBField ); + rSh.InsertField2( aNxtDBField ); if( !rSh.IsSttPara() ) rSh.SwEditShell::SplitNode(); diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx index 6dd35e9fe34c..fadba4319510 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -2702,7 +2702,7 @@ bool SwTransferable::PasteDDE( TransferableDataHelper& rData, { // insert SwDDEField aSwDDEField( pDDETyp ); - rWrtShell.Insert( aSwDDEField ); + rWrtShell.InsertField2( aSwDDEField ); } } while( false ); diff --git a/sw/source/uibase/fldui/fldmgr.cxx b/sw/source/uibase/fldui/fldmgr.cxx index df3bcf4a6ba3..e15bf6cf1d2f 100644 --- a/sw/source/uibase/fldui/fldmgr.cxx +++ b/sw/source/uibase/fldui/fldmgr.cxx @@ -1485,40 +1485,49 @@ bool SwFieldMgr::InsertField( // insert pCurShell->StartAllAction(); - pCurShell->Insert(*pField, rData.m_pAnnotationRange.get()); + bool const isSuccess = pCurShell->InsertField2(*pField, rData.m_pAnnotationRange.get()); - if (SwFieldTypesEnum::Input == rData.m_nTypeId) + if (isSuccess) { - pCurShell->Push(); + if (SwFieldTypesEnum::Input == rData.m_nTypeId) + { + pCurShell->Push(); - // start dialog, not before the field is inserted tdf#99529 - pCurShell->Left(CRSR_SKIP_CHARS, false, - (INP_VAR == (nSubType & 0xff) || pCurShell->GetViewOptions()->IsFieldName()) ? 1 : 2, - false); - pCurShell->StartInputFieldDlg(pField.get(), false, true, rData.m_pParent); + // start dialog, not before the field is inserted tdf#99529 + pCurShell->Left(CRSR_SKIP_CHARS, false, + (INP_VAR == (nSubType & 0xff) || pCurShell->GetViewOptions()->IsFieldName()) ? 1 : 2, + false); + pCurShell->StartInputFieldDlg(pField.get(), false, true, rData.m_pParent); - pCurShell->Pop(SwCursorShell::PopMode::DeleteCurrent); - } + pCurShell->Pop(SwCursorShell::PopMode::DeleteCurrent); + } - if(bExp && m_bEvalExp) - pCurShell->UpdateExpFields(true); + if (bExp && m_bEvalExp) + { + pCurShell->UpdateExpFields(true); + } - if(bTable) - { - pCurShell->Left(CRSR_SKIP_CHARS, false, 1, false ); - pCurShell->UpdateOneField(*pField); - pCurShell->Right(CRSR_SKIP_CHARS, false, 1, false ); + if (bTable) + { + pCurShell->Left(CRSR_SKIP_CHARS, false, 1, false ); + pCurShell->UpdateOneField(*pField); + pCurShell->Right(CRSR_SKIP_CHARS, false, 1, false ); + } + else if (bPageVar) + { + static_cast<SwRefPageGetFieldType*>(pCurShell->GetFieldType(0, SwFieldIds::RefPageGet))->UpdateFields(); + } + else if (SwFieldTypesEnum::GetRef == rData.m_nTypeId) + { + pField->GetTyp()->UpdateFields(); + } } - else if( bPageVar ) - static_cast<SwRefPageGetFieldType*>(pCurShell->GetFieldType( 0, SwFieldIds::RefPageGet ))->UpdateFields(); - else if( SwFieldTypesEnum::GetRef == rData.m_nTypeId ) - pField->GetTyp()->UpdateFields(); // delete temporary field pField.reset(); pCurShell->EndAllAction(); - return true; + return isSuccess; } // fields update diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx index 96c7cec3b31a..0b6f77d9804b 100644 --- a/sw/source/uibase/inc/wrtsh.hxx +++ b/sw/source/uibase/inc/wrtsh.hxx @@ -303,7 +303,7 @@ typedef bool (SwWrtShell::*FNSimpleMove)(); int IntelligentCut(SelectionType nSelectionType, bool bCut = true); // edit - void Insert(SwField const &, SwPaM* pAnnotationRange = nullptr); + bool InsertField2(SwField const &, SwPaM* pAnnotationRange = nullptr); void Insert(const OUString &); // graphic void Insert( const OUString &rPath, const OUString &rFilter, diff --git a/sw/source/uibase/wrtsh/wrtsh2.cxx b/sw/source/uibase/wrtsh/wrtsh2.cxx index 90f08fd33a81..ecee93b4866d 100644 --- a/sw/source/uibase/wrtsh/wrtsh2.cxx +++ b/sw/source/uibase/wrtsh/wrtsh2.cxx @@ -59,11 +59,11 @@ #include <sfx2/event.hxx> #include <sal/log.hxx> -void SwWrtShell::Insert(SwField const& rField, SwPaM* pAnnotationRange) +bool SwWrtShell::InsertField2(SwField const& rField, SwPaM* pAnnotationRange) { ResetCursorStack(); if(!CanInsert()) - return; + return false; StartAllAction(); SwRewriter aRewriter; @@ -111,7 +111,7 @@ void SwWrtShell::Insert(SwField const& rField, SwPaM* pAnnotationRange) } } - SwEditShell::Insert2(rField, bDeleted); + bool const isSuccess = SwEditShell::InsertField(rField, bDeleted); if ( pAnnotationTextRange ) { @@ -136,6 +136,8 @@ void SwWrtShell::Insert(SwField const& rField, SwPaM* pAnnotationRange) EndUndo(); EndAllAction(); + + return isSuccess; } // Start the field update |