[Libreoffice-commits] core.git: include/svx sd/source svx/source sw/source

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Mon Nov 6 08:39:38 UTC 2017


 include/svx/ClassificationCommon.hxx       |    8 +++
 sd/source/ui/view/drviews2.cxx             |   59 +++---------------------
 svx/source/dialog/ClassificationCommon.cxx |   31 +++++++++++--
 svx/source/dialog/ClassificationDialog.cxx |   69 ++++++++++++-----------------
 sw/source/core/edit/edfcol.cxx             |   67 +++-------------------------
 5 files changed, 81 insertions(+), 153 deletions(-)

New commits:
commit 0a4ad544daaec4f773480e6301238c7f6958a9ab
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Mon Nov 6 13:30:01 2017 +0900

    TSCP: put more duplicated methods to common
    
    Change-Id: Ic49e0dad1351684db3372214604d12b48d0be907
    Reviewed-on: https://gerrit.libreoffice.org/44337
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/svx/ClassificationCommon.hxx b/include/svx/ClassificationCommon.hxx
index 04e0494cc7ad..2276c962532d 100644
--- a/include/svx/ClassificationCommon.hxx
+++ b/include/svx/ClassificationCommon.hxx
@@ -23,6 +23,14 @@ namespace classification {
 
 SVX_DLLPUBLIC OUString convertClassificationResultToString(std::vector<svx::ClassificationResult> const & rResults);
 
+SVX_DLLPUBLIC OUString getProperty(css::uno::Reference<css::beans::XPropertyContainer> const & rxPropertyContainer,
+                                   OUString const & rName);
+
+SVX_DLLPUBLIC bool containsProperty(css::uno::Sequence<css::beans::Property> const & rProperties,
+                                    OUString const & rName);
+
+SVX_DLLPUBLIC void removeAllProperties(css::uno::Reference<css::beans::XPropertyContainer> const & rxPropertyContainer);
+
 SVX_DLLPUBLIC bool addOrInsertDocumentProperty(css::uno::Reference<css::beans::XPropertyContainer> const & rxPropertyContainer,
                                                OUString const & rsKey, OUString const & rsValue);
 
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index 8a0c20a41889..2095738f62f6 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -192,49 +192,6 @@ namespace sd {
 
 namespace {
 
-void lcl_removeAllProperties(uno::Reference<beans::XPropertyContainer> const & rxPropertyContainer)
-{
-    uno::Reference<beans::XPropertySet> xPropertySet(rxPropertyContainer, uno::UNO_QUERY);
-    uno::Sequence<beans::Property> aProperties = xPropertySet->getPropertySetInfo()->getProperties();
-
-    for (const beans::Property& rProperty : aProperties)
-    {
-        rxPropertyContainer->removeProperty(rProperty.Name);
-    }
-}
-
-bool lcl_containsProperty(const uno::Sequence<beans::Property> & rProperties, const OUString& rName)
-{
-    return std::find_if(rProperties.begin(), rProperties.end(), [&](const beans::Property& rProperty)
-    {
-        return rProperty.Name == rName;
-    }) != rProperties.end();
-}
-
-OUString lcl_getProperty(uno::Reference<beans::XPropertyContainer> const & rxPropertyContainer, const OUString& rName)
-{
-    uno::Reference<beans::XPropertySet> xPropertySet(rxPropertyContainer, uno::UNO_QUERY);
-    return xPropertySet->getPropertyValue(rName).get<OUString>();
-}
-
-bool addOrInsertDocumentProperty(uno::Reference<beans::XPropertyContainer> const & rxPropertyContainer, OUString const & rsKey, OUString const & rsValue)
-{
-    uno::Reference<beans::XPropertySet> xPropertySet(rxPropertyContainer, uno::UNO_QUERY);
-
-    try
-    {
-        if (lcl_containsProperty(xPropertySet->getPropertySetInfo()->getProperties(), rsKey))
-            xPropertySet->setPropertyValue(rsKey, uno::makeAny(rsValue));
-        else
-            rxPropertyContainer->addProperty(rsKey, beans::PropertyAttribute::REMOVABLE, uno::makeAny(rsValue));
-    }
-    catch (const uno::Exception& /*rException*/)
-    {
-        return false;
-    }
-    return true;
-}
-
 const SvxFieldItem* findField(editeng::Section const & rSection)
 {
     for (SfxPoolItem const * pPool: rSection.maAttributes)
@@ -321,22 +278,22 @@ private:
                 OUString aKey = pCustomPropertyField->GetName();
                 if (aKeyCreator.isMarkingTextKey(aKey))
                 {
-                    OUString aValue = lcl_getProperty(xPropertyContainer, aKey);
+                    OUString aValue = svx::classification::getProperty(xPropertyContainer, aKey);
                     m_aResults.push_back({ svx::ClassificationType::TEXT, aValue, sBlank, sBlank });
                 }
                 else if (aKeyCreator.isCategoryNameKey(aKey) || aKeyCreator.isCategoryIdentifierKey(aKey))
                 {
-                    OUString aValue = lcl_getProperty(xPropertyContainer, aKey);
+                    OUString aValue = svx::classification::getProperty(xPropertyContainer, aKey);
                     m_aResults.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank, sBlank });
                 }
                 else if (aKeyCreator.isMarkingKey(aKey))
                 {
-                    OUString aValue = lcl_getProperty(xPropertyContainer, aKey);
+                    OUString aValue = svx::classification::getProperty(xPropertyContainer, aKey);
                     m_aResults.push_back({ svx::ClassificationType::MARKING, aValue, sBlank, sBlank });
                 }
                 else if (aKeyCreator.isIntellectualPropertyPartKey(aKey))
                 {
-                    OUString aValue = lcl_getProperty(xPropertyContainer, aKey);
+                    OUString aValue = svx::classification::getProperty(xPropertyContainer, aKey);
                     m_aResults.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, aValue, sBlank, sBlank });
                 }
             }
