Search in sources :

Example 1 with TextEditor

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);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor)

Example 2 with TextEditor

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);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) TemplateBuilder(com.intellij.codeInsight.template.TemplateBuilder) PyFile(com.jetbrains.python.psi.PyFile) PsiElement(com.intellij.psi.PsiElement)

Example 3 with TextEditor

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));
    }
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Document(com.intellij.openapi.editor.Document) PsiComment(com.intellij.psi.PsiComment) TextEditor(com.intellij.openapi.fileEditor.TextEditor) LanguageLevel(com.jetbrains.python.psi.LanguageLevel) PsiFile(com.intellij.psi.PsiFile) PyElementGenerator(com.jetbrains.python.psi.PyElementGenerator) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 4 with TextEditor

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) DataContext(com.intellij.openapi.actionSystem.DataContext) FileEditor(com.intellij.openapi.fileEditor.FileEditor) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ArrayList(java.util.ArrayList) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

Example 5 with TextEditor

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

Aggregations

TextEditor (com.intellij.openapi.fileEditor.TextEditor)81 FileEditor (com.intellij.openapi.fileEditor.FileEditor)57 Editor (com.intellij.openapi.editor.Editor)32 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 Project (com.intellij.openapi.project.Project)21 Document (com.intellij.openapi.editor.Document)14 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)13 Nullable (org.jetbrains.annotations.Nullable)13 PsiFile (com.intellij.psi.PsiFile)11 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)6 NotNull (org.jetbrains.annotations.NotNull)6 Disposable (com.intellij.openapi.Disposable)3 EditorEx (com.intellij.openapi.editor.ex.EditorEx)3 EditorNotificationPanel (com.intellij.ui.EditorNotificationPanel)3 LightweightHint (com.intellij.ui.LightweightHint)3 NonNls (org.jetbrains.annotations.NonNls)3 HighlightingPass (com.intellij.codeHighlighting.HighlightingPass)2 TextEditorHighlightingPass (com.intellij.codeHighlighting.TextEditorHighlightingPass)2 TemplateBuilder (com.intellij.codeInsight.template.TemplateBuilder)2 UndoManager (com.intellij.openapi.command.undo.UndoManager)2