diff options
author | Shivam Kumar Singh <shivamhere247@gmail.com> | 2020-07-11 20:18:51 +0530 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2020-07-15 08:34:54 +0200 |
commit | 0bca30bff7d9e49c81459122735565ff0d9816c3 (patch) | |
tree | 36dc945bb1cf414e3714c85ffc111db6d8cd26fe /sw | |
parent | d851a02df57ab378ed0cc6d9362516de09c3279c (diff) |
tdf#134555 Show direct formatting at the Styles Inspector
Change-Id: I9141019f8ef66600614a4fdcc74fca8d75c80d05
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98561
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx | 212 | ||||
-rw-r--r-- | sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx | 6 |
2 files changed, 107 insertions, 111 deletions
diff --git a/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx b/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx index 7222c3de0989..5273a6a022d1 100644 --- a/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx +++ b/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx @@ -27,6 +27,7 @@ #include <com/sun/star/text/XTextCursor.hpp> #include <com/sun/star/awt/FontSlant.hpp> #include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/lang/IllegalArgumentException.hpp> @@ -109,152 +110,153 @@ static bool GetPropertyValues(const beans::Property rProperty, const uno::Any& r return true; } -static void UpdateTree(SwDocShell* pDocSh, svx::sidebar::TreeNode& pParentNode, - std::unordered_map<OUString, bool>& maIsDefined, StyleType sType) +static void UpdateTree(SwDocShell* pDocSh, std::vector<svx::sidebar::TreeNode>& aStore) { SwDoc* pDoc = pDocSh->GetDoc(); SwPaM* pCursor = pDoc->GetEditShell()->GetCursor(); + svx::sidebar::TreeNode pDFNode; + svx::sidebar::TreeNode pCharNode; + svx::sidebar::TreeNode pParaNode; - uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(pDocSh->GetBaseModel(), - uno::UNO_QUERY); - uno::Reference<container::XNameAccess> xStyleFamilies - = xStyleFamiliesSupplier->getStyleFamilies(); - uno::Reference<container::XNameAccess> xStyleFamily; - - if (sType == CHARACTERSTYLES) - xStyleFamilies->getByName("CharacterStyles") >>= xStyleFamily; - else - xStyleFamilies->getByName("ParagraphStyles") >>= xStyleFamily; + pDFNode.sNodeName = "Direct Formatting"; + pCharNode.sNodeName = "Character Styles"; + pParaNode.sNodeName = "Paragraph Styles"; - uno::Reference<text::XTextCursor> xCursor = dynamic_cast<text::XTextCursor*>(pCursor); uno::Reference<text::XTextRange> xRange( SwXTextRange::CreateXTextRange(*pDoc, *pCursor->GetPoint(), nullptr)); - uno::Reference<beans::XPropertySet> properties(xRange, uno::UNO_QUERY_THROW); - OUString sCurrentStyleName, sDisplayName; - if (sType == CHARACTERSTYLES) - properties->getPropertyValue("CharStyleName") >>= sCurrentStyleName; - else - properties->getPropertyValue("ParaStyleName") >>= sCurrentStyleName; + uno::Reference<beans::XPropertySet> xPropertiesSet(xRange, uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertyState> xPropertiesState(xRange, uno::UNO_QUERY_THROW); - if (sCurrentStyleName.isEmpty()) - return; // In case of Default Character Styles; + uno::Sequence<beans::Property> aProperties + = xPropertiesSet->getPropertySetInfo()->getProperties(); - while (true) + std::unordered_map<OUString, bool> aIsDefined; + for (const beans::Property& rProperty : std::as_const(aProperties)) { - uno::Reference<style::XStyle> xProp1; - uno::Reference<beans::XPropertySet> xProp1Set; - xStyleFamily->getByName(sCurrentStyleName) >>= xProp1; - xStyleFamily->getByName(sCurrentStyleName) >>= xProp1Set; - OUString aParentCharStyle = xProp1->getParentStyle(); - xProp1Set->getPropertyValue("DisplayName") >>= sDisplayName; - svx::sidebar::TreeNode pCurrentChild; - pCurrentChild.sNodeName = sDisplayName; - - if (aParentCharStyle.isEmpty()) + if (xPropertiesState->getPropertyState(rProperty.Name) == beans::PropertyState_DIRECT_VALUE) { - break; // when current style is "Standard" there is no parent + OUString aPropertyValuePair; + const uno::Any aAny = xPropertiesSet->getPropertyValue(rProperty.Name); + if (GetPropertyValues(rProperty, aAny, aPropertyValuePair)) + { + aIsDefined[rProperty.Name] = true; + svx::sidebar::TreeNode pTemp; + pTemp.sNodeName = aPropertyValuePair; + pDFNode.children.push_back(pTemp); + } } + } - const uno::Sequence<beans::Property> aProperties - = xProp1Set->getPropertySetInfo()->getProperties(); - const uno::Reference<beans::XPropertySet> xProp2Set( - xStyleFamily->getByName(aParentCharStyle), uno::UNO_QUERY); + uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(pDocSh->GetBaseModel(), + uno::UNO_QUERY); + uno::Reference<container::XNameAccess> xStyleFamilies + = xStyleFamiliesSupplier->getStyleFamilies(); + OUString sCurrentCharStyle, sCurrentParaStyle, sDisplayName; - try - { - for (const beans::Property& rProperty : aProperties) - { - OUString sPropName = rProperty.Name; + uno::Reference<container::XNameAccess> xStyleFamily( + xStyleFamilies->getByName("CharacterStyles"), uno::UNO_QUERY_THROW); + xPropertiesSet->getPropertyValue("CharStyleName") >>= sCurrentCharStyle; + xPropertiesSet->getPropertyValue("ParaStyleName") >>= sCurrentParaStyle; - if (maIsDefined[sPropName]) - continue; + if (!sCurrentCharStyle.isEmpty()) + { + xPropertiesSet.set(xStyleFamily->getByName(sCurrentCharStyle), css::uno::UNO_QUERY_THROW); + xPropertiesState.set(xPropertiesSet, css::uno::UNO_QUERY_THROW); + xPropertiesSet->getPropertyValue("DisplayName") >>= sDisplayName; + aProperties = xPropertiesSet->getPropertySetInfo()->getProperties(); + svx::sidebar::TreeNode pCurrentChild; + pCurrentChild.sNodeName = sDisplayName; - if (xProp1Set->getPropertyValue(sPropName) - != xProp2Set->getPropertyValue(sPropName)) + for (const beans::Property& rProperty : std::as_const(aProperties)) + { + OUString sPropName = rProperty.Name; + if (xPropertiesState->getPropertyState(sPropName) == beans::PropertyState_DIRECT_VALUE) + { + OUString aPropertyValuePair; + const uno::Any aAny = xPropertiesSet->getPropertyValue(sPropName); + if (GetPropertyValues(rProperty, aAny, aPropertyValuePair)) { - maIsDefined[sPropName] = true; - OUString aPropertyValuePair; - const uno::Any aAny = xProp1Set->getPropertyValue(sPropName); - GetPropertyValues(rProperty, aAny, aPropertyValuePair); - if (!aPropertyValuePair.isEmpty()) - { - svx::sidebar::TreeNode pTemp; - pTemp.sNodeName = aPropertyValuePair; - pCurrentChild.children.push_back(pTemp); - } + if (aIsDefined[sPropName]) // Already defined in "Direct Formatting" ? + aPropertyValuePair = aPropertyValuePair + " !!<GREY>!!"; + else + aIsDefined[sPropName] = true; + svx::sidebar::TreeNode pTemp; + pTemp.sNodeName = aPropertyValuePair; + pCurrentChild.children.push_back(pTemp); } } } - catch (const uno::Exception&) - { - //do nothing - } - pParentNode.children.emplace_back(pCurrentChild); - sCurrentStyleName = aParentCharStyle; + pCharNode.children.push_back(pCurrentChild); } - uno::Reference<beans::XPropertySet> aProp1Set; - xStyleFamily->getByName(sCurrentStyleName) >>= aProp1Set; + xStyleFamily.set(xStyleFamilies->getByName("ParagraphStyles"), uno::UNO_QUERY_THROW); - const uno::Sequence<beans::Property> aProperties - = aProp1Set->getPropertySetInfo()->getProperties(); - svx::sidebar::TreeNode pCurrentChild; - pCurrentChild.sNodeName = sDisplayName; - - for (const beans::Property& rProperty : aProperties) + while (true) { - OUString aPropertyValuePair, sPropName = rProperty.Name; - if (maIsDefined[sPropName]) - continue; - maIsDefined[sPropName] = true; + uno::Reference<style::XStyle> xPropertiesStyle(xStyleFamily->getByName(sCurrentParaStyle), + uno::UNO_QUERY_THROW); + xPropertiesSet.set(xPropertiesStyle, css::uno::UNO_QUERY_THROW); + xPropertiesState.set(xPropertiesSet, css::uno::UNO_QUERY_THROW); + xPropertiesSet->getPropertyValue("DisplayName") >>= sDisplayName; + aProperties = xPropertiesSet->getPropertySetInfo()->getProperties(); + OUString aParentParaStyle = xPropertiesStyle->getParentStyle(); + svx::sidebar::TreeNode pCurrentChild; + pCurrentChild.sNodeName = sDisplayName; + + const bool bStandardStyle = sCurrentParaStyle == "Standard"; // Last Parent Style - const uno::Any aAny = aProp1Set->getPropertyValue(sPropName); - if (GetPropertyValues(rProperty, aAny, aPropertyValuePair)) + for (const beans::Property& rProperty : std::as_const(aProperties)) { - if (!aPropertyValuePair.isEmpty()) + OUString sPropName = rProperty.Name; + if (bStandardStyle + || xPropertiesState->getPropertyState(sPropName) + == beans::PropertyState_DIRECT_VALUE) { - svx::sidebar::TreeNode pTemp; - pTemp.sNodeName = aPropertyValuePair; - pCurrentChild.children.push_back(pTemp); + OUString aPropertyValuePair; + const uno::Any aAny = xPropertiesSet->getPropertyValue(sPropName); + if (GetPropertyValues(rProperty, aAny, aPropertyValuePair)) + { + // Already defined in "Default Formatting" or "Character Styles" or any child Paragraph Style ? + if (aIsDefined[sPropName]) + aPropertyValuePair = aPropertyValuePair + " !!<GREY>!! "; + else + aIsDefined[sPropName] = true; + svx::sidebar::TreeNode pTemp; + pTemp.sNodeName = aPropertyValuePair; + pCurrentChild.children.push_back(pTemp); + } } } + + pParaNode.children.push_back(pCurrentChild); + sCurrentParaStyle = aParentParaStyle; + if (bStandardStyle) + break; } - pParentNode.children.emplace_back(pCurrentChild); - std::reverse(pParentNode.children.begin(), pParentNode.children.end()); + std::reverse(pParaNode.children.begin(), + pParaNode.children.end()); // Parent style should be first then children + + /* + Display Order :- + PARAGRAPH STYLE + CHARACTER STYLE + DEFAULT FORMATTING + */ + aStore.push_back(pParaNode); + aStore.push_back(pCharNode); + aStore.push_back(pDFNode); } IMPL_LINK_NOARG(WriterInspectorTextPanel, AttrChangedNotify, LinkParamNone*, void) { SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current()); std::vector<svx::sidebar::TreeNode> aStore; - std::unordered_map<OUString, bool> maIsDefined; if (pDocSh && pDocSh->GetDoc()->GetEditShell()->GetCursor()->GetNode().GetTextNode()) - { - /* - First check in the property set of Character Styles - (as CS has higher priority over PS), then look into - property set of Paragraph Styles; - */ - svx::sidebar::TreeNode pTempChar; - pTempChar.sNodeName = "CHARACTER STYLES"; - UpdateTree(pDocSh, pTempChar, maIsDefined, CHARACTERSTYLES); - svx::sidebar::TreeNode pTempPara; - pTempPara.sNodeName = "PARAGRAPH STYLES"; - UpdateTree(pDocSh, pTempPara, maIsDefined, PARAGRAPHSTYLES); - - /* - Order:- - PARAGRAPH STYLES - CHARACTER STYLES - DEFAULT FORMATTING - */ - aStore.push_back(pTempPara); - aStore.push_back(pTempChar); - } + UpdateTree(pDocSh, aStore); updateEntries(aStore); } diff --git a/sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx b/sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx index 8c674e380812..6f0c4e3fd6a9 100644 --- a/sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx +++ b/sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx @@ -25,12 +25,6 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <svx/sidebar/InspectorTextPanel.hxx> -enum StyleType -{ - DEFAULTFORMATTING, - CHARACTERSTYLES, - PARAGRAPHSTYLES -}; namespace sw { namespace sidebar |