[Libreoffice-commits] core.git: sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Tue Apr 13 13:24:20 UTC 2021


 sw/source/ui/index/swuiidxmrk.cxx |   26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

New commits:
commit ebba2ee004fce3472705867963fd4e9c7b82fb19
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Apr 13 14:45:34 2021 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Apr 13 15:23:34 2021 +0200

    sw define bibliography entry dialog, file picker: handle relative URLs
    
    On one hand, if we have a setting at tools -> options -> load/save ->
    general -> Save URLs relative to file system, then let's be consistent
    and handle that setting here as well.
    
    On the other hand, this is the default, so this helps the scenario where
    a bunch of PDFs are in a directory, a document is next to them, and
    copying all of them to a different location doesn't break these links.
    
    Change-Id: Ic6fc552b656a754b29887915ac35ef5c2390f156
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114049
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/sw/source/ui/index/swuiidxmrk.cxx b/sw/source/ui/index/swuiidxmrk.cxx
index ee5ea01bd037..9d5a41f05075 100644
--- a/sw/source/ui/index/swuiidxmrk.cxx
+++ b/sw/source/ui/index/swuiidxmrk.cxx
@@ -51,8 +51,12 @@
 #include <svl/cjkoptions.hxx>
 #include <comphelper/fileurl.hxx>
 #include <sfx2/filedlghelper.hxx>
+#include <officecfg/Office/Common.hxx>
+#include <tools/urlobj.hxx>
 #include <ndtxt.hxx>
 #include <SwRewriter.hxx>
+#include <doc.hxx>
+#include <docsh.hxx>
 
 #define POS_CONTENT 0
 #define POS_INDEX   1
@@ -1718,8 +1722,18 @@ IMPL_LINK_NOARG(SwCreateAuthEntryDlg_Impl, BrowseHdl, weld::Button&, void)
     sfx2::FileDialogHelper aFileDlg(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
                                     FileDialogFlags::NONE, getDialog());
     OUString aPath = GetEntryText(AUTH_FIELD_URL);
+    bool bSaveRelFSys = officecfg::Office::Common::Save::URL::FileSystem::get();
     if (!aPath.isEmpty())
     {
+        if (bSaveRelFSys && !comphelper::isFileUrl(aPath))
+        {
+            SwDocShell* pDocShell = rWrtSh.GetDoc()->GetDocShell();
+            OUString aBasePath = pDocShell->getDocumentBaseURL();
+            aPath = INetURLObject::GetAbsURL(aBasePath, aPath,
+                                             INetURLObject::EncodeMechanism::WasEncoded,
+                                             INetURLObject::DecodeMechanism::WithCharset);
+        }
+
         aFileDlg.SetDisplayDirectory(aPath);
     }
 
@@ -1728,12 +1742,22 @@ IMPL_LINK_NOARG(SwCreateAuthEntryDlg_Impl, BrowseHdl, weld::Button&, void)
         return;
     }
 
+    aPath = aFileDlg.GetPath();
+    if (bSaveRelFSys)
+    {
+        SwDocShell* pDocShell = rWrtSh.GetDoc()->GetDocShell();
+        OUString aBasePath = pDocShell->getDocumentBaseURL();
+        aPath
+            = INetURLObject::GetRelURL(aBasePath, aPath, INetURLObject::EncodeMechanism::WasEncoded,
+                                       INetURLObject::DecodeMechanism::WithCharset);
+    }
+
     for (int nIndex = 0; nIndex < AUTH_FIELD_END; nIndex++)
     {
         const TextInfo& rCurInfo = aTextInfoArr[nIndex];
         if (rCurInfo.nToxField == AUTH_FIELD_URL)
         {
-            pEdits[nIndex]->set_text(aFileDlg.GetPath());
+            pEdits[nIndex]->set_text(aPath);
             break;
         }
     }


More information about the Libreoffice-commits mailing list