sw/source/core/edit/edfcol.cxx |   37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

New commits:
commit e4969b2b63bff3f1dba2c46848107f4ab9c0fa3a
Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
Date:   Fri Nov 17 10:56:24 2017 +0900

    TSCP: add category from doc. properties if not found in header
    
    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 <qui...@gmail.com>
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>

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<svx::ClassificationResult> 
SwEditShell::CollectAdvancedClassificatio
     if (!pDocShell || !SfxObjectShell::Current())
         return aResult;
 
+    const OUString sBlank;
+
+    uno::Reference<document::XDocumentProperties> xDocumentProperties = 
SfxObjectShell::Current()->getDocProperties();
+    uno::Reference<beans::XPropertyContainer> xPropertyContainer = 
xDocumentProperties->getUserDefinedProperties();
+    sfx::ClassificationKeyCreator 
aCreator(SfxClassificationHelper::getPolicyType());
+
     uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
     uno::Reference<style::XStyleFamiliesSupplier> 
xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
     uno::Reference<container::XNameAccess> 
xStyleFamilies(xStyleFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY);
@@ -933,7 +939,13 @@ std::vector<svx::ClassificationResult> 
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<text::XText> xHeaderText;
     xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText;
@@ -941,12 +953,8 @@ std::vector<svx::ClassificationResult> 
SwEditShell::CollectAdvancedClassificatio
     uno::Reference<container::XEnumerationAccess> 
xParagraphEnumerationAccess(xHeaderText, uno::UNO_QUERY);
     uno::Reference<container::XEnumeration> xParagraphs = 
xParagraphEnumerationAccess->createEnumeration();
 
-    uno::Reference<document::XDocumentProperties> xDocumentProperties = 
SfxObjectShell::Current()->getDocProperties();
-    uno::Reference<beans::XPropertyContainer> 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<svx::ClassificationResult> 
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<svx::ClassificationResult> 
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;
 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to