Fix PY-14096 Add popup menu on right click
authorValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Fri, 7 Oct 2016 13:09:12 +0000 (16:09 +0300)
committerValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Mon, 24 Oct 2016 17:09:44 +0000 (20:09 +0300)
python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbCodePanel.java

index e933564146f1fc0a823cd91dc15461f4f103d292..31bf6dca95876bc6723b7f7ef6dcd247a4e95800 100644 (file)
@@ -25,8 +25,7 @@ import org.jetbrains.plugins.ipnb.format.cells.output.*;
 
 import javax.swing.*;
 import java.awt.*;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
+import java.awt.event.*;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
@@ -111,6 +110,9 @@ public class IpnbCodePanel extends IpnbEditablePanel<JComponent, IpnbCodeCell> {
   private MouseAdapter createHideOutputListener(final OnePixelSplitter splitter) {
     final JPanel toggleBar = createToggleBar(splitter);
     return new MouseAdapter() {
+      private final String TOGGLE_OUTPUT_TEXT = "Toggle output  Double Click";
+      private JPopupMenu myMenu;
+
       @Override
       public void mouseClicked(MouseEvent e) {
         if (e.getClickCount() == 2) {
@@ -118,6 +120,22 @@ public class IpnbCodePanel extends IpnbEditablePanel<JComponent, IpnbCodeCell> {
         }
       }
 
+      @Override
+      public void mousePressed(MouseEvent e) {
+        if (SwingUtilities.isRightMouseButton(e) && e.getClickCount() == 1) {
+          myMenu = new JPopupMenu("");
+          final JMenuItem item = new JMenuItem(TOGGLE_OUTPUT_TEXT);
+          item.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+              hideOutputPanel();
+            }
+          });
+          myMenu.add(item);
+          myMenu.show(e.getComponent(), e.getX(), e.getY());
+        }
+      }
+
       private void hideOutputPanel() {
         setOutputStateInCell(true);
         splitter.setFirstComponent(toggleBar);