sw/inc/expfld.hxx                |    4 +++
 sw/source/core/fields/expfld.cxx |   47 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 50 insertions(+), 1 deletion(-)

New commits:
commit 0c7ad92ce815350a6b68da7e05e253388cb83616
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: Wed Jan 28 12:35:33 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]>

diff --git a/sw/inc/expfld.hxx b/sw/inc/expfld.hxx
index 6ce2481aa313..56afd3834cc9 100644
--- a/sw/inc/expfld.hxx
+++ b/sw/inc/expfld.hxx
@@ -222,6 +222,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);
@@ -236,6 +237,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;
 
     virtual sal_uInt16              GetSubType() const override;
diff --git a/sw/source/core/fields/expfld.cxx b/sw/source/core/fields/expfld.cxx
index aa7953717a97..c8ac11dc82d2 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>
@@ -821,6 +824,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;
@@ -848,10 +888,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() );
+        + (sFieldText.isEmpty() ? GetTyp()->GetName() : sFieldText));
 
     // Sequence: without formula
     if (SwFieldTypesEnum::Sequence != nStrType)

Reply via email to