sw/inc/expfld.hxx | 4 +++ sw/source/core/fields/expfld.cxx | 47 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-)
New commits: commit 936ab761667feadc4e7dcb35a051e77bb281f1b1 Author: Gülşah Köse <[email protected]> AuthorDate: Thu Jan 22 10:08:38 2026 +0300 Commit: Gülşah Köse <[email protected]> CommitDate: Fri Jan 30 16:27:45 2026 +0100 tdf#127184 Use caption text instead of category in navigator At first creating a caption, navigator just gets the last name (Figure) from dialog without translated to UI language (as user type). But while opening again the same file, Figure is translated to UI language in sw::DocumentFieldsManager::InitFieldTypes. The problem is when user inserts a new category name and the category name is same with built in category names. Built in category names are always in English. There is no way for navigator to choose translated one or untranslated one. <text:sequence-decls> <text:sequence-decl text:display-outline-level="0" text:name="Illustration"/> <text:sequence-decl text:display-outline-level="0" text:name="Table"/> <text:sequence-decl text:display-outline-level="0" text:name="Text"/> <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/> <text:sequence-decl text:display-outline-level="0" text:name="Figure"/> <text:sequence-decl text:display-outline-level="0" text:name="Figure"/> </text:sequence-decls> Instead of we can use the caption directly just like inital caption insert function did. In this patch we use first two word of the caption to prevent long lines in the navigator. Signed-off-by: Gülşah Köse <[email protected]> Change-Id: I9bffdc3edad1eee91a000997b3ba9c8a3ea5b673 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197792 Tested-by: Caolán McNamara <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198428 Tested-by: Jenkins diff --git a/sw/inc/expfld.hxx b/sw/inc/expfld.hxx index 62b501ff160f..e04b66435261 100644 --- a/sw/inc/expfld.hxx +++ b/sw/inc/expfld.hxx @@ -223,6 +223,7 @@ public: void SetFormatField(SwFormatField & rFormatField); SwFormatField* GetFormatField() { return mpFormatField;} + const SwFormatField* GetFormatField() const { return mpFormatField;} double GetValue(SwRootFrame const* pLayout) const; void SetValue(const double& rVal, SwRootFrame const* pLayout); @@ -237,6 +238,9 @@ public: inline void SetInputFlag(bool bInp); inline bool GetInputFlag() const; + OUString GetFirstNWords(const OUString& rText, sal_Int32 nWords) const; + SwTextField* GetTextField() const; + virtual OUString GetFieldName() const override; SwGetSetExpType GetSubType() const; diff --git a/sw/source/core/fields/expfld.cxx b/sw/source/core/fields/expfld.cxx index 5ffe38a25f52..f060817e1876 100644 --- a/sw/source/core/fields/expfld.cxx +++ b/sw/source/core/fields/expfld.cxx @@ -30,6 +30,9 @@ #include <editeng/langitem.hxx> #include <editeng/fontitem.hxx> #include <com/sun/star/text/SetVariableType.hpp> +#include <com/sun/star/i18n/BreakIterator.hpp> +#include <com/sun/star/i18n/WordType.hpp> +#include <comphelper/processfactory.hxx> #include <unofield.hxx> #include <frmfmt.hxx> #include <fmtfld.hxx> @@ -826,6 +829,43 @@ SwSetExpField::SwSetExpField(SwSetExpFieldType* pTyp, const OUString& rFormel, } } +SwTextField* SwSetExpField::GetTextField() const +{ + SwTextField* pTextField = nullptr; + if(mpFormatField && mpFormatField->GetTextField()) + pTextField = mpFormatField->GetTextField(); + + return pTextField; +} + +OUString SwSetExpField::GetFirstNWords(const OUString& rText, sal_Int32 nWords) const +{ + if (rText.isEmpty()) + return rText; + + css::lang::Locale aLocale; + if(GetTextField()) + aLocale = g_pBreakIt->GetLocale(GetTextField()->GetTextNode().GetLang(0)); + + sal_Int32 nPos = 0; + for (sal_Int32 i = 0; i < nWords; ++i) + { + css::i18n::Boundary b = + g_pBreakIt->GetBreakIter()->getWordBoundary( + rText, nPos, aLocale, + css::i18n::WordType::ANY_WORD, true); + + if (b.endPos <= nPos) + break; + + nPos = b.endPos; + } + + auto sSub = rText.subView(0, nPos); + OUString s(sSub.data(), sSub.size()); + return s.trim(); +} + void SwSetExpField::SetFormatField(SwFormatField & rFormatField) { mpFormatField = &rFormatField; @@ -853,10 +893,15 @@ OUString SwSetExpField::GetFieldName() const ? SwFieldTypesEnum::SetInput : SwFieldTypesEnum::Set ); + OUString sFieldText = ""; + + if(GetTextField()) + sFieldText = GetFirstNWords(GetTextField()->GetTextNode().GetText(), 2); + OUString aStr( SwFieldType::GetTypeStr( nStrType ) + " " - + GetTyp()->GetName().toString() ); + + (sFieldText.isEmpty() ? GetTyp()->GetName().toString() : sFieldText)); // Sequence: without formula if (SwFieldTypesEnum::Sequence != nStrType)
