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

The following examples show how to use com.intellij.openapi.fileEditor.ex.FileEditorManagerEx#getCurrentWindow() . 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: 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 2
Source File: TabNavigationActionBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void update(@Nonnull AnActionEvent event) {
  Presentation presentation = event.getPresentation();
  Project project = event.getData(CommonDataKeys.PROJECT);
  presentation.setEnabled(false);
  if (project == null) {
    return;
  }
  final ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
  if (windowManager.isEditorComponentActive()) {
    final FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(project);
    EditorWindow currentWindow = event.getData(EditorWindow.DATA_KEY);
    if (currentWindow == null) {
      editorManager.getCurrentWindow();
    }
    if (currentWindow != null) {
      final VirtualFile[] files = currentWindow.getFiles();
      presentation.setEnabled(files.length > 1);
    }
    return;
  }

  ContentManager contentManager = event.getData(PlatformDataKeys.NONEMPTY_CONTENT_MANAGER);
  presentation.setEnabled(contentManager != null && contentManager.getContentCount() > 1 && contentManager.isSingleSelection());
}
 
Example 3
Source File: IdeDocumentHistoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected PlaceInfo createPlaceInfo(@Nonnull final FileEditor fileEditor, final FileEditorProvider fileProvider) {
  if (!fileEditor.isValid()) {
    return null;
  }

  FileEditorManagerEx editorManager = getFileEditorManager();
  final VirtualFile file = editorManager.getFile(fileEditor);
  LOG.assertTrue(file != null);
  FileEditorState state = fileEditor.getState(FileEditorStateLevel.NAVIGATION);

  return new PlaceInfo(file, state, fileProvider.getEditorTypeId(), editorManager.getCurrentWindow(), getCaretPosition(fileEditor), System.currentTimeMillis());
}
 
Example 4
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);
}