com.intellij.openapi.fileEditor.FileEditor Java Examples

The following examples show how to use com.intellij.openapi.fileEditor.FileEditor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatusBarUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Finds the current file editor.
 */
@Nullable
public static FileEditor getCurrentFileEditor(@Nonnull Project project, @Nullable StatusBar statusBar) {
  if (statusBar == null) {
    return null;
  }

  DockContainer c = DockManager.getInstance(project).getContainerFor(statusBar.getComponent());
  EditorsSplitters splitters = null;
  if (c instanceof DockableEditorTabbedContainer) {
    splitters = ((DockableEditorTabbedContainer)c).getSplitters();
  }

  if (splitters != null && splitters.getCurrentWindow() != null) {
    EditorWithProviderComposite editor = splitters.getCurrentWindow().getSelectedEditor();
    if (editor != null) {
      return editor.getSelectedEditorWithProvider().getFileEditor();
    }
  }
  return null;
}
 
Example #2
Source File: MacroManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static DataContext getCorrectContext(DataContext dataContext) {
  if (dataContext.getData(PlatformDataKeys.FILE_EDITOR) != null) {
    return dataContext;
  }
  Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project == null) {
    return dataContext;
  }
  FileEditorManager editorManager = FileEditorManager.getInstance(project);
  VirtualFile[] files = editorManager.getSelectedFiles();
  if (files.length == 0) {
    return dataContext;
  }
  FileEditor fileEditor = editorManager.getSelectedEditor(files[0]);
  return fileEditor == null ? dataContext : DataManager.getInstance().getDataContext(fileEditor.getComponent());
}
 
Example #3
Source File: PluginAdvertiserEditorNotificationProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@Nonnull VirtualFile file, @Nonnull FileEditor fileEditor) {
  if (file.getFileType() != PlainTextFileType.INSTANCE && !(file.getFileType() instanceof AbstractFileType)) return null;

  final String extension = file.getExtension();
  if (extension == null) {
    return null;
  }

  if (myEnabledExtensions.contains(extension) || isIgnoredFile(file)) return null;

  UnknownExtension fileFeatureForChecking = new UnknownExtension(FileTypeFactory.FILE_TYPE_FACTORY_EP.getName(), file.getName());

  List<PluginDescriptor> allPlugins = PluginsAdvertiserHolder.getLoadedPluginDescriptors();

  Set<PluginDescriptor> byFeature = PluginsAdvertiser.findByFeature(allPlugins, fileFeatureForChecking);
  if (!byFeature.isEmpty()) {
    return createPanel(file, byFeature);

  }
  return null;
}
 
Example #4
Source File: LatexEditorActionsWrapper.java    From idea-latex with MIT License 6 votes vote down vote up
LatexEditorActionsWrapper(@NotNull FileEditor fileEditor) {
    DefaultActionGroup actions = new DefaultActionGroup();

    actions.addAll(
            EditorActionsFactory.create(BOLD),
            EditorActionsFactory.create(ITALIC),
            EditorActionsFactory.create(UNDERLINE),
            Separator.getInstance(),
            EditorActionsFactory.create(ALIGN_LEFT),
            EditorActionsFactory.create(ALIGN_CENTER),
            EditorActionsFactory.create(ALIGN_RIGHT),
            Separator.getInstance(),
            EditorActionsFactory.create(IMAGE),
            EditorActionsFactory.create(TABLE),
            EditorActionsFactory.create(MATRIX)
    );

    actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.EDITOR_TAB, actions, true);
    actionToolbar.setMinimumButtonSize(ActionToolbar.NAVBAR_MINIMUM_BUTTON_SIZE);
    actionToolbar.setTargetComponent(fileEditor.getComponent());
}
 