@@ -463,7 +420,7 @@ public:
         uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
 
         // Clear properties
-        lcl_removeAllProperties(xPropertyContainer);
+        svx::classification::removeAllProperties(xPropertyContainer);
 
         SfxClassificationHelper aHelper(xDocumentProperties);
 
@@ -497,7 +454,7 @@ public:
                 case svx::ClassificationType::TEXT:
                 {
                     OUString sKey = aKeyCreator.makeNumberedMarkingTextKey();
-                    addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msName);
+                    svx::classification::addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msName);
                     pOutliner->QuickInsertField(SvxFieldItem(editeng::CustomPropertyField(sKey, rResult.msName), EE_FEATURE_FIELD), aPosition);
                 }
                 break;
@@ -512,7 +469,7 @@ public:
                 case svx::ClassificationType::MARKING:
                 {
                     OUString sKey = aKeyCreator.makeMarkingKey();
-                    addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msName);
+                    svx::classification::addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msName);
                     pOutliner->QuickInsertField(SvxFieldItem(editeng::CustomPropertyField(sKey, rResult.msName), EE_FEATURE_FIELD), aPosition);
                 }
                 break;
@@ -520,7 +477,7 @@ public:
                 case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART:
                 {
                     OUString sKey = aKeyCreator.makeIntellectualPropertyPartKey();
-                    addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msName);
+                    svx::classification::addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msName);
                     pOutliner->QuickInsertField(SvxFieldItem(editeng::CustomPropertyField(sKey, rResult.msName), EE_FEATURE_FIELD), aPosition);
                 }
                 break;
diff --git a/svx/source/dialog/ClassificationCommon.cxx b/svx/source/dialog/ClassificationCommon.cxx
index 60cfcf520ab4..4d5d74938d5b 100644
--- a/svx/source/dialog/ClassificationCommon.cxx
+++ b/svx/source/dialog/ClassificationCommon.cxx
@@ -40,7 +40,21 @@ OUString convertClassificationResultToString(std::vector<svx::ClassificationResu
     return sRepresentation;
 }
 
