sw/inc/UndoParagraphSignature.hxx | 2 sw/inc/editsh.hxx | 7 +- sw/source/core/edit/edfcol.cxx | 129 ++++++++++++++++++++++++-------------- sw/source/core/edit/edws.cxx | 5 + sw/source/core/txtnode/ndtxt.cxx | 2 sw/source/uibase/app/docsh.cxx | 2 6 files changed, 95 insertions(+), 52 deletions(-)
New commits: commit 30c10ae1b38342ced95889b33d95fe39c7cf6679 Author: Ashod Nakashian <[email protected]> Date: Tue Oct 31 21:52:49 2017 -0400 TSCP: refactor signature validation and simplify Change-Id: I20e2f2825c9bd19d76ab450ffa70aca72fbb8b9a Reviewed-on: https://gerrit.libreoffice.org/44146 Tested-by: Jenkins <[email protected]> Reviewed-by: Ashod Nakashian <[email protected]> diff --git a/sw/inc/UndoParagraphSignature.hxx b/sw/inc/UndoParagraphSignature.hxx index 763a25d1ba6e..39b6dbf5d770 100644 --- a/sw/inc/UndoParagraphSignature.hxx +++ b/sw/inc/UndoParagraphSignature.hxx @@ -42,7 +42,7 @@ private: const bool m_bRemove; public: - SwUndoParagraphSigning(const SwPosition& rPos, + SwUndoParagraphSigning(SwDoc* pDoc, const uno::Reference<text::XTextField>& xField, const uno::Reference<text::XTextContent>& xParent, const bool bRemove); diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx index 285c4413c597..4461d9b0a04a 100644 --- a/sw/inc/editsh.hxx +++ b/sw/inc/editsh.hxx @@ -377,8 +377,11 @@ public: /// Sign the paragraph at the cursor. void SignParagraph(); - /// Validate paragraph signatures, if any, at the cursor. - void ValidateParagraphSignatures(bool updateDontRemove); + /// Validate current paragraph signatures, if any, at the cursor start. + void ValidateCurrentParagraphSignatures(bool updateDontRemove); + + /// Validate all paragraph signatures. + void ValidateAllParagraphSignatures(bool updateDontRemove); /// Ensure that the classification of the doc is never lower than /// the paragraph with the highest classification. diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index 30abe8ff5801..0e2fc36051bc 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -481,6 +481,60 @@ bool lcl_UpdateParagraphClassificationField(SwDoc* pDoc, return false; } +void lcl_ValidateParagraphSignatures(SwDoc* pDoc, const uno::Reference<text::XTextContent>& xParagraph, const bool updateDontRemove) +{ + SwDocShell* pDocShell = pDoc->GetDocShell(); + if (!pDocShell) + return; + + uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel(); + uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraph, uno::UNO_QUERY); + if (!xTextPortionEnumerationAccess.is()) + return; + + uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration(); + if (!xTextPortions.is()) + return; + + // Get the text (without fields). + const OString utf8Text = lcl_getParagraphBodyText(xParagraph); + if (utf8Text.isEmpty()) + return; + + while (xTextPortions->hasMoreElements()) + { + uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY); + OUString aTextPortionType; + xTextPortion->getPropertyValue(UNO_NAME_TEXT_PORTION_TYPE) >>= aTextPortionType; + if (aTextPortionType != UNO_NAME_TEXT_FIELD) + continue; + + uno::Reference<lang::XServiceInfo> xTextField; + xTextPortion->getPropertyValue(UNO_NAME_TEXT_FIELD) >>= xTextField; + if (!xTextField->supportsService(MetadataFieldServiceName)) + continue; + + uno::Reference<text::XTextField> xField(xTextField, uno::UNO_QUERY); + if (!lcl_IsParagraphSignatureField(xModel, xField)) + { + continue; + } + + if (updateDontRemove) + { + lcl_UpdateParagraphSignatureField(pDoc, xModel, xField, utf8Text); + } + else if (!lcl_MakeParagraphSignatureFieldText(xModel, xField, utf8Text).first) + { + pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::PARA_SIGN_ADD, nullptr); + SwUndoParagraphSigning* pUndo = new SwUndoParagraphSigning(pDoc, xField, xParagraph, false); + pDoc->GetIDocumentUndoRedo().AppendUndo(pUndo); + lcl_RemoveParagraphMetadataField(xField); + pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::PARA_SIGN_ADD, nullptr); + } + } +} + } // anonymous namespace SwTextFormatColl& SwEditShell::GetDfltTextFormatColl() const @@ -1417,12 +1471,12 @@ void SwEditShell::SetWatermark(const SfxWatermarkItem& rWatermark) } } -SwUndoParagraphSigning::SwUndoParagraphSigning(const SwPosition& rPos, +SwUndoParagraphSigning::SwUndoParagraphSigning(SwDoc* pDoc, const uno::Reference<text::XTextField>& xField, const uno::Reference<text::XTextContent>& xParent, const bool bRemove) - : SwUndo(SwUndoId::PARA_SIGN_ADD, rPos.GetDoc()), - m_pDoc(rPos.GetDoc()), + : SwUndo(SwUndoId::PARA_SIGN_ADD, pDoc), + m_pDoc(pDoc), m_xField(xField), m_xParent(xParent), m_bRemove(bRemove) @@ -1564,13 +1618,13 @@ void SwEditShell::SignParagraph() lcl_UpdateParagraphSignatureField(GetDoc(), xModel, xField, utf8Text); - SwUndoParagraphSigning* pUndo = new SwUndoParagraphSigning(SwPosition(*pNode), xField, xParent, true); + SwUndoParagraphSigning* pUndo = new SwUndoParagraphSigning(GetDoc(), xField, xParent, true); GetDoc()->GetIDocumentUndoRedo().AppendUndo(pUndo); GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::PARA_SIGN_ADD, nullptr); } -void SwEditShell::ValidateParagraphSignatures(bool updateDontRemove) +void SwEditShell::ValidateCurrentParagraphSignatures(bool updateDontRemove) { SwDocShell* pDocShell = GetDoc()->GetDocShell(); if (!pDocShell || !IsParagraphSignatureValidationEnabled()) @@ -1582,14 +1636,20 @@ void SwEditShell::ValidateParagraphSignatures(bool updateDontRemove) if (!pNode) return; - // 2. For each signature field, update it. - const uno::Reference<text::XTextContent> xParent = SwXParagraph::CreateXParagraph(*pNode->GetDoc(), pNode); - uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParent, uno::UNO_QUERY); - if (!xTextPortionEnumerationAccess.is()) - return; + // Prevent recursive validation since this is triggered on node updates, which we do below. + const bool bOldValidationFlag = SetParagraphSignatureValidation(false); + comphelper::ScopeGuard const g([this, bOldValidationFlag] () { + SetParagraphSignatureValidation(bOldValidationFlag); + }); - uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel(); - uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration(); + lcl_ValidateParagraphSignatures(GetDoc(), SwXParagraph::CreateXParagraph(*pNode->GetDoc(), pNode), updateDontRemove); +} + +void SwEditShell::ValidateAllParagraphSignatures(bool updateDontRemove) +{ + SwDocShell* pDocShell = GetDoc()->GetDocShell(); + if (!pDocShell || !IsParagraphSignatureValidationEnabled()) + return; // Prevent recursive validation since this is triggered on node updates, which we do below. const bool bOldValidationFlag = SetParagraphSignatureValidation(false); @@ -1597,42 +1657,19 @@ void SwEditShell::ValidateParagraphSignatures(bool updateDontRemove) SetParagraphSignatureValidation(bOldValidationFlag); }); - // 2. Get the text (without fields). - const OString utf8Text = lcl_getParagraphBodyText(xParent); - if (utf8Text.isEmpty()) + uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel(); + const uno::Reference<text::XTextDocument> xDoc(xModel, uno::UNO_QUERY); + uno::Reference<text::XText> xParent = xDoc->getText(); + uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xParent, uno::UNO_QUERY); + if (!xParagraphEnumerationAccess.is()) return; - - while (xTextPortions->hasMoreElements()) + uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration(); + if (!xParagraphs.is()) + return; + while (xParagraphs->hasMoreElements()) { - uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY); - OUString aTextPortionType; - xTextPortion->getPropertyValue(UNO_NAME_TEXT_PORTION_TYPE) >>= aTextPortionType; - if (aTextPortionType != UNO_NAME_TEXT_FIELD) - continue; - - uno::Reference<lang::XServiceInfo> xTextField; - xTextPortion->getPropertyValue(UNO_NAME_TEXT_FIELD) >>= xTextField; - if (!xTextField->supportsService(MetadataFieldServiceName)) - continue; - - uno::Reference<text::XTextField> xField(xTextField, uno::UNO_QUERY); - if (!lcl_IsParagraphSignatureField(xModel, xField)) - { - continue; - } - - if (updateDontRemove) - { - lcl_UpdateParagraphSignatureField(GetDoc(), xModel, xField, utf8Text); - } - else if (!lcl_MakeParagraphSignatureFieldText(xModel, xField, utf8Text).first) - { - GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::PARA_SIGN_ADD, nullptr); - SwUndoParagraphSigning* pUndo = new SwUndoParagraphSigning(SwPosition(*pNode), xField, xParent, false); - GetDoc()->GetIDocumentUndoRedo().AppendUndo(pUndo); - lcl_RemoveParagraphMetadataField(xField); - GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::PARA_SIGN_ADD, nullptr); - } + uno::Reference<text::XTextContent> xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY); + lcl_ValidateParagraphSignatures(GetDoc(), xParagraph, updateDontRemove); } } diff --git a/sw/source/core/edit/edws.cxx b/sw/source/core/edit/edws.cxx index c19d373a8bfb..01dc694ab450 100644 --- a/sw/source/core/edit/edws.cxx +++ b/sw/source/core/edit/edws.cxx @@ -53,7 +53,10 @@ SwEditShell::SwEditShell( SwDoc& rDoc, vcl::Window *pWindow, const SwViewOption // Update the paragraph signatures. // Since this ctor is called only on creating/loading the doc, we validate once only. - ValidateParagraphSignatures(true); + //FIXME: This is taking too long for the scheduler's taste. + // Need to do a quick check to see if a paragraph is signed or not, + // but for that need paragraph RDF, which is in a later patch. + // ValidateAllParagraphSignatures(true); } SwEditShell::~SwEditShell() // USED diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index 666f8a05e1ca..2fc443a2d4ba 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -1214,7 +1214,7 @@ void SwTextNode::Update( // Update the paragraph signatures. if (SwEditShell* pEditShell = GetDoc()->GetEditShell()) { - pEditShell->ValidateParagraphSignatures(true); + pEditShell->ValidateCurrentParagraphSignatures(true); } // Inform LOK clients about change in position of redlines (if any) diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx index d5543c5af7cc..40d52c938b4f 100644 --- a/sw/source/uibase/app/docsh.cxx +++ b/sw/source/uibase/app/docsh.cxx @@ -473,7 +473,7 @@ bool SwDocShell::SaveAs( SfxMedium& rMedium ) m_pWrtShell->EndAllTableBoxEdit(); // Remove invalid signatures. - m_pWrtShell->ValidateParagraphSignatures(false); + m_pWrtShell->ValidateAllParagraphSignatures(false); m_pWrtShell->ClassifyDocPerHighestParagraphClass(); } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
