Package com.intellij.openapi.editor

Examples of com.intellij.openapi.editor.Editor


    private static String getActionFile(AnActionEvent e) {
        Module m = RunHaskellConsoleAction.getModule(e);
        if (m == null)
            return null;
        Editor editor = e.getData(DataKeys.EDITOR);
        if (editor == null || editor.getProject() == null)
            return null;
        PsiFile psiFile = PsiDocumentManager.getInstance(editor.getProject()).getPsiFile(editor.getDocument());
        if (psiFile == null || !(psiFile instanceof HaskellFile))
            return null;
        VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile == null || virtualFile instanceof LightVirtualFile)
            return null;
View Full Code Here


  @NotNull
  public static PsiClass[] getContainingClasses(@NotNull final DataContext dataContext) {
    final Project project = getProject(dataContext);

    final Editor selectedEditor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    if (selectedEditor == null) {
      throw new NullPointerException("Expected not null Editor");
    }
    if (project == null) {
      throw new NullPointerException("Expected not null project");
    }
    final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(selectedEditor.getDocument());

    //noinspection ZeroLengthArrayAllocation
    PsiClass[] clazzes = new PsiClass[0];
    if (psiFile instanceof PsiJavaFile) {
      clazzes = ((PsiJavaFile) psiFile).getClasses();
View Full Code Here

      return psiElement;
    }

    // Try through editor + PsiFile
    //final Editor editor = (Editor) dataContext.getData(DataConstants.EDITOR);// DataConstants.EDITOR
    final Editor editor = DataKeys.EDITOR.getData(dataContext);


    final PsiFile psiFile = getPsiFile(dataContext);
    if (editor != null && psiFile != null) {
      return psiFile.findElementAt(editor.getCaretModel().getOffset());
    }
    // Unable to find currentElement
    return null;
  }
View Full Code Here

   * @return The current SelectionModel or null if not found.
   */
  @Nullable
  public static SelectionModel getSelectionModel(@NotNull final DataContext dataContext) {
    //final Editor editor = (Editor) dataContext.getData(DataConstants.EDITOR);
    final Editor editor = DataKeys.EDITOR.getData(dataContext);
    if (editor != null) {
      final SelectionModel model = editor.getSelectionModel();
      if (model.hasSelection()) {
        return model;
      }
    }
    return null;
View Full Code Here

      final PsiFile psiFile = bugInstanceNode.getPsiFile();
      if (psiFile != null) {
        final Document document = PsiDocumentManager.getInstance(_project).getDocument(psiFile);
        if (document != null) {
          final Editor editor = createEditor(bugInstanceNode, document);
          _parent.setPreviewEditor(editor, psiFile);
          scrollToPreviewSource(bugInstanceNode, editor);
        }
      }
    }
View Full Code Here

    }
  }


  private Editor createEditor(final BugInstanceNode bugInstanceNode, final Document document) {
    final Editor editor = EditorFactory.getInstance().createEditor(document, _project, StdFileTypes.JAVA, false);
    final EditorColorsScheme scheme = editor.getColorsScheme();
    scheme.setEditorFontSize(scheme.getEditorFontSize() - 1);

    final EditorSettings editorSettings = editor.getSettings();
    editorSettings.setLineMarkerAreaShown(true);
    editorSettings.setLineNumbersShown(true);
    editorSettings.setFoldingOutlineShown(true);
    editorSettings.setAnimatedScrolling(true);
    editorSettings.setWheelFontChangeEnabled(true);
    editorSettings.setVariableInplaceRenameEnabled(true);

    final int lineStart = bugInstanceNode.getSourceLines()[0] - 1;
    final int lineEnd = bugInstanceNode.getSourceLines()[1];
    PsiElement element = null;
   
    final PsiFile psiFile = bugInstanceNode.getPsiFile();
    if(lineStart < 0 && lineEnd < 0) {   // find anonymous classes
      final PsiElement psiElement = IdeaUtilImpl.findAnonymousClassPsiElement(bugInstanceNode, _project);
      if (psiElement != null) {
        element = psiElement;
      }
    } else {
      if (psiFile != null) {
        element = IdeaUtilImpl.getElementAtLine(psiFile, lineStart);
      }
    }

    RangeMarker marker = null;
    if (element != null) {
      marker = document.createRangeMarker(element.getTextRange());
    } else if (lineStart >= 0 && lineEnd >= 0) {
      marker = document.createRangeMarker(document.getLineStartOffset(lineStart), document.getLineEndOffset(lineEnd));
    }

    if(marker != null) {
      editor.getMarkupModel().addRangeHighlighter(marker.getStartOffset(), marker.getEndOffset(), HighlighterLayer.FIRST - 1, new TextAttributes(null, null, JBColor.RED, EffectType.BOXED, Font.BOLD), HighlighterTargetArea.EXACT_RANGE);
    }

    return editor;
  }
View Full Code Here

    new WriteCommandAction.Simple/*<Object>*/(project,  "Add findbugs-idea Suppress warning", _psiElement.getContainingFile()) {

      @Override
      protected void run() throws Throwable {
        final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
        selectedValue.invoke(project, editor, _psiElement);
      }
    }.execute();

    return super.onChosen(selectedValue, finalChoice);
View Full Code Here

  }

  private static List<String> pluginForCurrentlyOpenFile(AnActionEvent event) {
    Project project = event.getProject();
    if (project == null) return Collections.emptyList();
    Editor selectedTextEditor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    if (selectedTextEditor == null) return Collections.emptyList();

    VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(selectedTextEditor.getDocument());
    if (virtualFile == null) return Collections.emptyList();

    final File file = new File(virtualFile.getPath());
    Map.Entry<String, String> entry = find(LivePluginAppComponent.pluginIdToPathMap().entrySet(), new Condition<Map.Entry<String, String>>() {
      @Override
View Full Code Here

  private PropertySorter propertySorter = new PropertySorter();
  private StringPropertyConverter stringPropertyConverter = new StringPropertyConverter();

  public void actionPerformed(AnActionEvent e) {

    final Editor editor = e.getData(DataKeys.EDITOR);
    final String fileText = e.getData(DataKeys.FILE_TEXT);

    MessageWindowComponent messageWindowComponent = getMessageComponent();

    if (fileText != null) {
      try {
        Properties properties = stringPropertyConverter.convertString(fileText);
        List<String> sortedKeys = propertySorter.getSortedKeys(properties);
        final String newDocumentContent = stringPropertyConverter.sortAndConvertProperties(properties,
                                                                                          sortedKeys);


        ApplicationManager.getApplication().runWriteAction(new Runnable() {

          public void run() {

            final Document document = editor.getDocument();

            CommandProcessor.getInstance().executeCommand(editor.getProject(), new Runnable() {
              public void run() {
                document.replaceString(0, document.getTextLength(), stringPropertyConverter.mergeComments(newDocumentContent, fileText));
              }
            }, "Property Sorter Plugin", null, UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION);
          }
View Full Code Here

  }

  private static Pair<Editor, PsiFile> getEditorAndPsiFile(final AnActionEvent e) {
    final Project project = e.getData(PlatformDataKeys.PROJECT);
    if (project == null) return Pair.create(null, null);
    Editor editor = e.getData(PlatformDataKeys.EDITOR);
    PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
    return Pair.create(editor, psiFile);
  }
View Full Code Here

TOP

Related Classes of com.intellij.openapi.editor.Editor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.