From e4969b2b63bff3f1dba2c46848107f4ab9c0fa3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Vajngerl?= Date: Fri, 17 Nov 2017 10:56:24 +0900 Subject: [PATCH] TSCP: add category from doc. properties if not found in header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we selected the classification on the toolbar and then go into the classification dialog, we need to add the current category from the doc. properties to the classification result so it is shown in the dialog automatically. Change-Id: I80909d39efa61f263fdb7dd10188f8d7ae12d1e0 Reviewed-on: https://gerrit.libreoffice.org/44853 Reviewed-by: Tomaž Vajngerl Tested-by: Tomaž Vajngerl --- sw/source/core/edit/edfcol.cxx | 37 +++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index d713d1ddca4f..48329c85a51e 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -921,6 +921,12 @@ std::vector SwEditShell::CollectAdvancedClassificatio if (!pDocShell || !SfxObjectShell::Current()) return aResult; + const OUString sBlank; + + uno::Reference xDocumentProperties = SfxObjectShell::Current()->getDocProperties(); + uno::Reference xPropertyContainer = xDocumentProperties->getUserDefinedProperties(); + sfx::ClassificationKeyCreator aCreator(SfxClassificationHelper::getPolicyType()); + uno::Reference xModel = pDocShell->GetBaseModel(); uno::Reference xStyleFamiliesSupplier(xModel, uno::UNO_QUERY); uno::Reference xStyleFamilies(xStyleFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY); @@ -933,7 +939,13 @@ std::vector SwEditShell::CollectAdvancedClassificatio bool bHeaderIsOn = false; xPageStyle->getPropertyValue(UNO_NAME_HEADER_IS_ON) >>= bHeaderIsOn; if (!bHeaderIsOn) + { + const OUString aValue = svx::classification::getProperty(xPropertyContainer, aCreator.makeCategoryNameKey()); + if (!aValue.isEmpty()) + aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank, sBlank }); + return aResult; + } uno::Reference xHeaderText; xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText; @@ -941,12 +953,8 @@ std::vector SwEditShell::CollectAdvancedClassificatio uno::Reference xParagraphEnumerationAccess(xHeaderText, uno::UNO_QUERY); uno::Reference xParagraphs = xParagraphEnumerationAccess->createEnumeration(); - uno::Reference xDocumentProperties = SfxObjectShell::Current()->getDocProperties(); - uno::Reference xPropertyContainer = xDocumentProperties->getUserDefinedProperties(); - - sfx::ClassificationKeyCreator aCreator(SfxClassificationHelper::getPolicyType()); - - const OUString sBlank(""); + // set to true if category was found in the header + bool bFoundClassificationCategory = false; while (xParagraphs->hasMoreElements()) { @@ -987,11 +995,19 @@ std::vector SwEditShell::CollectAdvancedClassificatio if (!aValue.isEmpty()) aResult.push_back({ svx::ClassificationType::TEXT, aValue, sBlank, sBlank }); } - else if (aCreator.isCategoryNameKey(aName) || aCreator.isCategoryIdentifierKey(aName)) + else if (aCreator.isCategoryNameKey(aName)) { const OUString aValue = svx::classification::getProperty(xPropertyContainer, aName); if (!aValue.isEmpty()) aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank, sBlank }); + bFoundClassificationCategory = true; + } + else if (aCreator.isCategoryIdentifierKey(aName)) + { + const OUString aValue = svx::classification::getProperty(xPropertyContainer, aName); + if (!aValue.isEmpty()) + aResult.push_back({ svx::ClassificationType::CATEGORY, sBlank, sBlank, aValue }); + bFoundClassificationCategory = true; } else if (aCreator.isMarkingKey(aName)) { @@ -1008,6 +1024,13 @@ std::vector SwEditShell::CollectAdvancedClassificatio } } + if (!bFoundClassificationCategory) + { + const OUString aValue = svx::classification::getProperty(xPropertyContainer, aCreator.makeCategoryNameKey()); + if (!aValue.isEmpty()) + aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank, sBlank }); + } + return aResult; }