diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-04-13 14:45:34 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-04-13 15:23:34 +0200 |
commit | ebba2ee004fce3472705867963fd4e9c7b82fb19 (patch) | |
tree | 6b56dc1cac5e58e2da69be486c5bdb0e0f182a28 /sw | |
parent | b5b12537b784b3af9f2e2ad76536a55e281d6cfb (diff) |
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@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/ui/index/swuiidxmrk.cxx | 26 |
1 files changed, 25 insertions, 1 deletions
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; } } |