Example #5
Source File: StructureViewSelectInTarget.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void selectIn(final SelectInContext context, final boolean requestFocus) {
  final FileEditor fileEditor = context.getFileEditorProvider().get();

  ToolWindowManager windowManager=ToolWindowManager.getInstance(context.getProject());
  final Runnable runnable = new Runnable() {
    @Override
    public void run() {
      StructureViewFactoryEx.getInstanceEx(myProject).runWhenInitialized(new Runnable() {
        @Override
        public void run() {
          final StructureViewWrapper structureView = getStructureViewWrapper();
          structureView.selectCurrentElement(fileEditor, context.getVirtualFile(), requestFocus);
        }
      });
    }
  };
  if (requestFocus) {
    windowManager.getToolWindow(ToolWindowId.STRUCTURE_VIEW).activate(runnable);
  }
  else {
    runnable.run();
  }

}
 
Example #6
Source File: XDebuggerInlayUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void createInlay(@Nonnull Project project, @Nonnull VirtualFile file, int offset, String inlayText) {
  UIUtil.invokeLaterIfNeeded(() -> {
    FileEditor editor = FileEditorManager.getInstance(project).getSelectedEditor(file);
    if (editor instanceof TextEditor) {
      Editor e = ((TextEditor)editor).getEditor();
      CharSequence text = e.getDocument().getImmutableCharSequence();

      int insertOffset = offset;
      while (insertOffset < text.length() && Character.isJavaIdentifierPart(text.charAt(insertOffset))) insertOffset++;

      List<Inlay> existing = e.getInlayModel().getInlineElementsInRange(insertOffset, insertOffset);
      for (Inlay inlay : existing) {
        if (inlay.getRenderer() instanceof MyRenderer) {
          Disposer.dispose(inlay);
        }
      }

      e.getInlayModel().addInlineElement(insertOffset, new MyRenderer(inlayText));
    }
  });
}
 
Example #7
Source File: UndoRedoAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void update(AnActionEvent event) {
  Presentation presentation = event.getPresentation();
  DataContext dataContext = event.getDataContext();
  FileEditor editor = event.getData(PlatformDataKeys.FILE_EDITOR);

  // do not allow global undo in dialogs
  if (editor == null) {
    final Boolean isModalContext = event.getData(PlatformDataKeys.IS_MODAL_CONTEXT);
    if (isModalContext != null && isModalContext) {
      presentation.setEnabled(false);
      return;
    }
  }

  UndoManager undoManager = getUndoManager(editor, dataContext);
  if (undoManager == null) {
    presentation.setEnabled(false);
    return;
  }
  presentation.setEnabled(isAvailable(editor, undoManager));

  Pair<String, String> pair = getActionNameAndDescription(editor, undoManager);

  presentation.setText(pair.first);
  presentation.setDescription(pair.second);
}
 
Example #8
Source File: SdkConfigurationNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull final VirtualFile file, @NotNull final FileEditor fileEditor) {

  // If this is a Bazel configured Flutter project, exit immediately, neither of the notifications should be shown for this project type.
  if (FlutterModuleUtils.isFlutterBazelProject(project)) return null;

  if (file.getFileType() != DartFileType.INSTANCE) return null;

  final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
  if (psiFile == null || psiFile.getLanguage() != DartLanguage.INSTANCE) return null;

  final Module module = ModuleUtilCore.findModuleForPsiElement(psiFile);
  if (!FlutterModuleUtils.isFlutterModule(module)) return null;

  final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project);
  if (flutterSdk == null) {
    return createNoFlutterSdkPanel(project);
  }
  else if (!flutterSdk.getVersion().isMinRecommendedSupported()) {
    return createOutOfDateFlutterSdkPanel(flutterSdk);
  }

  return null;
}
 
Example #9
Source File: SearchAgainAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent e) {
  final Project project = e.getData(CommonDataKeys.PROJECT);
  final FileEditor editor = e.getData(PlatformDataKeys.FILE_EDITOR);
  if (editor == null || project == null) return;
  CommandProcessor commandProcessor = CommandProcessor.getInstance();
  commandProcessor.executeCommand(
      project, new Runnable() {
      @Override
      public void run() {
        PsiDocumentManager.getInstance(project).commitAllDocuments();
        IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
        if(FindManager.getInstance(project).findNextUsageInEditor(editor)) {
          return;
        }

        FindUtil.searchAgain(project, editor, e.getDataContext());
      }
    },
    IdeBundle.message("command.find.next"),
    null
  );
}
 
