Java Code Examples for com.intellij.openapi.fileEditor.ex.FileEditorManagerEx#getInstanceEx()

The following examples show how to use com.intellij.openapi.fileEditor.ex.FileEditorManagerEx#getInstanceEx() . 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: EmacsIdeasAction.java    From emacsIDEAs with Apache License 2.0 6 votes vote down vote up
private ArrayList<Editor> collect_active_editors(AnActionEvent e) {
    ArrayList<Editor> editors = new ArrayList<Editor>();

    final Project project = e.getData(CommonDataKeys.PROJECT);
    final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
    FileEditor[] selectedEditors = fileEditorManager.getSelectedEditors();

    for (FileEditor selectedEditor : selectedEditors) {
        if (selectedEditor instanceof TextEditor) {
            Editor editor = ((TextEditor) selectedEditor).getEditor();
            editors.add(editor);
        }
    }

    return editors;
}
 
Example 2
Source File: DesktopToolWindowManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private EditorsSplitters getSplittersToFocus() {
  WindowManagerEx windowManager = (WindowManagerEx)myWindowManager.get();

  Window activeWindow = TargetAWT.to(windowManager.getMostRecentFocusedWindow());

  if (activeWindow instanceof DesktopFloatingDecorator) {
    IdeFocusManager ideFocusManager = IdeFocusManager.findInstanceByComponent(activeWindow);
    IdeFrame lastFocusedFrame = ideFocusManager.getLastFocusedFrame();
    JComponent frameComponent = lastFocusedFrame != null ? lastFocusedFrame.getComponent() : null;
    Window lastFocusedWindow = frameComponent != null ? SwingUtilities.getWindowAncestor(frameComponent) : null;
    activeWindow = ObjectUtil.notNull(lastFocusedWindow, activeWindow);
  }

  FileEditorManagerEx fem = FileEditorManagerEx.getInstanceEx(myProject);
  EditorsSplitters splitters = activeWindow != null ? fem.getSplittersFor(activeWindow) : null;
  return splitters != null ? splitters : fem.getSplitters();
}
 
Example 3
Source File: CloseAllEditorsButActiveAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  Project project = e.getData(CommonDataKeys.PROJECT);
  FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
  VirtualFile selectedFile;
  final EditorWindow window = e.getData(EditorWindow.DATA_KEY);
  if (window != null) {
    window.closeAllExcept(e.getData(PlatformDataKeys.VIRTUAL_FILE));
    return;
  }
  selectedFile = fileEditorManager.getSelectedFiles()[0];
  final VirtualFile[] siblings = fileEditorManager.getSiblings(selectedFile);
  for (final VirtualFile sibling : siblings) {
    if (!Comparing.equal(selectedFile, sibling)) {
      fileEditorManager.closeFile(sibling);
    }
  }
}
 
Example 4
Source File: EditorTabbedContainer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(final AnActionEvent e) {
  final FileEditorManagerEx mgr = FileEditorManagerEx.getInstanceEx(myProject);
  consulo.fileEditor.impl.EditorWindow window;
  final VirtualFile file = (VirtualFile)myTabInfo.getObject();
  if (ActionPlaces.EDITOR_TAB.equals(e.getPlace())) {
    window = myWindow;
  }
  else {
    window = mgr.getCurrentWindow();
  }

  if (window != null) {
    if (BitUtil.isSet(e.getModifiers(), InputEvent.ALT_MASK)) {
      window.closeAllExcept(file);
    }
    else {
      if (window.findFileComposite(file) != null) {
        mgr.closeFile(file, window);
      }
    }
  }
}
 
Example 5
Source File: EditorTabbedContainer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void close() {
  TabInfo selected = myTabs.getTargetInfo();
  if (selected == null) return;

  final VirtualFile file = (VirtualFile)selected.getObject();
  final FileEditorManagerEx mgr = FileEditorManagerEx.getInstanceEx(myProject);

  AsyncResult<EditorWindow> window = mgr.getActiveWindow();
  window.doWhenDone(wnd -> {
    if (wnd != null) {
      if (wnd.findFileComposite(file) != null) {
        mgr.closeFile(file, wnd);
      }
    }
  });
}
 
