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);
}
}
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);
}
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);
}
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);
}
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);
}
};
}
Aggregations