Example #10
Source File: CreateFileFix.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void openFile(@Nonnull Project project, PsiDirectory directory, PsiFile newFile, String text) {
  final FileEditorManager editorManager = FileEditorManager.getInstance(directory.getProject());
  final FileEditor[] fileEditors = editorManager.openFile(newFile.getVirtualFile(), true);

  if (text != null) {
    for (FileEditor fileEditor : fileEditors) {
      if (fileEditor instanceof TextEditor) { // JSP is not safe to edit via Psi
        final Document document = ((TextEditor)fileEditor).getEditor().getDocument();
        document.setText(text);

        if (ApplicationManager.getApplication().isUnitTestMode()) {
          FileDocumentManager.getInstance().saveDocument(document);
        }
        PsiDocumentManager.getInstance(project).commitDocument(document);
        break;
      }
    }
  }
}
 
Example #11
Source File: IncompatibleDartPluginNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
  if (!FlutterUtils.isFlutteryFile(file)) return null;

  final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
  if (psiFile == null) return null;

  if (psiFile.getLanguage() != DartLanguage.INSTANCE) return null;

  final Module module = ModuleUtilCore.findModuleForPsiElement(psiFile);
  if (module == null) return null;

  if (!FlutterModuleUtils.isFlutterModule(module)) return null;

  final Version minimumVersion = DartPlugin.getInstance().getMinimumVersion();
  final Version dartVersion = DartPlugin.getInstance().getVersion();
  if (dartVersion.minor == 0 && dartVersion.bugfix == 0) {
    return null; // Running from sources.
  }
  return dartVersion.compareTo(minimumVersion) < 0 ? createUpdateDartPanel(myProject, module, dartVersion.toCompactString(),
                                                                           getPrintableRequiredDartVersion()) : null;
}
 
Example #12
Source File: SdkConfigurationNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull final VirtualFile file, @NotNull final FileEditor fileEditor) {

  // If this is a Bazel configured Flutter project, exit immediately, neither of the notifications should be shown for this project type.
  if (FlutterModuleUtils.isFlutterBazelProject(project)) return null;

  if (file.getFileType() != DartFileType.INSTANCE) return null;

  final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
  if (psiFile == null || psiFile.getLanguage() != DartLanguage.INSTANCE) return null;

  final Module module = ModuleUtilCore.findModuleForPsiElement(psiFile);
  if (!FlutterModuleUtils.isFlutterModule(module)) return null;

  final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project);
  if (flutterSdk == null) {
    return createNoFlutterSdkPanel(project);
  }
  else if (!flutterSdk.getVersion().isMinRecommendedSupported()) {
    return createOutOfDateFlutterSdkPanel(flutterSdk);
  }

  return null;
}
 
Example #13
Source File: FileUtils.java    From lsp4intellij with Apache License 2.0 6 votes vote down vote up
public static List<Editor> getAllOpenedEditors(Project project) {
    return computableReadAction(() -> {
        List<Editor> editors = new ArrayList<>();
        FileEditor[] allEditors = FileEditorManager.getInstance(project).getAllEditors();
        for (FileEditor fEditor : allEditors) {
            if (fEditor instanceof TextEditor) {
                Editor editor = ((TextEditor) fEditor).getEditor();
                if (editor.isDisposed() || !isEditorSupported(editor)) {
                    continue;
                }
                editors.add(editor);
            }
        }
        return editors;
    });
}
 
Example #14
Source File: GraphQLIntrospectionHelper.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
void setEditorTextAndFormatLines(String text, FileEditor fileEditor) {
    if (fileEditor instanceof TextEditor) {
        final Editor editor = ((TextEditor) fileEditor).getEditor();
        editor.getDocument().setText(text);
        AnAction reformatCode = ActionManager.getInstance().getAction("ReformatCode");
        if (reformatCode != null) {
            final AnActionEvent actionEvent = AnActionEvent.createFromDataContext(
                    ActionPlaces.UNKNOWN,
                    null,
                    new DataManagerImpl.MyDataContext(editor.getComponent())
            );
            reformatCode.actionPerformed(actionEvent);
        }

    }
}
 
