List of usage examples for com.intellij.openapi.fileEditor FileEditorManager isFileOpen
public abstract boolean isFileOpen(@NotNull VirtualFile file);
From source file:com.intellij.codeInsight.navigation.NavigationUtil.java
License:Apache License
private static boolean activatePsiElementIfOpen(@NotNull PsiElement elt, boolean searchForOpen, boolean requestFocus) { if (!elt.isValid()) return false; elt = elt.getNavigationElement();/* w w w .j a v a2s.c o m*/ final PsiFile file = elt.getContainingFile(); if (file == null || !file.isValid()) return false; VirtualFile vFile = file.getVirtualFile(); if (vFile == null) return false; if (!EditorHistoryManager.getInstance(elt.getProject()).hasBeenOpen(vFile)) return false; final FileEditorManager fem = FileEditorManager.getInstance(elt.getProject()); if (!fem.isFileOpen(vFile)) { fem.openFile(vFile, requestFocus, searchForOpen); } final TextRange range = elt.getTextRange(); if (range == null) return false; final FileEditor[] editors = fem.getEditors(vFile); for (FileEditor editor : editors) { if (editor instanceof TextEditor) { final Editor text = ((TextEditor) editor).getEditor(); final int offset = text.getCaretModel().getOffset(); if (range.containsOffset(offset)) { // select the file fem.openFile(vFile, requestFocus, searchForOpen); return true; } } } return false; }
From source file:com.intellij.execution.console.LanguageConsoleImpl.java
License:Apache License
@Override public void dispose() { EditorFactory editorFactory = EditorFactory.getInstance(); editorFactory.releaseEditor(myConsoleEditor); editorFactory.releaseEditor(myHistoryViewer); if (getProject().isOpen()) { FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); if (editorManager.isFileOpen(myVirtualFile)) { editorManager.closeFile(myVirtualFile); }//from w w w . ja v a2 s .c o m } }
From source file:com.intellij.execution.console.LanguageConsoleImpl.java
License:Apache License
private void installEditorFactoryListener() { FileEditorManagerAdapter fileEditorListener = new FileEditorManagerAdapter() { @Override/*from w ww . ja v a2s . com*/ public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) { if (myConsoleEditor == null || !Comparing.equal(file, myVirtualFile)) { return; } Editor selectedTextEditor = source.getSelectedTextEditor(); for (FileEditor fileEditor : source.getAllEditors(file)) { if (!(fileEditor instanceof TextEditor)) { continue; } final EditorEx editor = (EditorEx) ((TextEditor) fileEditor).getEditor(); editor.addFocusListener(myFocusListener); if (selectedTextEditor == editor) { // already focused myCurrentEditor = editor; } EmptyAction.registerActionShortcuts(editor.getComponent(), myConsoleEditor.getComponent()); editor.getCaretModel().addCaretListener(new CaretAdapter() { @Override public void caretPositionChanged(CaretEvent e) { queueUiUpdate(false); } }); } queueUiUpdate(false); } @Override public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) { if (!Comparing.equal(file, myVirtualFile)) { return; } if (myUiUpdateRunnable != null && !Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN))) { if (myCurrentEditor != null && myCurrentEditor.isDisposed()) { myCurrentEditor = null; } ApplicationManager.getApplication().runReadAction(myUiUpdateRunnable); } } }; myProject.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, fileEditorListener); FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); if (editorManager.isFileOpen(myVirtualFile)) { fileEditorListener.fileOpened(editorManager, myVirtualFile); } }
From source file:javarepl.plugin.JavaREPLLanguageConsole.java
License:Apache License
public void dispose() { final EditorFactory editorFactory = EditorFactory.getInstance(); editorFactory.releaseEditor(myConsoleEditor); editorFactory.releaseEditor(myHistoryViewer); final FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); final boolean isOpen = editorManager.isFileOpen(myVirtualFile); if (isOpen) { editorManager.closeFile(myVirtualFile); }//from w ww .j av a 2 s .co m }
From source file:javarepl.plugin.JavaREPLLanguageConsole.java
License:Apache License
private void installEditorFactoryListener() { final FileEditorManagerAdapter fileEditorListener = new FileEditorManagerAdapter() { @Override//from w ww. j a va 2 s. c om public void fileOpened(FileEditorManager source, VirtualFile file) { if (!Comparing.equal(file, myVirtualFile) || myConsoleEditor == null) return; Editor selectedTextEditor = source.getSelectedTextEditor(); for (FileEditor fileEditor : source.getAllEditors(file)) { if (!(fileEditor instanceof TextEditor)) continue; final EditorEx editor = (EditorEx) ((TextEditor) fileEditor).getEditor(); editor.addFocusListener(myFocusListener); if (selectedTextEditor == editor) { // already focused myCurrentEditor = editor; } EmptyAction.registerActionShortcuts(editor.getComponent(), myConsoleEditor.getComponent()); editor.getCaretModel().addCaretListener(new CaretListener() { public void caretPositionChanged(CaretEvent e) { queueUiUpdate(false); } }); } queueUiUpdate(false); } @Override public void fileClosed(FileEditorManager source, VirtualFile file) { if (!Comparing.equal(file, myVirtualFile)) return; if (myUiUpdateRunnable != null && !Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN))) { if (myCurrentEditor != null && myCurrentEditor.isDisposed()) myCurrentEditor = null; ApplicationManager.getApplication().runReadAction(myUiUpdateRunnable); } } }; myProject.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, fileEditorListener); FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); if (editorManager.isFileOpen(myVirtualFile)) { fileEditorListener.fileOpened(editorManager, myVirtualFile); } }
From source file:net.stevechaloner.intellijad.IntelliJad.java
License:Apache License
/** * {@inheritDoc}/*w w w .j a v a 2 s . com*/ */ public void decompile(EnvironmentContext envContext, DecompilationDescriptor descriptor) { long startTime = System.currentTimeMillis(); Project project = envContext.getProject(); // this allows recovery from a canProjectClose method vetoed by another manager Boolean isPrimed = project.getUserData(IntelliJadConstants.INTELLIJAD_PRIMED); if (isPrimed == null || !isPrimed) { primeProject(project); } IntelliJadConsole console = consoleManager.getConsole(project); ConsoleContext consoleContext = console.createConsoleContext("message.class", descriptor.getClassName()); Config config = PluginUtil.getConfig(project); ValidationResult validationResult = EnvironmentValidator.validateEnvironment(config, envContext, consoleContext); if (!validationResult.isCancelled() && validationResult.isValid()) { if (config.isDecompileToMemory()) { checkSDKRoot(project); } else { LocalFileSystem lfs = (LocalFileSystem) VirtualFileManager.getInstance() .getFileSystem(LocalFileSystem.PROTOCOL); checkSDKRoot(project, lfs.findFileByPath(config.getOutputDirectory())); } StringBuilder sb = new StringBuilder(); sb.append(config.getJadPath()).append(' '); sb.append(config.renderCommandLinePropertyDescriptors()); DecompilationContext context = new DecompilationContext(project, consoleContext, sb.toString()); Decompiler decompiler = config.isDecompileToMemory() ? new MemoryDecompiler() : new FileSystemDecompiler(); try { VirtualFile file = decompiler.getVirtualFile(descriptor, context); FileEditorManager editorManager = FileEditorManager.getInstance(project); if (file != null && editorManager.isFileOpen(file)) { console.closeConsole(); FileEditorManager.getInstance(project).closeFile(descriptor.getClassFile()); editorManager.openFile(file, true); } else { file = decompiler.decompile(descriptor, context); if (file != null) { editorManager.closeFile(descriptor.getClassFile()); editorManager.openFile(file, true); } consoleContext.addSectionMessage(ConsoleEntryType.INFO, "message.operation-time", System.currentTimeMillis() - startTime); } } catch (DecompilationException e) { consoleContext.addSectionMessage(ConsoleEntryType.ERROR, "error", e.getMessage()); } consoleContext.close(); checkConsole(config, console, consoleContext); } }
From source file:org.eclipse.xtext.idea.highlighting.SemanticHighlightVisitor.java
License:Open Source License
@Override public boolean analyze(final PsiFile file, final boolean updateWholeFile, final HighlightInfoHolder holder, final Runnable action) { final VirtualFile virtualFile = XtextPsiUtils.findVirtualFile(file); Project _project = file.getProject(); FileEditorManager _instance = FileEditorManager.getInstance(_project); boolean _isFileOpen = _instance.isFileOpen(virtualFile); boolean _not = (!_isFileOpen); if (_not) {//from w w w . java 2s .c om return true; } try { final IHighlightedPositionAcceptor _function = (int offset, int length, String[] styles) -> { ProgressIndicatorProvider.checkCanceled(); if ((length > 0)) { final Consumer<String> _function_1 = (String it) -> { HighlightInfoType _highlightInfoType = this._ideaHighlightingAttributesProvider .getHighlightInfoType(it); HighlightInfo.Builder _newHighlightInfo = HighlightInfo .newHighlightInfo(_highlightInfoType); HighlightInfo.Builder _range = _newHighlightInfo.range(offset, (offset + length)); HighlightInfo.Builder _description = _range.description(it); final HighlightInfo info = _description.create(); holder.add(info); }; ((List<String>) Conversions.doWrapArray(styles)).forEach(_function_1); } }; this.acceptor = _function; ProgressIndicatorProvider.checkCanceled(); action.run(); } finally { this.acceptor = null; } return true; }
From source file:org.intellij.ideaplugins.tabswitch.action.SwitchTabAction.java
License:Apache License
@Nullable private VirtualFile getFile(Project project, FileEditorManager fileEditorManager) { boolean showRecentFiles = canShowRecentFiles(); VirtualFile[] recentFiles = EditorHistoryManager.getInstance(project).getFiles(); for (int i = recentFiles.length - 2; i >= 0; i--) { VirtualFile file = recentFiles[i]; if (showRecentFiles || fileEditorManager.isFileOpen(file)) { return file; }//from w w w. j av a2s .c om } return null; }
From source file:org.intellij.ideaplugins.tabswitch.Handler.java
License:Apache License
private List<VirtualFile> getFiles() { final List<VirtualFile> result = new ArrayList(); final FileEditorManager manager = FileEditorManager.getInstance(project); final VirtualFile[] files = EditorHistoryManager.getInstance(project).getFiles(); for (VirtualFile file : files) { if (showRecentFiles || editorTabLimitOne || manager.isFileOpen(file)) { result.add(file);/* ww w. j a v a 2 s.c o m*/ } } Collections.reverse(result); return result; }
From source file:org.intellij.ideaplugins.tabswitch.SwitchTabAction.java
License:Apache License
@Nullable private static VirtualFile getFile(Project project, boolean showRecentFiles) { final FileEditorManager manager = FileEditorManager.getInstance(project); final VirtualFile[] files = EditorHistoryManager.getInstance(project).getFiles(); for (int i = files.length - 2; i >= 0; i--) { final VirtualFile file = files[i]; if (showRecentFiles || manager.isFileOpen(file)) { return file; }//from w ww . j a va 2s.c o m } return null; }