use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class StudyProjectGenerator method openFirstTask.
public static void openFirstTask(@NotNull final Course course, @NotNull final Project project) {
LocalFileSystem.getInstance().refresh(false);
final Lesson firstLesson = StudyUtils.getFirst(course.getLessons());
if (firstLesson == null)
return;
final Task firstTask = StudyUtils.getFirst(firstLesson.getTaskList());
if (firstTask == null)
return;
final VirtualFile taskDir = firstTask.getTaskDir(project);
if (taskDir == null)
return;
final Map<String, TaskFile> taskFiles = firstTask.getTaskFiles();
VirtualFile activeVirtualFile = null;
for (Map.Entry<String, TaskFile> entry : taskFiles.entrySet()) {
final String relativePath = entry.getKey();
final TaskFile taskFile = entry.getValue();
taskDir.refresh(false, true);
final VirtualFile virtualFile = taskDir.findFileByRelativePath(relativePath);
if (virtualFile != null) {
if (!taskFile.getActivePlaceholders().isEmpty()) {
activeVirtualFile = virtualFile;
}
}
}
if (activeVirtualFile != null) {
final PsiFile file = PsiManager.getInstance(project).findFile(activeVirtualFile);
ProjectView.getInstance(project).select(file, activeVirtualFile, false);
final FileEditor[] editors = FileEditorManager.getInstance(project).openFile(activeVirtualFile, true);
if (editors.length == 0) {
return;
}
final FileEditor studyEditor = editors[0];
if (studyEditor instanceof StudyEditor) {
StudyUtils.selectFirstAnswerPlaceholder((StudyEditor) studyEditor, project);
}
FileEditorManager.getInstance(project).openFile(activeVirtualFile, true);
} else {
String first = StudyUtils.getFirst(taskFiles.keySet());
if (first != null) {
NewVirtualFile firstFile = ((VirtualDirectoryImpl) taskDir).refreshAndFindChild(first);
if (firstFile != null) {
FileEditorManager.getInstance(project).openFile(firstFile, true);
}
}
}
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class BreadcrumbsInitializingActivity method reinitBreadcrumbsComponent.
private static void reinitBreadcrumbsComponent(@NotNull final FileEditorManager fileEditorManager, @NotNull VirtualFile file) {
if (isSuitable(fileEditorManager.getProject(), file)) {
FileEditor[] fileEditors = fileEditorManager.getAllEditors(file);
for (final FileEditor fileEditor : fileEditors) {
if (fileEditor instanceof TextEditor && fileEditor.isValid()) {
Editor editor = ((TextEditor) fileEditor).getEditor();
final BreadcrumbsXmlWrapper existingWrapper = BreadcrumbsXmlWrapper.getBreadcrumbsComponent(editor);
if (existingWrapper != null) {
existingWrapper.queueUpdate();
continue;
}
final BreadcrumbsXmlWrapper wrapper = new BreadcrumbsXmlWrapper(editor);
final JComponent c = wrapper.getComponent();
fileEditorManager.addTopComponent(fileEditor, c);
Disposer.register(fileEditor, new Disposable() {
@Override
public void dispose() {
disposeWrapper(fileEditorManager, fileEditor, wrapper);
}
});
}
}
} else {
removeBreadcrumbs(fileEditorManager, file);
}
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class IpnbSaveAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
final DataContext context = event.getDataContext();
final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
if (editor instanceof IpnbFileEditor) {
saveAndCheckpoint((IpnbFileEditor) editor);
}
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class CreateClassQuickFix method applyFix.
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement anchor = myAnchor.getElement();
if (anchor == null || !anchor.isValid()) {
return;
}
if (!(anchor instanceof PyFile)) {
anchor = PyPsiUtils.getParentRightBefore(anchor, anchor.getContainingFile());
assert anchor != null;
}
PyClass pyClass = PyElementGenerator.getInstance(project).createFromText(LanguageLevel.getDefault(), PyClass.class, "class " + myClassName + "(object):\n pass");
if (anchor instanceof PyFile) {
pyClass = (PyClass) anchor.add(pyClass);
} else {
pyClass = (PyClass) anchor.getParent().addBefore(pyClass, anchor);
}
pyClass = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(pyClass);
final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(pyClass);
builder.replaceElement(pyClass.getSuperClassExpressions()[0], "object");
builder.replaceElement(pyClass.getStatementList(), PyNames.PASS);
final FileEditor editor = FileEditorManager.getInstance(project).getSelectedEditor(anchor.getContainingFile().getVirtualFile());
if (!(editor instanceof TextEditor)) {
return;
}
builder.run(((TextEditor) editor).getEditor(), false);
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class AddEncodingQuickFix method applyFix.
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
final PsiFile file = element.getContainingFile();
if (file == null)
return;
PsiElement firstLine = file.getFirstChild();
if (firstLine instanceof PsiComment && firstLine.getText().startsWith("#!")) {
firstLine = firstLine.getNextSibling();
}
final LanguageLevel languageLevel = LanguageLevel.forElement(file);
final String commentText = String.format(PyEncodingUtil.ENCODING_FORMAT_PATTERN[myEncodingFormatIndex], myDefaultEncoding);
final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
PsiComment encodingComment = elementGenerator.createFromText(languageLevel, PsiComment.class, commentText);
encodingComment = (PsiComment) file.addBefore(encodingComment, firstLine);
final FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(element.getContainingFile().getVirtualFile());
if (fileEditor instanceof TextEditor) {
if (encodingComment.getNextSibling() == null || !encodingComment.getNextSibling().textContains('\n')) {
file.addAfter(elementGenerator.createFromText(languageLevel, PsiWhiteSpace.class, "\n"), encodingComment);
}
final Editor editor = ((TextEditor) fileEditor).getEditor();
final Document document = editor.getDocument();
final int insertedLineNumber = document.getLineNumber(encodingComment.getTextOffset());
editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(insertedLineNumber + 1, 0));
}
}
Aggregations