Example #15
Source File: BasicFormatFilter.java    From CppTools with Apache License 2.0 6 votes vote down vote up
private static HyperlinkInfo createHyperLink(final VirtualFile child1, final int lineNumber, final int columnNumber) {
  return new HyperlinkInfo() {
    public void navigate(Project project) {
      new OpenFileDescriptor(project, child1).navigate(lineNumber == 0);

      if (lineNumber != 0) {
        final FileEditor[] fileEditors = FileEditorManager.getInstance(project).getEditors(child1);

        Editor editor = null;

        for(FileEditor fe:fileEditors) {
          if (fe instanceof TextEditor) {
            editor = ((TextEditor)fe).getEditor();
            break;
          }
        }

        if (editor != null) {
          int offset = editor.getDocument().getLineStartOffset(lineNumber - 1) + (columnNumber != 0?columnNumber - 1:0);
          new OpenFileDescriptor(project, child1,offset).navigate(true);
        }
      }
    }
  };

}
 
Example #16
Source File: XLineBreakpointManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean isFromMyProject(@Nonnull Editor editor) {
  if (myProject == editor.getProject()) {
    return true;
  }

  for (FileEditor fileEditor : FileEditorManager.getInstance(myProject).getAllEditors()) {
    if (fileEditor instanceof TextEditor && ((TextEditor)fileEditor).getEditor().equals(editor)) {
      return true;
    }
  }
  return false;
}
 
Example #17
Source File: WidgetEditToolbar.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
Editor getCurrentEditor() {
  final VirtualFile file = activeFile.getValue();
  if (file == null) return null;

  final FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(file);
  if (fileEditor instanceof TextEditor) {
    final TextEditor textEditor = (TextEditor)fileEditor;
    final Editor editor = textEditor.getEditor();
    if (!editor.isDisposed()) {
      return editor;
    }
  }
  return null;
}
 
Example #18
Source File: ComponentStructureView.java    From litho with Apache License 2.0 5 votes vote down vote up
synchronized void update() {
  final FileEditor selectedEditor = FileEditorManager.getInstance(project).getSelectedEditor();
  final PsiFile selectedFile = getSelectedFile(selectedEditor, project);
  final StructureView oldStructure = structureView;
  final Map<String, String> data = new HashMap<>();
  data.put(EventLogger.KEY_TYPE, "update");
  // Overriden below
  data.put(EventLogger.KEY_RESULT, "fail");
  final JComponent mainView =
      Optional.ofNullable(selectedFile)
          .flatMap(file -> LithoPluginUtils.getFirstClass(file, LithoPluginUtils::isLayoutSpec))
          .map(ComponentGenerateUtils::createLayoutModel)
          .map(
              model -> {
                updateComponent(model, selectedFile);
                structureView = createStructureView(model, selectedEditor, selectedFile, project);
                data.put(EventLogger.KEY_RESULT, "success");
                return structureView.getComponent();
              })
          .orElse(STUB);
  final JComponent newView = createView(refreshButton, mainView);
  contentContainer.setComponent(newView);
  // View wasn't updating without this step
  contentManager.setSelectedContent(contentContainer);
  dispose(oldStructure);
  LithoLoggerProvider.getEventLogger().log(EventLogger.EVENT_TOOLWINDOW, data);
}
 
Example #19
Source File: GeneratedFileEditingNotificationProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@Nonnull VirtualFile file, @Nonnull FileEditor fileEditor) {
  if (!GeneratedSourcesFilter.isGenerated(myProject, file)) return null;

  EditorNotificationPanel panel = new EditorNotificationPanel();
  panel.setText("Generated source files should not be edited. The changes will be lost when sources are regenerated.");
  return panel;
}
 