Example 6
Source File: NextSplitAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void update(final AnActionEvent event){
  final Project project = event.getData(CommonDataKeys.PROJECT);
  final Presentation presentation = event.getPresentation();
  if (project == null) {
    presentation.setEnabled(false);
    return;
  }
  final FileEditorManagerEx manager = FileEditorManagerEx.getInstanceEx(project);
  final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
  presentation.setEnabled (toolWindowManager.isEditorComponentActive() && manager.isInSplitter() && manager.getCurrentWindow() != null);
}
 
Example 7
Source File: GraphQLConfigSchemaNode.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
private boolean representsCurrentFile() {
    final Ref<Boolean> represents = Ref.create(false);
    final FileEditorManagerEx fileEditorManagerEx = FileEditorManagerEx.getInstanceEx(myProject);
    UIUtil.invokeLaterIfNeeded(() -> {
        represents.set(representsFile(fileEditorManagerEx.getCurrentFile()));
    });
    return represents.get();
}
 
Example 8
Source File: InfoAndProgressPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Component getAnchor(@Nonnull JRootPane pane) {
  Component tabWrapper = UIUtil.findComponentOfType(pane, TabbedPaneWrapper.TabWrapper.class);
  if (tabWrapper != null) {
    return tabWrapper;
  }
  EditorsSplitters splitters = AWTComponentProviderUtil.findChild(pane, EditorsSplitters.class);
  if (splitters != null) {
    return splitters.isShowing() ? splitters.getComponent() : pane;
  }
  FileEditorManagerEx ex = FileEditorManagerEx.getInstanceEx(ProjectUtil.guessCurrentProject(pane));
  if (ex == null) return pane;
  splitters = ex.getSplitters();
  return splitters.isShowing() ? splitters.getComponent() : pane;
}
 
Example 9
Source File: CloseEditorsActionBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
protected List<Pair<EditorComposite, EditorWindow>> getFilesToClose(final AnActionEvent event) {
  final ArrayList<Pair<EditorComposite, EditorWindow>> res = new ArrayList<>();
  final Project project = event.getData(CommonDataKeys.PROJECT);
  final FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(project);
  final EditorWindow editorWindow = event.getData(EditorWindow.DATA_KEY);
  final EditorWindow[] windows;
  if (editorWindow != null) {
    windows = new EditorWindow[]{editorWindow};
  }
  else {
    windows = editorManager.getWindows();
  }
  final FileStatusManager fileStatusManager = FileStatusManager.getInstance(project);
  if (fileStatusManager != null) {
    for (int i = 0; i != windows.length; ++i) {
      final EditorWindow window = windows[i];
      final EditorComposite[] editors = window.getEditors();
      for (final EditorComposite editor : editors) {
        if (isFileToClose(editor, window)) {
          res.add(Pair.create(editor, window));
        }
      }
    }
  }
  return res;
}
 
Example 10
Source File: TabNavigationActionBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void navigateImpl(final DataContext dataContext, Project project, VirtualFile selectedFile, final int dir) {
  LOG.assertTrue(dir == 1 || dir == -1);
  final FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(project);
  EditorWindow currentWindow = dataContext.getData(EditorWindow.DATA_KEY);
  if (currentWindow == null) {
    currentWindow = editorManager.getCurrentWindow();
  }
  final VirtualFile[] files = currentWindow.getFiles();
  int index = ArrayUtil.find(files, selectedFile);
  LOG.assertTrue(index != -1);
  editorManager.openFile(files[(index + files.length + dir) % files.length], true);
}
 
Example 11
Source File: SplitAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(final AnActionEvent event) {
  final Project project = event.getData(CommonDataKeys.PROJECT);
  final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
  final EditorWindow window = event.getData(EditorWindow.DATA_KEY);

  fileEditorManager.createSplitter(myOrientation, window);
}
 
