diff --git a/python/ipnb/resources/META-INF/ipython-notebook.xml b/python/ipnb/resources/META-INF/ipython-notebook.xml
index 9b20fea4dd65..ad039aaaeb88 100644
--- a/python/ipnb/resources/META-INF/ipython-notebook.xml
+++ b/python/ipnb/resources/META-INF/ipython-notebook.xml
@@ -27,10 +27,6 @@
use-shortcut-of="Run">
-
-
-
-
@@ -41,19 +37,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/IpnbFileEditor.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/IpnbFileEditor.java
index 6f79796fda34..44f50b3845dc 100644
--- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/IpnbFileEditor.java
+++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/IpnbFileEditor.java
@@ -89,6 +89,7 @@ public class IpnbFileEditor extends UserDataHolderBase implements FileEditor {
myEditorPanel.add(myScrollPane, BorderLayout.CENTER);
registerHeadingActions();
+ registerActions();
new IpnbDeleteCellAction(this);
}
@@ -101,6 +102,19 @@ public class IpnbFileEditor extends UserDataHolderBase implements FileEditor {
return myDocument;
}
+ private void registerActions() {
+ new IpnbAddCellAboveAction(this).registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift EQUALS")),
+ myIpnbFilePanel);
+ new IpnbMoveCellDownAction(this).registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift DOWN")),
+ myIpnbFilePanel);
+ new IpnbMoveCellUpAction(this).registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift UP")),
+ myIpnbFilePanel);
+ new IpnbMarkdownCellAction(this).registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift M")),
+ myIpnbFilePanel);
+ new IpnbCodeCellAction(this).registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift Y")),
+ myIpnbFilePanel);
+ }
+
private void registerHeadingActions() {
new IpnbHeading1CellAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift 1")), myIpnbFilePanel);
new IpnbHeading2CellAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift 2")), myIpnbFilePanel);
@@ -117,7 +131,7 @@ public class IpnbFileEditor extends UserDataHolderBase implements FileEditor {
final DefaultActionGroup toolbarGroup = new DefaultActionGroup();
toolbarGroup.add(new IpnbSaveAction(this));
toolbarGroup.add(new IpnbConvertToPythonAction(this));
- toolbarGroup.add( new Separator());
+ toolbarGroup.add(new Separator());
toolbarGroup.add(new IpnbAddCellBelowAction(this));
toolbarGroup.add(new Separator());
toolbarGroup.addAll(new IpnbCutCellAction(this), new IpnbCopyCellAction(this), new IpnbPasteCellAction(this));
diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbAddCellAboveAction.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbAddCellAboveAction.java
index ba9d3f156794..47acd214aa96 100644
--- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbAddCellAboveAction.java
+++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbAddCellAboveAction.java
@@ -2,10 +2,8 @@ package org.jetbrains.plugins.ipnb.editor.actions;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
-import com.intellij.openapi.fileEditor.FileEditor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.ipnb.editor.IpnbFileEditor;
import org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel;
@@ -13,14 +11,17 @@ import org.jetbrains.plugins.ipnb.format.cells.IpnbCodeCell;
public class IpnbAddCellAboveAction extends AnAction {
+ private final IpnbFileEditor myFileEditor;
+
+ public IpnbAddCellAboveAction(IpnbFileEditor fileEditor) {
+ super("Insert Cell Above");
+ myFileEditor = fileEditor;
+ }
+
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
- final DataContext context = event.getDataContext();
- final FileEditor editor = IpnbFileEditor.DATA_KEY.getData(context);
- if (editor != null) {
- final IpnbFilePanel component = ((IpnbFileEditor)editor).getIpnbFilePanel();
- addCell(component);
- }
+ final IpnbFilePanel component = myFileEditor.getIpnbFilePanel();
+ addCell(component);
}
public void addCell(@NotNull final IpnbFilePanel ipnbFilePanel) {
@@ -31,16 +32,4 @@ public class IpnbAddCellAboveAction extends AnAction {
}), "Ipnb.createAndAddCell", new Object());
}
-
- @Override
- public void update(AnActionEvent e) {
- final DataContext context = e.getDataContext();
- final FileEditor editor = IpnbFileEditor.DATA_KEY.getData(context);
- if (editor != null) {
- e.getPresentation().setEnabledAndVisible(true);
- }
- else {
- e.getPresentation().setEnabledAndVisible(false);
- }
- }
}
diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbCodeCellAction.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbCodeCellAction.java
index afd3f6b0db8c..1e3f61e089ac 100644
--- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbCodeCellAction.java
+++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbCodeCellAction.java
@@ -3,9 +3,6 @@ package org.jetbrains.plugins.ipnb.editor.actions;
import com.google.common.collect.Lists;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.DataContext;
-import com.intellij.openapi.actionSystem.PlatformDataKeys;
-import com.intellij.openapi.fileEditor.FileEditor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.ipnb.editor.IpnbFileEditor;
import org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel;
@@ -17,14 +14,16 @@ import org.jetbrains.plugins.ipnb.format.cells.IpnbEditableCell;
import java.util.List;
public class IpnbCodeCellAction extends AnAction {
+ private final IpnbFileEditor myEditor;
+
+ public IpnbCodeCellAction(IpnbFileEditor editor) {
+ super("Code Cell");
+ myEditor = editor;
+ }
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
- final DataContext context = event.getDataContext();
- final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
- if (editor instanceof IpnbFileEditor) {
- changeTypeToCode((IpnbFileEditor)editor);
- }
+ changeTypeToCode(myEditor);
}
public void changeTypeToCode(@NotNull final IpnbFileEditor editor) {
@@ -41,16 +40,4 @@ public class IpnbCodeCellAction extends AnAction {
}
filePanel.replaceComponent(selectedCellPanel, codeCell);
}
-
- @Override
- public void update(AnActionEvent e) {
- final DataContext context = e.getDataContext();
- final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
- if (editor instanceof IpnbFileEditor) {
- e.getPresentation().setEnabledAndVisible(true);
- }
- else {
- e.getPresentation().setEnabledAndVisible(false);
- }
- }
}
diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbMarkdownCellAction.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbMarkdownCellAction.java
index 6f688fc87907..2435dd3adcc5 100644
--- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbMarkdownCellAction.java
+++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbMarkdownCellAction.java
@@ -2,9 +2,6 @@ package org.jetbrains.plugins.ipnb.editor.actions;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.DataContext;
-import com.intellij.openapi.actionSystem.PlatformDataKeys;
-import com.intellij.openapi.fileEditor.FileEditor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.ipnb.editor.IpnbFileEditor;
import org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel;
@@ -16,14 +13,16 @@ import org.jetbrains.plugins.ipnb.format.cells.IpnbMarkdownCell;
import java.util.List;
public class IpnbMarkdownCellAction extends AnAction {
+ private final IpnbFileEditor myEditor;
+
+ public IpnbMarkdownCellAction(IpnbFileEditor editor) {
+ super("Markdown Cell");
+ myEditor = editor;
+ }
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
- final DataContext context = event.getDataContext();
- final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
- if (editor instanceof IpnbFileEditor) {
- changeTypeToMarkdown((IpnbFileEditor)editor);
- }
+ changeTypeToMarkdown(myEditor);
}
public void changeTypeToMarkdown(@NotNull final IpnbFileEditor editor) {
@@ -40,16 +39,4 @@ public class IpnbMarkdownCellAction extends AnAction {
}
filePanel.replaceComponent(selectedCellPanel, markdownCell);
}
-
- @Override
- public void update(AnActionEvent e) {
- final DataContext context = e.getDataContext();
- final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
- if (editor instanceof IpnbFileEditor) {
- e.getPresentation().setEnabledAndVisible(true);
- }
- else {
- e.getPresentation().setEnabledAndVisible(false);
- }
- }
}
diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbMoveCellDownAction.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbMoveCellDownAction.java
index 0fe61ddf8279..ab0bca4fe656 100644
--- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbMoveCellDownAction.java
+++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbMoveCellDownAction.java
@@ -2,37 +2,24 @@ package org.jetbrains.plugins.ipnb.editor.actions;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.DataContext;
-import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
-import com.intellij.openapi.fileEditor.FileEditor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.ipnb.editor.IpnbFileEditor;
import org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel;
public class IpnbMoveCellDownAction extends AnAction {
+ private final IpnbFileEditor myEditor;
+
+ public IpnbMoveCellDownAction(IpnbFileEditor editor) {
+ super("Move Cell Down");
+ myEditor = editor;
+ }
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
- final DataContext context = event.getDataContext();
- final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
- if (editor instanceof IpnbFileEditor) {
- final IpnbFilePanel ipnbFilePanel = ((IpnbFileEditor)editor).getIpnbFilePanel();
- CommandProcessor.getInstance().executeCommand(ipnbFilePanel.getProject(), () -> ApplicationManager.getApplication().runWriteAction(
- () -> ipnbFilePanel.moveCell(true)), "Ipnb.moveCell", new Object());
- }
- }
-
- @Override
- public void update(AnActionEvent e) {
- final DataContext context = e.getDataContext();
- final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
- if (editor instanceof IpnbFileEditor) {
- e.getPresentation().setEnabledAndVisible(true);
- }
- else {
- e.getPresentation().setEnabledAndVisible(false);
- }
+ final IpnbFilePanel ipnbFilePanel = myEditor.getIpnbFilePanel();
+ CommandProcessor.getInstance().executeCommand(ipnbFilePanel.getProject(), () -> ApplicationManager.getApplication().runWriteAction(
+ () -> ipnbFilePanel.moveCell(true)), "Ipnb.moveCell", new Object());
}
}
diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbMoveCellUpAction.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbMoveCellUpAction.java
index 379a74b03b47..cb34947f110e 100644
--- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbMoveCellUpAction.java
+++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbMoveCellUpAction.java
@@ -2,36 +2,25 @@ package org.jetbrains.plugins.ipnb.editor.actions;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.DataContext;
-import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
-import com.intellij.openapi.fileEditor.FileEditor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.ipnb.editor.IpnbFileEditor;
import org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel;
public class IpnbMoveCellUpAction extends AnAction {
+ private final IpnbFileEditor myEditor;
+
+ public IpnbMoveCellUpAction(IpnbFileEditor editor) {
+ super("Move Cell Up");
+ myEditor = editor;
+ }
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
- final DataContext context = event.getDataContext();
- final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
- if (editor instanceof IpnbFileEditor) {
- final IpnbFilePanel ipnbFilePanel = ((IpnbFileEditor)editor).getIpnbFilePanel();
- CommandProcessor.getInstance().executeCommand(ipnbFilePanel.getProject(),
- () -> ApplicationManager.getApplication().runWriteAction(() -> ipnbFilePanel.moveCell(false)), "Ipnb.moveCell", new Object());
- }
- }
- @Override
- public void update(AnActionEvent e) {
- final DataContext context = e.getDataContext();
- final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
- if (editor instanceof IpnbFileEditor) {
- e.getPresentation().setEnabledAndVisible(true);
- }
- else {
- e.getPresentation().setEnabledAndVisible(false);
- }
+ final IpnbFilePanel ipnbFilePanel = myEditor.getIpnbFilePanel();
+ CommandProcessor.getInstance().executeCommand(ipnbFilePanel.getProject(),
+ () -> ApplicationManager.getApplication().runWriteAction(
+ () -> ipnbFilePanel.moveCell(false)), "Ipnb.moveCell", new Object());
}
}