Example #20
Source File: MissingGitignoreNotificationProvider.java    From idea-gitignore with MIT License 5 votes vote down vote up
/**
 * Creates notification panel for given file and checks if is allowed to show the notification.
 *
 * @param file       current file
 * @param fileEditor current file editor
 * @return created notification panel
 */
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor,
                                                       @NotNull Project project) {
    // Break if feature is disabled in the Settings
    if (!settings.isMissingGitignore()) {
        return null;
    }
    // Break if user canceled previously this notification
    if (Properties.isIgnoreMissingGitignore(project)) {
        return null;
    }
    // Break if there is no Git directory in the project
    String vcsDirectory = GitLanguage.INSTANCE.getVcsDirectory();
    if (vcsDirectory == null) {
        return null;
    }

    final VirtualFile moduleRoot = Utils.getModuleRootForFile(file, project);
    if (moduleRoot == null) {
        return null;
    }

    final VirtualFile gitDirectory = moduleRoot.findChild(vcsDirectory);
    if (gitDirectory == null || !gitDirectory.isDirectory()) {
        return null;
    }
    // Break if there is Gitignore file already
    final VirtualFile gitignoreFile = moduleRoot.findChild(GitLanguage.INSTANCE.getFilename());
    if (gitignoreFile != null) {
        return null;
    }

    return createPanel(project, moduleRoot);
}
 
Example #21
Source File: LightToolWindowManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void runUpdateContent(ParameterizedRunnable<DesignerEditorPanelFacade> action) {
  for (FileEditor editor : myFileEditorManager.getAllEditors()) {
    DesignerEditorPanelFacade designer = getDesigner(editor);
    if (designer != null) {
      action.run(designer);
    }
  }
}
 
Example #22
Source File: BuildifierAutoFormatter.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void initComponent() {
  mMessageBusConnection = ApplicationManager.getApplication().getMessageBus().connect(this);
  mMessageBusConnection.subscribe(
      FileEditorManagerListener.FILE_EDITOR_MANAGER,
      new FileEditorManagerListener() {
        @Override
        public void selectionChanged(@NotNull FileEditorManagerEvent event) {
          Project project = event.getManager().getProject();
          if (!BuckProjectSettingsProvider.getInstance(project).isAutoFormatOnBlur()) {
            return;
          }
          FileEditor newFileEditor = event.getNewEditor();
          FileEditor oldFileEditor = event.getOldEditor();
          if (oldFileEditor == null || oldFileEditor.equals(newFileEditor)) {
            return; // still editing same file
          }
          VirtualFile virtualFile = oldFileEditor.getFile();
          Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
          if (document == null) {
            return; // couldn't find document
          }
          PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
          if (!BuckFileType.INSTANCE.equals(psiFile.getFileType())) {
            return; // file type isn't a Buck file
          }
          Runnable runnable = () -> BuildifierUtil.doReformat(project, virtualFile);
          LOGGER.info("Autoformatting " + virtualFile.getPath());
          CommandProcessor.getInstance()
              .executeCommand(
                  project,
                  runnable,
                  null,
                  null,
                  UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION,
                  document);
        }
      });
}
 
Example #23
Source File: FindInMindMapAction.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent anActionEvent) {
  final FileEditor fileEditor = (FileEditor) anActionEvent.getDataContext().getData("fileEditor");
  if (fileEditor instanceof MindMapDocumentEditor) {
    ((MindMapDocumentEditor) fileEditor).activateTextSearchPanel();
  }
}
 
Example #24
Source File: LanguageServerWrapper.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
private void connect(String uri) {
    FileEditor[] fileEditors = FileEditorManager.getInstance(project)
            .getAllEditors(Objects.requireNonNull(FileUtils.URIToVFS(uri)));

    List<Editor> editors = new ArrayList<>();
    for (FileEditor ed : fileEditors) {
        if (ed instanceof TextEditor) {
            editors.add(((TextEditor) ed).getEditor());
        }
    }
    if (!editors.isEmpty()) {
        connect(editors.get(0));
    }
}
 
