From ebba2ee004fce3472705867963fd4e9c7b82fb19 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 13 Apr 2021 14:45:34 +0200 Subject: 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 Tested-by: Jenkins --- sw/source/ui/index/swuiidxmrk.cxx | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'sw') 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 #include #include +#include +#include #include #include +#include +#include #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; } } -- cgit