Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Andro Max
Added: Nov 1, 2018 12:53 PM
Modified: Nov 1, 2018 12:57 PM
Views: 18
Tags: no tags
  1. package com.tagmycode.netbeans;
  2.  
  3. import com.tagmycode.plugin.Framework;
  4. import com.tagmycode.plugin.gui.IDocumentInsertText;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import javax.swing.text.BadLocationException;
  8. import javax.swing.text.JTextComponent;
  9. import org.openide.awt.ActionID;
  10. import org.openide.awt.ActionReference;
  11. import org.openide.awt.ActionReferences;
  12. import org.openide.awt.ActionRegistration;
  13. import org.openide.cookies.EditorCookie;
  14. import org.openide.util.Exceptions;
  15. import org.openide.util.NbBundle.Messages;
  16.  
  17. @ActionID(
  18.         category = "Edit",
  19.         id = "com.tagmycode.netbeans.SearchSnippet"
  20. )
  21. @ActionRegistration(
  22.         iconBase = "com/tagmycode/netbeans/resources/search.png",
  23.         displayName = "#CTL_SearchSnippet"
  24. )
  25.  
  26. @ActionReferences({
  27.     @ActionReference(path = "Menu/Edit", position = 2251),
  28.     @ActionReference(path = "Editors/Popup", position = 4041, separatorBefore = 4035, separatorAfter = 4045),
  29.     @ActionReference(path = "Shortcuts", name = "DOS-SPACE")
  30. })
  31.  
  32. @Messages("CTL_SearchSnippet=Search Snippets on TagMyCode...")
  33. public final class SearchSnippet implements ActionListener {
  34.  
  35.     private final EditorCookie context;
  36.     private final Framework framework;
  37.     private final TagMyCodeTopComponent topcomponent;
  38.  
  39.     public SearchSnippet(EditorCookie context) {
  40.         this.context = context;
  41.         this.topcomponent = TagMyCodeTopComponent.getInstance();
  42.         this.framework = topcomponent.getFramework();
  43.     }
  44.  
  45.     @Override
  46.     public void actionPerformed(ActionEvent ev) {
  47.         if (!framework.canOperate()) {
  48.             return;
  49.         }
  50.  
  51.         final JTextComponent component = context.getOpenedPanes()[0];
  52.  
  53.         final IDocumentInsertText iDocumentInsertText = new IDocumentInsertText() {
  54.  
  55.             @Override
  56.             public void insertText(String text) {
  57.                 try {
  58.                     NetBeansUtilities.insert(text, component);
  59.                 } catch (BadLocationException ex) {
  60.                     Exceptions.printStackTrace(ex);
  61.                 }
  62.             }
  63.         };
  64.  
  65.         framework.showSearchDialog(iDocumentInsertText);
  66.     }
  67.  
  68. }
  69.