Search in sources :

Example 11 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.

the class IpnbSplitCellAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final DataContext context = e.getDataContext();
    final IpnbFileEditor ipnbEditor = IpnbFileEditor.DATA_KEY.getData(context);
    if (ipnbEditor != null) {
        final IpnbFilePanel ipnbFilePanel = ipnbEditor.getIpnbFilePanel();
        splitCell(ipnbFilePanel);
    }
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) IpnbFilePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel) IpnbFileEditor(org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)

Example 12 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.

the class CCNewSubtaskAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (virtualFile == null || project == null || editor == null) {
        return;
    }
    Task task = StudyUtils.getTaskForFile(project, virtualFile);
    if (task == null) {
        return;
    }
    addSubtask(task, project);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) Task(com.jetbrains.edu.learning.courseFormat.Task) Editor(com.intellij.openapi.editor.Editor)

Example 13 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.

the class CCDeleteAllAnswerPlaceholdersAction method update.

@Override
public void update(AnActionEvent e) {
    Presentation presentation = e.getPresentation();
    presentation.setEnabledAndVisible(false);
    Project project = e.getProject();
    if (project == null) {
        return;
    }
    if (!CCUtils.isCourseCreator(project)) {
        return;
    }
    DataContext context = e.getDataContext();
    VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(context);
    if (file == null) {
        return;
    }
    TaskFile taskFile = StudyUtils.getTaskFile(project, file);
    if (taskFile == null || taskFile.getAnswerPlaceholders().isEmpty()) {
        return;
    }
    presentation.setEnabledAndVisible(true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) Presentation(com.intellij.openapi.actionSystem.Presentation)

Example 14 with DataContext

use of com.intellij.openapi.actionSystem.DataContext 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 15 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.

the class AbstractFix method createQuickFix.

@Nullable
public LocalQuickFix createQuickFix(boolean isOnTheFly) {
    final boolean requiresEditor = requiresEditor();
    if (requiresEditor && !isOnTheFly)
        return null;
    return new LocalQuickFix() {

        @NotNull
        public String getName() {
            return AbstractFix.this.getText();
        }

        @NotNull
        public String getFamilyName() {
            return AbstractFix.this.getFamilyName();
        }

        public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
            Editor editor;
            if (requiresEditor) {
                final DataContext dataContext = DataManager.getInstance().getDataContext();
                editor = CommonDataKeys.EDITOR.getData(dataContext);
                if (editor == null) {
                    if ((editor = FileEditorManager.getInstance(project).getSelectedTextEditor()) == null) {
                        return;
                    }
                }
            } else {
                editor = null;
            }
            final PsiFile psiFile = descriptor.getPsiElement().getContainingFile();
            if (!isAvailable(project, editor, psiFile)) {
                return;
            }
            invoke(project, editor, psiFile);
        }
    };
}
Also used : Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DataContext (com.intellij.openapi.actionSystem.DataContext)202 Project (com.intellij.openapi.project.Project)71 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 NotNull (org.jetbrains.annotations.NotNull)23 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)23 Editor (com.intellij.openapi.editor.Editor)21 Nullable (org.jetbrains.annotations.Nullable)21 FileEditor (com.intellij.openapi.fileEditor.FileEditor)20 PsiFile (com.intellij.psi.PsiFile)16 IpnbFilePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel)16 Module (com.intellij.openapi.module.Module)13 PsiElement (com.intellij.psi.PsiElement)13 SimpleDataContext (com.intellij.openapi.actionSystem.impl.SimpleDataContext)11 DataManager (com.intellij.ide.DataManager)9 Presentation (com.intellij.openapi.actionSystem.Presentation)9 List (java.util.List)9 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)8 Consumer (com.intellij.util.Consumer)7 AnAction (com.intellij.openapi.actionSystem.AnAction)6 Transferable (java.awt.datatransfer.Transferable)6