Anonymous avatar Anonymous committed 7447716

- Refactoring popup actions.
- Adding load file action - not finished.

Comments (0)

Files changed (7)

                menubarPath="group.add">
          </action>
       </objectContribution>
+      <objectContribution
+            adaptable="false"
+            id="org.lispdev.main.LoadLispFileAction.folder"
+            nameFilter="*.lisp"
+            objectClass="org.eclipse.core.resources.IFile">
+         <action
+               class="org.lispdev.main.LoadFileInAction"
+               enablesFor="+"
+               icon="icons/lisp-file.gif"
+               id="org.lispdev.main.LoadLispFileAction"
+               label="Load In"
+               menubarPath="group.add"
+               style="pulldown">
+         </action>
+      </objectContribution>
+      <objectContribution
+            adaptable="false"
+            id="org.lispdev.main.LoadCLFileAction.folder"
+            nameFilter="*.cl"
+            objectClass="org.eclipse.core.resources.IFile">
+         <action
+               class="org.lispdev.main.LoadFileInAction"
+               enablesFor="+"
+               icon="icons/lisp-file.gif"
+               id="org.lispdev.main.LoadCLFileAction"
+               label="Load In"
+               menubarPath="group.add"
+               style="pulldown">
+         </action>
+      </objectContribution>
    </extension>
    <extension
          point="org.eclipse.ui.decorators">

src/org/lispdev/main/AssociateProjectAction.java

 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IMenuCreator;
 import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Menu;
 
   @Override
   public void run(IAction action)
-  {
-  }
+  {}
 
   @Override
   public void selectionChanged(IAction action, ISelection selection)
       action.setMenuCreator(this);
       this.action = action;
     }
-    if( selection instanceof TreeSelection )
+    if( selection instanceof IStructuredSelection )
     {
-      Object obj = ((TreeSelection)selection).getFirstElement();
+      Object obj = ((IStructuredSelection)selection).getFirstElement();
       project = (IProject)( obj instanceof IProject ? obj : null);
     }
     else
 
   @Override
   public void dispose()
-  {
-  }
+  {}
 
   /**
    * Associates project with lisp process p

src/org/lispdev/main/DeleteCompilerOutputs.java

 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
 import org.lispdev.swank.debug.LispProcess;
 
-public class DeleteCompilerOutputs implements IObjectActionDelegate
+public class DeleteCompilerOutputs extends LispPopupAction
 {
-  IStructuredSelection selection;
 
   @Override
   public void run(IAction action)
       }
     }
   }
-
-  @Override
-  public void selectionChanged(IAction action, ISelection selection)
-  {
-    if( selection instanceof IStructuredSelection )
-    {
-      this.selection = (IStructuredSelection)selection;
-    }
-  }
-
-  @Override
-  public void setActivePart(IAction action, IWorkbenchPart targetPart)
-  {
-  }
-
 }

src/org/lispdev/main/LispPopupAction.java

+package org.lispdev.main;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.lispdev.swank.debug.LispProcess;
+
+/**
+ * Action that is available only when the project containing an object
+ * is associated with a lisp
+ */
+public abstract class LispPopupAction implements IObjectActionDelegate
+{
+  protected IWorkbenchPart part;
+  protected IProject project;
+  protected LispProcess process;
+  protected IStructuredSelection selection;
+
+  @Override
+  public void selectionChanged(IAction action, ISelection selection)
+  {
+    project = null;
+    if( selection instanceof IStructuredSelection )
+    {
+      this.selection = (IStructuredSelection)selection;
+    }
+    if( selection instanceof TreeSelection )
+    {
+      Object obj = this.selection.getFirstElement();
+      if( obj instanceof IProject )
+      {
+        project = (IProject)obj;
+      }
+      else if ( obj instanceof IFile )
+      {
+        project = ((IFile)obj).getProject();
+      }
+    }
+    process = LispPlugin.get().getActiveProcess(project);
+    action.setEnabled(process != null);
+  }
+
+  @Override
+  public void setActivePart(IAction action, IWorkbenchPart targetPart)
+  {
+    part = targetPart;
+  }
+
+}

src/org/lispdev/main/LoadFileInAction.java

+package org.lispdev.main;
+
+import org.eclipse.core.resources.IFile;
+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.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.lispdev.swank.SwankPlugin;
+import org.lispdev.swank.debug.LispProcess;
+
+public class LoadFileInAction implements IObjectActionDelegate, IMenuCreator
+{
+  private IAction action;
+  private IStructuredSelection selection;
+
+  @Override
+  public void run(IAction action)
+  {}
+
+  @Override
+  public void selectionChanged(IAction action, ISelection selection)
+  {
+    if( action != this.action )
+    {
+      action.setMenuCreator(this);
+      this.action = action;
+    }
+    if( selection instanceof IStructuredSelection )
+    {
+      this.selection = (IStructuredSelection)selection;
+    }
+    else
+    {
+      this.selection = null;
+    }
+  }
+
+  @Override
+  public void dispose()
+  {}
+
+  @Override
+  public Menu getMenu(Control parent)
+  {
+    return null;
+  }
+
+  @Override
+  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);
+    }
+    return menu;
+  }
+
+  private void loadIn(IStructuredSelection files, LispProcess pr)
+  {
+    if( files == null || pr == null ) return;
+    for( Object obj : files.toList() )
+    {
+      if( obj instanceof IFile )
+      {
+        IFile file = (IFile)obj;
+        String filePath = file.getLocation().toOSString().replace("\\", "\\\\");
+        String command = "(load \"" + filePath + "\")";
+
+        //pr.getSwank().sendEvalAndGrab(command,100000);
+      }
+    }
+  }
+
+  @Override
+  public void setActivePart(IAction action, IWorkbenchPart targetPart)
+  {}
+
+}

