public void selectPreviousWindow(@NotNull DataContext context) { final FileEditorManagerEx fileEditorManager = getFileEditorManager(context); final EditorWindow current = fileEditorManager.getCurrentWindow(); if (current != null) { fileEditorManager.getPrevWindow(current).setAsCurrentWindow(true); } }
public void closeCurrentWindow(@NotNull DataContext context) { final FileEditorManagerEx fileEditorManager = getFileEditorManager(context); final EditorWindow window = fileEditorManager.getSplitters().getCurrentWindow(); if (window != null) { window.closeAllExcept(null); } }
public void selectWindow(@NotNull DataContext context, int index) { final FileEditorManagerEx fileEditorManager = getFileEditorManager(context); final EditorWindow[] windows = fileEditorManager.getWindows(); if (index - 1 < windows.length) { windows[index - 1].setAsCurrentWindow(true); } }
public void closeAllExceptCurrent(@NotNull DataContext context) { final FileEditorManagerEx fileEditorManager = getFileEditorManager(context); final EditorWindow current = fileEditorManager.getCurrentWindow(); for (final EditorWindow window : fileEditorManager.getWindows()) { if (window != current) { window.closeAllExcept(null); } } }
public void selectWindowInRow( @NotNull DataContext context, int relativePosition, boolean vertical) { final FileEditorManagerEx fileEditorManager = getFileEditorManager(context); final EditorWindow currentWindow = fileEditorManager.getCurrentWindow(); if (currentWindow != null) { final EditorWindow[] windows = fileEditorManager.getWindows(); final List<EditorWindow> row = findWindowsInRow(currentWindow, Arrays.asList(windows), vertical); selectWindow(currentWindow, row, relativePosition); } }
@Override public void actionPerformed(AnActionEvent e) { PsiElement element = myElements[myIndex]; PsiElement navigationElement = element.getNavigationElement(); PsiFile file = getContainingFile(navigationElement); if (file == null) return; VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) return; Project project = element.getProject(); FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project); OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile, navigationElement.getTextOffset()); fileEditorManager.openTextEditor(descriptor, myFocusEditor); }
private void updateFinished() { myDumb = false; if (myProject.isDisposed()) return; if (ApplicationManager.getApplication().isInternal()) LOG.info("updateFinished"); try { myPublisher.exitDumbMode(); FileEditorManagerEx.getInstanceEx(myProject).refreshIcons(); } finally { // It may happen that one of the pending runWhenSmart actions triggers new dumb mode; // in this case we should quit processing pending actions and postpone them until the newly // started dumb mode finishes. while (!myDumb) { final Runnable runnable; synchronized (myRunWhenSmartQueue) { if (myRunWhenSmartQueue.isEmpty()) { break; } runnable = myRunWhenSmartQueue.pullFirst(); } try { runnable.run(); } catch (Throwable e) { LOG.error(e); } } } }
public void setConsoleEditorEnabled(boolean consoleEditorEnabled) { if (isConsoleEditorEnabled() == consoleEditorEnabled) return; final FileEditorManagerEx fileManager = FileEditorManagerEx.getInstanceEx(getProject()); if (consoleEditorEnabled) { fileManager.closeFile(myVirtualFile); myPanel.removeAll(); myPanel.add(myHistoryViewer.getComponent()); myPanel.add(myConsoleEditor.getComponent()); myHistoryViewer.setHorizontalScrollbarVisible(false); myCurrentEditor = myConsoleEditor; } else { myPanel.removeAll(); myPanel.add(myHistoryViewer.getComponent(), BorderLayout.CENTER); myHistoryViewer.setHorizontalScrollbarVisible(true); } }
@Nullable private VirtualFile getCurrentFile() { final Project project = getProject(); if (project == null) return null; EditorsSplitters splitters = FileEditorManagerEx.getInstanceEx(project).getSplittersFor(myStatusBar.getComponent()); return splitters.getCurrentFile(); }
private void updateTabName(final List<MavenProject> projects) { MavenUtil.invokeLater( myProject, () -> { for (MavenProject each : projects) { FileEditorManagerEx.getInstanceEx(myProject).updateFilePresentation(each.getFile()); } }); }
private void splitWindow( int orientation, @NotNull DataContext context, @NotNull String filename) { final Project project = PlatformDataKeys.PROJECT.getData(context); final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project); VirtualFile virtualFile = null; if (filename.length() > 0 && project != null) { virtualFile = VimPlugin.getFile().findFile(filename, project); if (virtualFile == null) { VimPlugin.showMessage("Could not find file: " + filename); return; } } final EditorWindow editorWindow = fileEditorManager.getSplitters().getCurrentWindow(); if (editorWindow != null) { editorWindow.split(orientation, true, virtualFile, true); } }
@Nullable public Editor getEditor() { if (project == null) return null; FileEditorManagerEx instanceEx = FileEditorManagerEx.getInstanceEx(project); if (instanceEx != null) { FileEditor[] editors = instanceEx.getEditors(instanceEx.getCurrentFile()); if (editors.length > 0) { FileEditor fileEditor = editors[0]; if (fileEditor instanceof TextEditor) { Editor editor1 = ((TextEditor) fileEditor).getEditor(); if (editor != null) { editor.getMarkupModel().removeAllHighlighters(); } editor = editor1; } } } return editor; }
private static EditorWindow getEditorWindow(DataContext dataContext) { EditorWindow editorWindow = EditorWindow.DATA_KEY.getData(dataContext); if (editorWindow == null) { Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project != null) { editorWindow = FileEditorManagerEx.getInstanceEx(project).getCurrentWindow(); } } return editorWindow; }
@Override public void mouseReleased(MouseEvent e) { if (UIUtil.isCloseClick(e, MouseEvent.MOUSE_RELEASED)) { final TabInfo info = myTabs.findInfo(e); if (info != null) { IdeEventQueue.getInstance().blockNextEvents(e); FileEditorManagerEx.getInstanceEx(myProject) .closeFile((VirtualFile) info.getObject(), myWindow); } } }
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( new AsyncResult.Handler<EditorWindow>() { @Override public void run(EditorWindow wnd) { if (wnd != null) { if (wnd.findFileComposite(file) != null) { mgr.closeFile(file, wnd); } } } }); }
public void actionPerformed(final AnActionEvent e) { final FileEditorManagerEx mgr = FileEditorManagerEx.getInstanceEx(myProject); 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 ((e.getModifiers() & InputEvent.ALT_MASK) != 0) { window.closeAllExcept(file); } else { if (window.findFileComposite(file) != null) { mgr.closeFile(file, window); } } } }
@Override protected void tearDown() throws Exception { try { FileEditorManagerEx.getInstanceEx(getProject()).closeAllFiles(); if (myDebugProcess != null) { myDebugProcess.stop(true); myDebugProcess.waitFor(); } } finally { super.tearDown(); } }
@Override @Nullable public Object getData(@NonNls String dataId) { if (CommonDataKeys.PROJECT.is(dataId)) { return myProject; } else if (PlatformDataKeys.EDITOR.is(dataId) || OpenFileDescriptor.NAVIGATE_IN_EDITOR.is(dataId)) { if (myProject == null) return null; return FileEditorManager.getInstance(myProject).getSelectedTextEditor(); } else { Editor editor = (Editor) getData(PlatformDataKeys.EDITOR.getName()); if (editor != null) { FileEditorManagerEx manager = FileEditorManagerEx.getInstanceEx(myProject); return manager.getData(dataId, editor, manager.getSelectedFiles()[0]); } else if (LangDataKeys.IDE_VIEW.is(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; } }
@Override public void dragOutFinished(MouseEvent event, TabInfo source) { boolean copy = event.isMetaDown() || (!SystemInfo.isMac && event.isControlDown()); if (!copy) { myFile.putUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN, Boolean.TRUE); FileEditorManagerEx.getInstanceEx(myProject).closeFile(myFile, myWindow); } else { source.setHidden(false); } mySession.process(event); if (!copy) { myFile.putUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN, null); } myFile = null; mySession = null; }
public void navigate(int injectedOffset) { if (myAction.isShowInBalloon()) { final JComponent component = myAction.createBalloonComponent(myNewFile); if (component != null) { final Balloon balloon = JBPopupFactory.getInstance() .createBalloonBuilder(component) .setShadow(true) .setAnimationCycle(0) .setHideOnClickOutside(true) .setHideOnKeyOutside(true) .setHideOnAction(false) .setFillColor(UIUtil.getControlColor()) .createBalloon(); new AnAction() { @Override public void actionPerformed(AnActionEvent e) { balloon.hide(); } }.registerCustomShortcutSet(CommonShortcuts.ESCAPE, component); Disposer.register(myNewFile.getProject(), balloon); final Balloon.Position position = QuickEditAction.getBalloonPosition(myEditor); RelativePoint point = JBPopupFactory.getInstance().guessBestPopupLocation(myEditor); if (position == Balloon.Position.above) { final Point p = point.getPoint(); point = new RelativePoint( point.getComponent(), new Point(p.x, p.y - myEditor.getLineHeight())); } balloon.show(point, position); } } else { final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(myProject); final FileEditor[] editors = fileEditorManager.getEditors(myNewVirtualFile); if (editors.length == 0) { final EditorWindow curWindow = fileEditorManager.getCurrentWindow(); mySplittedWindow = curWindow.split(SwingConstants.HORIZONTAL, false, myNewVirtualFile, true); } Editor editor = fileEditorManager.openTextEditor( new OpenFileDescriptor(myProject, myNewVirtualFile, injectedOffset), true); // fold missing values if (editor != null) { editor.putUserData(QuickEditAction.QUICK_EDIT_HANDLER, this); final FoldingModel foldingModel = editor.getFoldingModel(); foldingModel.runBatchFoldingOperation( () -> { for (RangeMarker o : ContainerUtil.reverse(((DocumentEx) myNewDocument).getGuardedBlocks())) { String replacement = o.getUserData(REPLACEMENT_KEY); if (StringUtil.isEmpty(replacement)) continue; FoldRegion region = foldingModel.addFoldRegion(o.getStartOffset(), o.getEndOffset(), replacement); if (region != null) region.setExpanded(false); } }); } SwingUtilities.invokeLater( () -> myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE)); } }
@NotNull private static FileEditorManagerEx getFileEditorManager(@NotNull DataContext context) { final Project project = PlatformDataKeys.PROJECT.getData(context); return FileEditorManagerEx.getInstanceEx(project); }