mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed NPE ipython notebook (open empty file)
This commit is contained in:
+13
-3
@@ -2,6 +2,8 @@ package org.jetbrains.plugins.ipnb.editor.actions;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel;
|
||||
import org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel;
|
||||
@@ -17,11 +19,19 @@ public abstract class IpnbRunCellBaseAction extends AnAction {
|
||||
cell.runCell();
|
||||
if (selectNext) {
|
||||
final int index = ipnbFilePanel.getSelectedIndex();
|
||||
if (ipnbFilePanel.getIpnbPanels().size()-1 == index) {
|
||||
if (ipnbFilePanel.getIpnbPanels().size() - 1 == index) {
|
||||
ipnbFilePanel.createAndAddCell(true);
|
||||
ipnbFilePanel.saveToFile();
|
||||
CommandProcessor.getInstance().executeCommand(ipnbFilePanel.getProject(), new Runnable() {
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ipnbFilePanel.saveToFile();
|
||||
ipnbFilePanel.selectNext(cell);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, "Ipnb.runCell", new Object());
|
||||
}
|
||||
ipnbFilePanel.selectNext(cell);
|
||||
}
|
||||
ipnbFilePanel.revalidate();
|
||||
ipnbFilePanel.repaint();
|
||||
|
||||
@@ -106,9 +106,7 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider, D
|
||||
mySelectedCell = null;
|
||||
myIpnbFile = IpnbParser.parseIpnbFile(myDocument, myVirtualFile.getPath());
|
||||
if (myIpnbFile.getCells().isEmpty()) {
|
||||
final IpnbCodeCell cell = new IpnbCodeCell("python", new String[]{""}, null, new ArrayList<IpnbOutputCell>());
|
||||
myIpnbFile.addCell(cell, 0);
|
||||
saveToFile();
|
||||
createAndAddCell(true);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (showError)
|
||||
|
||||
@@ -108,7 +108,10 @@ public class IpnbCodePanel extends IpnbEditablePanel<JComponent, IpnbCodeCell> {
|
||||
@Override
|
||||
public void switchToEditing() {
|
||||
setEditing(true);
|
||||
getParent().repaint();
|
||||
final Container parent = getParent();
|
||||
if (parent != null) {
|
||||
parent.repaint();
|
||||
}
|
||||
UIUtil.requestFocus(myCodeSourcePanel.getEditor().getContentComponent());
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -105,7 +105,9 @@ public class IpnbCodeSourcePanel extends IpnbPanel<JComponent, IpnbCodeCell> imp
|
||||
getIpnbCodePanel().setEditing(false);
|
||||
UIUtil.requestFocus(getIpnbCodePanel().getFileEditor().getIpnbFilePanel());
|
||||
}
|
||||
else if (keyCode == KeyEvent.VK_ENTER && InputEvent.CTRL_DOWN_MASK == e.getModifiersEx()) {
|
||||
|
||||
|
||||
else if (keyCode == KeyEvent.VK_ENTER && InputEvent.CTRL_MASK == e.getModifiers()) {
|
||||
IpnbRunCellBaseAction.runCell(ipnbFilePanel, false);
|
||||
}
|
||||
else if (keyCode == KeyEvent.VK_ENTER && InputEvent.SHIFT_DOWN_MASK == e.getModifiersEx()) {
|
||||
|
||||
Reference in New Issue
Block a user