[Libreoffice-commits] core.git: officecfg/registry sw/inc sw/qa sw/sdi sw/source sw/uiconfig
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Thu Jul 22 14:22:29 UTC 2021
officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu | 8 +
sw/inc/cmdid.h | 1
sw/qa/uibase/shells/shells.cxx | 38 +++++++++
sw/sdi/_textsh.sdi | 5 +
sw/sdi/swriter.sdi | 17 ++++
sw/source/uibase/shells/textsh1.cxx | 41 ++++++++++
sw/uiconfig/swriter/popupmenu/text.xml | 1
7 files changed, 111 insertions(+)
New commits:
commit b85becd0d427c7375f1d8e6309f348304b6ebbac
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Jul 22 14:23:07 2021 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Jul 22 16:21:49 2021 +0200
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 at collabora.com>
Tested-by: Jenkins
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
index eb8d07581cca..7015b06c306e 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
@@ -7249,6 +7249,14 @@ bit 3 (0x8): #define UICOMMANDDESCRIPTION_PROPERTIES_TOGGLEBUTTON 8
<value>1</value>
</prop>
</node>
+ <node oor:name=".uno:OpenLocalURL" oor:op="replace">
+ <prop oor:name="Label" oor:type="xs:string">
+ <value xml:lang="en-US">~Open Local Copy</value>
+ </prop>
+ <prop oor:name="Properties" oor:type="xs:int">
+ <value>1</value>
+ </prop>
+ </node>
<node oor:name=".uno:EditChart" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">~Edit Chart</value>
diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h
index 198aaded1608..79b6ffc392ba 100644
--- a/sw/inc/cmdid.h
+++ b/sw/inc/cmdid.h
@@ -495,6 +495,7 @@
#define FN_CHANGE_PAGENUM (FN_EXTRA + 34) /* change page numbers*/
#define FN_ADD_TEXT_BOX (FN_EXTRA + 35) /* add text box to draw shape */
#define FN_REMOVE_TEXT_BOX (FN_EXTRA + 36) /* remove text box of draw shape */
+#define FN_OPEN_LOCAL_URL (FN_EXTRA + 37) /* open local copy for bibliography */
// Region: Glossary
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: */
diff --git a/sw/sdi/_textsh.sdi b/sw/sdi/_textsh.sdi
index 7e6d2c32a6d6..6af93a628eb6 100644
--- a/sw/sdi/_textsh.sdi
+++ b/sw/sdi/_textsh.sdi
@@ -1656,6 +1656,11 @@ interface BaseText
ExecMethod = Execute ;
StateMethod = GetState ;
]
+ FN_OPEN_LOCAL_URL
+ [
+ ExecMethod = Execute ;
+ StateMethod = GetState ;
+ ]
SID_OPEN_SMARTTAGMENU
[
ExecMethod = Execute ;
diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index a3eff026d42c..0e994261c28c 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -7880,6 +7880,23 @@ SfxVoidItem RemoveTextBox FN_REMOVE_TEXT_BOX
GroupId = SfxGroupId::Drawing;
]
+SfxVoidItem OpenLocalURL FN_OPEN_LOCAL_URL
+()
+[
+ AutoUpdate = FALSE,
+ FastCall = TRUE,
+ ReadOnlyDoc = TRUE,
+ Toggle = FALSE,
+ Container = FALSE,
+ RecordAbsolute = FALSE,
+ RecordPerSet;
+
+ AccelConfig = FALSE,
+ MenuConfig = FALSE,
+ ToolBoxConfig = TRUE,
+ GroupId = SfxGroupId::Navigator;
+]
+
SfxUInt16Item JumpToSpecificPage SID_JUMP_TO_SPECIFIC_PAGE
( SfxUInt16Item JumpToSpecificPage SID_JUMP_TO_SPECIFIC_PAGE )
[
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index ed5bc5a1b91e..0114119d1fc7 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -351,6 +351,30 @@ void InsertBreak(SwWrtShell& rWrtSh,
}
}
+OUString GetLocalURL(SwWrtShell& rSh)
+{
+ SwField* pField = rSh.GetCurField();
+ if (!pField)
+ {
+ return OUString();
+ }
+
+ if (pField->GetTyp()->Which() != SwFieldIds::TableOfAuthorities)
+ {
+ return OUString();
+ }
+
+ const auto& rAuthorityField = *static_cast<const SwAuthorityField*>(pField);
+ SwAuthEntry* pAuthEntry = rAuthorityField.GetAuthEntry();
+ if (!pAuthEntry)
+ {
+ return OUString();
+ }
+
+ const OUString& rLocalURL = pAuthEntry->GetAuthorField(AUTH_FIELD_LOCAL_URL);
+ return rLocalURL;
+}
+
}
void SwTextShell::Execute(SfxRequest &rReq)
@@ -1388,6 +1412,15 @@ void SwTextShell::Execute(SfxRequest &rReq)
}
}
break;
+ case FN_OPEN_LOCAL_URL:
+ {
+ OUString aLocalURL = GetLocalURL(rWrtSh);
+ if (!aLocalURL.isEmpty())
+ {
+ ::LoadURL(rWrtSh, aLocalURL, LoadUrlFlags::NewView, /*rTargetFrameName=*/OUString());
+ }
+ }
+ break;
case SID_OPEN_XML_FILTERSETTINGS:
{
HandleOpenXmlFilterSettings(rReq);
@@ -2033,6 +2066,14 @@ void SwTextShell::GetState( SfxItemSet &rSet )
rSet.DisableItem(nWhich);
}
break;
+ case FN_OPEN_LOCAL_URL:
+ {
+ if (GetLocalURL(rSh).isEmpty())
+ {
+ rSet.DisableItem(nWhich);
+ }
+ }
+ break;
case SID_OPEN_SMARTTAGMENU:
{
std::vector< OUString > aSmartTagTypes;
diff --git a/sw/uiconfig/swriter/popupmenu/text.xml b/sw/uiconfig/swriter/popupmenu/text.xml
index f89bd0fa2cce..47d0ac89039d 100644
--- a/sw/uiconfig/swriter/popupmenu/text.xml
+++ b/sw/uiconfig/swriter/popupmenu/text.xml
@@ -84,6 +84,7 @@
<menu:menuitem menu:id=".uno:EditHyperlink"/>
<menu:menuitem menu:id=".uno:CopyHyperlinkLocation"/>
<menu:menuitem menu:id=".uno:RemoveHyperlink"/>
+ <menu:menuitem menu:id=".uno:OpenLocalURL"/>
<menu:menuitem menu:id=".uno:OpenSmartTagMenuOnCursor"/>
<menu:menuitem menu:id=".uno:ThesaurusFromContext"/>
<menu:menuseparator/>
More information about the Libreoffice-commits
mailing list