From 0bca30bff7d9e49c81459122735565ff0d9816c3 Mon Sep 17 00:00:00 2001 From: Shivam Kumar Singh Date: Sat, 11 Jul 2020 20:18:51 +0530 Subject: 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 --- .../uibase/sidebar/WriterInspectorTextPanel.cxx | 212 +++++++++++---------- .../uibase/sidebar/WriterInspectorTextPanel.hxx | 6 - 2 files changed, 107 insertions(+), 111 deletions(-) (limited to 'sw') 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 #include #include +#include #include #include @@ -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& maIsDefined, StyleType sType) +static void UpdateTree(SwDocShell* pDocSh, std::vector& aStore) { SwDoc* pDoc = pDocSh->GetDoc(); SwPaM* pCursor = pDoc->GetEditShell()->GetCursor(); + svx::sidebar::TreeNode pDFNode; + svx::sidebar::TreeNode pCharNode; + svx::sidebar::TreeNode pParaNode; - uno::Reference xStyleFamiliesSupplier(pDocSh->GetBaseModel(), - uno::UNO_QUERY); - uno::Reference xStyleFamilies - = xStyleFamiliesSupplier->getStyleFamilies(); - uno::Reference 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 xCursor = dynamic_cast(pCursor); uno::Reference xRange( SwXTextRange::CreateXTextRange(*pDoc, *pCursor->GetPoint(), nullptr)); - uno::Reference properties(xRange, uno::UNO_QUERY_THROW); - OUString sCurrentStyleName, sDisplayName; - if (sType == CHARACTERSTYLES) - properties->getPropertyValue("CharStyleName") >>= sCurrentStyleName; - else - properties->getPropertyValue("ParaStyleName") >>= sCurrentStyleName; + uno::Reference xPropertiesSet(xRange, uno::UNO_QUERY_THROW); + uno::Reference xPropertiesState(xRange, uno::UNO_QUERY_THROW); - if (sCurrentStyleName.isEmpty()) - return; // In case of Default Character Styles; + uno::Sequence aProperties + = xPropertiesSet->getPropertySetInfo()->getProperties(); - while (true) + std::unordered_map aIsDefined; + for (const beans::Property& rProperty : std::as_const(aProperties)) { - uno::Reference xProp1; - uno::Reference 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 aProperties - = xProp1Set->getPropertySetInfo()->getProperties(); - const uno::Reference xProp2Set( - xStyleFamily->getByName(aParentCharStyle), uno::UNO_QUERY); + uno::Reference xStyleFamiliesSupplier(pDocSh->GetBaseModel(), + uno::UNO_QUERY); + uno::Reference xStyleFamilies + = xStyleFamiliesSupplier->getStyleFamilies(); + OUString sCurrentCharStyle, sCurrentParaStyle, sDisplayName; - try - { - for (const beans::Property& rProperty : aProperties) - { - OUString sPropName = rProperty.Name; + uno::Reference 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 + " !!!!"; + 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 aProp1Set; - xStyleFamily->getByName(sCurrentStyleName) >>= aProp1Set; + xStyleFamily.set(xStyleFamilies->getByName("ParagraphStyles"), uno::UNO_QUERY_THROW); - const uno::Sequence 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 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 + " !!!! "; + 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(SfxObjectShell::Current()); std::vector aStore; - std::unordered_map 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 #include -enum StyleType -{ - DEFAULTFORMATTING, - CHARACTERSTYLES, - PARAGRAPHSTYLES -}; namespace sw { namespace sidebar -- cgit