-bool lcl_containsProperty(const uno::Sequence<beans::Property> & rProperties, const OUString& rName)
+OUString getProperty(uno::Reference<beans::XPropertyContainer> const & rxPropertyContainer, OUString const & rName)
+{
+    try
+    {
+        uno::Reference<beans::XPropertySet> xPropertySet(rxPropertyContainer, uno::UNO_QUERY);
+        return xPropertySet->getPropertyValue(rName).get<OUString>();
+    }
+    catch (const css::uno::Exception&)
+    {
+    }
+
+    return OUString();
+}
+
+bool containsProperty(uno::Sequence<beans::Property> const & rProperties, OUString const & rName)
 {
     return std::find_if(rProperties.begin(), rProperties.end(), [&](const beans::Property& rProperty)
     {
@@ -48,13 +62,24 @@ bool lcl_containsProperty(const uno::Sequence<beans::Property> & rProperties, co
     }) != rProperties.end();
 }
 
+void removeAllProperties(uno::Reference<beans::XPropertyContainer> const & rxPropertyContainer)
+{
+    uno::Reference<beans::XPropertySet> xPropertySet(rxPropertyContainer, uno::UNO_QUERY);
+    uno::Sequence<beans::Property> aProperties = xPropertySet->getPropertySetInfo()->getProperties();
+
+    for (const beans::Property& rProperty : aProperties)
+    {
+        rxPropertyContainer->removeProperty(rProperty.Name);
+    }
+}
+
 bool addOrInsertDocumentProperty(uno::Reference<beans::XPropertyContainer> const & rxPropertyContainer, OUString const & rsKey, OUString const & rsValue)
 {
     uno::Reference<beans::XPropertySet> xPropertySet(rxPropertyContainer, uno::UNO_QUERY);
 
     try
     {
-        if (lcl_containsProperty(xPropertySet->getPropertySetInfo()->getProperties(), rsKey))
+        if (containsProperty(xPropertySet->getPropertySetInfo()->getProperties(), rsKey))
             xPropertySet->setPropertyValue(rsKey, uno::makeAny(rsValue));
         else
             rxPropertyContainer->addProperty(rsKey, beans::PropertyAttribute::REMOVABLE, uno::makeAny(rsValue));
@@ -70,7 +95,7 @@ void insertFullTextualRepresentationAsDocumentProperty(uno::Reference<beans::XPr
                                                        sfx::ClassificationKeyCreator const & rKeyCreator,
                                                        std::vector<svx::ClassificationResult> const & rResults)
 {
-    OUString sString = svx::classification::convertClassificationResultToString(rResults);
+    OUString sString = convertClassificationResultToString(rResults);
     addOrInsertDocumentProperty(rxPropertyContainer, rKeyCreator.makeFullTextualRepresentationKey(), sString);
 }
 
diff --git a/svx/source/dialog/ClassificationDialog.cxx b/svx/source/dialog/ClassificationDialog.cxx
index 9458ceb95b3e..34b5d1504344 100644
--- a/svx/source/dialog/ClassificationDialog.cxx
+++ b/svx/source/dialog/ClassificationDialog.cxx
@@ -9,6 +9,7 @@
  */
 
 #include <svx/ClassificationDialog.hxx>
+#include <svx/ClassificationCommon.hxx>
 #include <svx/strings.hrc>
 #include <svx/dialmgr.hxx>
 
@@ -78,6 +79,15 @@ namespace {
 
 constexpr size_t RECENTLY_USED_LIMIT = 5;
 
+const OUString constRecentlyUsedFileName("recentlyUsed.xml");
+
+OUString lcl_getClassificationUserPath()
+{
+    OUString sPath("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/user/classification/");
+    rtl::Bootstrap::expandMacros(sPath);
+    return sPath;
+}
+
 const SvxFieldItem* findField(editeng::Section const & rSection)
 {
     for (SfxPoolItem const * pPool : rSection.maAttributes)
@@ -112,26 +122,22 @@ bool stringToClassificationType(OString const & rsType, svx::ClassificationType
     return true;
 }
 
-OUString getStringRepresentation(std::vector<ClassificationResult> const & rResults)
+OUString classificationTypeToString(svx::ClassificationType const & reType)
 {
-    OUString sRepresentation = "";
-    for (ClassificationResult const & rResult : rResults)
+    switch(reType)
     {
-        switch (rResult.meType)
-        {
-            case svx::ClassificationType::CATEGORY:
-            case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART:
-            case svx::ClassificationType::MARKING:
-            case svx::ClassificationType::TEXT:
-                sRepresentation += rResult.msName;
-            break;
-
-            case svx::ClassificationType::PARAGRAPH:
-                sRepresentation += " ";
-            break;
-        }
+        case svx::ClassificationType::CATEGORY:
+            return OUString("CATEGORY"); break;
+        case svx::ClassificationType::MARKING:
+            return OUString("MARKING"); break;
+        case svx::ClassificationType::TEXT:
+            return OUString("TEXT"); break;
+        case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART:
+            return OUString("INTELLECTUAL_PROPERTY_PART"); break;
+        case svx::ClassificationType::PARAGRAPH:
+            return OUString("PARAGRAPH"); break;
     }
-    return sRepresentation;
+    return OUString();
 }
 
 void writeResultToXml(tools::XmlWriter & rXmlWriter,
@@ -140,20 +146,7 @@ void writeResultToXml(tools::XmlWriter & rXmlWriter,
     for (ClassificationResult const & rResult : rResultCollection)
     {
         rXmlWriter.startElement("element");
-        OUString sType;
-        switch(rResult.meType)
-        {
-            case svx::ClassificationType::CATEGORY:
-                sType = "CATEGORY"; break;
-            case svx::ClassificationType::MARKING:
-                sType = "MARKING"; break;
-            case svx::ClassificationType::TEXT:
-                sType = "TEXT"; break;
-            case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART:
-                sType = "INTELLECTUAL_PROPERTY_PART"; break;
-            case svx::ClassificationType::PARAGRAPH:
-                sType = "PARAGRAPH"; break;
-        }
+        OUString sType = classificationTypeToString(rResult.meType);
         rXmlWriter.attribute("type", sType);
         rXmlWriter.startElement("string");
         rXmlWriter.content(rResult.msName);
@@ -276,7 +269,7 @@ short ClassificationDialog::Execute()
     {
         for (std::vector<ClassificationResult> const & rResults : m_aRecentlyUsedValuesCollection)
         {
-            OUString rContentRepresentation = getStringRepresentation(rResults);
+            OUString rContentRepresentation = svx::classification::convertClassificationResultToString(rResults);
             OUString rDescription = OUString::number(nNumber) + ": ";
             nNumber++;
 
@@ -310,10 +303,8 @@ void ClassificationDialog::setupValues(std::vector<ClassificationResult> const &
 
 void ClassificationDialog::readRecentlyUsed()
 {
-    OUString sPath("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/user/classification/");
-    rtl::Bootstrap::expandMacros(sPath);
-
-    OUString sFilePath(sPath + "recentlyUsed.xml");
+    OUString sPath = lcl_getClassificationUserPath();
+    OUString sFilePath(sPath + constRecentlyUsedFileName);
 
     if (!fileExists(sFilePath))
         return;
@@ -378,11 +369,9 @@ void ClassificationDialog::readRecentlyUsed()
 
 void ClassificationDialog::writeRecentlyUsed()
 {
-    OUString sPath("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/user/classification/");
-    rtl::Bootstrap::expandMacros(sPath);
+    OUString sPath = lcl_getClassificationUserPath();
     osl::Directory::createPath(sPath);
-
-    OUString sFilePath(sPath + "recentlyUsed.xml");
+    OUString sFilePath(sPath + constRecentlyUsedFileName);
 
     std::unique_ptr<SvStream> pStream;
     pStream.reset(new SvFileStream(sFilePath, StreamMode::STD_READWRITE | StreamMode::TRUNC));
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index 2486c3fb769e..a388be593dc1 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -621,57 +621,6 @@ SwTextFormatColl& SwEditShell::GetTextFormatColl(sal_uInt16 nFormatColl) const
     return *((*(GetDoc()->GetTextFormatColls()))[nFormatColl]);
 }
 
-OUString lcl_getProperty(uno::Reference<beans::XPropertyContainer> const & rxPropertyContainer, const OUString& rName)
-{
-    try
-    {
-        uno::Reference<beans::XPropertySet> xPropertySet(rxPropertyContainer, uno::UNO_QUERY);
-        return xPropertySet->getPropertyValue(rName).get<OUString>();
-    }
-    catch (const css::uno::Exception&)
-    {
-    }
-
-    return OUString();
-}
-
-static bool lcl_containsProperty(const uno::Sequence<beans::Property> & rProperties, const OUString& rName)
-{
-    return std::find_if(rProperties.begin(), rProperties.end(), [&](const beans::Property& rProperty)
-    {
-        return rProperty.Name == rName;
-    }) != rProperties.end();
-}
-
-static void lcl_removeAllProperties(uno::Reference<beans::XPropertyContainer> const & rxPropertyContainer)
-{
-    uno::Reference<beans::XPropertySet> xPropertySet(rxPropertyContainer, uno::UNO_QUERY);
-    uno::Sequence<beans::Property> aProperties = xPropertySet->getPropertySetInfo()->getProperties();
-
-    for (const beans::Property& rProperty : aProperties)
-    {
-        rxPropertyContainer->removeProperty(rProperty.Name);
-    }
-}
-
-bool addOrInsertDocumentProperty(uno::Reference<beans::XPropertyContainer> const & rxPropertyContainer, OUString const & rsKey, OUString const & rsValue)
-{
-    uno::Reference<beans::XPropertySet> xPropertySet(rxPropertyContainer, uno::UNO_QUERY);
-
-    try
-    {
-        if (lcl_containsProperty(xPropertySet->getPropertySetInfo()->getProperties(), rsKey))
-            xPropertySet->setPropertyValue(rsKey, uno::makeAny(rsValue));
-        else
-            rxPropertyContainer->addProperty(rsKey, beans::PropertyAttribute::REMOVABLE, uno::makeAny(rsValue));
-    }
-    catch (const uno::Exception& /*rException*/)
-    {
-        return false;
-    }
-    return true;
-}
-
 void insertFieldToDocument(uno::Reference<lang::XMultiServiceFactory> const & rxMultiServiceFactory,
                            uno::Reference<text::XText> const & rxText, uno::Reference<text::XParagraphCursor> const & rxParagraphCursor,
                            OUString const & rsKey)
@@ -791,7 +740,7 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes
 
     // Clear properties
     uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
-    lcl_removeAllProperties(xPropertyContainer);
+    svx::classification::removeAllProperties(xPropertyContainer);
 
     SfxClassificationHelper aHelper(xDocumentProperties);
 
@@ -842,7 +791,7 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes
                 {
                     OUString sKey = aCreator.makeNumberedMarkingTextKey();
 
-                    addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msName);
+                    svx::classification::addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msName);
                     insertFieldToDocument(xMultiServiceFactory, xHeaderText, xHeaderParagraphCursor, sKey);
                     insertFieldToDocument(xMultiServiceFactory, xFooterText, xFooterParagraphCursor, sKey);
                 }
@@ -859,7 +808,7 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes
                 case svx::ClassificationType::MARKING:
                 {
                     OUString sKey = aCreator.makeMarkingKey();
-                    addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msName);
+                    svx::classification::addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msName);
                     insertFieldToDocument(xMultiServiceFactory, xHeaderText, xHeaderParagraphCursor, sKey);
                     insertFieldToDocument(xMultiServiceFactory, xFooterText, xFooterParagraphCursor, sKey);
                 }
@@ -868,7 +817,7 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes
                 case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART:
                 {
                     OUString sKey = aCreator.makeIntellectualPropertyPartKey();
-                    addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msName);
+                    svx::classification::addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msName);
                     insertFieldToDocument(xMultiServiceFactory, xHeaderText, xHeaderParagraphCursor, sKey);
                     insertFieldToDocument(xMultiServiceFactory, xFooterText, xFooterParagraphCursor, sKey);
                 }
@@ -979,25 +928,25 @@ std::vector<svx::ClassificationResult> SwEditShell::CollectAdvancedClassificatio
 
             if (aCreator.isMarkingTextKey(aName))
             {
-                const OUString aValue = lcl_getProperty(xPropertyContainer, aName);
+                const OUString aValue = svx::classification::getProperty(xPropertyContainer, aName);
                 if (!aValue.isEmpty())
                     aResult.push_back({ svx::ClassificationType::TEXT, aValue, sBlank, sBlank });
             }
             else if (aCreator.isCategoryNameKey(aName) || aCreator.isCategoryIdentifierKey(aName))
             {
-                const OUString aValue = lcl_getProperty(xPropertyContainer, aName);
+                const OUString aValue = svx::classification::getProperty(xPropertyContainer, aName);
                 if (!aValue.isEmpty())
                     aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank, sBlank });
             }
             else if (aCreator.isMarkingKey(aName))
             {
-                const OUString aValue = lcl_getProperty(xPropertyContainer, aName);
+                const OUString aValue = svx::classification::getProperty(xPropertyContainer, aName);
                 if (!aValue.isEmpty())
                     aResult.push_back({ svx::ClassificationType::MARKING, aValue, sBlank, sBlank });
             }
             else if (aCreator.isIntellectualPropertyPartKey(aName))
             {
-                const OUString aValue = lcl_getProperty(xPropertyContainer, aName);
+                const OUString aValue = svx::classification::getProperty(xPropertyContainer, aName);
                 if (!aValue.isEmpty())
                     aResult.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, aValue, sBlank, sBlank });
             }


More information about the Libreoffice-commits mailing list