Merge remote-tracking branch 'origin/master'
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Thu, 22 Aug 2013 00:06:57 +0000 (02:06 +0200)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Thu, 22 Aug 2013 00:06:57 +0000 (02:06 +0200)
plugins/terminal/lib/jediterm-pty-0.08.jar
plugins/terminal/src/org/jetbrains/plugins/terminal/AbstractTerminalRunner.java
plugins/terminal/src/org/jetbrains/plugins/terminal/JBTabbedTerminalWidget.java
plugins/terminal/src/org/jetbrains/plugins/terminal/JBTerminalPanel.java
plugins/terminal/src/org/jetbrains/plugins/terminal/JBTerminalWidget.java
plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalView.java

index e9bf3366fd6eff5dadf73dcc37885b125e7086b6..9a974f6311d460b312830218265a33dc98691b9e 100644 (file)
Binary files a/plugins/terminal/lib/jediterm-pty-0.08.jar and b/plugins/terminal/lib/jediterm-pty-0.08.jar differ
index 0ddfd9f18b6f9062dce5a8a9c7db71969107737d..c1ceb923a569fa2d5ea131fc1fd48a2fb14d61f6 100644 (file)
@@ -19,6 +19,7 @@ import com.intellij.openapi.wm.IdeFocusManager;
 import com.intellij.openapi.wm.ToolWindow;
 import com.intellij.openapi.wm.ToolWindowManager;
 import com.intellij.util.ui.UIUtil;
+import com.jediterm.pty.PtyProcessTtyConnector;
 import com.jediterm.terminal.TtyConnector;
 import com.jediterm.terminal.emulator.ColorPalette;
 import com.jediterm.terminal.ui.AbstractSystemSettingsProvider;
@@ -30,6 +31,7 @@ import javax.swing.*;
 import java.awt.*;
 import java.awt.event.ActionEvent;
 import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.ExecutionException;
 
 /**
@@ -191,7 +193,7 @@ public abstract class AbstractTerminalRunner<T extends Process> {
     }
 
     private KeyStroke[] getKeyStrokesByActionId(String actionId) {
-      java.util.List<KeyStroke> keyStrokes = new ArrayList<KeyStroke>();
+      List<KeyStroke> keyStrokes = new ArrayList<KeyStroke>();
       Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(actionId);
       for (Shortcut sc : shortcuts) {
         if (sc instanceof KeyboardShortcut) {
@@ -202,6 +204,11 @@ public abstract class AbstractTerminalRunner<T extends Process> {
 
       return keyStrokes.toArray(new KeyStroke[keyStrokes.size()]);
     }
+
+    @Override
+    public boolean shouldCloseTabOnLogout(TtyConnector ttyConnector) {
+      return ttyConnector instanceof PtyProcessTtyConnector; //close tab only on logout of local pty, not remote
+    }
   }
 
   public void openSession(TerminalWidget terminalWidget) {
index 53d52f89e5daea5e207d62f7dddaae48bd1ab28b..4747ea1515783592f13a686f468b9b61a63c4a49 100644 (file)
@@ -1,16 +1,36 @@
 package org.jetbrains.plugins.terminal;
 
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.jediterm.terminal.ui.JediTermWidget;
 import com.jediterm.terminal.ui.SystemSettingsProvider;
 import com.jediterm.terminal.ui.TabbedTerminalWidget;
+import com.jediterm.terminal.ui.TerminalAction;
 import org.jetbrains.annotations.NotNull;
 
+import javax.swing.*;
+import java.util.List;
+
 /**
  * @author traff
  */
 public class JBTabbedTerminalWidget extends TabbedTerminalWidget {
   public JBTabbedTerminalWidget(@NotNull SystemSettingsProvider settingsProvider) {
     super(settingsProvider);
+
+    convertActions(this, getActions());
+  }
+
+  public static void convertActions(JComponent component, List<TerminalAction> actions) {
+    for (final TerminalAction action : actions) {
+      AnAction a = new AnAction() {
+        @Override
+        public void actionPerformed(AnActionEvent e) {
+          action.perform();
+        }
+      };
+      a.registerCustomShortcutSet(action.getKeyCode(), action.getModifiers(), component);
+    }
   }
 
   @Override
index 7a83c324fba1f25cc54d7e93152ac72ddcb425a0..661658631586ef8960c65ddda15849d952797402 100644 (file)
@@ -62,6 +62,8 @@ public class JBTerminalPanel extends TerminalPanel {
                                     TerminalColor.awt(myColorScheme.getColor(EditorColors.SELECTION_BACKGROUND_COLOR))));
 
     setLineSpace(myColorScheme.getConsoleLineSpacing());
