summaryrefslogtreecommitdiff
path: root/sw/source/uibase/shells/textsh1.cxx
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-12-06 14:41:45 +0100
committerMiklos Vajna <vmiklos@collabora.com>2022-12-16 08:09:01 +0000
commit07e6d948ae2a6118bde4f2dce83b5f1e3684fa87 (patch)
treed5293c6bffaf6ac8f182f0d05aa36dd24cc52307 /sw/source/uibase/shells/textsh1.cxx
parent403051783e14edbe0781fdefd40e286aacbd03b5 (diff)
sw, .uno:InsertBookmark: add a new BookmarkText parameter and accept HTML there
There was already an UNO command to insert a new bookmark with the provided name, in a non-interactive way. What was missing is to allow specifying the bookmark text, which is to some extent not part of the bookmark, but e.g. the bookmark dialog allows editing that still. Add a new BookmarkText parameter to .uno:InsertBookmark, in case it's specified then we interpret this as HTML and we create the bookmark on the imported content, not simply at the current cursor position. This is similar to commit 1c2ef850db29beb369dcc89a58fc73416ecd9c5c (sw, .uno:TextFormField command: accept HTML in the FieldResult parameter, 2022-11-16), but that was for the field mode, while this is for the bookmark mode of Zotero. (cherry picked from commit fa82e151d80d15eeb6dfae434f1dbb3b68907188) Conflicts: sw/source/uibase/shells/textsh1.cxx Change-Id: I4928d173e197796d40fdb53f81e84b6bfd77cdc5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144209 Tested-by: Miklos Vajna <vmiklos@collabora.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/source/uibase/shells/textsh1.cxx')
-rw-r--r--sw/source/uibase/shells/textsh1.cxx43
1 files changed, 43 insertions, 0 deletions
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index 53813ff905e6..151cdff40a63 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -106,6 +106,7 @@
#include <translatelangselect.hxx>
#include <svtools/deeplcfg.hxx>
#include <translatehelper.hxx>
+#include <IDocumentContentOperations.hxx>
using namespace ::com::sun::star;
using namespace com::sun::star::beans;
@@ -693,10 +694,52 @@ void SwTextShell::Execute(SfxRequest &rReq)
}
case FN_INSERT_BOOKMARK:
{
+ const SfxStringItem* pBookmarkText = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
+ SwPaM* pCursorPos = rWrtSh.GetCursor();
if ( pItem )
{
+ rWrtSh.StartAction();
OUString sName = static_cast<const SfxStringItem*>(pItem)->GetValue();
+
+ if (pBookmarkText)
+ {
+ OUString aBookmarkText = pBookmarkText->GetValue();
+ // Split node to remember where the start position is.
+ bool bSuccess = rWrtSh.GetDoc()->getIDocumentContentOperations().SplitNode(
+ *pCursorPos->GetPoint(), /*bChkTableStart=*/false);
+ if (bSuccess)
+ {
+ SwPaM aBookmarkPam(*pCursorPos->GetPoint());
+ aBookmarkPam.Move(fnMoveBackward, GoInContent);
+
+ // Paste HTML content.
+ SwTranslateHelper::PasteHTMLToPaM(
+ rWrtSh, pCursorPos, aBookmarkText.toUtf8(), /*bSetSelection=*/true);
+ if (pCursorPos->GetPoint()->nContent == 0)
+ {
+ // The paste created a last empty text node, remove it.
+ SwPaM aPam(*pCursorPos->GetPoint());
+ aPam.SetMark();
+ aPam.Move(fnMoveBackward, GoInContent);
+ rWrtSh.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(aPam);
+ }
+
+ // Undo the above SplitNode().
+ aBookmarkPam.SetMark();
+ aBookmarkPam.Move(fnMoveForward, GoInContent);
+ rWrtSh.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(
+ aBookmarkPam);
+ *aBookmarkPam.GetMark() = *pCursorPos->GetPoint();
+ *pCursorPos = aBookmarkPam;
+ }
+ }
+
rWrtSh.SetBookmark( vcl::KeyCode(), sName );
+ if (pBookmarkText)
+ {
+ pCursorPos->DeleteMark();
+ }
+ rWrtSh.EndAction();
}
else
{