Search in sources :

Example 6 with DataContext

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());
}
Also used : GroovyRefactoringBundle(org.jetbrains.plugins.groovy.refactoring.GroovyRefactoringBundle) HelpID(org.jetbrains.plugins.groovy.refactoring.HelpID) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) DataContext(com.intellij.openapi.actionSystem.DataContext) SelectionModel(com.intellij.openapi.editor.SelectionModel) GrParametersOwner(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrParametersOwner) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) StringPartInfo(org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo) RefactoringBundle(com.intellij.refactoring.RefactoringBundle) GrIntroduceVariableHandler(org.jetbrains.plugins.groovy.refactoring.introduce.variable.GrIntroduceVariableHandler) MethodOrClosureScopeChooser(org.jetbrains.plugins.groovy.refactoring.ui.MethodOrClosureScopeChooser) ArrayList(java.util.ArrayList) InitialInfo(org.jetbrains.plugins.groovy.refactoring.extract.InitialInfo) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) IntroduceOccurrencesChooser(org.jetbrains.plugins.groovy.refactoring.introduce.IntroduceOccurrencesChooser) GrIntroduceHandlerBase(org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceHandlerBase) GrRefactoringError(org.jetbrains.plugins.groovy.refactoring.GrRefactoringError) Map(java.util.Map) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) IntroduceTargetChooser(com.intellij.refactoring.IntroduceTargetChooser) GrIntroduceContext(org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceContext) PsiMethod(com.intellij.psi.PsiMethod) TextRange(com.intellij.openapi.util.TextRange) SuperMethodWarningUtil(com.intellij.ide.util.SuperMethodWarningUtil) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup) CommonRefactoringUtil(com.intellij.refactoring.util.CommonRefactoringUtil) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Pass(com.intellij.openapi.util.Pass) OccurrencesChooser(com.intellij.refactoring.introduce.inplace.OccurrencesChooser) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) ApplicationManager(com.intellij.openapi.application.ApplicationManager) RefactoringActionHandler(com.intellij.refactoring.RefactoringActionHandler) NotNull(org.jetbrains.annotations.NotNull) GroovyExtractChooser(org.jetbrains.plugins.groovy.refactoring.extract.GroovyExtractChooser) Pass(com.intellij.openapi.util.Pass) SelectionModel(com.intellij.openapi.editor.SelectionModel) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) TextRange(com.intellij.openapi.util.TextRange)

Example 7 with DataContext

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);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) IpnbConnectionManager(org.jetbrains.plugins.ipnb.configuration.IpnbConnectionManager) IpnbFilePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel) IpnbFileEditor(org.jetbrains.plugins.ipnb.editor.IpnbFileEditor) IpnbEditablePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel)

Example 8 with DataContext

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);
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) IpnbFileEditor(org.jetbrains.plugins.ipnb.editor.IpnbFileEditor) Presentation(com.intellij.openapi.actionSystem.Presentation)

Example 9 with DataContext

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);
    }
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) IpnbFilePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel) IpnbFileEditor(org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)

Example 10 with DataContext

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);
    }
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) FileEditor(com.intellij.openapi.fileEditor.FileEditor) IpnbFileEditor(org.jetbrains.plugins.ipnb.editor.IpnbFileEditor) IpnbFileEditor(org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)

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