diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-03-23 11:36:21 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-03-24 12:48:04 +0100 |
commit | faa8f4ff3536f9328c6dcf11feff3a7c5fca0ea4 (patch) | |
tree | 749ec77ac90add7e4d8a8d73557e3e2d17228080 /sw | |
parent | b6632bd41b56a2485dc6dd67a19d930c9654f835 (diff) |
sw bibliography, refer to a page: add open hyperlink context menu
This brings bibliography entry fields with URLs closer to hyperlinks,
which already had the same context menu.
Change-Id: I8680a0fccb1f75c15cdcc52f86fabf1c57b5635e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112981
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/uibase/shells/shells.cxx | 40 | ||||
-rw-r--r-- | sw/source/uibase/shells/textsh1.cxx | 28 |
2 files changed, 67 insertions, 1 deletions
diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx index d267bda51a96..6334be3a553b 100644 --- a/sw/qa/uibase/shells/shells.cxx +++ b/sw/qa/uibase/shells/shells.cxx @@ -11,6 +11,8 @@ #include <com/sun/star/frame/XStorable.hpp> #include <com/sun/star/packages/zip/ZipFileAccess.hpp> +#include <com/sun/star/text/BibliographyDataType.hpp> +#include <com/sun/star/text/XTextDocument.hpp> #include <sfx2/dispatch.hxx> #include <sfx2/viewfrm.hxx> @@ -21,6 +23,7 @@ #include <editeng/outlobj.hxx> #include <editeng/editobj.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/propertyvalue.hxx> #include <IDocumentContentOperations.hxx> #include <cmdid.h> @@ -130,6 +133,43 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testOleSavePreviewUpdate) CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Object 2")); } +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testBibliographyUrlContextMenu) +{ + // Given a document with a bibliography field: + SwDoc* pDoc = createSwDoc(); + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xField( + xFactory->createInstance("com.sun.star.text.TextField.Bibliography"), uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aFields = { + comphelper::makePropertyValue("BibiliographicType", text::BibliographyDataType::WWW), + comphelper::makePropertyValue("Identifier", OUString("AT")), + comphelper::makePropertyValue("Author", OUString("Author")), + comphelper::makePropertyValue("Title", OUString("Title")), + comphelper::makePropertyValue("URL", OUString("http://www.example.com/test.pdf#page=1")), + }; + xField->setPropertyValue("Fields", uno::makeAny(aFields)); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextContent> xContent(xField, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xContent, /*bAbsorb=*/false); + + // When selecting the field and opening the context menu: + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false); + SfxDispatcher* pDispatcher = pDocShell->GetViewShell()->GetViewFrame()->GetDispatcher(); + css::uno::Any aState; + SfxItemState eState = pDispatcher->QueryState(SID_OPEN_HYPERLINK, aState); + + // Then the "open hyperlink" menu item should be visible: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 32 (SfxItemState::DEFAULT) + // - Actual : 1 (SfxItemState::DISABLED) + // i.e. the menu item was not visible for biblio entry fields with an URL. + CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eState); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index 9535ceef1fa9..1b2cd56fb2f0 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -99,6 +99,7 @@ #include <xmloff/odffields.hxx> #include <bookmrk.hxx> #include <linguistic/misc.hxx> +#include <authfld.hxx> using namespace ::com::sun::star; using namespace com::sun::star::beans; @@ -1351,6 +1352,21 @@ void SwTextShell::Execute(SfxRequest &rReq) else rWrtSh.ClickToINetAttr(rINetFormat); } + else + { + SwField* pField = rWrtSh.GetCurField(); + if (pField && pField->GetTyp()->Which() == SwFieldIds::TableOfAuthorities) + { + const auto& rAuthorityField = *static_cast<const SwAuthorityField*>(pField); + if (rAuthorityField.HasURL()) + { + // Bibliography entry with URL also provides a hyperlink. + const OUString& rURL + = rAuthorityField.GetAuthEntry()->GetAuthorField(AUTH_FIELD_URL); + ::LoadURL(rWrtSh, rURL, LoadUrlFlags::NewView, /*rTargetFrameName=*/OUString()); + } + } + } } break; case SID_OPEN_XML_FILTERSETTINGS: @@ -1984,7 +2000,17 @@ void SwTextShell::GetState( SfxItemSet &rSet ) svl::Items<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT>{}); rSh.GetCurAttr(aSet); - if(SfxItemState::SET > aSet.GetItemState( RES_TXTATR_INETFMT, false )) + + bool bAuthorityFieldURL = false; + 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); + bAuthorityFieldURL = rAuthorityField.HasURL(); + } + if (SfxItemState::SET > aSet.GetItemState(RES_TXTATR_INETFMT, false) + && !bAuthorityFieldURL) rSet.DisableItem(nWhich); } break; |