summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2021-12-01 17:06:08 +0100
committerMichael Stahl <michael.stahl@allotropia.de>2021-12-03 20:08:12 +0100
commit770d6634d20aa4f102032c0917babe7ba0c91466 (patch)
treec428930608cadf5fa6b467b843ea98dcd4c08208
parenttdf#145062 sw: really destroy text attribute when insertion fails (diff)
downloadcore-770d6634d20aa4f102032c0917babe7ba0c91466.tar.gz
core-770d6634d20aa4f102032c0917babe7ba0c91466.zip
tdf#145062 sw: deal with failing insertion of field in SwWrtShell
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) Change-Id: Ic0c479e97b7a5f6fcc7f7eb454eb77a5c47de9db Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126329 Tested-by: Michael Stahl <michael.stahl@allotropia.de> Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
-rw-r--r--sw/inc/editsh.hxx2
-rw-r--r--sw/qa/extras/tiledrendering/tiledrendering.cxx2
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx26
-rw-r--r--sw/source/core/edit/edfld.cxx6
-rw-r--r--sw/source/ui/dbui/dbinsdlg.cxx4
-rw-r--r--sw/source/uibase/dochdl/swdtflvr.cxx2
-rw-r--r--sw/source/uibase/fldui/fldmgr.cxx53
-rw-r--r--sw/source/uibase/inc/wrtsh.hxx2
-rw-r--r--sw/source/uibase/wrtsh/wrtsh2.cxx8
9 files changed, 59 insertions, 46 deletions
diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx
index 53b91f44db98..c2224d0575bc 100644
--- a/sw/inc/editsh.hxx
+++ b/sw/inc/editsh.hxx
@@ -400,7 +400,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 e6b624a5cb1e..04ece78d298f 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -2138,7 +2138,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 7e28d0f57ead..eaa2e40bb636 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -1271,7 +1271,7 @@ void SwUiWriterTest::testFdo74981()
SwDoc* pDoc = createDoc();
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
@@ -1302,10 +1302,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);
@@ -2756,14 +2756,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();
@@ -2771,7 +2771,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);
@@ -2992,38 +2992,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());
@@ -7131,7 +7131,7 @@ void SwUiWriterTest::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 7525a9af80af..29365cfa263c 100644
--- a/sw/source/core/edit/edfld.cxx
+++ b/sw/source/core/edit/edfld.cxx
@@ -149,7 +149,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)
{
SET_CURR_SHELL( this );
StartAllAction();
@@ -159,13 +159,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 4ead5f41f49b..64fd72b9a253 100644
--- a/sw/source/ui/dbui/dbinsdlg.cxx
+++ b/sw/source/ui/dbui/dbinsdlg.cxx
@@ -1290,7 +1290,7 @@ void SwInsertDBColAutoPilot::DataToDoc( const Sequence<Any>& rSelection,
}
pField->SetInitialized();
- rSh.Insert( *pField );
+ rSh.InsertField2( *pField );
}
break;
@@ -1354,7 +1354,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 f6e5990b1b3d..7c05f1c93086 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -2580,7 +2580,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 871cb366df1c..6bc001c99e0e 100644
--- a/sw/source/uibase/fldui/fldmgr.cxx
+++ b/sw/source/uibase/fldui/fldmgr.cxx
@@ -1494,40 +1494,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()->ModifyNotification( nullptr, nullptr );
+ }
}
- else if( bPageVar )
- static_cast<SwRefPageGetFieldType*>(pCurShell->GetFieldType( 0, SwFieldIds::RefPageGet ))->UpdateFields();
- else if( SwFieldTypesEnum::GetRef == rData.m_nTypeId )
- pField->GetTyp()->ModifyNotification( nullptr, nullptr );
// 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 6ec17d5b0e78..049cb3d9ae5c 100644
--- a/sw/source/uibase/inc/wrtsh.hxx
+++ b/sw/source/uibase/inc/wrtsh.hxx
@@ -300,7 +300,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 82d7c27cb0c6..3197c596e52a 100644
--- a/sw/source/uibase/wrtsh/wrtsh2.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh2.cxx
@@ -68,11 +68,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;
@@ -120,7 +120,7 @@ void SwWrtShell::Insert(SwField const& rField, SwPaM* pAnnotationRange)
}
}
- SwEditShell::Insert2(rField, bDeleted);
+ bool const isSuccess = SwEditShell::InsertField(rField, bDeleted);
if ( pAnnotationTextRange )
{
@@ -145,6 +145,8 @@ void SwWrtShell::Insert(SwField const& rField, SwPaM* pAnnotationRange)
EndUndo();
EndAllAction();
+
+ return isSuccess;
}
// Start the field update