Search in sources :

Example 16 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.

the class CCTaskFileActionTest method testAddTaskFile.

public void testAddTaskFile() {
    VirtualFile virtualFile = copyFileToTask("nonTaskFile.txt");
    myFixture.configureFromExistingVirtualFile(virtualFile);
    launchAction(virtualFile, new CCAddAsTaskFile());
    TaskFile taskFile = StudyUtils.getTaskFile(getProject(), virtualFile);
    assertNotNull(taskFile);
    FileEditor fileEditor = FileEditorManager.getInstance(getProject()).getSelectedEditor(virtualFile);
    UndoManager.getInstance(getProject()).undo(fileEditor);
    assertNull(StudyUtils.getTaskFile(getProject(), virtualFile));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) FileEditor(com.intellij.openapi.fileEditor.FileEditor)

Example 17 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor 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 18 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor 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)

Example 19 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.

the class CommandProcessorImpl method finishCommand.

@Override
public void finishCommand(final Project project, final Object command, final Throwable throwable) {
    if (myCurrentCommand != command)
        return;
    final boolean failed;
    try {
        if (throwable instanceof AbnormalCommandTerminationException) {
            final AbnormalCommandTerminationException rollback = (AbnormalCommandTerminationException) throwable;
            if (ApplicationManager.getApplication().isUnitTestMode()) {
                throw new RuntimeException(rollback);
            }
            failed = true;
        } else if (throwable != null) {
            failed = true;
            if (throwable instanceof Error) {
                throw (Error) throwable;
            } else if (throwable instanceof RuntimeException)
                throw (RuntimeException) throwable;
            CommandLog.LOG.error(throwable);
        } else {
            failed = false;
        }
    } finally {
        super.finishCommand(project, command, throwable);
    }
    if (failed) {
        if (project != null) {
            FileEditor editor = new FocusBasedCurrentEditorProvider().getCurrentEditor();
            final UndoManager undoManager = UndoManager.getInstance(project);
            if (undoManager.isUndoAvailable(editor)) {
                undoManager.undo(editor);
            }
        }
        Messages.showErrorDialog(project, "Cannot perform operation. Too complex, sorry.", "Failed to Perform Operation");
    }
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) UndoManager(com.intellij.openapi.command.undo.UndoManager) AbnormalCommandTerminationException(com.intellij.openapi.command.AbnormalCommandTerminationException)

Example 20 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.

the class ForcedSoftWrapsNotificationProvider method createNotificationPanel.

@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull final VirtualFile file, @NotNull final FileEditor fileEditor) {
    if (!(fileEditor instanceof TextEditor))
        return null;
    final Editor editor = ((TextEditor) fileEditor).getEditor();
    final Project project = editor.getProject();
    if (project == null || !Boolean.TRUE.equals(editor.getUserData(EditorImpl.FORCED_SOFT_WRAPS)) || PropertiesComponent.getInstance().isTrueValue(DISABLED_NOTIFICATION_KEY))
        return null;
    final EditorNotificationPanel panel = new EditorNotificationPanel();
    panel.setText(EditorBundle.message("forced.soft.wrap.message"));
    panel.createActionLabel(EditorBundle.message("forced.soft.wrap.hide.message"), () -> {
        editor.putUserData(EditorImpl.FORCED_SOFT_WRAPS, null);
        EditorNotifications.getInstance(project).updateNotifications(file);
    });
    panel.createActionLabel(EditorBundle.message("forced.soft.wrap.dont.show.again.message"), () -> {
        PropertiesComponent.getInstance().setValue(DISABLED_NOTIFICATION_KEY, "true");
        EditorNotifications.getInstance(project).updateAllNotifications();
    });
    return panel;
}
Also used : Project(com.intellij.openapi.project.Project) TextEditor(com.intellij.openapi.fileEditor.TextEditor) EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FileEditor (com.intellij.openapi.fileEditor.FileEditor)157 VirtualFile (com.intellij.openapi.vfs.VirtualFile)62 TextEditor (com.intellij.openapi.fileEditor.TextEditor)59 Editor (com.intellij.openapi.editor.Editor)43 Project (com.intellij.openapi.project.Project)40 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)37 Nullable (org.jetbrains.annotations.Nullable)21 DataContext (com.intellij.openapi.actionSystem.DataContext)20 PsiFile (com.intellij.psi.PsiFile)19 Document (com.intellij.openapi.editor.Document)15 NotNull (org.jetbrains.annotations.NotNull)14 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)14 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)10 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)9 IpnbFilePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel)8 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)7 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)6 BlobExplorerFileEditor (com.microsoft.intellij.helpers.storage.BlobExplorerFileEditor)6 QueueFileEditor (com.microsoft.intellij.helpers.storage.QueueFileEditor)6 TableFileEditor (com.microsoft.intellij.helpers.storage.TableFileEditor)6