sw/inc/editsh.hxx                              |    2 
 sw/qa/extras/tiledrendering/tiledrendering.cxx |    2 
 sw/qa/extras/uiwriter/uiwriter.cxx             |   24 +++++------
 sw/qa/extras/uiwriter/uiwriter4.cxx            |    2 
 sw/source/core/edit/edfld.cxx                  |    6 +-
 sw/source/ui/dbui/dbinsdlg.cxx                 |    4 -
 sw/source/uibase/dochdl/swdtflvr.cxx           |    2 
 sw/source/uibase/fldui/fldmgr.cxx              |   53 ++++++++++++++-----------
 sw/source/uibase/inc/wrtsh.hxx                 |    2 
 sw/source/uibase/wrtsh/wrtsh2.cxx              |    8 ++-
 10 files changed, 59 insertions(+), 46 deletions(-)

New commits:
commit e58583e70b3434a158a3902cc7ae81d0b3bdfc49
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Wed Dec 1 17:06:08 2021 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri Dec 3 10:17:55 2021 +0100

    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.st...@allotropia.de>

diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx
index 076cbbf5b3bb..72571775af91 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 46a4eab3ac98..b8f3430e3269 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -2367,7 +2367,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 76ee8d22f846..0e9c604badc7 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);
@@ -2658,14 +2658,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();
@@ -2673,7 +2673,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);
@@ -2894,38 +2894,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 f9cb31778e16..40db48e65e92 100644
--- a/sw/qa/extras/uiwriter/uiwriter4.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter4.cxx
@@ -2882,7 +2882,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 33089ef827bc..b08f1b247a8d 100644
--- a/sw/source/core/edit/edfld.cxx
+++ b/sw/source/core/edit/edfld.cxx
@@ -140,7 +140,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();
@@ -150,13 +150,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 83440e7bde58..c73a8aa2bed0 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 8245b420295a..bf26e57476af 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -2705,7 +2705,7 @@ bool SwTransferable::PasteDDE( const 
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 013c65198f1f..90fdaad22a1d 100644
--- a/sw/source/uibase/fldui/fldmgr.cxx
+++ b/sw/source/uibase/fldui/fldmgr.cxx
@@ -1486,40 +1486,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 77136362c81f..41ef84d1d00f 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 77a6d4c19d28..e53580e6a746 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

Reply via email to