Search in sources :

Example 1 with IpnbEditablePanel

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

the class IpnbMarkdownCellAction method changeTypeToMarkdown.

public void changeTypeToMarkdown(@NotNull final IpnbFileEditor editor) {
    final IpnbFilePanel filePanel = editor.getIpnbFilePanel();
    final IpnbEditablePanel selectedCellPanel = filePanel.getSelectedCellPanel();
    if (selectedCellPanel == null)
        return;
    final IpnbEditableCell cell = selectedCellPanel.getCell();
    final List<IpnbCell> cells = filePanel.getIpnbFile().getCells();
    final int index = cells.indexOf(selectedCellPanel.getCell());
    final IpnbMarkdownCell markdownCell = new IpnbMarkdownCell(cell.getSource(), cell.getMetadata());
    if (index >= 0) {
        cells.set(index, markdownCell);
    }
    filePanel.replaceComponent(selectedCellPanel, markdownCell);
}
Also used : IpnbCell(org.jetbrains.plugins.ipnb.format.cells.IpnbCell) IpnbFilePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel) IpnbEditableCell(org.jetbrains.plugins.ipnb.format.cells.IpnbEditableCell) IpnbMarkdownCell(org.jetbrains.plugins.ipnb.format.cells.IpnbMarkdownCell) IpnbEditablePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel)

Example 2 with IpnbEditablePanel

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

the class IpnbMergeCellAboveAction method update.

@Override
public void update(AnActionEvent e) {
    final DataContext context = e.getDataContext();
    final IpnbFileEditor ipnbEditor = IpnbFileEditor.DATA_KEY.getData(context);
    if (ipnbEditor != null) {
        final IpnbFilePanel ipnbFilePanel = ipnbEditor.getIpnbFilePanel();
        final IpnbEditablePanel cell = ipnbFilePanel.getSelectedCellPanel();
        final boolean isEnabled = cell != null && ipnbFilePanel.hasPrevCell(cell);
        e.getPresentation().setEnabled(isEnabled);
    }
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) IpnbFilePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel) IpnbFileEditor(org.jetbrains.plugins.ipnb.editor.IpnbFileEditor) IpnbEditablePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel)

Example 3 with IpnbEditablePanel

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

the class IpnbMergeCellBelowAction method update.

@Override
public void update(AnActionEvent e) {
    final DataContext context = e.getDataContext();
    final IpnbFileEditor ipnbEditor = IpnbFileEditor.DATA_KEY.getData(context);
    if (ipnbEditor != null) {
        final IpnbFilePanel ipnbFilePanel = ipnbEditor.getIpnbFilePanel();
        final IpnbEditablePanel cell = ipnbFilePanel.getSelectedCellPanel();
        final boolean isEnabled = cell != null && ipnbFilePanel.hasNextCell(cell);
        e.getPresentation().setEnabled(isEnabled);
    }
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) IpnbFilePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel) IpnbFileEditor(org.jetbrains.plugins.ipnb.editor.IpnbFileEditor) IpnbEditablePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel)

Example 4 with IpnbEditablePanel

use of org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel 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 5 with IpnbEditablePanel

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

the class IpnbRunCellBaseAction method runCell.

public static void runCell(@NotNull final IpnbFilePanel ipnbFilePanel, boolean selectNext) {
    final IpnbEditablePanel cell = ipnbFilePanel.getSelectedCellPanel();
    if (cell == null)
        return;
    cell.runCell(selectNext);
}
Also used : IpnbEditablePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel)

Aggregations

IpnbEditablePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel)12 IpnbFilePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel)9 DataContext (com.intellij.openapi.actionSystem.DataContext)3 Editor (com.intellij.openapi.editor.Editor)3 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)3 IpnbCodePanel (org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodePanel)3 IpnbCell (org.jetbrains.plugins.ipnb.format.cells.IpnbCell)3 IpnbEditableCell (org.jetbrains.plugins.ipnb.format.cells.IpnbEditableCell)3 PsiFile (com.intellij.psi.PsiFile)2 NotNull (org.jetbrains.annotations.NotNull)2 JsonWriter (com.google.gson.stream.JsonWriter)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ResolveResult (com.intellij.psi.ResolveResult)1 Nullable (org.jetbrains.annotations.Nullable)1 IpnbConnectionManager (org.jetbrains.plugins.ipnb.configuration.IpnbConnectionManager)1 IpnbCodeCell (org.jetbrains.plugins.ipnb.format.cells.IpnbCodeCell)1 IpnbHeadingCell (org.jetbrains.plugins.ipnb.format.cells.IpnbHeadingCell)1 IpnbMarkdownCell (org.jetbrains.plugins.ipnb.format.cells.IpnbMarkdownCell)1