Example 12
Source File: SplitAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void update(final AnActionEvent event) {
  final Project project = event.getData(CommonDataKeys.PROJECT);
  final Presentation presentation = event.getPresentation();
  presentation.setText (myOrientation == SwingConstants.VERTICAL
                        ? IdeBundle.message("action.split.vertically")
                        : IdeBundle.message("action.split.horizontally"));
  if (project == null) {
    presentation.setEnabled(false);
    return;
  }
  final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
  presentation.setEnabled(fileEditorManager.hasOpenedFile ());
}
 
Example 13
Source File: UnsplitAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void actionPerformed(final AnActionEvent event) {
  final Project project = event.getData(CommonDataKeys.PROJECT);
  final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
  //VirtualFile file = fileEditorManager.getSelectedFiles()[0];
  fileEditorManager.unsplitWindow();
}
 
Example 14
Source File: ChangeSplitterOrientationAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void actionPerformed(final AnActionEvent event) {
  final Project project = event.getData(CommonDataKeys.PROJECT);
  final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
  fileEditorManager.changeSplitterOrientation ();
}
 
Example 15
Source File: UnsplitAllAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void actionPerformed(final AnActionEvent event) {
  final Project project = event.getData(CommonDataKeys.PROJECT);
  final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
  //VirtualFile file = fileEditorManager.getSelectedFiles()[0];
  fileEditorManager.unsplitAllWindow();
}
 
Example 16
Source File: SplitterActionBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected boolean isActionEnabled(Project project) {
  final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
  return fileEditorManager.isInSplitter();
}
 
Example 17
Source File: IdeDocumentHistoryImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected FileEditorManagerEx getFileEditorManager() {
  return FileEditorManagerEx.getInstanceEx(myProject);
}
 
Example 18
Source File: EditorHistoryManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void updateHistoryEntry(@Nullable final VirtualFile file, @Nullable final FileEditor fallbackEditor, @Nullable FileEditorProvider fallbackProvider, final boolean changeEntryOrderOnly) {
  if (file == null) {
    return;
  }
  final FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(myProject);
  final Pair<FileEditor[], FileEditorProvider[]> editorsWithProviders = editorManager.getEditorsWithProviders(file);
  FileEditor[] editors = editorsWithProviders.getFirst();
  FileEditorProvider[] providers = editorsWithProviders.getSecond();
  if (editors.length <= 0 && fallbackEditor != null) {
    editors = new FileEditor[]{fallbackEditor};
    providers = new FileEditorProvider[]{fallbackProvider};
  }

  if (editors.length == 0) {
    // obviously not opened in any editor at the moment,
    // makes no sense to put the file in the history
    return;
  }
  final HistoryEntry entry = getEntry(file);
  if (entry == null) {
    // Size of entry list can be less than number of opened editors (some entries can be removed)
    if (file.isValid()) {
      // the file could have been deleted, so the isValid() check is essential
      fileOpenedImpl(file, fallbackEditor, fallbackProvider);
    }
    return;
  }

  if (!changeEntryOrderOnly) { // update entry state
    //LOG.assertTrue(editors.length > 0);
    for (int i = editors.length - 1; i >= 0; i--) {
      final FileEditor editor = editors[i];
      final FileEditorProvider provider = providers[i];
      if (!editor.isValid()) {
        // this can happen for example if file extension was changed
        // and this method was called during corresponding myEditor close up
        continue;
      }

      final FileEditorState oldState = entry.getState(provider);
      final FileEditorState newState = editor.getState(FileEditorStateLevel.FULL);
      if (!newState.equals(oldState)) {
        entry.putState(provider, newState);
      }
    }
  }
  final FileEditorWithProvider selectedEditorWithProvider = editorManager.getSelectedEditorWithProvider(file);
  if (selectedEditorWithProvider != null) {
    //LOG.assertTrue(selectedEditorWithProvider != null);
    entry.setSelectedProvider(selectedEditorWithProvider.getProvider());
    LOG.assertTrue(entry.getSelectedProvider() != null);

    if (changeEntryOrderOnly) {
      moveOnTop(entry);
    }
  }
}
 
