use of com.intellij.openapi.fileEditor.TextEditor in project oxy-template-support-plugin by mutant-industries.
the class CompiledPreviewController method showCompiledCode.
public boolean showCompiledCode(@NotNull final PsiFile originalFile) {
PsiFile psiFile;
Document document = null;
VirtualFile virtualFile = null;
EditorWindow editorWindow = null;
boolean result, newTabCreated = false;
FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(myProject);
// check for already opened editor with compiled source first
for (FileEditor fileEditor : fileEditorManager.getAllEditors()) {
if (!(fileEditor instanceof TextEditor)) {
continue;
}
EditorEx editor = (EditorEx) ((TextEditor) fileEditor).getEditor();
virtualFile = editor.getVirtualFile();
psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
if (psiFile != null && originalFile.isEquivalentTo(psiFile.getUserData(ORIGINAL_FILE_KEY))) {
document = editor.getDocument();
// find editor window where the file is opened
for (EditorWindow window : fileEditorManager.getWindows()) {
if (findFileIndex(window, virtualFile) != -1) {
editorWindow = window;
break;
}
}
break;
}
}
// create new editor
if (document == null) {
virtualFile = new LightVirtualFile(originalFile.getName() + COMPILED_FILE_SUFFIX);
((LightVirtualFile) virtualFile).setLanguage(CompiledPreview.INSTANCE);
((LightVirtualFile) virtualFile).setFileType(CompiledPreviewFileType.INSTANCE);
psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
assert psiFile != null;
document = PsiDocumentManager.getInstance(myProject).getDocument(psiFile);
assert document != null;
psiFile.putUserData(ORIGINAL_FILE_KEY, originalFile);
editorWindow = fileEditorManager.getCurrentWindow();
newTabCreated = true;
}
assert editorWindow != null;
if (result = showCompiledCode(originalFile, document)) {
if (newTabCreated) {
editorWindow.split(SwingConstants.HORIZONTAL, false, virtualFile, false);
}
if (findFileIndex(editorWindow, virtualFile) == -1) {
fileEditorManager.openFile(virtualFile, false);
}
// switch to editor with recompiled source
editorWindow.setEditor(editorWindow.findFileComposite(virtualFile), false);
}
return result;
}
use of com.intellij.openapi.fileEditor.TextEditor in project Perl5-IDEA by Camelcade.
the class PerlUXPerformanceTest method testHighlighting.
public void testHighlighting() {
initWithPerlTidy();
final PsiFile file = getFile();
final Editor editor = getEditor();
final Project project = getProject();
CodeInsightTestFixtureImpl.ensureIndexesUpToDate(project);
final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(project);
final TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(editor);
DaemonCodeAnalyzerEx codeAnalyzerEx = DaemonCodeAnalyzerEx.getInstanceEx(project);
final int iterations = 30;
for (int i = 0; i < iterations; i++) {
codeAnalyzer.restart();
((PsiModificationTrackerImpl) getPsiManager().getModificationTracker()).incCounter();
codeAnalyzer.runPasses(file, editor.getDocument(), Collections.singletonList(textEditor), ArrayUtil.EMPTY_INT_ARRAY, false, null);
codeAnalyzerEx.getFileLevelHighlights(project, file);
}
final int time = 1100;
PlatformTestUtil.startPerformanceTest("PerlTidy highlighting", iterations * time, () -> {
long start = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
codeAnalyzer.restart();
((PsiModificationTrackerImpl) getPsiManager().getModificationTracker()).incCounter();
codeAnalyzer.runPasses(file, editor.getDocument(), Collections.singletonList(textEditor), ArrayUtil.EMPTY_INT_ARRAY, false, null);
DaemonCodeAnalyzerEx.getInstanceEx(project).getFileLevelHighlights(project, file);
}
long length = System.currentTimeMillis() - start;
System.err.println("Highlighting done in " + length / iterations + " ms per iteration of " + time);
}).assertTiming();
}
use of com.intellij.openapi.fileEditor.TextEditor in project azure-tools-for-java by Microsoft.
the class IDEHelperImpl method openFileInEditor.
private boolean openFileInEditor(final Consumer<? super String> contentSaver, VirtualFile virtualFile, FileEditorManager fileEditorManager) {
final FileEditor[] editors = fileEditorManager.openFile(virtualFile, true, true);
if (editors.length == 0) {
return false;
}
for (final FileEditor fileEditor : editors) {
if (fileEditor instanceof TextEditor) {
final String originContent = getTextEditorContent((TextEditor) fileEditor);
final MessageBusConnection messageBusConnection = fileEditorManager.getProject().getMessageBus().connect(fileEditor);
messageBusConnection.subscribe(FileEditorManagerListener.Before.FILE_EDITOR_MANAGER, new FileEditorManagerListener.Before() {
@Override
public void beforeFileClosed(FileEditorManager source, VirtualFile file) {
try {
final String content = getTextEditorContent((TextEditor) fileEditor);
if (file == virtualFile && !StringUtils.equals(content, originContent)) {
final boolean result = DefaultLoader.getUIHelper().showYesNoDialog(fileEditor.getComponent(), SAVE_CHANGES, APP_SERVICE_FILE_EDITING, Messages.getQuestionIcon());
if (result) {
contentSaver.consume(content);
}
}
} catch (final RuntimeException e) {
AzureMessager.getMessager().error(e);
} finally {
messageBusConnection.disconnect();
}
}
});
}
}
return true;
}
use of com.intellij.openapi.fileEditor.TextEditor in project intellij-plugins by JetBrains.
the class ActionScriptStubsTest method doTest.
private void doTest(@Nullable final ThrowableRunnable<Exception> runnable, String... files) throws Exception {
Runnable r = runnable != null ? () -> {
try {
runnable.run();
} catch (Exception e) {
throw new RuntimeException(e);
}
} : null;
doTestFor(true, r, files);
// the first one was parsed during highlighting
assertNotParsed(myPsiFiles.subList(1, myPsiFiles.size()));
// we need to go though files open in editors
assertNotParsed(ContainerUtil.mapNotNull(FileEditorManager.getInstance(myProject).getOpenFiles(), virtualFile -> {
if (Comparing.equal(virtualFile, myFile.getVirtualFile())) {
return null;
}
Document document = ((TextEditor) FileEditorManager.getInstance(myProject).getSelectedEditor(virtualFile)).getEditor().getDocument();
return PsiDocumentManager.getInstance(myProject).getPsiFile(document);
}));
}
use of com.intellij.openapi.fileEditor.TextEditor in project intellij-plugins by JetBrains.
the class ActionScriptHighlightingTest method setActiveEditor.
private void setActiveEditor(String relativePath) {
VirtualFile file = myFile.getVirtualFile().findFileByRelativePath(relativePath);
FileEditor[] editors = FileEditorManager.getInstance(myProject).getEditors(file);
assertEquals(1, editors.length);
FileEditor fileEditor = editors[0];
assertTrue(fileEditor instanceof TextEditor);
setActiveEditor(((TextEditor) fileEditor).getEditor());
}
Aggregations