summaryrefslogtreecommitdiff
path: root/sw/qa/uibase
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-07-22 14:23:07 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-07-22 16:21:49 +0200
commitb85becd0d427c7375f1d8e6309f348304b6ebbac (patch)
tree3fe265fa9c727e6c54de08bb99b8d792a77dd0c4 /sw/qa/uibase
parent8ea426bfa978d338683bf4c715d358187a527ccd (diff)
sw bibliography, local copy: add context menu
This way in case a bibliography entry (field) has both a URL and a LocalURL, it is possible to choose which one should be opened when the context menu is used on the field. This is meant to be the primary way the user consumes this information. Change-Id: I21b72505f8387943424665bff70905f774771d4a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119373 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/qa/uibase')
-rw-r--r--sw/qa/uibase/shells/shells.cxx38
1 files changed, 38 insertions, 0 deletions
diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index badc17d1f4ce..e1f5d048c018 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -170,6 +170,44 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testBibliographyUrlContextMenu)
CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eState);
}
+CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testBibliographyLocalCopyContextMenu)
+{
+ // Given a document with a bibliography field's local copy:
+ 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")),
+ comphelper::makePropertyValue("LocalURL", OUString("file:///home/me/test.pdf")),
+ };
+ 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(FN_OPEN_LOCAL_URL, aState);
+
+ // Then the "open local copy" 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 context menu was disabled all the time, even for biblio fields.
+ CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eState);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */