editeng/source/items/flditem.cxx  |   27 ++++++++++++++++++++++-----
 sc/inc/editutil.hxx               |    5 +++++
 sc/source/core/tool/editutil.cxx  |   19 ++++++++++++++++++-
 sc/source/ui/view/prevwsh.cxx     |    7 +------
 sc/source/ui/view/printfun.cxx    |    7 +------
 sc/source/ui/view/tabvwsh4.cxx    |    8 ++------
 sw/source/core/fields/docufld.cxx |   23 ++++++++++++++++++-----
 7 files changed, 67 insertions(+), 29 deletions(-)

New commits:
commit 45c7509c7fbe00ff0117778116598ba9f38729ef
Author:     Caolán McNamara <[email protected]>
AuthorDate: Fri Jan 30 10:43:23 2026 +0000
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri Feb 6 11:36:01 2026 +0100

    Use Documents/filename in jailed mode as file path field results
    
    The path is useless in jailed kit mode, so present a field result that
    the document is in some (translated) "Documents" toplevel directory when
    LibreOfficeKit::isActive() so it's stable between runs and retains some
    structural hint to distinguish between the various field modes.
    
    Change-Id: Ia8040924396207583e1a12b989d8862962371fc9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198420
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/editeng/source/items/flditem.cxx b/editeng/source/items/flditem.cxx
index ca0b9f43546a..a474a82b1708 100644
--- a/editeng/source/items/flditem.cxx
+++ b/editeng/source/items/flditem.cxx
@@ -25,11 +25,15 @@
 #include <svl/zforlist.hxx>
 #include <tools/urlobj.hxx>
 
+#include <comphelper/lok.hxx>
 #include <editeng/flditem.hxx>
 #include <editeng/CustomPropertyField.hxx>
 #include <editeng/measfld.hxx>
 #include <editeng/unonames.hxx>
 
+#include <sfx2/sfxresid.hxx>
+#include <sfx2/strings.hrc>
+
 #include <tools/debug.hxx>
 
 #include <com/sun/star/beans/XPropertySet.hpp>
