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

Szymon Kłos szymon.klos at collabora.com
Sun Nov 19 17:17:17 UTC 2017


 sw/source/uibase/wrtsh/wrtsh2.cxx |   21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

New commits:
commit 4b9e237850efe36f7e35d65e14d6953f1e1f3a45
Author: Szymon Kłos <szymon.klos at collabora.com>
Date:   Tue Nov 14 19:29:33 2017 +0100

    tdf#86087 Open relative links in Writer
    
    Change-Id: I3f6caad559d92ec559b8ae1c66e7fea13f52cb76
    Reviewed-on: https://gerrit.libreoffice.org/44734
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>

diff --git a/sw/source/uibase/wrtsh/wrtsh2.cxx b/sw/source/uibase/wrtsh/wrtsh2.cxx
index 011f96d17d71..5076f8604bd9 100644
--- a/sw/source/uibase/wrtsh/wrtsh2.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh2.cxx
@@ -514,10 +514,27 @@ void LoadURL( SwViewShell& rVSh, const OUString& rURL, LoadUrlFlags nFilter,
     if ( dynamic_cast<const SwCursorShell*>( &rVSh) ==  nullptr )
         return;
 
+    OUString sFileURL = rURL;
+    INetURLObject aURL( sFileURL );
+    if( aURL.GetProtocol() == INetProtocol::NotValid && !sFileURL.startsWith("#") )
+    {
+        // May be the relative link -> try to convert to absolute path
+        OUString sParentPath =
+            rVSh.GetDoc()->GetDocShell()->GetMedium()->GetURLObject().GetPath();
+
+        bool bCorrectURL = true;
+        aURL = INetURLObject();
+        bCorrectURL &= aURL.setFSysPath( sParentPath, FSysStyle::Detect );
+        bCorrectURL &= aURL.insertName( sFileURL );
+
+        if( bCorrectURL )
+            sFileURL = aURL.GetMainURL( INetURLObject::DecodeMechanism::WithCharset );
+    }
+
     // We are doing tiledRendering, let the client handles the URL loading.
     if (comphelper::LibreOfficeKit::isActive())
     {
-        rVSh.GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_HYPERLINK_CLICKED, rURL.toUtf8().getStr());
+        rVSh.GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_HYPERLINK_CLICKED, sFileURL.toUtf8().getStr());
         return;
     }
 
@@ -542,7 +559,7 @@ void LoadURL( SwViewShell& rVSh, const OUString& rURL, LoadUrlFlags nFilter,
         sReferer = pDShell->GetMedium()->GetName();
     SfxViewFrame* pViewFrame = rSh.GetView().GetViewFrame();
     SfxFrameItem aView( SID_DOCFRAME, pViewFrame );
-    SfxStringItem aName( SID_FILE_NAME, rURL );
+    SfxStringItem aName( SID_FILE_NAME, sFileURL );
     SfxStringItem aTargetFrameName( SID_TARGETNAME, sTargetFrame );
     SfxStringItem aReferer( SID_REFERER, sReferer );
 


More information about the Libreoffice-commits mailing list