use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class GrIntroduceParameterHandler method invoke.
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, @Nullable final DataContext dataContext) {
if (editor == null || file == null)
return;
final SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) {
final int offset = editor.getCaretModel().getOffset();
final List<GrExpression> expressions = GrIntroduceHandlerBase.collectExpressions(file, editor, offset, false);
if (expressions.isEmpty()) {
GrIntroduceHandlerBase.updateSelectionForVariable(editor, file, selectionModel, offset);
} else if (expressions.size() == 1 || ApplicationManager.getApplication().isUnitTestMode()) {
final TextRange textRange = expressions.get(0).getTextRange();
selectionModel.setSelection(textRange.getStartOffset(), textRange.getEndOffset());
} else {
IntroduceTargetChooser.showChooser(editor, expressions, new Pass<GrExpression>() {
@Override
public void pass(final GrExpression selectedValue) {
invoke(project, editor, file, selectedValue.getTextRange().getStartOffset(), selectedValue.getTextRange().getEndOffset());
}
}, grExpression -> grExpression.getText());
return;
}
}
invoke(project, editor, file, selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
}
use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class IpnbRunAllCellsAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
final DataContext context = event.getDataContext();
final IpnbFileEditor ipnbEditor = IpnbFileEditor.DATA_KEY.getData(context);
if (ipnbEditor != null) {
final IpnbFilePanel ipnbFilePanel = ipnbEditor.getIpnbFilePanel();
final List<IpnbEditablePanel> cells = ipnbFilePanel.getIpnbPanels();
final Project project = ipnbFilePanel.getProject();
final IpnbConnectionManager connectionManager = IpnbConnectionManager.getInstance(project);
final VirtualFile virtualFile = ipnbEditor.getVirtualFile();
final String path = virtualFile.getPath();
if (!connectionManager.hasConnection(path)) {
String url = IpnbSettings.getInstance(project).getURL();
if (StringUtil.isEmptyOrSpaces(url)) {
url = IpnbConnectionManager.showDialogUrl(url);
}
if (url == null)
return;
IpnbSettings.getInstance(project).setURL(url);
final String finalUrl = url;
ApplicationManager.getApplication().executeOnPooledThread(() -> {
final boolean serverStarted = connectionManager.startIpythonServer(finalUrl, ipnbEditor);
if (!serverStarted) {
return;
}
UIUtil.invokeLaterIfNeeded(() -> connectionManager.startConnection(null, path, finalUrl, false));
runCells(cells, ipnbFilePanel);
});
} else {
runCells(cells, ipnbFilePanel);
}
}
}
use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class IpnbRunCellBaseAction method update.
@Override
public void update(AnActionEvent e) {
final DataContext context = e.getDataContext();
final IpnbFileEditor editor = IpnbFileEditor.DATA_KEY.getData(context);
final Presentation presentation = e.getPresentation();
presentation.setEnabledAndVisible(editor != null);
}
use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class IpnbRunCellInplaceAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
final DataContext context = event.getDataContext();
final IpnbFileEditor ipnbEditor = IpnbFileEditor.DATA_KEY.getData(context);
if (ipnbEditor != null) {
final IpnbFilePanel component = ipnbEditor.getIpnbFilePanel();
runCell(component, false);
}
}
use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class IpnbSaveAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
final DataContext context = event.getDataContext();
final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
if (editor instanceof IpnbFileEditor) {
saveAndCheckpoint((IpnbFileEditor) editor);
}
}
Aggregations