summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2019-10-11 14:50:57 +0200
committerMichael Stahl <michael.stahl@cib.de>2019-10-23 13:01:11 +0200
commit12385f9e79e15b215c1d398b4bfb212ef1b23fb3 (patch)
tree2e163dee7af2a5f83b4f2def9bd2f610ce1456e7
parentbc5e4104e281b89c08df102851e5693f35772c40 (diff)
sw: fieldmark insert/delete Undo
SwHistoryTextFieldmark implementation doesn't work that well with its hardcoded +5 etc. so reimplement that storing all 3 positions. Add Undo classes for deletion as well, and use them automatically when deleteMark() is called with Undo enabled. Change-Id: I45a73080b08bde9e046525892c101aa2d622269e Reviewed-on: https://gerrit.libreoffice.org/80627 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de>
-rw-r--r--sw/source/core/crsr/bookmrk.cxx19
-rw-r--r--sw/source/core/inc/UndoBookmark.hxx28
-rw-r--r--sw/source/core/inc/rolbck.hxx8
-rw-r--r--sw/source/core/undo/rolbck.cxx51
-rw-r--r--sw/source/core/undo/unbkmk.cxx36
5 files changed, 118 insertions, 24 deletions
diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx
index 713d36d2d63d..7e514b7e18da 100644
--- a/sw/source/core/crsr/bookmrk.cxx
+++ b/sw/source/core/crsr/bookmrk.cxx
@@ -511,6 +511,12 @@ namespace sw { namespace mark
void TextFieldmark::ReleaseDoc(SwDoc* const pDoc)
{
+ IDocumentUndoRedo & rIDUR(pDoc->GetIDocumentUndoRedo());
+ if (rIDUR.DoesUndo())
+ {
+ rIDUR.AppendUndo(std::make_unique<SwUndoDelTextFieldmark>(*this));
+ }
+ ::sw::UndoGuard const ug(rIDUR); // prevent SwUndoDeletes
lcl_RemoveFieldMarks(this, pDoc, CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FIELDEND);
}
@@ -540,6 +546,12 @@ namespace sw { namespace mark
void NonTextFieldmark::ReleaseDoc(SwDoc* const pDoc)
{
+ IDocumentUndoRedo & rIDUR(pDoc->GetIDocumentUndoRedo());
+ if (rIDUR.DoesUndo())
+ {
+ rIDUR.AppendUndo(std::make_unique<SwUndoDelNoTextFieldmark>(*this));
+ }
+ ::sw::UndoGuard const ug(rIDUR); // prevent SwUndoDeletes
lcl_RemoveFieldMarks(this, pDoc,
CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FORMELEMENT);
}
@@ -656,6 +668,13 @@ namespace sw { namespace mark
void DateFieldmark::ReleaseDoc(SwDoc* const pDoc)
{
+ IDocumentUndoRedo & rIDUR(pDoc->GetIDocumentUndoRedo());
+ if (rIDUR.DoesUndo())
+ {
+ // TODO does this need a 3rd Undo class?
+ rIDUR.AppendUndo(std::make_unique<SwUndoDelTextFieldmark>(*this));
+ }
+ ::sw::UndoGuard const ug(rIDUR); // prevent SwUndoDeletes
lcl_RemoveFieldMarks(this, pDoc, CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FIELDEND);
}
diff --git a/sw/source/core/inc/UndoBookmark.hxx b/sw/source/core/inc/UndoBookmark.hxx
index 3e2017d0721d..ebaac8cd19e7 100644
--- a/sw/source/core/inc/UndoBookmark.hxx
+++ b/sw/source/core/inc/UndoBookmark.hxx
@@ -111,6 +111,20 @@ public:
virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
};
+/// Handling undo / redo of checkbox and drop-down form field deletion
+class SwUndoDelNoTextFieldmark : public SwUndo
+{
+private:
+ const std::unique_ptr<SwHistoryNoTextFieldmark> m_pHistoryNoTextFieldmark;
+
+public:
+ SwUndoDelNoTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark);
+ ~SwUndoDelNoTextFieldmark();
+
+ virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
+ virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
+};
+
/// Handling undo / redo of text form field insertion
class SwUndoInsTextFieldmark : public SwUndo
{
@@ -124,6 +138,20 @@ public:
virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
};
+/// Handling undo / redo of text form field deletion
+class SwUndoDelTextFieldmark : public SwUndo
+{
+private:
+ const std::unique_ptr<SwHistoryTextFieldmark> m_pHistoryTextFieldmark;
+
+public:
+ SwUndoDelTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark);
+ ~SwUndoDelTextFieldmark();
+
+ virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
+ virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
+};
+
#endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOBOOKMARK_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/inc/rolbck.hxx b/sw/source/core/inc/rolbck.hxx
index 6fb81943af4d..91e9d85574b1 100644
--- a/sw/source/core/inc/rolbck.hxx
+++ b/sw/source/core/inc/rolbck.hxx
@@ -288,8 +288,12 @@ class SwHistoryTextFieldmark : public SwHistoryHint
private:
const OUString m_sName;
const OUString m_sType;
- const sal_uLong m_nNode;
- const sal_Int32 m_nContent;
+ const sal_uLong m_nStartNode;
+ const sal_Int32 m_nStartContent;
+ const sal_uLong m_nEndNode;
+ const sal_Int32 m_nEndContent;
+ /*const*/ sal_uLong m_nSepNode;
+ /*const*/ sal_Int32 m_nSepContent;
};
class SwHistorySetAttrSet : public SwHistoryHint
diff --git a/sw/source/core/undo/rolbck.cxx b/sw/source/core/undo/rolbck.cxx
index d500679eefee..8a2c027b93f5 100644
--- a/sw/source/core/undo/rolbck.cxx
+++ b/sw/source/core/undo/rolbck.cxx
@@ -722,9 +722,14 @@ SwHistoryTextFieldmark::SwHistoryTextFieldmark(const ::sw::mark::IFieldmark& rFi
: SwHistoryHint(HSTRY_TEXTFIELDMARK)
, m_sName(rFieldMark.GetName())
, m_sType(rFieldMark.GetFieldname())
- , m_nNode(rFieldMark.GetMarkPos().nNode.GetIndex())
- , m_nContent(rFieldMark.GetMarkPos().nContent.GetIndex())
+ , m_nStartNode(rFieldMark.GetMarkStart().nNode.GetIndex())
+ , m_nStartContent(rFieldMark.GetMarkStart().nContent.GetIndex())
+ , m_nEndNode(rFieldMark.GetMarkEnd().nNode.GetIndex())
+ , m_nEndContent(rFieldMark.GetMarkEnd().nContent.GetIndex())
{
+ SwPosition const sepPos(sw::mark::FindFieldSep(rFieldMark));
+ m_nSepNode = sepPos.nNode.GetIndex();
+ m_nSepContent = sepPos.nContent.GetIndex();
}
void SwHistoryTextFieldmark::SetInDoc(SwDoc* pDoc, bool)
@@ -732,19 +737,23 @@ void SwHistoryTextFieldmark::SetInDoc(SwDoc* pDoc, bool)
::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
SwNodes& rNds = pDoc->GetNodes();
- std::unique_ptr<SwPaM> pPam;
- const SwContentNode* pContentNd = rNds[m_nNode]->GetContentNode();
- if(pContentNd)
- pPam.reset(new SwPaM(*pContentNd, m_nContent));
+ assert(rNds[m_nStartNode]->IsContentNode());
+ assert(rNds[m_nEndNode]->IsContentNode());
+ assert(rNds[m_nSepNode]->IsContentNode());
- if (pPam)
- {
- IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess();
- SwPaM aFieldPam(pPam->GetPoint()->nNode, pPam->GetPoint()->nContent.GetIndex(),
- pPam->GetPoint()->nNode, pPam->GetPoint()->nContent.GetIndex() + 5);
- pMarksAccess->makeFieldBookmark(aFieldPam, m_sName, m_sType);
- }
+ SwPaM const pam(*rNds[m_nStartNode]->GetContentNode(), m_nStartContent,
+ *rNds[m_nEndNode]->GetContentNode(),
+ m_nStartNode == m_nEndNode
+ ? (m_nEndContent - 2)
+ : m_nSepNode == m_nEndNode
+ ? (m_nEndContent - 1)
+ : m_nEndContent);
+ SwPosition const sepPos(*rNds[m_nSepNode]->GetContentNode(),
+ m_nStartNode == m_nSepNode ? (m_nSepContent - 1) : m_nSepContent);
+
+ IDocumentMarkAccess & rMarksAccess(*pDoc->getIDocumentMarkAccess());
+ rMarksAccess.makeFieldBookmark(pam, m_sName, m_sType, &sepPos);
}
void SwHistoryTextFieldmark::ResetInDoc(SwDoc* pDoc)
@@ -752,17 +761,15 @@ void SwHistoryTextFieldmark::ResetInDoc(SwDoc* pDoc)
::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
SwNodes& rNds = pDoc->GetNodes();
- std::unique_ptr<SwPaM> pPam;
- const SwContentNode* pContentNd = rNds[m_nNode]->GetContentNode();
- if(pContentNd)
- pPam.reset(new SwPaM(*pContentNd, m_nContent));
+ assert(rNds[m_nStartNode]->IsContentNode());
+ assert(rNds[m_nEndNode]->IsContentNode());
+ assert(rNds[m_nSepNode]->IsContentNode());
- if (pPam)
- {
- IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
- pMarkAccess->deleteFieldmarkAt(*pPam->GetPoint());
- }
+ SwPosition const pos(*rNds[m_nStartNode]->GetContentNode(), m_nStartContent);
+
+ IDocumentMarkAccess & rMarksAccess(*pDoc->getIDocumentMarkAccess());
+ rMarksAccess.deleteFieldmarkAt(pos);
}
SwHistorySetAttrSet::SwHistorySetAttrSet( const SfxItemSet& rSet,
diff --git a/sw/source/core/undo/unbkmk.cxx b/sw/source/core/undo/unbkmk.cxx
index 310113ff4ed7..6cc805d1518d 100644
--- a/sw/source/core/undo/unbkmk.cxx
+++ b/sw/source/core/undo/unbkmk.cxx
@@ -164,6 +164,24 @@ void SwUndoInsNoTextFieldmark::RedoImpl(::sw::UndoRedoContext & rContext)
m_pHistoryNoTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
}
+SwUndoDelNoTextFieldmark::SwUndoDelNoTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
+ : SwUndo(SwUndoId::DELETE, rFieldmark.GetMarkPos().GetDoc())
+ , m_pHistoryNoTextFieldmark(new SwHistoryNoTextFieldmark(rFieldmark))
+{
+}
+
+SwUndoDelNoTextFieldmark::~SwUndoDelNoTextFieldmark() = default;
+
+void SwUndoDelNoTextFieldmark::UndoImpl(::sw::UndoRedoContext & rContext)
+{
+ m_pHistoryNoTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
+}
+
+void SwUndoDelNoTextFieldmark::RedoImpl(::sw::UndoRedoContext & rContext)
+{
+ m_pHistoryNoTextFieldmark->ResetInDoc(&rContext.GetDoc());
+}
+
SwUndoInsTextFieldmark::SwUndoInsTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
: SwUndo(SwUndoId::INSERT, rFieldmark.GetMarkPos().GetDoc())
, m_pHistoryTextFieldmark(new SwHistoryTextFieldmark(rFieldmark))
@@ -180,4 +198,22 @@ void SwUndoInsTextFieldmark::RedoImpl(::sw::UndoRedoContext & rContext)
m_pHistoryTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
}
+SwUndoDelTextFieldmark::SwUndoDelTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
+ : SwUndo(SwUndoId::DELETE, rFieldmark.GetMarkPos().GetDoc())
+ , m_pHistoryTextFieldmark(new SwHistoryTextFieldmark(rFieldmark))
+{
+}
+
+SwUndoDelTextFieldmark::~SwUndoDelTextFieldmark() = default;
+
+void SwUndoDelTextFieldmark::UndoImpl(::sw::UndoRedoContext & rContext)
+{
+ m_pHistoryTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
+}
+
+void SwUndoDelTextFieldmark::RedoImpl(::sw::UndoRedoContext & rContext)
+{
+ m_pHistoryTextFieldmark->ResetInDoc(&rContext.GetDoc());
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */