Search in sources :

Example 1 with IpnbHeadingCell

use of org.jetbrains.plugins.ipnb.format.cells.IpnbHeadingCell in project intellij-community by JetBrains.

the class IpnbFileEditor method updateCellType.

private void updateCellType(@NotNull final String selectedItem, @NotNull final IpnbEditablePanel selectedCell) {
    selectedCell.updateCellSource();
    if (selectedCell instanceof IpnbHeadingPanel) {
        final IpnbHeadingCell cell = ((IpnbHeadingPanel) selectedCell).getCell();
        if (selectedItem.startsWith(headingCellType)) {
            final char c = selectedItem.charAt(selectedItem.length() - 1);
            final int level = Character.getNumericValue(c);
            if (level != cell.getLevel()) {
                cell.setLevel(level);
                selectedCell.updateCellView();
            }
        } else if (selectedItem.equals(markdownCellType)) {
            final List<IpnbCell> cells = myIpnbFilePanel.getIpnbFile().getCells();
            final int index = cells.indexOf(((IpnbHeadingPanel) selectedCell).getCell());
            final IpnbMarkdownCell markdownCell = new IpnbMarkdownCell(cell.getSource(), cell.getMetadata());
            if (index >= 0) {
                cells.set(index, markdownCell);
            }
            myIpnbFilePanel.replaceComponent(selectedCell, markdownCell);
        } else if (selectedItem.equals(codeCellType)) {
            final List<IpnbCell> cells = myIpnbFilePanel.getIpnbFile().getCells();
            final int index = cells.indexOf(((IpnbHeadingPanel) selectedCell).getCell());
            final IpnbCodeCell codeCell = new IpnbCodeCell("python", cell.getSource(), null, Lists.newArrayList(), cell.getMetadata());
            if (index >= 0) {
                cells.set(index, codeCell);
            }
            myIpnbFilePanel.replaceComponent(selectedCell, codeCell);
        }
    } else if (selectedCell instanceof IpnbMarkdownPanel) {
        final IpnbMarkdownCell cell = ((IpnbMarkdownPanel) selectedCell).getCell();
        if (selectedItem.startsWith(headingCellType)) {
            final char c = selectedItem.charAt(selectedItem.length() - 1);
            final int level = Character.getNumericValue(c);
            final List<IpnbCell> cells = myIpnbFilePanel.getIpnbFile().getCells();
            final int index = cells.indexOf(((IpnbMarkdownPanel) selectedCell).getCell());
            final IpnbHeadingCell headingCell = new IpnbHeadingCell(cell.getSource(), level, cell.getMetadata());
            if (index >= 0) {
                cells.set(index, headingCell);
            }
            myIpnbFilePanel.replaceComponent(selectedCell, headingCell);
        } else if (selectedItem.equals(codeCellType)) {
            final List<IpnbCell> cells = myIpnbFilePanel.getIpnbFile().getCells();
            final int index = cells.indexOf(((IpnbMarkdownPanel) selectedCell).getCell());
            final IpnbCodeCell codeCell = new IpnbCodeCell("python", cell.getSource(), null, Lists.newArrayList(), cell.getMetadata());
            if (index >= 0) {
                cells.set(index, codeCell);
            }
            myIpnbFilePanel.replaceComponent(selectedCell, codeCell);
        }
    } else if (selectedCell instanceof IpnbCodePanel) {
        final IpnbCodeCell cell = ((IpnbCodePanel) selectedCell).getCell();
        if (selectedItem.startsWith(headingCellType)) {
            final char c = selectedItem.charAt(selectedItem.length() - 1);
            final int level = Character.getNumericValue(c);
            final List<IpnbCell> cells = myIpnbFilePanel.getIpnbFile().getCells();
            final int index = cells.indexOf(((IpnbCodePanel) selectedCell).getCell());
            final IpnbHeadingCell headingCell = new IpnbHeadingCell(cell.getSource(), level, cell.getMetadata());
            if (index >= 0) {
                cells.set(index, headingCell);
            }
            myIpnbFilePanel.replaceComponent(selectedCell, headingCell);
        } else if (selectedItem.equals(markdownCellType)) {
            final List<IpnbCell> cells = myIpnbFilePanel.getIpnbFile().getCells();
            final int index = cells.indexOf(((IpnbCodePanel) selectedCell).getCell());
            final IpnbMarkdownCell markdownCell = new IpnbMarkdownCell(cell.getSource(), cell.getMetadata());
            if (index >= 0) {
                cells.set(index, markdownCell);
            }
            myIpnbFilePanel.replaceComponent(selectedCell, markdownCell);
        }
    }
}
Also used : IpnbCell(org.jetbrains.plugins.ipnb.format.cells.IpnbCell) IpnbMarkdownCell(org.jetbrains.plugins.ipnb.format.cells.IpnbMarkdownCell) IpnbCodeCell(org.jetbrains.plugins.ipnb.format.cells.IpnbCodeCell) List(java.util.List) IpnbHeadingCell(org.jetbrains.plugins.ipnb.format.cells.IpnbHeadingCell) IpnbCodePanel(org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodePanel)

Example 2 with IpnbHeadingCell

use of org.jetbrains.plugins.ipnb.format.cells.IpnbHeadingCell in project intellij-community by JetBrains.

the class IpnbFileEditor method updateCellTypeCombo.

private void updateCellTypeCombo(@NotNull final IpnbPanel ipnbPanel) {
    if (ipnbPanel instanceof IpnbHeadingPanel) {
        final IpnbHeadingCell cell = ((IpnbHeadingPanel) ipnbPanel).getCell();
        final int level = cell.getLevel();
        myCellTypeCombo.setSelectedItem(headingCellType + level);
    } else if (ipnbPanel instanceof IpnbMarkdownPanel) {
        myCellTypeCombo.setSelectedItem(markdownCellType);
    } else if (ipnbPanel instanceof IpnbCodePanel) {
        myCellTypeCombo.setSelectedItem(codeCellType);
    }
}
Also used : IpnbHeadingCell(org.jetbrains.plugins.ipnb.format.cells.IpnbHeadingCell) IpnbCodePanel(org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodePanel)

Example 3 with IpnbHeadingCell

use of org.jetbrains.plugins.ipnb.format.cells.IpnbHeadingCell in project intellij-community by JetBrains.

the class IpnbHeadingCellActionBase method changeTypeToHeading.

public void changeTypeToHeading(@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 IpnbHeadingCell heading = new IpnbHeadingCell(cell.getSource(), myLevel, cell.getMetadata());
    if (index >= 0) {
        cells.set(index, heading);
    }
    filePanel.replaceComponent(selectedCellPanel, heading);
}
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) IpnbHeadingCell(org.jetbrains.plugins.ipnb.format.cells.IpnbHeadingCell) IpnbEditablePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel)

Aggregations

IpnbHeadingCell (org.jetbrains.plugins.ipnb.format.cells.IpnbHeadingCell)3 IpnbCodePanel (org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodePanel)2 IpnbCell (org.jetbrains.plugins.ipnb.format.cells.IpnbCell)2 List (java.util.List)1 IpnbEditablePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel)1 IpnbFilePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel)1 IpnbCodeCell (org.jetbrains.plugins.ipnb.format.cells.IpnbCodeCell)1 IpnbEditableCell (org.jetbrains.plugins.ipnb.format.cells.IpnbEditableCell)1 IpnbMarkdownCell (org.jetbrains.plugins.ipnb.format.cells.IpnbMarkdownCell)1