JAL-4061 JAL-4062 button in Find dialog to copy highlighted regions to clipboard
[jalview.git] / src / jalview / gui / Finder.java
index 2de06ec..6dacbd8 100755 (executable)
@@ -20,8 +20,6 @@
  */
 package jalview.gui;
 
-import java.util.Locale;
-
 import java.awt.Dimension;
 import java.awt.event.ActionEvent;
 import java.awt.event.FocusAdapter;
@@ -30,6 +28,7 @@ import java.awt.event.KeyEvent;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
@@ -254,6 +253,37 @@ public class Finder extends GFinder
     new FeatureEditor(ap, seqs, features, true).showDialog();
   }
 
+  @Override
+  protected void copyToClipboard_actionPerformed()
+  {
+    if (searchResults.isEmpty())
+    {
+      return; // shouldn't happen
+    }
+    List<SequenceI> seqs = new ArrayList<>();
+
+    String searchString = searchBox.getUserInput();
+    String desc = "Search Results";
+
+    /*
+     * assemble dataset sequences, and template new sequence features,
+     * for the amend features dialog
+     */
+    for (SearchResultMatchI match : searchResults.getResults())
+    {
+      SequenceI seq = match.getSequence();
+      while (seq.getDatasetSequence() != null)
+      {
+        seq = seq.getDatasetSequence();
+      }
+      seqs.add(seq.getSubSequence(seq.findIndex(match.getStart()),
+              seq.findIndex(match.getEnd()) + 1));
+    }
+    Desktop.jalviewClipboard = new Object[] {
+        seqs.toArray(new SequenceI[0]), ap.av.getAlignment().getDataset(),
+        ap.av.getAlignment().getHiddenColumns() };
+  }
+
   /**
    * Search the alignment for the next or all matches. If 'all matches', a
    * dialog is shown with the number of sequence ids and subsequences matched.
@@ -263,6 +293,7 @@ public class Finder extends GFinder
   void doSearch(boolean doFindAll)
   {
     createFeatures.setEnabled(false);
+    copyToClipboard.setEnabled(false);
 
     String searchString = searchBox.getUserInput();
 
@@ -310,6 +341,7 @@ public class Finder extends GFinder
     else
     {
       createFeatures.setEnabled(true);
+      copyToClipboard.setEnabled(true);
     }
 
     searchBox.updateCache();