@Override protected final void actionPerformed(PhpModule phpModule) { // called via shortcut if (!CakePhpUtils.isCakePHP(phpModule)) { return; } JTextComponent editor = EditorRegistry.lastFocusedComponent(); if (editor == null) { return; } Document document = editor.getDocument(); if (document == null) { return; } FileObject fileObject = NbEditorUtilities.getFileObject(document); if (fileObject == null) { return; } // get go to files CakePhpGoToStatusFactory factory = CakePhpGoToStatusFactory.getInstance(); CakePhpGoToStatus status = factory.create(fileObject, editor.getCaretPosition()); final List<GoToItem> items = getGoToItems(status); if (items == null || items.isEmpty()) { return; } // if there are multiple items, show popup list if (items.size() == 1 && !CakePreferences.isShowPopupForOneItem(phpModule)) { for (GoToItem item : items) { UiUtils.open(item.getFileObject(), item.getOffset()); return; } } // show popup try { Rectangle rectangle = editor.modelToView(editor.getCaretPosition()); final Point point = new Point(rectangle.x, rectangle.y + rectangle.height); SwingUtilities.convertPointToScreen(point, editor); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { String title = getPopupTitle(); if (title == null) { title = ""; // NOI18N } PopupUtil.showPopup(new GoToPopup(title, items), title, point.x, point.y, true, 0); } }); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } }
@Override protected StyledDocument createStyledDocument(EditorKit kit) { StyledDocument doc = super.createStyledDocument(kit); // Enter the file object in to InputAtrributes. It can be used by lexer. InputAttributes attributes = new InputAttributes(); FileObject fileObject = NbEditorUtilities.getFileObject(doc); final GsfLanguage lng = language.getGsfLanguage(); if (lng != null) { attributes.setValue(lng.getLexerLanguage(), FileObject.class, fileObject, false); } doc.putProperty(InputAttributes.class, attributes); return doc; }
@Override public CompletionTask createTask(int queryType, JTextComponent component) { if (queryType != CompletionProvider.COMPLETION_QUERY_TYPE) { return null; } Document doc = component.getDocument(); FileObject fileObject = NbEditorUtilities.getFileObject(doc); if (fileObject == null) { return null; } PhpModule phpModule = PhpModule.forFileObject(fileObject); if (!YiiUtils.isYii(phpModule)) { return null; } return createTask(queryType, component, phpModule); }
static String getFileName(JTextComponent targetComponent) { FileObject fo = NbEditorUtilities.getFileObject(targetComponent.getDocument()); return fo.getName(); }