sw/inc/editsh.hxx | 4 +++ sw/source/core/crsr/pam.cxx | 28 ++------------------------ sw/source/core/edit/edfcol.cxx | 44 ++++++++++++++++++++++++++++++++--------- 3 files changed, 42 insertions(+), 34 deletions(-)
New commits: commit 3823697d99b28592d8923e099b6aab577d5cd339 Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sun Sep 24 21:51:13 2017 -0400 TSCP: refactor paragraph metadata field check This moves the logic into SwEditShell next to the exiting paragraph metadata infrastructure. Change-Id: I6c12bfca3d2e1b2bc8697f03f4de1b7c3e14b95a Reviewed-on: https://gerrit.libreoffice.org/42742 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx index 50c5bf75e44e..7a8164c9ef70 100644 --- a/sw/inc/editsh.hxx +++ b/sw/inc/editsh.hxx @@ -380,6 +380,10 @@ public: /// Validate paragraph signatures, if any, at the cursor. void ValidateParagraphSignatures(bool updateDontRemove); + /// Returns true iff the cursor is within a paragraph metadata field. + /// Currently there are two variants: signature and classification. + bool IsCursorInParagraphMetadataField() const; + void Insert2(SwField const &, const bool bForceExpandHints); void UpdateFields( SwField & ); ///< One single field. diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx index dc7314e4896e..2afae847e64b 100644 --- a/sw/source/core/crsr/pam.cxx +++ b/sw/source/core/crsr/pam.cxx @@ -43,9 +43,7 @@ #include <hints.hxx> #include <xmloff/odffields.hxx> -#include <rdfhelper.hxx> -#include <txtatr.hxx> -#include <docsh.hxx> +#include <editsh.hxx> // for the dump "MSC-" compiler inline sal_Int32 GetSttOrEnd( bool bCondition, const SwContentNode& rNd ) @@ -715,30 +713,10 @@ bool SwPaM::HasReadonlySel( bool bFormView ) const bRet = !( pA == pB && pA != nullptr ); } - // Paragraph Signatures are read-only. if (!bRet) { - SwTextNode* pNode = Start()->nNode.GetNode().GetTextNode(); - if (pNode != nullptr) - { - SwTextAttr* pAttr = pNode->GetTextAttrAt(Start()->nContent.GetIndex(), RES_TXTATR_METAFIELD); - SwTextMeta* pTextMeta = static_txtattr_cast<SwTextMeta*>(pAttr); - if (pTextMeta) - { - SwFormatMeta& rFormatMeta(static_cast<SwFormatMeta&>(pTextMeta->GetAttr())); - if (::sw::Meta* pMeta = rFormatMeta.GetMeta()) - { - if (const SwDocShell* pDocSh = pDoc->GetDocShell()) - { - static const OUString metaNS("urn:bails"); - const css::uno::Reference<css::rdf::XResource> xSubject(pMeta->MakeUnoObject(), uno::UNO_QUERY); - uno::Reference<frame::XModel> xModel = pDocSh->GetBaseModel(); - const std::map<OUString, OUString> aStatements = SwRDFHelper::getStatements(xModel, metaNS, xSubject); - bRet = (aStatements.find("loext:paragraph:signature") != aStatements.end()); - } - } - } - } + // Paragraph Signatures and Classification fields are read-only. + bRet = pDoc->GetEditShell()->IsCursorInParagraphMetadataField(); } return bRet; diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index 134682671242..d696fe02eaa3 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -79,6 +79,7 @@ #include <strings.hrc> #include <undobj.hxx> #include <UndoParagraphSignature.hxx> +#include <txtatr.hxx> #include <officecfg/Office/Common.hxx> #include <com/sun/star/beans/PropertyAttribute.hpp> @@ -1155,6 +1156,32 @@ void SwEditShell::ValidateParagraphSignatures(bool updateDontRemove) } } +bool SwEditShell::IsCursorInParagraphMetadataField() const +{ + SwTextNode* pNode = GetCursor()->Start()->nNode.GetNode().GetTextNode(); + if (pNode != nullptr) + { + SwTextAttr* pAttr = pNode->GetTextAttrAt(GetCursor()->Start()->nContent.GetIndex(), RES_TXTATR_METAFIELD); + SwTextMeta* pTextMeta = static_txtattr_cast<SwTextMeta*>(pAttr); + if (pTextMeta != nullptr) + { + SwFormatMeta& rFormatMeta(static_cast<SwFormatMeta&>(pTextMeta->GetAttr())); + if (::sw::Meta* pMeta = rFormatMeta.GetMeta()) + { + if (const SwDocShell* pDocSh = GetDoc()->GetDocShell()) + { + const css::uno::Reference<css::rdf::XResource> xSubject(pMeta->MakeUnoObject(), uno::UNO_QUERY); + uno::Reference<frame::XModel> xModel = pDocSh->GetBaseModel(); + const std::map<OUString, OUString> aStatements = SwRDFHelper::getStatements(xModel, MetaNS, xSubject); + return (aStatements.find(ParagraphSignatureRDFName) != aStatements.end()); + } + } + } + } + + return false; +} + // #i62675# void SwEditShell::SetTextFormatColl(SwTextFormatColl *pFormat, const bool bResetListAttrs) commit cfb355ec205044234840405fde4343898c2ea97b Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sun Sep 24 21:15:49 2017 -0400 TSCP: cleanup more constant strings Change-Id: I244a3fc7899b3269cfdc76172f5dd57a2b987373 Reviewed-on: https://gerrit.libreoffice.org/42741 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index 9ab83df7e36f..134682671242 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -91,6 +91,7 @@ static const OUString MetaFilename("bails.rdf"); static const OUString MetaNS("urn:bails"); static const OUString ParagraphSignatureRDFName = "loext:paragraph:signature"; static const OUString MetadataFieldServiceName = "com.sun.star.text.textfield.MetadataField"; +static const OUString DocInfoServiceName = "com.sun.star.text.TextField.DocInfo.Custom"; /// Find all page styles which are currently used in the document. std::vector<OUString> lcl_getUsedPageStyles(SwViewShell const * pShell) @@ -382,10 +383,9 @@ bool addOrInsertDocumentProperty(uno::Reference<beans::XPropertyContainer> const void insertFieldToDocument(uno::Reference<lang::XMultiServiceFactory> const & rxMultiServiceFactory, uno::Reference<text::XText> const & rxText, OUString const & rsKey) { - const OUString aServiceName = "com.sun.star.text.TextField.DocInfo.Custom"; - if (!lcl_hasField(rxText, aServiceName, rsKey)) + if (!lcl_hasField(rxText, DocInfoServiceName, rsKey)) { - uno::Reference<beans::XPropertySet> xField(rxMultiServiceFactory->createInstance(aServiceName), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xField(rxMultiServiceFactory->createInstance(DocInfoServiceName), uno::UNO_QUERY); xField->setPropertyValue(UNO_NAME_NAME, uno::makeAny(rsKey)); uno::Reference<text::XTextContent> xTextContent(xField, uno::UNO_QUERY); rxText->insertTextContent(rxText->getEnd(), xTextContent, false); @@ -544,7 +544,7 @@ std::vector<svx::ClassificationResult> SwEditShell::CollectAdvancedClassificatio uno::Reference<lang::XServiceInfo> xTextField; xTextPortion->getPropertyValue(UNO_NAME_TEXT_FIELD) >>= xTextField; - if (!xTextField->supportsService("com.sun.star.text.TextField.DocInfo.Custom")) + if (!xTextField->supportsService(DocInfoServiceName)) continue; OUString aName; @@ -607,7 +607,6 @@ void SwEditShell::SetClassification(const OUString& rName, SfxClassificationPoli for (const OUString& rPageStyleName : aStyles) { uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY); - const OUString aServiceName = "com.sun.star.text.TextField.DocInfo.Custom"; uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY); if (bHeaderIsNeeded || bWatermarkIsNeeded || bHadWatermark) @@ -624,10 +623,10 @@ void SwEditShell::SetClassification(const OUString& rName, SfxClassificationPoli if (bHeaderIsNeeded) { - if (!lcl_hasField(xHeaderText, aServiceName, SfxClassificationHelper::PROP_PREFIX_INTELLECTUALPROPERTY() + SfxClassificationHelper::PROP_DOCHEADER())) + if (!lcl_hasField(xHeaderText, DocInfoServiceName, SfxClassificationHelper::PROP_PREFIX_INTELLECTUALPROPERTY() + SfxClassificationHelper::PROP_DOCHEADER())) { // Append a field to the end of the header text. - uno::Reference<beans::XPropertySet> xField(xMultiServiceFactory->createInstance(aServiceName), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xField(xMultiServiceFactory->createInstance(DocInfoServiceName), uno::UNO_QUERY); xField->setPropertyValue(UNO_NAME_NAME, uno::makeAny(SfxClassificationHelper::PROP_PREFIX_INTELLECTUALPROPERTY() + SfxClassificationHelper::PROP_DOCHEADER())); uno::Reference<text::XTextContent> xTextContent(xField, uno::UNO_QUERY); xHeaderText->insertTextContent(xHeaderText->getEnd(), xTextContent, /*bAbsorb=*/false); @@ -651,10 +650,10 @@ void SwEditShell::SetClassification(const OUString& rName, SfxClassificationPoli uno::Reference<text::XText> xFooterText; xPageStyle->getPropertyValue(UNO_NAME_FOOTER_TEXT) >>= xFooterText; static OUString sFooter = SfxClassificationHelper::PROP_PREFIX_INTELLECTUALPROPERTY() + SfxClassificationHelper::PROP_DOCFOOTER(); - if (!lcl_hasField(xFooterText, aServiceName, sFooter)) + if (!lcl_hasField(xFooterText, DocInfoServiceName, sFooter)) { // Append a field to the end of the footer text. - uno::Reference<beans::XPropertySet> xField(xMultiServiceFactory->createInstance(aServiceName), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xField(xMultiServiceFactory->createInstance(DocInfoServiceName), uno::UNO_QUERY); xField->setPropertyValue(UNO_NAME_NAME, uno::makeAny(sFooter)); uno::Reference<text::XTextContent> xTextContent(xField, uno::UNO_QUERY); xFooterText->insertTextContent(xFooterText->getEnd(), xTextContent, /*bAbsorb=*/false); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits