当前位置: 首页>>代码示例>>Java>>正文


Java FileEditorManager.getSelectedTextEditor方法代码示例

本文整理汇总了Java中com.intellij.openapi.fileEditor.FileEditorManager.getSelectedTextEditor方法的典型用法代码示例。如果您正苦于以下问题:Java FileEditorManager.getSelectedTextEditor方法的具体用法?Java FileEditorManager.getSelectedTextEditor怎么用?Java FileEditorManager.getSelectedTextEditor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.fileEditor.FileEditorManager的用法示例。


在下文中一共展示了FileEditorManager.getSelectedTextEditor方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: scrollFromSource

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
public void scrollFromSource() {
  final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
  final Editor selectedTextEditor = fileEditorManager.getSelectedTextEditor();
  if (selectedTextEditor != null) {
    selectElementAtCaret(selectedTextEditor);
    return;
  }
  final FileEditor[] editors = fileEditorManager.getSelectedEditors();
  for (FileEditor fileEditor : editors) {
    if (fileEditor instanceof TextEditor) {
      Editor editor = ((TextEditor)fileEditor).getEditor();
      selectElementAtCaret(editor);
      return;
    }
  }
  final VirtualFile[] selectedFiles = fileEditorManager.getSelectedFiles();
  if (selectedFiles.length > 0) {
    final PsiFile file = PsiManager.getInstance(myProject).findFile(selectedFiles[0]);
    if (file != null) {
      scrollFromFile(file, null);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:ProjectViewImpl.java

示例2: scrollFromSource

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
public void scrollFromSource() {
  FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
  Editor selectedTextEditor = fileEditorManager.getSelectedTextEditor();
  if (selectedTextEditor != null) {
    selectElementAtCaret(selectedTextEditor, false);
    return;
  }
  final FileEditor[] editors = fileEditorManager.getSelectedEditors();
  for (FileEditor fileEditor : editors) {
    if (fileEditor instanceof TextEditor) {
      Editor editor = ((TextEditor)fileEditor).getEditor();
      selectElementAtCaret(editor, false);
      return;
    }
  }
  final VirtualFile[] selectedFiles = fileEditorManager.getSelectedFiles();
  if (selectedFiles.length > 0) {
    PsiFile file = PsiManager.getInstance(myProject).findFile(selectedFiles[0]);
    selectFile(file, false);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:MvcProjectViewPane.java

示例3: highlightElement

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
private static void highlightElement(@NotNull PsiElement element) {
  final Project project = element.getProject();
  final FileEditorManager editorManager =
    FileEditorManager.getInstance(project);
  final HighlightManager highlightManager =
    HighlightManager.getInstance(project);
  final EditorColorsManager editorColorsManager =
    EditorColorsManager.getInstance();
  final Editor editor = editorManager.getSelectedTextEditor();
  final EditorColorsScheme globalScheme =
    editorColorsManager.getGlobalScheme();
  final TextAttributes textattributes =
    globalScheme.getAttributes(
      EditorColors.SEARCH_RESULT_ATTRIBUTES);
  final PsiElement[] elements = new PsiElement[]{element};
  highlightManager.addOccurrenceHighlights(editor, elements,
                                           textattributes, true, null);

  StatusBar.Info.set(IntentionPowerPackBundle.message(
    "status.bar.escape.highlighting.message"), project);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:MoveDeclarationIntention.java

示例4: getSelectedFile

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
/**
 * Returns the currently selected file, based on which VcsBranch or StatusBar components will identify the current repository root.
 */
@Nullable
public static VirtualFile getSelectedFile(@NotNull Project project) {
  StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
  final FileEditor fileEditor = StatusBarUtil.getCurrentFileEditor(project, statusBar);
  VirtualFile result = null;
  if (fileEditor != null) {
    if (fileEditor instanceof TextEditor) {
      Document document = ((TextEditor)fileEditor).getEditor().getDocument();
      result = FileDocumentManager.getInstance().getFile(document);
    }
    else if (fileEditor instanceof ImageFileEditor) {
      result = ((ImageFileEditor)fileEditor).getImageEditor().getFile();
    }
  }

  if (result == null) {
    final FileEditorManager manager = FileEditorManager.getInstance(project);
    if (manager != null) {
      Editor editor = manager.getSelectedTextEditor();
      if (editor != null) {
        result = FileDocumentManager.getInstance().getFile(editor.getDocument());
      }
    }
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:DvcsUtil.java

示例5: applyFix

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
  final FileEditorManager editorManager = FileEditorManager.getInstance(project);
  final Editor editor = editorManager.getSelectedTextEditor();
  if (editor == null) {
    return;
  }
  final EditorSettings settings = editor.getSettings();
  settings.setWhitespacesShown(!settings.isWhitespacesShown());
  editor.getComponent().repaint();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:ProblematicWhitespaceInspection.java

示例6: showRenameTemplate

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
public static void showRenameTemplate(PsiElement context,
                                      PsiNameIdentifierOwner element,
                                      PsiReference... references) {
  context = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(
    context);
  final Project project = context.getProject();
  final FileEditorManager fileEditorManager =
    FileEditorManager.getInstance(project);
  final Editor editor = fileEditorManager.getSelectedTextEditor();
  if (editor == null) {
    return;
  }
  final TemplateBuilderImpl builder = new TemplateBuilderImpl(context);
  final Expression macroCallNode = new MacroCallNode(
    new SuggestVariableNameMacro());
  final PsiElement identifier = element.getNameIdentifier();
  builder.replaceElement(identifier, "PATTERN", macroCallNode, true);
  for (PsiReference reference : references) {
    builder.replaceElement(reference, "PATTERN", "PATTERN",
                           false);
  }
  final Template template = builder.buildInlineTemplate();
  final TextRange textRange = context.getTextRange();
  final int startOffset = textRange.getStartOffset();
  editor.getCaretModel().moveToOffset(startOffset);
  final TemplateManager templateManager =
    TemplateManager.getInstance(project);
  templateManager.startTemplate(editor, template);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:HighlightUtils.java

示例7: isEnabled

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
protected boolean isEnabled(AnActionEvent event, boolean checkAvailable) {
    final Project project = CommonDataKeys.PROJECT.getData(event.getDataContext());
    if (project == null) {
        // no active project
        return false;
    }

    Editor editor = CommonDataKeys.EDITOR.getData(event.getDataContext());
    if (editor == null) {
        FileEditorManager fem = FileEditorManager.getInstance(project);
        editor = fem.getSelectedTextEditor();
    }
    if (editor == null) {
        return false;
    }

    // do we have an xml file?
    final PsiDocumentManager cem = PsiDocumentManager.getInstance(project);
    final PsiFile psiFile = cem.getPsiFile(editor.getDocument());
    // this is also true for DTD documents...
    if (!(psiFile instanceof XmlFile)) {
        return false;
    } else if (psiFile.getLanguage() == StdFileTypes.DTD.getLanguage()) {
        return false;
    }

    return !checkAvailable || isEnabledAt((XmlFile)psiFile, editor.getCaretModel().getOffset());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:XPathAction.java

示例8: actionPerformed

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
@Override
public void actionPerformed(AnActionEvent event) {
    final Project project = CommonDataKeys.PROJECT.getData(event.getDataContext());
    if (project == null) {
        // no active project
        LOG.debug("No project");
        return;
    }

    Editor editor = CommonDataKeys.EDITOR.getData(event.getDataContext());
    if (editor == null) {
        FileEditorManager fem = FileEditorManager.getInstance(project);
        editor = fem.getSelectedTextEditor();
    }
    if (editor == null) {
        // no editor available
        LOG.debug("No editor");
        return;
    }

    // do we have an xml file?
    final PsiDocumentManager pdm = PsiDocumentManager.getInstance(project);
    final PsiFile psiFile = pdm.getPsiFile(editor.getDocument());
    if (!(psiFile instanceof XmlFile)) {
        // not xml
        LOG.debug("No XML-File: " + psiFile);
        return;
    }

    // make sure PSI is in sync with document
    pdm.commitDocument(editor.getDocument());

    execute(editor);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:XPathEvalAction.java

示例9: showRenameTemplate

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
public static void showRenameTemplate(PsiElement context, PsiNameIdentifierOwner element) {
  context = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(context);
  final Query<PsiReference> query = ReferencesSearch.search(element, element.getUseScope());
  final Collection<PsiReference> references = query.findAll();
  final Project project = context.getProject();
  final FileEditorManager fileEditorManager =
    FileEditorManager.getInstance(project);
  final Editor editor = fileEditorManager.getSelectedTextEditor();
  if (editor == null) {
    return;
  }
  final TemplateBuilderImpl builder = new TemplateBuilderImpl(context);
  final Expression macroCallNode = new MacroCallNode(
    new SuggestVariableNameMacro());
  final PsiElement identifier = element.getNameIdentifier();
  builder.replaceElement(identifier, "PATTERN", macroCallNode, true);
  for (PsiReference reference : references) {
    builder.replaceElement(reference, "PATTERN", "PATTERN", false);
  }
  final Template template = builder.buildInlineTemplate();
  final TextRange textRange = context.getTextRange();
  final int startOffset = textRange.getStartOffset();
  editor.getCaretModel().moveToOffset(startOffset);
  final TemplateManager templateManager =
    TemplateManager.getInstance(project);
  templateManager.startTemplate(editor, template);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:HighlightUtil.java

示例10: selectConfigMatch

import com.intellij.openapi.fileEditor.FileEditorManager; //导入方法依赖的package包/类
@NotNull
private ConfigMatch selectConfigMatch(@NotNull List<ConfigMatch> matches) {
  List<String> deviceIds = myManager.getStateManager().getProjectState().getDeviceIds();
  Map<String, Integer> idRank = Maps.newHashMapWithExpectedSize(deviceIds.size());
  int rank = 0;
  for (String id : deviceIds) {
    idRank.put(id, rank++);
  }

  // API 11-13: look for a x-large device
  Comparator<ConfigMatch> comparator = null;
  IAndroidTarget projectTarget = myManager.getProjectTarget();
  if (projectTarget != null) {
    int apiLevel = projectTarget.getVersion().getFeatureLevel();
    if (apiLevel >= 11 && apiLevel < 14) {
      // TODO: Maybe check the compatible-screen tag in the manifest to figure out
      // what kind of device should be used for display.
      comparator = new TabletConfigComparator(idRank);
    }
  }

  if (comparator == null) {
    // lets look for a high density device
    comparator = new PhoneConfigComparator(idRank);
  }

  Collections.sort(matches, comparator);

  // Look at the currently active editor to see if it's a layout editor, and if so,
  // look up its configuration and if the configuration is in our match list,
  // use it. This means we "preserve" the current configuration when you open
  // new layouts.
  // TODO: This is running too late for the layout preview; the new editor has
  // already taken over so getSelectedTextEditor() returns self. Perhaps we
  // need to fish in the open editors instead.

  //Editor activeEditor = ApplicationManager.getApplication().runReadAction(new Computable<Editor>() {
  //  @Override
  //  public Editor compute() {
  //    FileEditorManager editorManager = FileEditorManager.getInstance(myManager.getProject());
  //    return editorManager.getSelectedTextEditor();
  //  }
  //});

  // TODO: How do I redispatch without risking lock?
  //Editor activeEditor = AndroidUtils.getSelectedEditor(myManager.getProject());
  if (ApplicationManager.getApplication().isDispatchThread()) {
    FileEditorManager editorManager = FileEditorManager.getInstance(myManager.getProject());
    Editor activeEditor = editorManager.getSelectedTextEditor();
    if (activeEditor != null) {
      FileDocumentManager documentManager = FileDocumentManager.getInstance();
      VirtualFile file = documentManager.getFile(activeEditor.getDocument());
      if (file != null && !file.equals(myFile) && file.getFileType() == StdFileTypes.XML
          && ResourceHelper.getFolderType(myFile) == ResourceHelper.getFolderType(file)) {
        Configuration configuration = myManager.getConfiguration(file);
        FolderConfiguration fullConfig = configuration.getFullConfig();
        for (ConfigMatch match : matches) {
          if (fullConfig.equals(match.testConfig)) {
            return match;
          }
        }
      }
    }
  }

  // the list has been sorted so that the first item is the best config
  return matches.get(0);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:69,代码来源:ConfigurationMatcher.java


注:本文中的com.intellij.openapi.fileEditor.FileEditorManager.getSelectedTextEditor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。