@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);
    }
  }
Exemplo n.º 2
0
  public static Project GetProjectFromDocument(Document document) {
    try {
      FileObject fileObject =
          (FileObject) NbEditorUtilities.getDataObject(document).files().toArray()[0];
      return FileOwnerQuery.getOwner(fileObject);
    } catch (Exception ex) {

      return null;
    }
  }
Exemplo n.º 3
0
 @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;
 }
 /** *** Annotation Stuff ******* */
 static void processAnnotations(
     NbEditorDocument doc,
     List<PPLine> lineList) { // XXX needs to be split for errors and warnings
   final ArrayList<ErrorDescription> errs = new ArrayList();
   DataObject dob = NbEditorUtilities.getDataObject(doc);
   FileObject fo = dob == null ? null : dob.getPrimaryFile();
   for (PPLine line : lineList) {
     for (PPLine.Error err : line.getErrors()) {
       PPToken tok = err.token;
       int shift =
           (tok.getType() == LineParserTokens.END_OF_FILE
                   || tok.getType() == LineParserTokens.END_OF_LINE
                   || tok.getType() == LineParserTokens.OTHER_TEXT)
               ? Math.max(1, tok.getPadding().length())
               : 0;
       int loff = NbDocument.findLineOffset(doc, line.getLineNumber() - 1);
       errs.add(
           ErrorDescriptionFactory.createErrorDescription(
               err.warning ? Severity.WARNING : Severity.ERROR,
               err.message,
               fo,
               loff + tok.getColumn() - shift,
               loff + tok.getColumn() + tok.getText().length()));
     }
     ArrayList<Fix> fixes = new ArrayList();
     int start = Utilities.getRowStartFromLineOffset(doc, line.getLineNumber() - 1);
     if (line.getTokens().size() > 1
         && "//#include".equals(line.getTokens().get(0).getText())) { // NOI18N
       fixes.add(
           new InlineIncludeHint(
               (NbEditorDocument) doc, start, line.getTokens().get(1).getText()));
     } else if (line.getType() == PPLine.OLDIF || line.getType() == PPLine.OLDENDIF) {
       PPBlockInfo b = line.getBlock();
       while (b != null && b.getType() != PPLine.OLDIF) {
         b = b.getParent();
       }
       if (b != null) fixes.add(new ReplaceOldSyntaxHint(doc, lineList, b));
     }
     if (line.getType() == PPLine.UNKNOWN)
       fixes.add(new DisableHint((NbEditorDocument) doc, start));
     if (fixes.size() > 0)
       errs.add(
           ErrorDescriptionFactory.createErrorDescription(
               Severity.HINT,
               NbBundle.getMessage(DocumentPreprocessor.class, "LBL_PreprocessorHint"),
               fixes,
               doc,
               line.getLineNumber())); // NOI18N
   }
   HintsController.setErrors(doc, "preprocessor-errors", errs); // NOI18N
 }
 public MarkOccurrencesHighlighter(Document doc) {
   rp = new RequestProcessor(MarkOccurrencesHighlighter.class);
   bag = new OffsetsBag(doc);
   weakDoc = new WeakReference<Document>((Document) doc);
   DataObject dobj = NbEditorUtilities.getDataObject(weakDoc.get());
   if (dobj != null) {
     EditorCookie pane = dobj.getLookup().lookup(EditorCookie.class);
     JEditorPane[] panes = pane.getOpenedPanes();
     if (panes != null && panes.length > 0) {
       comp = panes[0];
       comp.addCaretListener(this);
     }
   }
 }
  @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);
  }
Exemplo n.º 7
0
 static String getFileName(JTextComponent targetComponent) {
   FileObject fo = NbEditorUtilities.getFileObject(targetComponent.getDocument());
   return fo.getName();
 }