public BookmarkInContextInfo invoke() { myBookmarkAtPlace = null; myFile = null; myLine = -1; BookmarkManager bookmarkManager = BookmarkManager.getInstance(myProject); if (ToolWindowManager.getInstance(myProject).isEditorComponentActive()) { Editor editor = CommonDataKeys.EDITOR.getData(myDataContext); if (editor != null) { Document document = editor.getDocument(); myLine = editor.getCaretModel().getLogicalPosition().line; myFile = FileDocumentManager.getInstance().getFile(document); myBookmarkAtPlace = bookmarkManager.findEditorBookmark(document, myLine); } } if (myFile == null) { myFile = CommonDataKeys.VIRTUAL_FILE.getData(myDataContext); myLine = -1; if (myBookmarkAtPlace == null && myFile != null) { myBookmarkAtPlace = bookmarkManager.findFileBookmark(myFile); } } return this; }
@SuppressWarnings("unchecked") private static DefaultListModel buildModel(Project project) { DefaultListModel model = new DefaultListModel(); for (Bookmark bookmark : BookmarkManager.getInstance(project).getValidBookmarks()) { model.addElement(new BookmarkItem(bookmark)); } return model; }
@Override @Nullable public JComponent createAccessoryView(Project project) { if (!BookmarkManager.getInstance(project).hasBookmarksWithMnemonics()) { return null; } JLabel mnemonicLabel = new JLabel(); mnemonicLabel.setFont(Bookmark.MNEMONIC_FONT); mnemonicLabel.setPreferredSize(new JLabel("W.").getPreferredSize()); mnemonicLabel.setOpaque(false); return mnemonicLabel; }
@Override public void handleMnemonic(KeyEvent e, Project project, JBPopup popup) { char mnemonic = e.getKeyChar(); final Bookmark bookmark = BookmarkManager.getInstance(project).findBookmarkForMnemonic(mnemonic); if (bookmark != null) { popup.cancel(); IdeFocusManager.getInstance(project) .doWhenFocusSettlesDown( new Runnable() { @Override public void run() { bookmark.navigate(true); } }); } }