src/org/lispdev/main/LoadProjectAction.java

 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IMenuCreator;
 import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.TreeSelection;
+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.lispdev.swank.SwankPlugin;
 import org.lispdev.swank.debug.LispProcess;
 import org.lispdev.swank.runnables.SwankCompilationRunnable;
+import org.lispdev.swank.runnables.SwankCompilationRunnable.CompilationInfo;
+import org.lispdev.swank.runnables.SwankCompilationRunnable.CompileMessage;
 
 public class LoadProjectAction implements IObjectActionDelegate, IMenuCreator
 {
       action.setMenuCreator(this);
       this.action = action;
     }
-    if( selection instanceof TreeSelection )
+    project = null;
+    file = null;
+    if( selection instanceof IStructuredSelection )
     {
-      Object obj = ((TreeSelection)selection).getFirstElement();
-      try
+      Object obj = ((IStructuredSelection)selection).getFirstElement();
+      if(obj instanceof IProject )
       {
-        if(obj instanceof IProject
-            && ((IProject)obj).getNature(LispNature.ID) != null )
-        {
-          project = (IProject)obj;
-          file = null;
-        }
-        else if( obj instanceof IFile
-            && ((IFile)obj).getFileExtension().equals("asd"))
-        {
-          project = null;
-          file = (IFile)obj;
-        }
-        else
-        {
-          project = null;
-          file = null;
-        }
+        project = (IProject)obj;
       }
-      catch(CoreException e)
+      else if( obj instanceof IFile
+          && ((IFile)obj).getFileExtension().equals("asd"))
       {
-        project = null;
-        file = null;
+        file = (IFile)obj;
       }
     }
-    else
-    {
-      project = null;
-      file = null;
-    }
   }
 
   @Override
   public void dispose()
-  {
-  }
+  {}
 
   /**
    * Loads and associates project with lisp process p
           {
             CompilationInfo info = getInfo();
             final IProject proj = asdfile.getProject();
-            for( CompileMessage cm : info.messages )
-            {
-              IPath path = new Path(cm.file);
-              IPath projPath = Platform.getLocation().append(proj.getFullPath());
-              if( projPath.isPrefixOf(path) )
-              {
-                IPath relativePath = path.makeRelativeTo(projPath);
-                IFile file = proj.getFile(relativePath);
-                if( file.exists() && cm.position >= 0 )
-                {
-                  LispMarkers.addMarker(file, cm.position, 1, cm.message,
-                      cm.severity, LispMarkers.COMPILE);
-                }
-                else
-                {
-                  LispMarkers.addMarker((file == null ? proj : file),
-                      cm.message, cm.severity, LispMarkers.COMPILE);
-                }
-              }
-              else
-              {
-                LispMarkers.addMarker(proj,
-                    cm.message, cm.severity, LispMarkers.COMPILE);
-              }
-            }
+            addCompilationMarkers(info, proj);
           }
         });
   }
 
+  public static void addCompilationMarkers(CompilationInfo info,
+      final IProject proj)
+  {
+    for( CompileMessage cm : info.messages )
+    {
+      IPath path = new Path(cm.file);
+      IPath projPath = Platform.getLocation().append(proj.getFullPath());
+      if( projPath.isPrefixOf(path) )
+      {
+        IPath relativePath = path.makeRelativeTo(projPath);
+        IFile file = proj.getFile(relativePath);
+        if( file.exists() && cm.position >= 0 )
+        {
+          LispMarkers.addMarker(file, cm.position, 1, cm.message,
+              cm.severity, LispMarkers.COMPILE);
+        }
+        else
+        {
+          LispMarkers.addMarker((file == null ? proj : file),
+              cm.message, cm.severity, LispMarkers.COMPILE);
+        }
+      }
+      else
+      {
+        LispMarkers.addMarker(proj,
+            cm.message, cm.severity, LispMarkers.COMPILE);
+      }
+    }
+  }
+
   private IFile getAsdFile()
   {
     if( file != null )
           loadIn(getAsdFile(),pr);
         }
       };
-      a.setDescription("Associate project with " + label);
+      a.setDescription("Load project in " + label);
       ActionContributionItem item = new ActionContributionItem(a);
       item.fill(menu, -1);
     }
 ----------------
 
 Frames do not disapear when resumed. Need to close and open tree for them
-to disappear.
+to disappear.
+
+----------------
+
+If just one lisp is opened, default to load etc. in it
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.