mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Jupyter: register actions only for notebook
This commit is contained in:
@@ -27,10 +27,6 @@
|
||||
use-shortcut-of="Run">
|
||||
<add-to-group group-id="RunMenu" anchor="last"/>
|
||||
</action>
|
||||
<action class="org.jetbrains.plugins.ipnb.editor.actions.IpnbAddCellAboveAction" id="IpnbAddCellAboveAction" text="Insert Cell Above">
|
||||
<keyboard-shortcut keymap="$default" first-keystroke="ctrl shift EQUALS"/>
|
||||
</action>
|
||||
|
||||
<action class="org.jetbrains.plugins.ipnb.editor.actions.IpnbConvertToPythonAction" id="IpnbConvertToPythonAction"
|
||||
text="Convert to Python Script">
|
||||
<add-to-group group-id="ProjectViewPopupMenuSettingsGroup"/>
|
||||
@@ -41,19 +37,6 @@
|
||||
<add-to-group group-id="ToolsMenu" anchor="last"/>
|
||||
</action>
|
||||
|
||||
<action class="org.jetbrains.plugins.ipnb.editor.actions.IpnbMoveCellDownAction" id="IpnbMoveCellDownAction" text="Move Cell Down">
|
||||
<keyboard-shortcut keymap="$default" first-keystroke="ctrl shift DOWN"/>
|
||||
</action>
|
||||
<action class="org.jetbrains.plugins.ipnb.editor.actions.IpnbMoveCellUpAction" id="IpnbMoveCellUpAction" text="Move Cell Up">
|
||||
<keyboard-shortcut keymap="$default" first-keystroke="ctrl shift UP"/>
|
||||
</action>
|
||||
|
||||
<action class="org.jetbrains.plugins.ipnb.editor.actions.IpnbMarkdownCellAction" id="IpnbMarkdownCellAction" text="Markdown Cell">
|
||||
<keyboard-shortcut keymap="$default" first-keystroke="ctrl shift m"/>
|
||||
</action>
|
||||
<action class="org.jetbrains.plugins.ipnb.editor.actions.IpnbCodeCellAction" id="IpnbCodeCellAction" text="Code Cell">
|
||||
<keyboard-shortcut keymap="$default" first-keystroke="ctrl shift s"/>
|
||||
</action>
|
||||
<action id="NewIPynbFile" class="org.jetbrains.plugins.ipnb.editor.actions.IpnbCreateFileAction">
|
||||
<add-to-group group-id="NewGroup" anchor="after" relative-to-action="NewPythonFile"/>
|
||||
</action>
|
||||
|
||||
@@ -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));
|
||||
|
||||
+9
-20
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-20
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-22
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
+10
-21
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user