use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.
the class CreateFileFix method openFile.
protected void openFile(@NotNull Project project, PsiDirectory directory, PsiFile newFile, String text) {
final FileEditorManager editorManager = FileEditorManager.getInstance(directory.getProject());
final FileEditor[] fileEditors = editorManager.openFile(newFile.getVirtualFile(), true);
if (text != null) {
for (FileEditor fileEditor : fileEditors) {
if (fileEditor instanceof TextEditor) {
// JSP is not safe to edit via Psi
final Document document = ((TextEditor) fileEditor).getEditor().getDocument();
document.setText(text);
if (ApplicationManager.getApplication().isUnitTestMode()) {
FileDocumentManager.getInstance().saveDocument(document);
}
PsiDocumentManager.getInstance(project).commitDocument(document);
break;
}
}
}
}
use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method testInterruptOnTyping.
public void testInterruptOnTyping() throws Throwable {
@NonNls String filePath = "/psi/resolve/Thinlet.java";
configureByFile(filePath);
highlightErrors();
final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject());
codeAnalyzer.restart();
try {
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
PsiFile file = getFile();
Editor editor = getEditor();
Project project = file.getProject();
CodeInsightTestFixtureImpl.ensureIndexesUpToDate(project);
TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(editor);
codeAnalyzer.runPasses(file, editor.getDocument(), textEditor, ArrayUtil.EMPTY_INT_ARRAY, true, () -> type(' '));
} catch (ProcessCanceledException ignored) {
return;
}
fail("PCE must have been thrown");
}
use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method checkDaemonReaction.
private void checkDaemonReaction(boolean mustCancelItself, @NotNull final Runnable action) {
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
highlightErrors();
myDaemonCodeAnalyzer.waitForTermination();
TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(getEditor());
final AtomicBoolean run = new AtomicBoolean();
Disposable disposable = Disposer.newDisposable();
final AtomicReference<RuntimeException> stopDaemonReason = new AtomicReference<>();
StorageUtilKt.setDEBUG_LOG("");
getProject().getMessageBus().connect(disposable).subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonCodeAnalyzer.DaemonListenerAdapter() {
@Override
public void daemonCancelEventOccurred(@NotNull String reason) {
RuntimeException e = new RuntimeException("Some bastard's restarted daemon: " + reason + "\nStorage write log: ----------\n" + StorageUtilKt.getDEBUG_LOG() + "\n--------------");
stopDaemonReason.compareAndSet(null, e);
}
});
try {
while (true) {
try {
myDaemonCodeAnalyzer.runPasses(getFile(), getDocument(getFile()), textEditor, new int[0], true, () -> {
if (!run.getAndSet(true)) {
action.run();
}
});
break;
} catch (ProcessCanceledException ignored) {
}
}
if (mustCancelItself) {
assertNotNull(stopDaemonReason.get());
} else {
if (stopDaemonReason.get() != null)
throw stopDaemonReason.get();
}
} finally {
StorageUtilKt.setDEBUG_LOG(null);
Disposer.dispose(disposable);
}
}
use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.
the class DvcsUtil method getSelectedFile.
/**
* Returns the currently selected file, based on which VcsBranch or StatusBar components will identify the current repository root.
*/
@Nullable
@CalledInAwt
public static VirtualFile getSelectedFile(@NotNull Project project) {
StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
final FileEditor fileEditor = StatusBarUtil.getCurrentFileEditor(project, statusBar);
VirtualFile result = null;
if (fileEditor != null) {
if (fileEditor instanceof TextEditor) {
Document document = ((TextEditor) fileEditor).getEditor().getDocument();
result = FileDocumentManager.getInstance().getFile(document);
} else if (fileEditor instanceof ImageFileEditor) {
result = ((ImageFileEditor) fileEditor).getImageEditor().getFile();
}
}
if (result == null) {
final FileEditorManager manager = FileEditorManager.getInstance(project);
if (manager != null) {
Editor editor = manager.getSelectedTextEditor();
if (editor != null) {
result = FileDocumentManager.getInstance().getFile(editor.getDocument());
}
}
}
return result;
}
use of com.intellij.openapi.fileEditor.TextEditor in project android by JetBrains.
the class AndroidCodeStyleNotificationProvider method createNotificationPanel.
@Nullable
@Override
public MyPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
if (file.getFileType() != XmlFileType.INSTANCE || !(fileEditor instanceof TextEditor)) {
return null;
}
final Module module = ModuleUtilCore.findModuleForFile(file, myProject);
if (module == null) {
return null;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null) {
return null;
}
final VirtualFile parent = file.getParent();
final VirtualFile resDir = parent != null ? parent.getParent() : null;
if (resDir == null || !facet.getLocalResourceManager().isResourceDir(resDir)) {
return null;
}
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(myProject);
final AndroidXmlCodeStyleSettings androidSettings = AndroidXmlCodeStyleSettings.getInstance(settings);
if (androidSettings.USE_CUSTOM_SETTINGS) {
return null;
}
if (NotificationsConfigurationImpl.getSettings(ANDROID_XML_CODE_STYLE_NOTIFICATION_GROUP).getDisplayType() == NotificationDisplayType.NONE) {
return null;
}
NotificationsConfiguration.getNotificationsConfiguration().register(ANDROID_XML_CODE_STYLE_NOTIFICATION_GROUP, NotificationDisplayType.BALLOON, false);
return new MyPanel();
}
Aggregations