@@ -754,17 +758,30 @@ OUString SvxExtFileField::GetFormatted() const
     }
     else if( INetProtocol::File == aURLObj.GetProtocol() )
     {
+        // Note: The path is useless in jailed kit mode, so present a view that
+        // the document is in a Documents toplevel directory for 
LibreOfficeKit::isActive()
         switch( eFormat )
         {
             case SvxFileFormat::PathFull:
-                aString = aURLObj.getFSysPath(FSysStyle::Detect);
+                if (comphelper::LibreOfficeKit::isActive())
+                {
+                    aString = "/" + SfxResId(STR_GID_DOCUMENT) + "/" +
+                        aURLObj.getName(INetURLObject::LAST_SEGMENT, true, 
INetURLObject::DecodeMechanism::Unambiguous);
+                }
+                else
+                    aString = aURLObj.getFSysPath(FSysStyle::Detect);
             break;
 
             case SvxFileFormat::PathOnly:
-                aURLObj.removeSegment(INetURLObject::LAST_SEGMENT, false);
-                // #101742# Leave trailing slash at the pathname
-                aURLObj.setFinalSlash();
-                aString = aURLObj.getFSysPath(FSysStyle::Detect);
+                if (comphelper::LibreOfficeKit::isActive())
+                    aString = "/" + SfxResId(STR_GID_DOCUMENT);
+                else
+                {
+                    aURLObj.removeSegment(INetURLObject::LAST_SEGMENT, false);
+                    // #101742# Leave trailing slash at the pathname
+                    aURLObj.setFinalSlash();
+                    aString = aURLObj.getFSysPath(FSysStyle::Detect);
+                }
             break;
 
             case SvxFileFormat::NameOnly:
diff --git a/sc/inc/editutil.hxx b/sc/inc/editutil.hxx
index 0173b4aa7f26..fd8452e0e291 100644
--- a/sc/inc/editutil.hxx
+++ b/sc/inc/editutil.hxx
@@ -29,6 +29,7 @@
 #include <tools/fract.hxx>
 #include <vcl/outdev.hxx>
 
+class INetURLObject;
 class ScDocument;
 class ScPatternAttr;
 class ScEditEngineDefaulter;
@@ -213,6 +214,10 @@ struct ScHeaderFieldData
     SvxNumType  eNumType;
 
     ScHeaderFieldData();
+
+    // Set aLongDocName and aShortDocName from rURLObj,
+    // falling back back to aTitle,
+    void SetDocNames(const INetURLObject& rURLObj);
 };
 
 // for headers/footers with fields
diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx
index 1b9330cf3866..3719a2163abf 100644
--- a/sc/source/core/tool/editutil.cxx
+++ b/sc/source/core/tool/editutil.cxx
@@ -18,6 +18,7 @@
  */
 
 #include <scitems.hxx>
+#include <comphelper/lok.hxx>
 #include <comphelper/processfactory.hxx>
 #include <editeng/eeitem.hxx>
 
@@ -32,7 +33,8 @@
 #include <svl/numformat.hxx>
 #include <svl/inethist.hxx>
 #include <sfx2/objsh.hxx>
-#include <comphelper/lok.hxx>
+#include <sfx2/sfxresid.hxx>
+#include <sfx2/strings.hrc>
 #include <osl/diagnose.h>
 
 #include <com/sun/star/text/textfield/Type.hpp>
@@ -892,6 +894,21 @@ OUString ScHeaderEditEngine::CalcFieldValue( const 
SvxFieldItem& rField,
     return aRet;
 }
 
+void ScHeaderFieldData::SetDocNames(const INetURLObject& rURLObj)
+{
+    aLongDocName = 
rURLObj.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous);
+    if (!aLongDocName.isEmpty())
+    {
+        aShortDocName = 
rURLObj.GetLastName(INetURLObject::DecodeMechanism::Unambiguous);
+        // The path is useless in jailed kit mode, so present a view that the
+        // document is in a Documents toplevel directory for 
LibreOfficeKit::isActive()
+        if (comphelper::LibreOfficeKit::isActive())
+            aLongDocName = "/" + SfxResId(STR_GID_DOCUMENT) + "/" + 
aShortDocName;
+    }
+    else
+        aShortDocName = aLongDocName = aTitle;
+}
+
 //                          field data
 
 ScFieldEditEngine::ScFieldEditEngine(
diff --git a/sc/source/ui/view/prevwsh.cxx b/sc/source/ui/view/prevwsh.cxx
index a1f65fd1d02f..36466772aaed 100644
--- a/sc/source/ui/view/prevwsh.cxx
+++ b/sc/source/ui/view/prevwsh.cxx
@@ -876,12 +876,7 @@ void ScPreviewShell::FillFieldData( ScHeaderFieldData& 
rData )
     else
         rData.aTitle = pDocShell->GetTitle();
 
-    const INetURLObject& rURLObj = pDocShell->GetMedium()->GetURLObject();
-    rData.aLongDocName  = rURLObj.GetMainURL( 
INetURLObject::DecodeMechanism::Unambiguous );
-    if ( !rData.aLongDocName.isEmpty() )
-        rData.aShortDocName = 
rURLObj.GetLastName(INetURLObject::DecodeMechanism::Unambiguous);
-    else
-        rData.aShortDocName = rData.aLongDocName = rData.aTitle;
+    rData.SetDocNames(pDocShell->GetMedium()->GetURLObject());
     rData.nPageNo       = pPreview->GetPageNo() + 1;
 
     bool bAllTested = pPreview->AllTested();
diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx
index 2a0306aeb1f9..9264b1b42a2a 100644
--- a/sc/source/ui/view/printfun.cxx
+++ b/sc/source/ui/view/printfun.cxx
@@ -1103,12 +1103,7 @@ void ScPrintFunc::InitParam( const ScPrintOptions* 
pOptions )
     else
         aFieldData.aTitle = pDocShell->GetTitle();
 
-    const INetURLObject& rURLObj = pDocShell->GetMedium()->GetURLObject();
-    aFieldData.aLongDocName = rURLObj.GetMainURL( 
INetURLObject::DecodeMechanism::Unambiguous );
-    if ( !aFieldData.aLongDocName.isEmpty() )
-        aFieldData.aShortDocName = 
rURLObj.GetLastName(INetURLObject::DecodeMechanism::Unambiguous);
-    else
-        aFieldData.aShortDocName = aFieldData.aLongDocName = aFieldData.aTitle;
+    aFieldData.SetDocNames(pDocShell->GetMedium()->GetURLObject());
 
     //  Printer settings (Orientation, Paper) at DoPrint
 }