+    
+    JBTabbedTerminalWidget.convertActions(this, getActions());
   }
 
   protected Font createFont() {
index 1701a18926a71989a0588e43fc6943b92842e943..6f2e49da3f27a0ea520e549b9928e2b2875aca26 100644 (file)
@@ -28,6 +28,8 @@ public class JBTerminalWidget extends JediTermWidget {
 
   public JBTerminalWidget(SystemSettingsProvider settingsProvider) {
     super(settingsProvider);
+
+    JBTabbedTerminalWidget.convertActions(this, getActions());
   }
 
   @Override
index 73c8d69ea2e67c20ac300623ce72e8ddf8091b1f..bd7cfd23675e6fa49f30116a7f591ab9d893ae9a 100644 (file)
@@ -4,12 +4,15 @@ import com.intellij.icons.AllIcons;
 import com.intellij.notification.EventLog;
 import com.intellij.openapi.actionSystem.*;
 import com.intellij.openapi.components.ServiceManager;
+import com.intellij.openapi.project.DumbAwareAction;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.SimpleToolWindowPanel;
 import com.intellij.openapi.wm.ToolWindow;
 import com.intellij.openapi.wm.ToolWindowManager;
 import com.intellij.ui.content.Content;
 import com.intellij.ui.content.ContentFactory;
+import com.jediterm.terminal.ui.JediTermWidget;
+import com.jediterm.terminal.ui.TabbedTerminalWidget;
 import com.jediterm.terminal.ui.TerminalWidget;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.Nullable;
@@ -26,7 +29,7 @@ public class TerminalView {
   private JBTabbedTerminalWidget myTerminalWidget;
   private Project myProject;
 
-  public void initTerminal(Project project, ToolWindow toolWindow) {
+  public void initTerminal(Project project, final ToolWindow toolWindow) {
     myProject = project;
     LocalTerminalDirectRunner terminalRunner = OpenLocalTerminalAction.createTerminalRunner(project);
     
@@ -34,6 +37,12 @@ public class TerminalView {
     
     if (terminalRunner != null) {
       myTerminalWidget = terminalRunner.createTerminalWidget();
+      myTerminalWidget.addTabListener(new TabbedTerminalWidget.TabListener() {
+        @Override
+        public void tabClosed(JediTermWidget terminal) {
+          hideIfNoActiveSessions(toolWindow, myTerminalWidget);
+        }
+      });
     }
 
     Content content = createToolWindowContentPanel(terminalRunner, myTerminalWidget, toolWindow);
@@ -142,7 +151,20 @@ public class TerminalView {
     }, true);
   }
 
-  private static class NewSession extends AnAction {
+  private void hideIfNoActiveSessions(final ToolWindow toolWindow, JBTabbedTerminalWidget terminal) {
+    if (terminal.isNoActiveSessions()) {
+      toolWindow.getContentManager().removeAllContents(true);
+
+      toolWindow.getActivation().doWhenDone(new Runnable() {
+        @Override
+        public void run() {
+          initTerminal(myProject, toolWindow);
+        }
+      });
+    }
+  }
+
+  private static class NewSession extends DumbAwareAction {
     private final LocalTerminalDirectRunner myTerminalRunner;
     private final TerminalWidget myTerminal;
 
@@ -158,7 +180,7 @@ public class TerminalView {
     }
   }
 
-  private class CloseSession extends AnAction {
+  private class CloseSession extends DumbAwareAction {
     private final JBTabbedTerminalWidget myTerminal;
     private ToolWindow myToolWindow;
 
@@ -170,20 +192,9 @@ public class TerminalView {
 
     @Override
     public void actionPerformed(AnActionEvent e) {
-      boolean singleSession = myTerminal.isSingleSession();
-      
       myTerminal.closeCurrentSession();
-      
-      if (singleSession) {
-        myToolWindow.getContentManager().removeAllContents(true);
-        
-        myToolWindow.getActivation().doWhenDone(new Runnable() {
-          @Override
-          public void run() {
-            initTerminal(myProject, myToolWindow);
-          }
-        });
-      }
+
+      hideIfNoActiveSessions(myToolWindow, myTerminal);
     }
   }
 }