From c46da44592cbaa084dc44d8ebeef49f5439a8e2b Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Wed, 11 Nov 2020 09:23:17 +0000 Subject: [PATCH] add ability to copy full id from results table --- .../com/muwire/gui/SearchTabController.groovy | 8 +++++++ gui/griffon-app/i18n/messages.properties | 2 +- .../views/com/muwire/gui/SearchTabView.groovy | 22 +++++++++++++++++++ .../java/com/muwire/gui/CopyPasteSupport.java | 7 ++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/gui/griffon-app/controllers/com/muwire/gui/SearchTabController.groovy b/gui/griffon-app/controllers/com/muwire/gui/SearchTabController.groovy index cbf5bbdb..461be940 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/SearchTabController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/SearchTabController.groovy @@ -207,4 +207,12 @@ class SearchTabController { params.core = model.core mvcGroup.parentGroup.createMVCGroup("new-message", UUID.randomUUID().toString(), params) } + + @ControllerAction + void copyFullID() { + Persona sender = view.selectedSender() + if (sender == null) + return + CopyPasteSupport.copyToClipboard(sender.toBase64()) + } } \ No newline at end of file diff --git a/gui/griffon-app/i18n/messages.properties b/gui/griffon-app/i18n/messages.properties index 57344e07..01d210b5 100644 --- a/gui/griffon-app/i18n/messages.properties +++ b/gui/griffon-app/i18n/messages.properties @@ -258,7 +258,7 @@ RESULTS=Results FEED=Feed NEUTRAL=Neutral DISTRUST=Distrust -COPY_FULL_ID=Copy full ID +COPY_FULL_ID=Copy Full ID # results table (group by sender) DIRECT_SOURCES=Direct Sources diff --git a/gui/griffon-app/views/com/muwire/gui/SearchTabView.groovy b/gui/griffon-app/views/com/muwire/gui/SearchTabView.groovy index b51e0260..773eb6ea 100644 --- a/gui/griffon-app/views/com/muwire/gui/SearchTabView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/SearchTabView.groovy @@ -318,6 +318,25 @@ class SearchTabView { parent.setTabComponentAt(index, tabPanel) mvcGroup.parentGroup.view.showSearchWindow.call() + + // senders popup menu + JPopupMenu popupMenu = new JPopupMenu() + JMenuItem copyFullIDItem = new JMenuItem(trans("COPY_FULL_ID")) + copyFullIDItem.addActionListener({mvcGroup.controller.copyFullID()}) + popupMenu.add(copyFullIDItem) + + def mouseListener = new MouseAdapter() { + public void mousePressed(MouseEvent e) { + if (e.isPopupTrigger() || e.button == MouseEvent.BUTTON3) + popupMenu.show(e.getComponent(), e.getX(), e.getY()) + } + public void mouseReleased(MouseEvent e) { + if (e.isPopupTrigger() || e.button == MouseEvent.BUTTON3) + popupMenu.show(e.getComponent(), e.getX(), e.getY()) + } + } + + def centerRenderer = new DefaultTableCellRenderer() centerRenderer.setHorizontalAlignment(JLabel.CENTER) resultsTable.setDefaultRenderer(Integer.class,centerRenderer) @@ -360,6 +379,7 @@ class SearchTabView { }) // senders table + sendersTable.addMouseListener(mouseListener) sendersTable.setDefaultRenderer(Integer.class, centerRenderer) sendersTable.rowSorter.addRowSorterListener({evt -> lastSendersSortEvent = evt}) sendersTable.rowSorter.setSortsOnUpdates(true) @@ -390,6 +410,7 @@ class SearchTabView { } }) + // results table 2 resultsTable2.setDefaultRenderer(Integer.class,centerRenderer) resultsTable2.columnModel.getColumn(1).setCellRenderer(new SizeRenderer()) @@ -430,6 +451,7 @@ class SearchTabView { // TODO: add download right-click action // senders table 2 + sendersTable2.addMouseListener(mouseListener) sendersTable2.setDefaultRenderer(Integer.class, centerRenderer) sendersTable2.rowSorter.addRowSorterListener({ evt -> lastSenders2SortEvent = evt}) sendersTable2.rowSorter.setSortsOnUpdates(true) diff --git a/gui/src/main/java/com/muwire/gui/CopyPasteSupport.java b/gui/src/main/java/com/muwire/gui/CopyPasteSupport.java index 28aed6d0..e57ea767 100644 --- a/gui/src/main/java/com/muwire/gui/CopyPasteSupport.java +++ b/gui/src/main/java/com/muwire/gui/CopyPasteSupport.java @@ -1,6 +1,8 @@ package com.muwire.gui; +import java.awt.Toolkit; import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; public class CopyPasteSupport { @@ -14,4 +16,9 @@ public class CopyPasteSupport { throw new RuntimeException(impossible); } } + + public static void copyToClipboard(String str) { + StringSelection selection = new StringSelection(str); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, null); + } }