diff --git a/sc/source/ui/view/tabvwsh4.cxx b/sc/source/ui/view/tabvwsh4.cxx
index bf43d7191fed..c1b0187478cb 100644
--- a/sc/source/ui/view/tabvwsh4.cxx
+++ b/sc/source/ui/view/tabvwsh4.cxx
@@ -2305,12 +2305,8 @@ void ScTabViewShell::FillFieldData( ScHeaderFieldData& 
rData )
     else
         rData.aTitle = pDocShell->GetTitle();
 
-    const INetURLObject& rURLObj = pDocShell->GetMedium()->GetURLObject();
-    rData.aLongDocName  = rURLObj.GetMainURL( 
INetURLObject::DecodeMechanism::Unambiguous );
-    if ( !rData.aLongDocName.isEmpty() )
-        rData.aShortDocName = 
rURLObj.GetLastName(INetURLObject::DecodeMechanism::Unambiguous);
-    else
-        rData.aShortDocName = rData.aLongDocName = rData.aTitle;
+    rData.SetDocNames(pDocShell->GetMedium()->GetURLObject());
+
     rData.nPageNo       = 1;
     rData.nTotalPages   = 99;
 
diff --git a/sw/source/core/fields/docufld.cxx 
b/sw/source/core/fields/docufld.cxx
index a6b69cf536ec..c6ff61f4a873 100644
--- a/sw/source/core/fields/docufld.cxx
+++ b/sw/source/core/fields/docufld.cxx
@@ -37,6 +37,7 @@
 #include <o3tl/any.hxx>
 #include <o3tl/string_view.hxx>
 #include <unotools/localedatawrapper.hxx>
+#include <comphelper/lok.hxx>
 #include <comphelper/processfactory.hxx>
 #include <comphelper/string.hxx>
 #include <tools/urlobj.hxx>
@@ -55,6 +56,8 @@
 #include <swmodule.hxx>
 #include <sfx2/docfile.hxx>
 #include <sfx2/doctempl.hxx>
+#include <sfx2/sfxresid.hxx>
+#include <sfx2/strings.hrc>
 #include <fmtfld.hxx>
 #include <txtfld.hxx>
 #include <charfmt.hxx>
@@ -435,9 +438,14 @@ OUString SwFileNameFieldType::Expand(sal_uLong nFormat) 
const
     if( pDShell && pDShell->HasName() )
     {
         const INetURLObject& rURLObj = pDShell->GetMedium()->GetURLObject();
+        // Note: The path is useless in jailed kit mode, so present a view that
+        // the document is in a Documents toplevel directory for 
LibreOfficeKit::isActive()
         switch( nFormat & ~FF_FIXED )
         {
             case FF_PATH:
+                if (comphelper::LibreOfficeKit::isActive())
+                    aRet = "/" + SfxResId(STR_GID_DOCUMENT);
+                else
                 {
                     if( INetProtocol::File == rURLObj.GetProtocol() )
                     {
@@ -469,12 +477,17 @@ OUString SwFileNameFieldType::Expand(sal_uLong nFormat) 
const
                 break;
 
             default:
-                if( INetProtocol::File == rURLObj.GetProtocol() )
-                    aRet = rURLObj.GetFull();
+                if (comphelper::LibreOfficeKit::isActive())
+                    aRet = "/" + SfxResId(STR_GID_DOCUMENT) + "/" + 
rURLObj.GetLastName(INetURLObject::DecodeMechanism::WithCharset);
                 else
-                    aRet = URIHelper::removePassword(
-                                    rURLObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE ),
-                                    
INetURLObject::EncodeMechanism::WasEncoded, URL_DECODE );
+                {
+                    if( INetProtocol::File == rURLObj.GetProtocol() )
+                        aRet = rURLObj.GetFull();
+                    else
+                        aRet = URIHelper::removePassword(
+                                        rURLObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE ),
+                                        
INetURLObject::EncodeMechanism::WasEncoded, URL_DECODE );
+                }
         }
     }
     return aRet;

Reply via email to