Commits

Anonymous committed 538d96c

Switching consoles also switches active configuration.

Comments (0)

Files changed (4)

org.lispdev.repl/src/org/lispdev/repl/AbstractRepl.java

     Assert.isNotNull(config);
     LispProcess process = SwankPlugin.get().getProcess(config);
     Assert.isNotNull(process);
+    Assert.isLegal(ReplPlugin.get().launch2repl.get(config) == null,
+        "Repl already exist for: " + config);
+    ReplPlugin.get().launch2repl.put(config, this);
     swank = process.getSwank();
     readRunnable = new ReadRunnable(this);
     disconnectRunnable = new DisconnectRunnable(this);
     swank.addDebugListener(debugInfoRunnable);
     swank.addDebugActivateListener(debugRunnable);
     swank.addDebugReturnListener(debugStopRunnable);
-    ReplPlugin.get().launch2repl.put(config, this);
     this.config = config;
   }
 
   protected IState currState()
   {
     if( states.isEmpty() )
-    { // Shouldn't ever happen, but it has
+    { // Should never happen, but it has
       IState s = new EvalState(this);
       states.push(s);
       Trace.DEBUG.trace("Repl is in state: " + String.valueOf(s));
     }
   }
 
+  protected abstract void activate();
+
   public void dispose()
   {
     swank.removeListener(debugInfoRunnable);

org.lispdev.repl/src/org/lispdev/repl/ReplPlugin.java

   {
     return getRepl(SwankPlugin.get().getActiveConfig());
   }
+
+  public void setActiveConfig(ILaunchConfiguration config)
+  {
+    SwankPlugin.get().setActiveConfig(config);
+  }
 }

org.lispdev.replview/src/org/lispdev/replview/ReplConsole.java

   @Override
   public IPageBookViewPage createPage(IConsoleView view)
   {
-    page = new ReplConsolePage(process);
+    page = new ReplConsolePage(process, this);
     return page;
   }
 

org.lispdev.replview/src/org/lispdev/replview/ReplConsolePage.java

 import org.eclipse.jface.util.PropertyChangeEvent;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
 import org.eclipse.swt.events.VerifyEvent;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.PartInitException;
 import org.lispdev.repl.AbstractRepl;
 import org.lispdev.repl.IState;
 import org.lispdev.repl.ReadState;
+import org.lispdev.swank.SwankPlugin;
 import org.lispdev.swank.debug.LispDebugTarget;
 import org.lispdev.swank.debug.LispProcess;
 import org.lispdev.swank.debug.LispThread;
 
   private LispConsoleViewer replConsole; //viewer
   private Repl repl;
+  private final ReplConsole console;
   private final LispProcess process;
   private ConsoleEnterTrigger enterTrigger;
 
   /**
    * Constructs a repl console page corresponding to given process
    */
-  public ReplConsolePage(LispProcess pr)
+  public ReplConsolePage(LispProcess pr, ReplConsole c)
   {
     process = pr;
+    console = c;
   }
 
 
   private class Repl extends AbstractRepl implements IConsoleInputListener
   {
-    public Repl(ILaunchConfiguration s)
+    private final ReplConsole console;
+
+    public Repl(ILaunchConfiguration s, ReplConsole c)
     {
       super(s);
+      console = c;
     }
 
     @Override
       }
     }
 
+    @Override
+    protected void activate()
+    {
+      console.activate();
+    }
+
   }
 
   final IPropertyChangeListener fontListener = new IPropertyChangeListener(){
   @Override
   public void createControl(Composite parent)
   {
-    repl = new Repl(process.getLaunch().getLaunchConfiguration());
+    repl = new Repl(process.getLaunch().getLaunchConfiguration(),console);
     replConsole = new LispConsoleViewer(parent/*comp*/, new VerticalRuler(10),
         SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.LEFT | SWT.BORDER,
         new IVariableResolver(){
         });
     replConsole.getTextWidget().setFont(JFaceResources.getTextFont());
     JFaceResources.getFontRegistry().addListener(fontListener);
+    replConsole.getTextWidget().addFocusListener(new FocusListener(){
+      @Override
+      public void focusLost(FocusEvent e)
+      {
+      }
+
+      @Override
+      public void focusGained(FocusEvent e)
+      {
+        if( !SwankPlugin.get().getActiveConfig().equals(repl.getConfig()) )
+        {
+          SwankPlugin.get().setActiveConfig(repl.getConfig());
+          MessageBox mbox =
+            new MessageBox(fSite.getShell(), SWT.ICON_INFORMATION
+                | SWT.APPLICATION_MODAL);
+        mbox.setText("Info");
+        mbox.setMessage("Active configuration is " + repl.getConfig().getName());
+        mbox.open();
+        }
+      }
+    });
 
     enterTrigger =
       new ConsoleEnterTrigger(replConsole,SWT.SHIFT,