summaryrefslogtreecommitdiff
path: root/sw/source/uibase
diff options
context:
space:
mode:
authorVojtěch Doležal <dolezvo1@cvut.cz>2023-04-06 00:25:34 +0200
committerMiklos Vajna <vmiklos@collabora.com>2023-05-05 08:32:09 +0200
commitd543eb2d8e45999a3d8fa6134f0d98f08acb8037 (patch)
treed5a1c6d1e2b2d5cd7084746f6428d03d9c35a802 /sw/source/uibase
parent671d1c6cd14b28b5960ad56086299bd69533dfd8 (diff)
Reworked bibliography mark link target to have user-selectable type
Without this change, havign no link is not possible, if the bibliography entry has URL. This commit adds a select box for user to choose between target types (Entry URL, specific Target URL, None, bibliography table row) The main features are that it also makes it more obvious to the user and makes it possible to easily extend target types in the future. As for compatibility, files from before 7b99871635 are fully compatible without any hurdles, as missing property maps to the old behaviour. Bibliography marks saved after 7b99871635 will also revert to the old behaviour, however no actual data (such as target URLs) will be lost. Change-Id: Iad61dd8b4df337fa202f45d117313ee47ec20c05 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150708 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/source/uibase')
-rw-r--r--sw/source/uibase/docvw/edtwin2.cxx9
-rw-r--r--sw/source/uibase/shells/textsh1.cxx33
-rw-r--r--sw/source/uibase/utlui/initui.cxx2
-rw-r--r--sw/source/uibase/wrtsh/wrtsh2.cxx23
4 files changed, 33 insertions, 34 deletions
diff --git a/sw/source/uibase/docvw/edtwin2.cxx b/sw/source/uibase/docvw/edtwin2.cxx
index a98d38cf1e79..1c9563782050 100644
--- a/sw/source/uibase/docvw/edtwin2.cxx
+++ b/sw/source/uibase/docvw/edtwin2.cxx
@@ -575,16 +575,13 @@ void SwEditWin::RequestHelp(const HelpEvent &rEvt)
const auto pAuthorityField = static_cast<const SwAuthorityField*>(pField);
sText = pAuthorityField->GetAuthority(rSh.GetLayout());
- if (!pAuthorityField->UseTargetURL() && pAuthorityField->HasURL())
+ if (auto t = pAuthorityField->GetTargetType();
+ t == SwAuthorityField::TargetType::UseDisplayURL
+ || t == SwAuthorityField::TargetType::UseTargetURL)
{
const OUString& rURL = pAuthorityField->GetAbsoluteURL();
sText += "\n" + SfxHelp::GetURLHelpText(rURL);
}
- else if (pAuthorityField->UseTargetURL() && pAuthorityField->HasTargetURL())
- {
- const OUString& rURL = pAuthorityField->GetAbsoluteTargetURL();
- sText += "\n" + SfxHelp::GetURLHelpText(rURL);
- }
break;
}
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index cdef2ec7d2bb..fd0d4454492a 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -1812,6 +1812,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
if(SfxItemState::SET <= aSet.GetItemState( RES_TXTATR_INETFMT ))
{
const SwFormatINetFormat& rINetFormat = aSet.Get(RES_TXTATR_INETFMT);
+
if (nSlot == SID_OPEN_HYPERLINK)
{
rWrtSh.ClickToINetAttr(rINetFormat);
@@ -1829,22 +1830,26 @@ void SwTextShell::Execute(SfxRequest &rReq)
if (pField && pField->GetTyp()->Which() == SwFieldIds::TableOfAuthorities)
{
const auto& rAuthorityField = *static_cast<const SwAuthorityField*>(pField);
- if ((!rAuthorityField.UseTargetURL() && rAuthorityField.HasURL())
- || (rAuthorityField.UseTargetURL() && rAuthorityField.HasTargetURL()))
+ OUString targetURL = "";
+
+ if (auto targetType = rAuthorityField.GetTargetType();
+ targetType == SwAuthorityField::TargetType::UseDisplayURL
+ || targetType == SwAuthorityField::TargetType::UseTargetURL)
{
// Bibliography entry with URL also provides a hyperlink.
- const OUString& rURL
- = rAuthorityField.GetAuthEntry()->GetAuthorField(
- rAuthorityField.UseTargetURL() ? AUTH_FIELD_TARGET_URL : AUTH_FIELD_URL);
-
+ targetURL = rAuthorityField.GetAbsoluteURL();
+ }
+
+ if (targetURL.getLength() > 0)
+ {
if (nSlot == SID_OPEN_HYPERLINK)
{
- ::LoadURL(rWrtSh, rURL, LoadUrlFlags::NewView, /*rTargetFrameName=*/OUString());
+ ::LoadURL(rWrtSh, targetURL, LoadUrlFlags::NewView, /*rTargetFrameName=*/OUString());
}
else if (nSlot == SID_COPY_HYPERLINK_LOCATION)
{
::uno::Reference< datatransfer::clipboard::XClipboard > xClipboard = GetView().GetEditWin().GetClipboard();
- vcl::unohelper::TextDataObject::CopyStringTo(rURL, xClipboard, SfxViewShell::Current());
+ vcl::unohelper::TextDataObject::CopyStringTo(targetURL, xClipboard, SfxViewShell::Current());
}
}
}
@@ -2571,12 +2576,14 @@ void SwTextShell::GetState( SfxItemSet &rSet )
SwField* pField = rSh.GetCurField();
if (pField && pField->GetTyp()->Which() == SwFieldIds::TableOfAuthorities)
{
- // Bibliography entry with URL also provides a hyperlink.
const auto& rAuthorityField = *static_cast<const SwAuthorityField*>(pField);
- if (!rAuthorityField.UseTargetURL())
- bAuthorityFieldURL = rAuthorityField.HasURL();
- else
- bAuthorityFieldURL = rAuthorityField.HasTargetURL();
+ if (auto targetType = rAuthorityField.GetTargetType();
+ targetType == SwAuthorityField::TargetType::UseDisplayURL
+ || targetType == SwAuthorityField::TargetType::UseTargetURL)
+ {
+ // Check if the Bibliography entry has a target URL
+ bAuthorityFieldURL = rAuthorityField.GetAbsoluteURL().getLength() > 0;
+ }
}
if (SfxItemState::SET > aSet.GetItemState(RES_TXTATR_INETFMT, false)
&& !bAuthorityFieldURL)
diff --git a/sw/source/uibase/utlui/initui.cxx b/sw/source/uibase/utlui/initui.cxx
index 51e2b8e8894e..2444d652ea73 100644
--- a/sw/source/uibase/utlui/initui.cxx
+++ b/sw/source/uibase/utlui/initui.cxx
@@ -236,8 +236,8 @@ namespace
STR_AUTH_FIELD_CUSTOM5,
STR_AUTH_FIELD_ISBN,
STR_AUTH_FIELD_LOCAL_URL,
+ STR_AUTH_FIELD_TARGET_TYPE,
STR_AUTH_FIELD_TARGET_URL,
- STR_AUTH_FIELD_USE_TARGET_URL,
};
}
diff --git a/sw/source/uibase/wrtsh/wrtsh2.cxx b/sw/source/uibase/wrtsh/wrtsh2.cxx
index 5136659b708d..f4881304f95c 100644
--- a/sw/source/uibase/wrtsh/wrtsh2.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh2.cxx
@@ -414,23 +414,18 @@ void SwWrtShell::ClickToField(const SwField& rField, bool bExecHyperlinks)
Point vStartPoint = GetCursor_()->GetPtPos();
const SwAuthorityField* pField = static_cast<const SwAuthorityField*>(&rField);
- if (!pField->UseTargetURL() && pField->HasURL())
+ if (auto targetType = pField->GetTargetType();
+ targetType == SwAuthorityField::TargetType::UseDisplayURL
+ || targetType == SwAuthorityField::TargetType::UseTargetURL)
{
- // Since user didn't opt in to use Target URL, open standard URL
-
- const OUString& rURL = pField->GetAbsoluteURL();
- ::LoadURL(*this, rURL, LoadUrlFlags::NewView, /*rTargetFrameName=*/OUString());
- }
- else if (pField->UseTargetURL() && pField->HasTargetURL())
- {
- // Since user opted in to use Target URL and field has Target URL, use it
-
- const OUString& rURL = pField->GetAbsoluteTargetURL();
- ::LoadURL(*this, rURL, LoadUrlFlags::NewView, /*rTargetFrameName=*/OUString());
+ // Since the user selected target type with URL, try to use it if not empty
+ if (const OUString& rURL = pField->GetAbsoluteURL();
+ rURL.getLength() > 0)
+ ::LoadURL(*this, rURL, LoadUrlFlags::NewView, /*rTargetFrameName=*/OUString());
}
- else if (pField->UseTargetURL())
+ else if (targetType == SwAuthorityField::TargetType::BibliographyTableRow)
{
- // Since user opted in to use Target URL but the field doesn't have Target URL,
+ // Since the user selected to target Bibliography Table Row,
// try finding matching bibliography table line
const bool bWasViewLocked = IsViewLocked();