use of com.intellij.openapi.fileEditor.TextEditor 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.TextEditor 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.TextEditor 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));
}
}
use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.
the class CCDeleteAllAnswerPlaceholdersAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final DataContext context = e.getDataContext();
final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(context);
final Project project = e.getProject();
if (file == null || project == null) {
return;
}
final TaskFile taskFile = StudyUtils.getTaskFile(project, file);
if (taskFile == null) {
return;
}
Editor editor = CommonDataKeys.EDITOR.getData(context);
if (editor == null) {
FileEditorManager instance = FileEditorManager.getInstance(project);
if (!instance.isFileOpen(file)) {
return;
}
FileEditor fileEditor = instance.getSelectedEditor(file);
if (!(fileEditor instanceof TextEditor)) {
return;
}
editor = ((TextEditor) fileEditor).getEditor();
}
List<AnswerPlaceholder> placeholders = new ArrayList<>(taskFile.getAnswerPlaceholders());
final ClearPlaceholders action = new ClearPlaceholders(taskFile, placeholders, editor);
EduUtils.runUndoableAction(project, ACTION_NAME, action, UndoConfirmationPolicy.REQUEST_CONFIRMATION);
}
use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.
the class JvmSmartStepIntoActionHandler method doStep.
private static void doStep(@NotNull final Project project, @Nullable final SourcePosition position, @NotNull final DebuggerSession session) {
final VirtualFile file = position != null ? position.getFile().getVirtualFile() : null;
final FileEditor fileEditor = file != null ? FileEditorManager.getInstance(project).getSelectedEditor(file) : null;
if (fileEditor instanceof TextEditor) {
for (JvmSmartStepIntoHandler handler : Extensions.getExtensions(JvmSmartStepIntoHandler.EP_NAME)) {
if (handler.isAvailable(position) && handler.doSmartStep(position, session, (TextEditor) fileEditor)) {
return;
}
}
}
doStepInto(session, Registry.is("debugger.single.smart.step.force"), null);
}
Aggregations