tdf#158276 tdf#86395 Make alphabetical sort setting persist
by using a bitwise storage approach inspired by the ActiveBlock
setting where each content type corresponds to one bit position of
the stored integer, e.g., bookmarks content type corresponds to bit
5.
Change-Id: I50de26e44a8d2afb917f3a651eef9a8f704b751f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159916
Tested-by: Jenkins
Reviewed-by: Jim Raykowski <raykowj@gmail.com>
diff --git a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs
index 61054ae..2bd5995 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs
@@ -5197,6 +5197,13 @@
</info>
<value>false</value>
</prop>
<prop oor:name="SortAlphabeticallyBlock" oor:type="xs:int" oor:nillable="false">
<!-- UIHints: Navigator -->
<info>
<desc>Specifies whether the contents of a content type are alphabetically sorted in the Navigator list box. Each content type corresponds to one bit position of the stored int. A bit with value 1 indicates alphabetical sorting for the corresponding content type.</desc>
</info>
<value>0</value>
</prop>
</group>
<group oor:name="Envelope">
<info>
diff --git a/sw/source/uibase/inc/navicfg.hxx b/sw/source/uibase/inc/navicfg.hxx
index ad4bb10..b39614f 100644
--- a/sw/source/uibase/inc/navicfg.hxx
+++ b/sw/source/uibase/inc/navicfg.hxx
@@ -37,6 +37,8 @@ class SwNavigationConfig final : public utl::ConfigItem
o3tl::enumarray<ContentTypeId, bool> mContentTypeTrack;
sal_Int32 m_nSortAlphabeticallyBlock = 0; // persists content type alphabetical sort setting
static css::uno::Sequence<OUString> GetPropertyNames();
virtual void ImplCommit() override;
@@ -125,6 +127,16 @@ public:
}
bool IsNavigateOnSelect() const {return m_bIsNavigateOnSelect;}
sal_Int32 GetSortAlphabeticallyBlock() const {return m_nSortAlphabeticallyBlock;}
void SetSortAlphabeticallyBlock(sal_Int32 nSet)
{
if(m_nSortAlphabeticallyBlock != nSet)
{
SetModified();
m_nSortAlphabeticallyBlock = nSet;
}
}
};
#endif
diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx
index 8d46ef5..72fd76c 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -431,6 +431,13 @@ SwContentType::SwContentType(SwWrtShell* pShell, ContentTypeId nType, sal_uInt8
break;
default: break;
}
const int nShift = static_cast<int>(m_nContentType);
assert(nShift > -1);
const sal_Int32 nMask = 1 << nShift;
const sal_Int32 nBlock = SW_MOD()->GetNavigationConfig()->GetSortAlphabeticallyBlock();
m_bAlphabeticSort = nBlock & nMask;
FillMemberList();
}
@@ -1739,10 +1746,12 @@ IMPL_LINK(SwContentTree, CommandHdl, const CommandEvent&, rCEvt, bool)
const ContentTypeId nContentType = pType->GetType();
if (nContentType != ContentTypeId::FOOTNOTE && nContentType != ContentTypeId::ENDNOTE
&& nContentType != ContentTypeId::POSTIT)
&& nContentType != ContentTypeId::POSTIT && nContentType != ContentTypeId::UNKNOWN)
{
bRemoveSortEntry = false;
xPop->set_active("sort", pType->IsAlphabeticSort());
const sal_Int32 nMask = 1 << static_cast<int>(nContentType);
sal_uInt64 nSortAlphabeticallyBlock = m_pConfig->GetSortAlphabeticallyBlock();
xPop->set_active("sort", nSortAlphabeticallyBlock & nMask);
}
OUString aIdent;
@@ -4960,7 +4969,15 @@ void SwContentTree::ExecuteContextMenuAction(const OUString& rSelectedPopupEntry
pCntType = weld::fromId<SwContentType*>(rId);
else
pCntType = const_cast<SwContentType*>(weld::fromId<SwContent*>(rId)->GetParent());
pCntType->SetAlphabeticSort(!pCntType->IsAlphabeticSort());
// toggle and persist alphabetical sort setting
const int nShift = static_cast<int>(pCntType->GetType());
assert(nShift > -1);
const sal_Int32 nMask = 1 << nShift;
const sal_Int32 nBlock = m_pConfig->GetSortAlphabeticallyBlock();
pCntType->SetAlphabeticSort(~nBlock & nMask);
m_pConfig->SetSortAlphabeticallyBlock(nBlock ^ nMask);
pCntType->FillMemberList();
Display(true);
return;
diff --git a/sw/source/uibase/utlui/navicfg.cxx b/sw/source/uibase/utlui/navicfg.cxx
index 0170a8f..dfda882 100644
--- a/sw/source/uibase/utlui/navicfg.cxx
+++ b/sw/source/uibase/utlui/navicfg.cxx
@@ -74,7 +74,8 @@ Sequence<OUString> SwNavigationConfig::GetPropertyNames()
OUString("FieldTracking"),
OUString("FootnoteTracking"),
OUString("EndnoteTracking"),
OUString("NavigateOnSelect")};
OUString("NavigateOnSelect"),
OUString("SortAlphabeticallyBlock")};
}
SwNavigationConfig::SwNavigationConfig() :
@@ -146,6 +147,7 @@ void SwNavigationConfig::Load()
break;
}
case 22: m_bIsNavigateOnSelect = *o3tl::doAccess<bool>(pValues[nProp]); break;
case 23: pValues[nProp] >>= m_nSortAlphabeticallyBlock; break;
}
}
}
@@ -180,6 +182,7 @@ void SwNavigationConfig::ImplCommit()
break;
}
case 22: pValues[nProp] <<= m_bIsNavigateOnSelect; break;
case 23: pValues[nProp] <<= m_nSortAlphabeticallyBlock; break;
}
}
PutProperties(aNames, aValues);