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

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Wed Apr 14 10:09:24 UTC 2021


 sw/source/ui/index/swuiidxmrk.cxx |   20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

New commits:
commit 7526e77820956238a1a903d73ff15a49c082d6de
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Apr 14 11:06:00 2021 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Apr 14 12:08:49 2021 +0200

    sw define bibliography entry dialog: recognize relative file URLs
    
    So that in case a file:// document has relative URLs, we show the type
    as local file (with a file picker), not as "www document".
    
    Change-Id: Id7a5d181dc6b2b9e6165d83bd294d7350bd4ce24
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114078
    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 9d5a41f05075..464614f7eeb3 100644
--- a/sw/source/ui/index/swuiidxmrk.cxx
+++ b/sw/source/ui/index/swuiidxmrk.cxx
@@ -72,6 +72,20 @@ using namespace com::sun::star::lang;
 using namespace com::sun::star::util;
 using namespace ::comphelper;
 
+namespace
+{
+/// Similar to comphelper::isFileUrl(), but handles relative URLs as well.
+bool IsFileUrl(SwWrtShell& rWrtSh, const OUString& rUrl)
+{
+    SwDocShell* pDocShell = rWrtSh.GetDoc()->GetDocShell();
+    OUString aBaseUrl = pDocShell->getDocumentBaseURL();
+    OUString aAbs = INetURLObject::GetAbsURL(aBaseUrl, rUrl,
+            INetURLObject::EncodeMechanism::WasEncoded,
+            INetURLObject::DecodeMechanism::WithCharset);
+    return comphelper::isFileUrl(aAbs);
+}
+}
+
 // dialog to insert a directory selection
 SwIndexMarkPane::SwIndexMarkPane(const std::shared_ptr<weld::Dialog>& rDialog, weld::Builder& rBuilder, bool bNewDlg,
     SwWrtShell* pWrtShell)
@@ -1557,7 +1571,7 @@ SwCreateAuthEntryDlg_Impl::SwCreateAuthEntryDlg_Impl(weld::Window* pParent,
             if(!pFields[aCurInfo.nToxField].isEmpty())
             {
                 int nPos = pFields[aCurInfo.nToxField].toInt32();
-                if (nPos == AUTH_TYPE_WWW && comphelper::isFileUrl(pFields[AUTH_FIELD_URL]))
+                if (nPos == AUTH_TYPE_WWW && IsFileUrl(rWrtSh, pFields[AUTH_FIELD_URL]))
                 {
                     // Map file URL to local file.
                     nPos = AUTH_TYPE_END;
@@ -1626,7 +1640,7 @@ SwCreateAuthEntryDlg_Impl::SwCreateAuthEntryDlg_Impl(weld::Window* pParent,
                 }
             }
             else if (aCurInfo.nToxField == AUTH_FIELD_URL
-                     && comphelper::isFileUrl(pFields[aCurInfo.nToxField]))
+                     && IsFileUrl(rWrtSh, pFields[aCurInfo.nToxField]))
             {
                 m_xBrowseButton = m_aBuilders.back()->weld_button("browse");
                 m_xBrowseButton->connect_clicked(LINK(this, SwCreateAuthEntryDlg_Impl, BrowseHdl));
@@ -1725,7 +1739,7 @@ IMPL_LINK_NOARG(SwCreateAuthEntryDlg_Impl, BrowseHdl, weld::Button&, void)
     bool bSaveRelFSys = officecfg::Office::Common::Save::URL::FileSystem::get();
     if (!aPath.isEmpty())
     {
-        if (bSaveRelFSys && !comphelper::isFileUrl(aPath))
+        if (bSaveRelFSys && !IsFileUrl(rWrtSh, aPath))
         {
             SwDocShell* pDocShell = rWrtSh.GetDoc()->GetDocShell();
             OUString aBasePath = pDocShell->getDocumentBaseURL();


More information about the Libreoffice-commits mailing list