use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class ScratchFileServiceImpl method initFileOpenedListener.
private void initFileOpenedListener(MessageBus messageBus) {
final FileEditorManagerListener editorListener = new FileEditorManagerListener() {
@Override
public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
if (!isEditable(file))
return;
RootType rootType = getRootType(file);
if (rootType == null)
return;
rootType.fileOpened(file, source);
}
@Override
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
if (Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN)))
return;
if (!isEditable(file))
return;
RootType rootType = getRootType(file);
if (rootType == null)
return;
rootType.fileClosed(file, source);
}
boolean isEditable(@NotNull VirtualFile file) {
return FileDocumentManager.getInstance().getDocument(file) != null;
}
};
ProjectManagerAdapter projectListener = new ProjectManagerAdapter() {
@Override
public void projectOpened(Project project) {
project.getMessageBus().connect(project).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, editorListener);
FileEditorManager editorManager = FileEditorManager.getInstance(project);
for (VirtualFile virtualFile : editorManager.getOpenFiles()) {
editorListener.fileOpened(editorManager, virtualFile);
}
}
};
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
projectListener.projectOpened(project);
}
messageBus.connect().subscribe(ProjectManager.TOPIC, projectListener);
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class DetectedIndentOptionsNotificationProvider method updateIndentNotification.
public static void updateIndentNotification(@NotNull PsiFile file, boolean enforce) {
VirtualFile vFile = file.getVirtualFile();
if (vFile == null)
return;
if (!ApplicationManager.getApplication().isHeadlessEnvironment() || ApplicationManager.getApplication().isUnitTestMode() && myShowNotificationInTest) {
Project project = file.getProject();
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
if (fileEditorManager == null)
return;
FileEditor fileEditor = fileEditorManager.getSelectedEditor(vFile);
if (fileEditor != null) {
Boolean notifiedFlag = fileEditor.getUserData(NOTIFIED_FLAG);
if (notifiedFlag == null || enforce) {
fileEditor.putUserData(NOTIFIED_FLAG, Boolean.TRUE);
EditorNotifications.getInstance(project).updateNotifications(vFile);
}
}
}
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class BraceHighlightingHandler method highlightBraces.
private void highlightBraces(@Nullable TextRange lBrace, @Nullable TextRange rBrace, boolean matched, boolean scopeHighlighting, @NotNull FileType fileType) {
if (!matched && fileType == FileTypes.PLAIN_TEXT) {
return;
}
EditorColorsScheme scheme = myEditor.getColorsScheme();
final TextAttributes attributes = matched ? scheme.getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES) : scheme.getAttributes(CodeInsightColors.UNMATCHED_BRACE_ATTRIBUTES);
if (rBrace != null && !scopeHighlighting) {
highlightBrace(rBrace, matched);
}
if (lBrace != null && !scopeHighlighting) {
highlightBrace(lBrace, matched);
}
// null in default project
FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
if (fileEditorManager == null || !myEditor.equals(fileEditorManager.getSelectedTextEditor())) {
return;
}
if (lBrace != null && rBrace != null) {
final int startLine = myEditor.offsetToLogicalPosition(lBrace.getStartOffset()).line;
final int endLine = myEditor.offsetToLogicalPosition(rBrace.getEndOffset()).line;
if (endLine - startLine > 0) {
final Runnable runnable = () -> {
if (myProject.isDisposed() || myEditor.isDisposed())
return;
Color color = attributes.getBackgroundColor();
if (color == null)
return;
color = ColorUtil.isDark(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground()) ? ColorUtil.shift(color, 1.5d) : color.darker();
lineMarkFragment(startLine, endLine, color);
};
if (!scopeHighlighting) {
myAlarm.addRequest(runnable, 300);
} else {
runnable.run();
}
} else {
removeLineMarkers();
}
if (!scopeHighlighting) {
showScopeHint(lBrace.getStartOffset(), lBrace.getEndOffset());
}
} else {
if (!myCodeInsightSettings.HIGHLIGHT_SCOPE) {
removeLineMarkers();
}
}
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class MacroManager method getCorrectContext.
private static DataContext getCorrectContext(DataContext dataContext) {
if (PlatformDataKeys.FILE_EDITOR.getData(dataContext) != null) {
return dataContext;
}
Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) {
return dataContext;
}
FileEditorManager editorManager = FileEditorManager.getInstance(project);
VirtualFile[] files = editorManager.getSelectedFiles();
if (files.length == 0) {
return dataContext;
}
FileEditor fileEditor = editorManager.getSelectedEditor(files[0]);
return fileEditor == null ? dataContext : DataManager.getInstance().getDataContext(fileEditor.getComponent());
}
use of com.intellij.openapi.fileEditor.FileEditorManager 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;
}
}
}
}
Aggregations