Example 19
Source File: EditorHistoryManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Makes file most recent one
 */
private void fileOpenedImpl(@Nonnull final VirtualFile file, @Nullable final FileEditor fallbackEditor, @Nullable FileEditorProvider fallbackProvider) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  // don't add files that cannot be found via VFM (light & etc.)
  if (VirtualFileManager.getInstance().findFileByUrl(file.getUrl()) == null) return;

  final FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(myProject);

  final Pair<FileEditor[], FileEditorProvider[]> editorsWithProviders = editorManager.getEditorsWithProviders(file);
  FileEditor[] editors = editorsWithProviders.getFirst();
  FileEditorProvider[] oldProviders = editorsWithProviders.getSecond();
  if (editors.length <= 0 && fallbackEditor != null) {
    editors = new FileEditor[]{fallbackEditor};
  }
  if (oldProviders.length <= 0 && fallbackProvider != null) {
    oldProviders = new FileEditorProvider[]{fallbackProvider};
  }
  if (editors.length <= 0) {
    LOG.error("No editors for file " + file.getPresentableUrl());
  }
  FileEditor selectedEditor = editorManager.getSelectedEditor(file);
  if (selectedEditor == null) {
    selectedEditor = fallbackEditor;
  }
  LOG.assertTrue(selectedEditor != null);
  final int selectedProviderIndex = ArrayUtilRt.find(editors, selectedEditor);
  LOG.assertTrue(selectedProviderIndex != -1, "Can't find " + selectedEditor + " among " + Arrays.asList(editors));

  final HistoryEntry entry = getEntry(file);
  if (entry != null) {
    moveOnTop(entry);
  }
  else {
    final FileEditorState[] states = new FileEditorState[editors.length];
    final FileEditorProvider[] providers = new FileEditorProvider[editors.length];
    for (int i = states.length - 1; i >= 0; i--) {
      final FileEditorProvider provider = oldProviders[i];
      LOG.assertTrue(provider != null);
      FileEditor editor = editors[i];
      if (!editor.isValid()) continue;
      providers[i] = provider;
      states[i] = editor.getState(FileEditorStateLevel.FULL);
    }
    addEntry(HistoryEntry.createHeavy(myProject, file, providers, states, providers[selectedProviderIndex]));
    trimToSize();
  }
}
 
Example 20
Source File: HeavyIdeaTestFixtureImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
public Object getData(@Nonnull @NonNls Key<?> dataId) {
  if (CommonDataKeys.PROJECT == dataId) {
    return myProject;
  }
  else if (PlatformDataKeys.EDITOR == dataId || OpenFileDescriptor.NAVIGATE_IN_EDITOR == dataId) {
    if (myProject == null) return null;
    return FileEditorManager.getInstance(myProject).getSelectedTextEditor();
  }
  else {
    Editor editor = (Editor)getData(PlatformDataKeys.EDITOR);
    if (editor != null) {
      FileEditorManagerEx manager = FileEditorManagerEx.getInstanceEx(myProject);
      return manager.getData(dataId, editor, editor.getCaretModel().getCurrentCaret());
    }
    else if (LangDataKeys.IDE_VIEW == dataId) {
      VirtualFile[] contentRoots = ProjectRootManager.getInstance(myProject).getContentRoots();
      final PsiDirectory psiDirectory = PsiManager.getInstance(myProject).findDirectory(contentRoots[0]);
      if (contentRoots.length > 0) {
        return new IdeView() {
          @Override
          public void selectElement(PsiElement element) {

          }

          @Override
          public PsiDirectory[] getDirectories() {
            return new PsiDirectory[] {psiDirectory};
          }

          @Override
          public PsiDirectory getOrChooseDirectory() {
            return psiDirectory;
          }
        };
      }
    }
    return null;
  }
}