[Pydev-cvs] org.python.pydev/src/org/python/pydev/ui/actions/container PyDeleteErrors.java, NONE,
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-10-03 00:44:10
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/ui/actions/container In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv10036/src/org/python/pydev/ui/actions/container Modified Files: PyDeletePycAndClassFiles.java Added Files: PyDeleteErrors.java PyContainerAction.java Log Message: Synching with aptana svn repo for release 1.3.22 (see http://pydev.sourceforge.net/developers.html) Index: PyDeletePycAndClassFiles.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/ui/actions/container/PyDeletePycAndClassFiles.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PyDeletePycAndClassFiles.java 14 Jan 2008 00:21:45 -0000 1.2 --- PyDeletePycAndClassFiles.java 3 Oct 2008 00:43:54 -0000 1.3 *************** *** 1,8 **** package org.python.pydev.ui.actions.container; - import java.util.ArrayList; - import java.util.Iterator; - import java.util.List; - import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; --- 1,4 ---- *************** *** 11,20 **** import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; - import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.MessageDialog; - import org.eclipse.jface.viewers.ISelection; - import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IObjectActionDelegate; - import org.eclipse.ui.IWorkbenchPart; import org.python.pydev.core.docutils.StringUtils; import org.python.pydev.plugin.PydevPlugin; --- 7,12 ---- *************** *** 25,39 **** * @author Fabio */ ! public class PyDeletePycAndClassFiles implements IObjectActionDelegate { ! ! /** ! * List with the containers the user selected ! */ ! protected List<IContainer> selectedContainers; ! - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - //empty - } /** --- 17,22 ---- * @author Fabio */ ! public class PyDeletePycAndClassFiles extends PyContainerAction implements IObjectActionDelegate { /** *************** *** 44,48 **** * @return the number of files deleted */ ! protected int deletePycFiles(IContainer container) { IProgressMonitor nullProgressMonitor = new NullProgressMonitor(); --- 27,31 ---- * @return the number of files deleted */ ! protected int doActionOnContainer(IContainer container) { IProgressMonitor nullProgressMonitor = new NullProgressMonitor(); *************** *** 53,57 **** for (IResource c:members) { if(c instanceof IContainer){ ! deleted += this.deletePycFiles((IContainer) c); }else if(c instanceof IFile){ --- 36,40 ---- for (IResource c:members) { if(c instanceof IContainer){ ! deleted += this.doActionOnContainer((IContainer) c); }else if(c instanceof IFile){ *************** *** 72,127 **** } ! /** ! * Act on the selection to delete the pyc/$py.class files. ! */ ! public void run(IAction action) { ! //should not happen ! if(selectedContainers == null){ ! return; ! } ! ! if (!MessageDialog.openConfirm(null, "Confirm deletion", "Are you sure that you want to delete the *.pyc and *$py.class files from the selected folder(s)?")){ ! return; ! } ! ! int nDeleted = 0; ! IProgressMonitor nullProgressMonitor = new NullProgressMonitor(); ! ! for (Iterator<IContainer> iter = this.selectedContainers.iterator(); iter.hasNext();) { ! IContainer next = iter.next(); ! //as files are generated externally, if we don't refresh, it's very likely that we won't delete a bunch of files. ! try { ! next.refreshLocal(IResource.DEPTH_INFINITE, nullProgressMonitor); ! } catch (Exception e) { ! PydevPlugin.log(e); ! } ! nDeleted += this.deletePycFiles(next); ! } ! ! MessageDialog.openInformation(null, "Files deleted", StringUtils.format("Deleted %s files.", nDeleted)); } ! /** ! * When the selection changes, we've to keep the selected containers... ! */ ! @SuppressWarnings("unchecked") ! public void selectionChanged(IAction action, ISelection selection) { ! if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) { ! selectedContainers = null; ! return; ! } ! ! IStructuredSelection selections = (IStructuredSelection) selection; ! ArrayList<IContainer> containers = new ArrayList<IContainer>(); ! ! for(Iterator<Object> it = selections.iterator(); it.hasNext();){ ! Object o = it.next(); ! if(o instanceof IContainer){ ! containers.add((IContainer) o); ! } ! } ! ! this.selectedContainers = containers; } } --- 55,71 ---- } ! @Override ! protected void afterRun(int deleted) { ! MessageDialog.openInformation(null, "Files deleted", StringUtils.format("Deleted %s files.", deleted)); } ! @Override ! protected boolean confirmRun() { ! return MessageDialog.openConfirm(null, "Confirm deletion", "Are you sure that you want to delete the *.pyc and *$py.class files from the selected folder(s)?"); } + + + + } --- NEW FILE: PyDeleteErrors.java --- package org.python.pydev.ui.actions.container; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.IObjectActionDelegate; import org.python.pydev.plugin.PydevPlugin; /** * Action used to delete the error markers * * @author Fabio */ public class PyDeleteErrors extends PyContainerAction implements IObjectActionDelegate { /** * Deletes the error markers... recursively pass the folders and delete the files (and sum them so that we know how many * files were affected). * * @param container the folder from where we want to remove the markers * @return the number of markers deleted */ protected int doActionOnContainer(IContainer container) { try { container.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { PydevPlugin.log(e); } try{ container.deleteMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); } catch (CoreException e) { PydevPlugin.log(e); } return -1; } @Override protected void afterRun(int deleted) { } @Override protected boolean confirmRun() { return MessageDialog.openConfirm(null, "Confirm deletion", "Are you sure that you want to recursively remove all the markers from the selected folder(s)?"); } } --- NEW FILE: PyContainerAction.java --- package org.python.pydev.ui.actions.container; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IWorkbenchPart; import org.python.pydev.plugin.PydevPlugin; /** * Abstract class for actions that'll act upon the selected containers. * * @author Fabio */ public abstract class PyContainerAction { /** * List with the containers the user selected */ protected List<IContainer> selectedContainers; public void setActivePart(IAction action, IWorkbenchPart targetPart) { //empty } /** * When the selection changes, we've to keep the selected containers... */ @SuppressWarnings("unchecked") public void selectionChanged(IAction action, ISelection selection) { if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) { selectedContainers = null; return; } IStructuredSelection selections = (IStructuredSelection) selection; ArrayList<IContainer> containers = new ArrayList<IContainer>(); for(Iterator<Object> it = selections.iterator(); it.hasNext();){ Object o = it.next(); if(o instanceof IContainer){ containers.add((IContainer) o); } } this.selectedContainers = containers; } /** * Act on the selection to do the needed action (will confirm and make a refresh before executing) */ public void run(IAction action) { //should not happen if(selectedContainers == null){ return; } if (!confirmRun()){ return; } int nDeleted = 0; IProgressMonitor nullProgressMonitor = new NullProgressMonitor(); for (Iterator<IContainer> iter = this.selectedContainers.iterator(); iter.hasNext();) { IContainer next = iter.next(); //as files are generated externally, if we don't refresh, it's very likely that we won't delete a bunch of files. try { next.refreshLocal(IResource.DEPTH_INFINITE, nullProgressMonitor); } catch (Exception e) { PydevPlugin.log(e); } nDeleted += this.doActionOnContainer(next); } afterRun(nDeleted); } /** * @return true if the action should be run and false otherwise */ protected abstract boolean confirmRun() ; /** * Hook for clients to implement after the run is done (useful to show message) * * @param resourcesAffected the number of resources that've been affected. */ protected abstract void afterRun(int resourcesAffected); /** * Executes the action on the container passed * * @param next the container where the action should be executed * @return the number of resources affected in the action */ protected abstract int doActionOnContainer(IContainer next); } |