Search in sources :

Example 21 with IpnbFilePanel

use of org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel in project intellij-community by JetBrains.

the class IpnbPyFunction method navigate.

@Override
public void navigate(boolean requestFocus) {
    final IpnbCodeSourcePanel sourcePanel = ((IpnbPyFragment) getContainingFile()).getCodeSourcePanel();
    final Editor editor = sourcePanel.getEditor();
    final IpnbCodePanel codePanel = sourcePanel.getIpnbCodePanel();
    final IpnbFileEditor fileEditor = codePanel.getFileEditor();
    final IpnbFilePanel filePanel = fileEditor.getIpnbFilePanel();
    codePanel.setEditing(true);
    filePanel.setSelectedCellPanel(codePanel);
    super.navigate(false);
    UIUtil.requestFocus(editor.getContentComponent());
}
Also used : IpnbFilePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel) IpnbCodeSourcePanel(org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodeSourcePanel) IpnbFileEditor(org.jetbrains.plugins.ipnb.editor.IpnbFileEditor) Editor(com.intellij.openapi.editor.Editor) IpnbFileEditor(org.jetbrains.plugins.ipnb.editor.IpnbFileEditor) IpnbCodePanel(org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodePanel)

Example 22 with IpnbFilePanel

use of org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel in project intellij-community by JetBrains.

the class IpnbPyReference method multiResolve.

@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    ResolveResult[] results = super.multiResolve(incompleteCode);
    if (results.length == 0) {
        PsiFile file = myElement.getContainingFile();
        if (file instanceof IpnbPyFragment) {
            final IpnbFilePanel panel = ((IpnbPyFragment) file).getFilePanel();
            final List<IpnbEditablePanel> panels = panel.getIpnbPanels();
            final String referencedName = myElement.getReferencedName();
            if (referencedName == null)
                return ResolveResult.EMPTY_ARRAY;
            for (IpnbEditablePanel editablePanel : panels) {
                if (!(editablePanel instanceof IpnbCodePanel))
                    continue;
                final Editor editor = ((IpnbCodePanel) editablePanel).getEditor();
                final IpnbPyFragment psiFile = (IpnbPyFragment) PsiDocumentManager.getInstance(myElement.getProject()).getPsiFile(editor.getDocument());
                if (psiFile == null)
                    continue;
                final PyResolveProcessor processor = new PyResolveProcessor(referencedName);
                PyResolveUtil.scopeCrawlUp(processor, psiFile, referencedName, psiFile);
                final List<RatedResolveResult> resultList = getResultsFromProcessor(referencedName, processor, psiFile, psiFile);
                if (resultList.size() > 0) {
                    List<RatedResolveResult> ret = RatedResolveResult.sorted(resultList);
                    return ret.toArray(new RatedResolveResult[ret.size()]);
                }
            }
        }
    }
    return results;
}
Also used : IpnbEditablePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel) IpnbFilePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel) PsiFile(com.intellij.psi.PsiFile) IpnbCodePanel(org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodePanel) Editor(com.intellij.openapi.editor.Editor) ResolveResult(com.intellij.psi.ResolveResult) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with IpnbFilePanel

use of org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel in project intellij-community by JetBrains.

the class IpnbPyTargetExpression method navigate.

@Override
public void navigate(boolean requestFocus) {
    final IpnbCodeSourcePanel sourcePanel = ((IpnbPyFragment) getContainingFile()).getCodeSourcePanel();
    final Editor editor = sourcePanel.getEditor();
    final IpnbCodePanel codePanel = sourcePanel.getIpnbCodePanel();
    final IpnbFileEditor fileEditor = codePanel.getFileEditor();
    final IpnbFilePanel filePanel = fileEditor.getIpnbFilePanel();
    codePanel.setEditing(true);
    filePanel.setSelectedCellPanel(codePanel);
    super.navigate(false);
    UIUtil.requestFocus(editor.getContentComponent());
}
Also used : IpnbFilePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel) IpnbCodeSourcePanel(org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodeSourcePanel) IpnbFileEditor(org.jetbrains.plugins.ipnb.editor.IpnbFileEditor) Editor(com.intellij.openapi.editor.Editor) IpnbFileEditor(org.jetbrains.plugins.ipnb.editor.IpnbFileEditor) IpnbCodePanel(org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodePanel)

