1. Sergey Kolos
  2. lispdev

Commits

sk  committed 234d701

Added load file in action.

  • Participants
  • Parent commits 538d96c
  • Branches default

Comments (0)

Files changed (4)

File org.lispdev.main/src/org/lispdev/main/LoadFileInAction.java

View file
 package org.lispdev.main;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IMenuCreator;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.ui.IObjectActionDelegate;
 import org.eclipse.ui.IWorkbenchPart;
+import org.lispdev.repl.AbstractRepl;
+import org.lispdev.repl.ReplPlugin;
+import org.lispdev.swank.ISwank;
+import org.lispdev.swank.SwankPlugin;
 import org.lispdev.swank.debug.LispProcess;
+import org.lispdev.swank.runnables.SwankCompilationRunnable;
 
 public class LoadFileInAction implements IObjectActionDelegate, IMenuCreator
 {
   private IAction action;
   private IStructuredSelection selection;
+  private IWorkbenchPart part;
 
   @Override
   public void run(IAction action)
   public Menu getMenu(Menu parent)
   {
     Menu menu = new Menu(parent);
-//    for( LispProcess p : SwankPlugin.get().getProcesses() )
-//    {
-//      final String label = p.getLabel();
-//      final LispProcess pr = p;
-//      Action a = new Action(label){
-//        @Override
-//        public void run()
-//        {
-//          loadIn(selection,pr);
-//        }
-//      };
-//      a.setDescription("Load file(s) in " + label);
-//      ActionContributionItem item = new ActionContributionItem(a);
-//      item.fill(menu, -1);
-//    }
+    for( ILaunchConfiguration p : SwankPlugin.getConfigs() )
+    {
+      final String label = p.getName();
+      final ILaunchConfiguration pr = p;
+      Action a = new Action(label){
+        @Override
+        public void run()
+        {
+          loadIn(selection,pr);
+        }
+      };
+      a.setDescription("Load project in " + label);
+      ActionContributionItem item = new ActionContributionItem(a);
+      item.fill(menu, -1);
+    }
     return menu;
   }
 
-  private void loadIn(IStructuredSelection files, LispProcess pr)
+  private void loadIn(IStructuredSelection files,
+      final ILaunchConfiguration pr)
   {
     if( files == null || pr == null ) return;
+    LispProcess process = SwankPlugin.get().getProcess(pr);
+    if( process == null )
+    {
+      MessageBox mbox =
+        new MessageBox(part.getSite().getShell(), SWT.CANCEL | SWT.ICON_ERROR
+            | SWT.APPLICATION_MODAL);
+      mbox.setText("Error");
+      mbox.setMessage(pr.getName() + " is not started");
+      mbox.open();
+      return;
+    }
+    ISwank swank = process.getSwank();
+    Assert.isNotNull(swank);
+    if( !swank.isConnected() )
+    {
+      swank.connect();
+    }
     for( Object obj : files.toList() )
     {
       if( obj instanceof IFile )
       {
-        IFile file = (IFile)obj;
-        String filePath = file.getLocation().toOSString().replace("\\", "\\\\");
-        String command = "(load \"" + filePath + "\")";
+        final IFile file = (IFile)obj;
+        swank.sendCompileFile(file.getLocation().toOSString(),
+        new SwankCompilationRunnable(process.getSwank().getLispImplementation())
+        {
+          @Override
+          public void run()
+          {
+            CompilationInfo info = getInfo();
+            final IProject proj = file.getProject();
 
-        //pr.getSwank().sendEvalAndGrab(command,100000);
+            AbstractRepl repl = ReplPlugin.get().getRepl(pr);
+            repl.appendOut("Loaded " + file.getName() + "\n");
+            repl.doInput();
+            LoadProjectAction.addCompilationMarkers(info, proj);
+          }
+        });
       }
     }
   }
 
   @Override
   public void setActivePart(IAction action, IWorkbenchPart targetPart)
-  {}
+  {
+    part = targetPart;
+  }
 
 }

File org.lispdev.swank/src/org/lispdev/swank/ISwank.java

View file
   void sendQuitDebug(SwankRunnable callBack, String threadId);
   void sendListThreads(SwankRunnable callBack);
 
-  public LispVariable[] getFrameLocals(int frameNum, String threadId,
+  LispVariable[] getFrameLocals(int frameNum, String threadId,
       LispDebugTarget target);
-  public void sendLoadASDF(String asdfile, SwankCompilationRunnable callback);
+  void sendLoadASDF(String asdfile, SwankCompilationRunnable callback);
+  void sendCompileFile(String filePath,
+      SwankCompilationRunnable callBack);
 
   /*
    * To be used only in LispImplementation:
    */
-  public LispNode getInspectFrameLocal(String threadNum,
+  LispNode getInspectFrameLocal(String threadNum,
       String frameNum, String varNum, long timeout);
-  public LispNode inspectNthPart(String partNum, long timeout);
-  public LispNode inspectReplResult(String id, long timeout);
+  LispNode inspectNthPart(String partNum, long timeout);
+  LispNode inspectReplResult(String id, long timeout);
 
 }

File org.lispdev.swank/src/org/lispdev/swank/SwankInterface.java

View file
   }
 
   public synchronized void sendCompileFile(String filePath,
-      SwankRunnable callBack)
+      SwankCompilationRunnable callBack)
   {
     filePath = filePath.replace('\\', '/');
     filePath = swank.translateLocalFilePath(filePath);

File org.lispdev.swank/src/org/lispdev/swank/SwankInterfaceTest.java

View file
   @Test
   public void test_compileFile()
   {
-    final SwankRunnable callBack = new SwankRunnable(si.getLispImplementation()){
+    final SwankCompilationRunnable callBack = new SwankCompilationRunnable(si.getLispImplementation()){
       @Override
       public void run()
       {
           this.notifyAll();
         }
       }
-
-      @Override
-      public Object getInfo()
-      {
-        return null;
-      }
     };
     try
     {