Example #25
Source File: DockManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public Pair<FileEditor[], FileEditorProvider[]> createNewDockContainerFor(@Nonnull VirtualFile file, @Nonnull FileEditorManagerImpl fileEditorManager) {
  DockContainer container = getFactory(DockableEditorContainerFactory.TYPE).createContainer(null);
  register(container);

  final DockWindow window = createWindowFor(null, container);

  window.show(true);
  final EditorWindow editorWindow = ((DockableEditorTabbedContainer)container).getSplitters().getOrCreateCurrentWindow(file);
  final Pair<FileEditor[], FileEditorProvider[]> result = fileEditorManager.openFileImpl2(UIAccess.get(), editorWindow, file, true);
  container.add(EditorTabbedContainer.createDockableEditor(myProject, null, file, new Presentation(file.getName()), editorWindow), null);

  SwingUtilities.invokeLater(() -> window.myUiContainer.setPreferredSize(null));
  return result;
}
 
Example #26
Source File: DesktopEditorComposite.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void manageTopOrBottomComponent(FileEditor editor, JComponent component, boolean top, boolean remove) {
  final JComponent container = top ? myTopComponents.get(editor) : myBottomComponents.get(editor);
  assert container != null;

  if (remove) {
    container.remove(component.getParent());
  }
  else {
    NonOpaquePanel wrapper = new NonOpaquePanel(component);
    wrapper.setBorder(createTopBottomSideBorder(top));
    container.add(wrapper, calcComponentInsertionIndex(component, container));
  }
  container.revalidate();
}
 
Example #27
Source File: FocusBasedCurrentEditorProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
public FileEditor getCurrentEditor() {
  if(Platform.current().isWebService()) {
    return null;
  }
  // [kirillk] this is a hack, since much of editor-related code was written long before
  // own focus managenent in the platform, so this method should be strictly synchronous
  final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
  return DataManager.getInstance().getDataContext(owner).getData(PlatformDataKeys.FILE_EDITOR);
}
 
Example #28
Source File: BreadcrumbsInitializingActivity.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void add(@Nonnull FileEditorManager manager, @Nonnull FileEditor editor, @Nonnull BreadcrumbsWrapper wrapper) {
  if (wrapper.breadcrumbs.above) {
    manager.addTopComponent(editor, wrapper);
  }
  else {
    manager.addBottomComponent(editor, wrapper);
  }
}
 
Example #29
Source File: VcsAnnotateUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static List<Editor> getEditors(@Nonnull Project project, @Nonnull VirtualFile file) {
  FileEditor[] editors = FileEditorManager.getInstance(project).getEditors(file);
  return ContainerUtil.mapNotNull(editors, new Function<FileEditor, Editor>() {
    @Override
    public Editor fun(FileEditor fileEditor) {
      return fileEditor instanceof TextEditor ? ((TextEditor)fileEditor).getEditor() : null;
    }
  });
}
 
Example #30
Source File: FlutterSampleNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(
  @NotNull VirtualFile file, @NotNull FileEditor fileEditor, @NotNull Project project) {
  if (!(fileEditor instanceof TextEditor)) {
    return null;
  }

  final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
  if (sdk == null) {
    return null;
  }

  final String flutterPackagePath = sdk.getHomePath() + "/packages/flutter/lib/src/";
  final String filePath = file.getPath();

  // Only show for files in the flutter sdk.
  if (!filePath.startsWith(flutterPackagePath)) {
    return null;
  }

  final TextEditor textEditor = (TextEditor)fileEditor;
  final Editor editor = textEditor.getEditor();
  final Document document = editor.getDocument();

  final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
  if (psiFile == null || !psiFile.isValid()) {
    return null;
  }

  // Run the code to query the document in a read action.
  final List<FlutterSample> samples = ApplicationManager.getApplication().
    runReadAction((Computable<List<FlutterSample>>)() -> {
      //noinspection CodeBlock2Expr
      return getSamplesFromDoc(flutterPackagePath, document, filePath);
    });

  return samples.isEmpty() ? null : new FlutterSampleActionsPanel(samples);
}