Commits

Anonymous committed ca51d07

Added delete compiler outputs action for lisp project.

Comments (0)

Files changed (3)

                menubarPath="group.add"
                style="pulldown">
          </action>
+         <filter
+               name="projectNature"
+               value="org.lispdev.lispNature">
+         </filter>
       </objectContribution>
       <objectContribution
             adaptable="false"
                menubarPath="group.add"
                style="pulldown">
          </action>
+         <filter
+               name="projectNature"
+               value="org.lispdev.lispNature">
+         </filter>
+      </objectContribution>
+      <objectContribution
+            id="org.lispdev.main.DeleteCompilerOutputs.folder"
+            objectClass="org.eclipse.core.resources.IProject">
+         <action
+               class="org.lispdev.main.DeleteCompilerOutputs"
+               enablesFor="1"
+               icon="icons/clear.gif"
+               id="org.lispdev.main.DeleteCompilerOutputs"
+               label="Delete Compiler Outputs"
+               menubarPath="group.add">
+         </action>
+         <filter
+               name="projectNature"
+               value="org.lispdev.lispNature">
+         </filter>
       </objectContribution>
    </extension>
    <extension

src/org/lispdev/main/AssociateProjectAction.java

 package org.lispdev.main;
 
 import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.ActionContributionItem;
 import org.eclipse.jface.action.IAction;
 public class AssociateProjectAction
 implements IObjectActionDelegate, IMenuCreator
 {
-  private IWorkbenchPart part;
   private IAction action;
   private IProject project;
 
     if( selection instanceof TreeSelection )
     {
       Object obj = ((TreeSelection)selection).getFirstElement();
-      try
-      {
-        if(obj instanceof IProject
-            && ((IProject)obj).getNature(LispProjectNature.ID) != null )
-        {
-          project = (IProject)obj;
-          action.setEnabled(true);
-        }
-        else
-        {
-          action.setEnabled(false);
-        }
-      }
-      catch(CoreException e)
-      {
-        action.setEnabled(false);
-      }
+      project = (IProject)( obj instanceof IProject ? obj : null);
     }
     else
     {
-      action.setEnabled(false);
+      project = null;
     }
   }
 
   @Override
   public Menu getMenu(Menu parent)
   {
+    if( project == null )
+    {
+      return null;
+    }
     Menu menu = new Menu(parent);
     for( LispProcess p : SwankPlugin.get().getProcesses() )
     {
 
   @Override
   public void setActivePart(IAction action, IWorkbenchPart targetPart)
-  {
-    part = targetPart;
-  }
+  {}
 
 }

src/org/lispdev/main/DeleteCompilerOutputs.java

+package org.lispdev.main;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+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
+{
+  IStructuredSelection selection;
+
+  @Override
+  public void run(IAction action)
+  {
+    if( selection != null && selection.size() == 1 )
+    {
+      Object obj = selection.getFirstElement();
+      if( obj instanceof IProject )
+      {
+        final IProject project = (IProject)obj;
+        if( project.isOpen() )
+        {
+          IRunnableWithProgress op = new IRunnableWithProgress(){
+            public void run(IProgressMonitor monitor)
+                throws InvocationTargetException
+            {
+              monitor.beginTask("Deleting fasls...", 10);
+              try
+              {
+                project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+              }
+              catch(CoreException e)
+              {
+                e.printStackTrace();
+              }
+              monitor.worked(2);
+              cleanFasls(project, monitor);
+              monitor.done();
+            }
+          };
+          try
+          {
+            LispPlugin.get().getWorkbench().getProgressService()
+              .run(true, false, op);
+          }
+          catch(InvocationTargetException e)
+          {
+            e.printStackTrace();
+          }
+          catch(InterruptedException e)
+          {
+            e.printStackTrace();
+          }
+        }
+      }
+    }
+  }
+
+  private void cleanFasls(IContainer folder, IProgressMonitor monitor)
+  {
+    if( folder.exists() )
+    {
+      try
+      {
+        for(IResource resource : folder.members())
+        {
+          if( resource instanceof IContainer )
+          {
+            cleanFasls((IContainer)resource, monitor);
+          }
+          else if( resource instanceof IFile )
+          {
+            IFile file = (IFile)resource;
+            String fname = file.getName();
+
+            LispProcess process =
+              LispPlugin.get().getActiveProcess(file.getProject());
+
+            if( process == null )
+            {
+              return;
+            }
+            if( file.exists() &&
+                process.getSwank().getLispImplementation().isCompilerOutput(fname) )
+            {
+              file.delete(true, monitor);
+            }
+          }
+        }
+      }
+      catch(CoreException e)
+      {
+        e.printStackTrace();
+      }
+    }
+  }
+
+  @Override
+  public void selectionChanged(IAction action, ISelection selection)
+  {
+    if( selection instanceof IStructuredSelection )
+    {
+      this.selection = (IStructuredSelection)selection;
+    }
+  }
+
+  @Override
+  public void setActivePart(IAction action, IWorkbenchPart targetPart)
+  {
+  }
+
+}