From 8731dd1abfdf18747dd168311cdd30acd0be2298 Mon Sep 17 00:00:00 2001 From: stroomdev66 Date: Tue, 28 Jan 2025 16:24:58 +0000 Subject: [PATCH] #4672 Add right click menu to copyable items --- .../data/client/presenter/CopyTextUtil.java | 44 ++++++++++++++----- .../data/client/presenter/DataPresenter.java | 2 +- .../presenter/InfoDocumentPresenter.java | 2 +- .../20250128_162441_331__4672.md | 24 ++++++++++ 4 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 unreleased_changes/20250128_162441_331__4672.md diff --git a/stroom-core-client/src/main/java/stroom/data/client/presenter/CopyTextUtil.java b/stroom-core-client/src/main/java/stroom/data/client/presenter/CopyTextUtil.java index 99045295cf4..49005e1fd51 100644 --- a/stroom-core-client/src/main/java/stroom/data/client/presenter/CopyTextUtil.java +++ b/stroom-core-client/src/main/java/stroom/data/client/presenter/CopyTextUtil.java @@ -3,6 +3,10 @@ import stroom.svg.shared.SvgImage; import stroom.util.client.ClipboardUtil; import stroom.util.shared.GwtNullSafe; +import stroom.widget.menu.client.presenter.IconMenuItem; +import stroom.widget.menu.client.presenter.Item; +import stroom.widget.menu.client.presenter.ShowMenuEvent; +import stroom.widget.popup.client.presenter.PopupPosition; import stroom.widget.util.client.ElementUtil; import stroom.widget.util.client.MouseUtil; import stroom.widget.util.client.SvgImageUtil; @@ -11,11 +15,15 @@ import com.google.gwt.dom.client.BrowserEvents; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; +import com.google.gwt.event.shared.HasHandlers; import com.google.gwt.safehtml.client.SafeHtmlTemplates; import com.google.gwt.safehtml.shared.SafeHtml; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.safehtml.shared.SafeHtmlUtils; +import java.util.ArrayList; +import java.util.List; + public class CopyTextUtil { public static final String ICON_NAME = "svgIcon"; @@ -79,17 +87,33 @@ public static void render(final String value, } } - public static void onClick(final NativeEvent e) { - if (BrowserEvents.MOUSEDOWN.equals(e.getType()) && MouseUtil.isPrimary(e)) { + public static void onClick(final NativeEvent e, + final HasHandlers hasHandlers) { + if (BrowserEvents.MOUSEDOWN.equals(e.getType())) { final Element element = e.getEventTarget().cast(); - final Element copy = - ElementUtil.findParent(element, CopyTextUtil.COPY_CLASS_NAME, 5); - if (copy != null) { - final Element container = ElementUtil.findParent( - element, "docRefLinkContainer", 5); - - GwtNullSafe.consumeNonBlankString(container, Element::getInnerText, text -> - ClipboardUtil.copy(text.trim())); + final Element container = ElementUtil.findParent( + element, "docRefLinkContainer", 5); + final String text = GwtNullSafe.get(container, Element::getInnerText); + if (GwtNullSafe.isNonBlankString(text)) { + if (MouseUtil.isPrimary(e)) { + final Element copy = ElementUtil.findParent(element, CopyTextUtil.COPY_CLASS_NAME, 5); + if (copy != null) { + ClipboardUtil.copy(text.trim()); + } + } else { + final List menuItems = new ArrayList<>(); + menuItems.add(new IconMenuItem.Builder() + .priority(1) + .icon(SvgImage.COPY) + .text("Copy") + .command(() -> ClipboardUtil.copy(text.trim())) + .build()); + ShowMenuEvent + .builder() + .items(menuItems) + .popupPosition(new PopupPosition(e.getClientX(), e.getClientY())) + .fire(hasHandlers); + } } } } diff --git a/stroom-core-client/src/main/java/stroom/data/client/presenter/DataPresenter.java b/stroom-core-client/src/main/java/stroom/data/client/presenter/DataPresenter.java index 4d55f9967b8..201b5753c4d 100644 --- a/stroom-core-client/src/main/java/stroom/data/client/presenter/DataPresenter.java +++ b/stroom-core-client/src/main/java/stroom/data/client/presenter/DataPresenter.java @@ -267,7 +267,7 @@ protected void onBind() { onNewTabSelected(event.getSelectedItem()))); registerHandler(dataView.getTabBar().addShowMenuHandler(e -> getEventBus().fireEvent(e))); registerHandler(htmlPresenter.getWidget().addDomHandler(e -> - CopyTextUtil.onClick(e.getNativeEvent()), MouseDownEvent.getType())); + CopyTextUtil.onClick(e.getNativeEvent(), this), MouseDownEvent.getType())); } private void onNewTabSelected(final TabData tab) { diff --git a/stroom-core-client/src/main/java/stroom/entity/client/presenter/InfoDocumentPresenter.java b/stroom-core-client/src/main/java/stroom/entity/client/presenter/InfoDocumentPresenter.java index 551361801fc..630a66c1930 100644 --- a/stroom-core-client/src/main/java/stroom/entity/client/presenter/InfoDocumentPresenter.java +++ b/stroom-core-client/src/main/java/stroom/entity/client/presenter/InfoDocumentPresenter.java @@ -62,7 +62,7 @@ public InfoDocumentPresenter(final EventBus eventBus, @Override protected void onBind() { registerHandler(getView().asWidget().addDomHandler(e -> - CopyTextUtil.onClick(e.getNativeEvent()), MouseDownEvent.getType())); + CopyTextUtil.onClick(e.getNativeEvent(), this), MouseDownEvent.getType())); } @Override diff --git a/unreleased_changes/20250128_162441_331__4672.md b/unreleased_changes/20250128_162441_331__4672.md new file mode 100644 index 00000000000..4ea1f33af0f --- /dev/null +++ b/unreleased_changes/20250128_162441_331__4672.md @@ -0,0 +1,24 @@ +* Issue **#4672** : Add right click menu to copyable items. + + +```sh +# ******************************************************************************** +# Issue title: Add right click context menu to table cells, especially doc ref cells. +# Issue link: https://github.com/gchq/stroom/issues/4672 +# ******************************************************************************** + +# ONLY the top line will be included as a change entry in the CHANGELOG. +# The entry should be in GitHub flavour markdown and should be written on a SINGLE +# line with no hard breaks. You can have multiple change files for a single GitHub issue. +# The entry should be written in the imperative mood, i.e. 'Fix nasty bug' rather than +# 'Fixed nasty bug'. +# +# Examples of acceptable entries are: +# +# +# * Issue **123** : Fix bug with an associated GitHub issue in this repository +# +# * Issue **namespace/other-repo#456** : Fix bug with an associated GitHub issue in another repository +# +# * Fix bug with no associated GitHub issue. +```