Example 24 with IpnbFilePanel

use of org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel in project intellij-community by JetBrains.

the class IpnbUnresolvedReferenceSkipper method unusedImportShouldBeSkipped.

@Override
public boolean unusedImportShouldBeSkipped(@NotNull final PyImportedNameDefiner importNameDefiner) {
    final PsiFile file = importNameDefiner.getContainingFile();
    if (file instanceof IpnbPyFragment) {
        final IpnbFilePanel panel = ((IpnbPyFragment) file).getFilePanel();
        final List<IpnbEditablePanel> panels = panel.getIpnbPanels();
        for (IpnbEditablePanel editablePanel : panels) {
            if (!(editablePanel instanceof IpnbCodePanel))
                continue;
            final Editor editor = ((IpnbCodePanel) editablePanel).getEditor();
            final IpnbPyFragment psiFile = (IpnbPyFragment) PsiDocumentManager.getInstance(importNameDefiner.getProject()).getPsiFile(editor.getDocument());
            if (psiFile == null)
                continue;
            final MyVisitor visitor = new MyVisitor(importNameDefiner);
            psiFile.accept(visitor);
            if (visitor.used)
                return true;
        }
    }
    return false;
}
Also used : IpnbFilePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel) IpnbCodePanel(org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodePanel) Editor(com.intellij.openapi.editor.Editor) IpnbEditablePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel)

Example 25 with IpnbFilePanel

use of org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel in project intellij-community by JetBrains.

the class IpnbCodePanel method updatePanel.

public void updatePanel(@Nullable final String replacementContent, @Nullable final IpnbOutputCell outputContent) {
    final Application application = ApplicationManager.getApplication();
    application.invokeAndWait(() -> {
        if (replacementContent == null && outputContent == null) {
            myCell.removeCellOutputs();
            myViewPanel.removeAll();
            application.runReadAction(() -> {
                final JComponent panel = createViewPanel();
                myViewPanel.add(panel);
                String prompt = IpnbEditorUtil.prompt(-1, IpnbEditorUtil.PromptType.In);
                myPromptLabel.setText(prompt);
            });
        }
        if (replacementContent != null) {
            myCell.setSource(Arrays.asList(StringUtil.splitByLinesKeepSeparators(replacementContent)));
            String prompt = IpnbEditorUtil.prompt(null, IpnbEditorUtil.PromptType.In);
            myCell.setPromptNumber(null);
            myPromptLabel.setText(prompt);
            application.runWriteAction(() -> myCodeSourcePanel.getEditor().getDocument().setText(replacementContent));
        }
        if (outputContent != null) {
            myCell.addCellOutput(outputContent);
            final JComponent component = myHideableOutputPanel.getSecondComponent();
            if (component != null) {
                addOutputPanel(component, outputContent, outputContent instanceof IpnbOutOutputCell);
            }
        }
        final IpnbFilePanel filePanel = myParent.getIpnbFilePanel();
        filePanel.revalidateAndRepaint();
    }, ModalityState.stateForComponent(this));
}
Also used : IpnbFilePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel) Application(com.intellij.openapi.application.Application)

Aggregations

IpnbFilePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel)29 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)19 DataContext (com.intellij.openapi.actionSystem.DataContext)16 IpnbEditablePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel)9 FileEditor (com.intellij.openapi.fileEditor.FileEditor)8 Editor (com.intellij.openapi.editor.Editor)5 IpnbCodePanel (org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodePanel)5 IpnbCell (org.jetbrains.plugins.ipnb.format.cells.IpnbCell)3 IpnbEditableCell (org.jetbrains.plugins.ipnb.format.cells.IpnbEditableCell)3 Application (com.intellij.openapi.application.Application)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 NotNull (org.jetbrains.annotations.NotNull)2 IpnbCodeSourcePanel (org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodeSourcePanel)2 Disposable (com.intellij.openapi.Disposable)1 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)1 EditorMouseAdapter (com.intellij.openapi.editor.event.EditorMouseAdapter)1 EditorMouseEvent (com.intellij.openapi.editor.event.EditorMouseEvent)1 Project (com.intellij.openapi.project.Project)1 ResolveResult (com.intellij.psi.ResolveResult)1