mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-14224 show line numbers in code cell
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
package org.jetbrains.plugins.ipnb.editor.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.EditorSettings;
|
||||
import org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodePanel;
|
||||
|
||||
public class IpnbToggleLineNumbersAction extends AnAction {
|
||||
private final IpnbCodePanel myPanel;
|
||||
|
||||
public IpnbToggleLineNumbersAction(IpnbCodePanel panel) {
|
||||
super("Toggle line numbers");
|
||||
myPanel = panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
toggleLineNumbers(myPanel);
|
||||
}
|
||||
|
||||
public static void toggleLineNumbers(IpnbCodePanel panel) {
|
||||
final Editor editor = panel.getEditor();
|
||||
final EditorSettings editorSettings = editor.getSettings();
|
||||
editorSettings.setLineNumbersShown(!editorSettings.isLineNumbersShown());
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import org.jetbrains.plugins.ipnb.editor.IpnbFileEditor;
|
||||
import org.jetbrains.plugins.ipnb.editor.actions.IpnbCutCellAction;
|
||||
import org.jetbrains.plugins.ipnb.editor.actions.IpnbDeleteCellAction;
|
||||
import org.jetbrains.plugins.ipnb.editor.actions.IpnbPasteCellAction;
|
||||
import org.jetbrains.plugins.ipnb.editor.actions.IpnbToggleLineNumbersAction;
|
||||
import org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodePanel;
|
||||
import org.jetbrains.plugins.ipnb.format.IpnbFile;
|
||||
import org.jetbrains.plugins.ipnb.format.IpnbParser;
|
||||
@@ -196,8 +197,7 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider, D
|
||||
IpnbEditablePanel panel;
|
||||
if (cell instanceof IpnbCodeCell) {
|
||||
panel = new IpnbCodePanel(myProject, myParent, (IpnbCodeCell)cell);
|
||||
add(panel);
|
||||
myIpnbPanels.add(panel);
|
||||
addComponent(panel);
|
||||
}
|
||||
else if (cell instanceof IpnbMarkdownCell) {
|
||||
panel = new IpnbMarkdownPanel((IpnbMarkdownCell)cell, this);
|
||||
@@ -567,7 +567,6 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider, D
|
||||
mySelectedCellPanel.switchToEditing();
|
||||
repaint();
|
||||
}
|
||||
|
||||
if (e.getKeyCode() == KeyEvent.VK_UP) {
|
||||
selectPrev(mySelectedCellPanel);
|
||||
}
|
||||
@@ -579,6 +578,11 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider, D
|
||||
IpnbDeleteCellAction.deleteCell(this);
|
||||
}
|
||||
}
|
||||
else if (e.getKeyCode() == KeyEvent.VK_L) {
|
||||
if (mySelectedCellPanel instanceof IpnbCodePanel && !mySelectedCellPanel.isEditing()) {
|
||||
IpnbToggleLineNumbersAction.toggleLineNumbers((IpnbCodePanel)mySelectedCellPanel);
|
||||
}
|
||||
}
|
||||
else if (e.getModifiers() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_X) {
|
||||
if (!mySelectedCellPanel.isEditing()) {
|
||||
|
||||
+1
-3
@@ -53,13 +53,11 @@ public class IpnbCodeSourcePanel extends IpnbPanel<JComponent, IpnbCodeCell> imp
|
||||
private Editor myEditor;
|
||||
@NotNull private final Project myProject;
|
||||
@NotNull private final IpnbCodePanel myParent;
|
||||
@NotNull private final String mySource;
|
||||
|
||||
public IpnbCodeSourcePanel(@NotNull final Project project, @NotNull final IpnbCodePanel parent, @NotNull final IpnbCodeCell cell) {
|
||||
super(cell, new HorizontalLayout(5));
|
||||
myProject = project;
|
||||
myParent = parent;
|
||||
mySource = cell.getSourceAsString();
|
||||
final JComponent panel = createViewPanel();
|
||||
add(panel);
|
||||
addRightClickMenu();
|
||||
@@ -210,7 +208,7 @@ public class IpnbCodeSourcePanel extends IpnbPanel<JComponent, IpnbCodeCell> imp
|
||||
final MouseEvent mouseEvent = e.getMouseEvent();
|
||||
if (SwingUtilities.isRightMouseButton(mouseEvent) && mouseEvent.getClickCount() == 1) {
|
||||
final ListPopup menu = createPopupMenu(new DefaultActionGroup(new IpnbMergeCellAboveAction(), new IpnbMergeCellBelowAction(),
|
||||
new IpnbSplitCellAction()));
|
||||
new IpnbSplitCellAction(), new IpnbToggleLineNumbersAction(myParent)));
|
||||
menu.show(RelativePoint.fromScreen(e.getMouseEvent().getLocationOnScreen()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user