From adb5da842f7a6d44d07bcdcf99dbf7be9703a82d Mon Sep 17 00:00:00 2001 From: lonnen Date: Wed, 28 Jul 2010 00:47:54 +0000 Subject: [PATCH] All known problems not marked with a TODO are resolved. New Processing Sketch wizard creates projects and associates them with the nature / builder. The builder successfully captures change events and rebuilds. The builder writes files to the bin, but doesn't fully compile sketches. --- editor/org.processing.editor/plugin.xml | 3 - .../builder/ProcessingSketchAuditor.java | 3 +- .../builder/ProcessingSketchNature.java | 83 +++++++++++++++++++ .../editor/ProcessingEditorPlugin.java | 2 +- .../processing/wizards/NewSketchWizard.java | 20 ++--- 5 files changed, 93 insertions(+), 18 deletions(-) diff --git a/editor/org.processing.editor/plugin.xml b/editor/org.processing.editor/plugin.xml index 8c1b4d1d8..ab20e83e1 100644 --- a/editor/org.processing.editor/plugin.xml +++ b/editor/org.processing.editor/plugin.xml @@ -57,9 +57,6 @@ - - diff --git a/editor/org.processing.editor/src/org/processing/builder/ProcessingSketchAuditor.java b/editor/org.processing.editor/src/org/processing/builder/ProcessingSketchAuditor.java index 8453820ca..db97920a3 100644 --- a/editor/org.processing.editor/src/org/processing/builder/ProcessingSketchAuditor.java +++ b/editor/org.processing.editor/src/org/processing/builder/ProcessingSketchAuditor.java @@ -49,7 +49,7 @@ import processing.app.preproc.PreprocessResult; */ public class ProcessingSketchAuditor extends IncrementalProjectBuilder { - public static final String BUILDER_ID = ProcessingEditorPlugin.PLUGIN_ID + ".procesingSketchBuilder"; + public static final String BUILDER_ID = ProcessingEditorPlugin.PLUGIN_ID + ".processingSketchBuilder"; /** * Adds the processing builder to a project @@ -157,7 +157,6 @@ public class ProcessingSketchAuditor extends IncrementalProjectBuilder { // incrementalBuild(delta, monitor); // } // } - System.out.println("BUILD!"); // every build is a full build for now, @see incrementalBuild fullBuild(monitor); diff --git a/editor/org.processing.editor/src/org/processing/builder/ProcessingSketchNature.java b/editor/org.processing.editor/src/org/processing/builder/ProcessingSketchNature.java index 4ae46010f..4aefece80 100644 --- a/editor/org.processing.editor/src/org/processing/builder/ProcessingSketchNature.java +++ b/editor/org.processing.editor/src/org/processing/builder/ProcessingSketchNature.java @@ -1,16 +1,23 @@ package org.processing.builder; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IProjectNature; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; +import org.processing.editor.ProcessingEditorPlugin; import org.processing.editor.ProcessingLog; public class ProcessingSketchNature implements IProjectNature { + private static final String NATURE_ID = "org.processing.editor.processingSketchNature"; private IProject project; /** @@ -62,6 +69,82 @@ public class ProcessingSketchNature implements IProjectNature { if (!project.isOpen()) return; + // Get the description + IProjectDescription description; + + try { + description = project.getDescription(); + } + catch (CoreException e){ + ProcessingLog.logError(e); + return; + } + + // If the project already has this nature we're done, otherwise keep going + List newIds = new ArrayList(); + newIds.addAll(Arrays.asList(description.getNatureIds())); + int index = newIds.indexOf(NATURE_ID); + if (index != -1) + return; + + // Add the nature + newIds.add(NATURE_ID); + description.setNatureIds(newIds.toArray(new String[newIds.size()])); + + // Save the description + try { + project.setDescription(description, null); + } catch(CoreException e){ + ProcessingLog.logError(e); + } } + /** + * Tests a project to see if it has the Processing nature + * + * IProject project to test + * returns true if the project has the processing nature + */ + public static boolean hasNature(IProject project){ + try{ + return project.isOpen() && project.hasNature(NATURE_ID); + } catch (CoreException e){ + ProcessingLog.logError(e); + return false; + } + } + + public static void removeNature(IProject project){ + // Cannot modify closed projects + if (!project.isOpen()) + return; + + // Get the description + IProjectDescription description; + try { + description = project.getDescription(); + } catch (CoreException e){ + ProcessingLog.logError(e); + return; + } + + // Determine if the project has the nature + List newIds = new ArrayList(); + newIds.addAll(Arrays.asList(description.getNatureIds())); + int index = newIds.indexOf(NATURE_ID); + if (index == -1) + return; + + // Remove the nature + newIds.remove(index); + description.setNatureIds(newIds.toArray(new String[newIds.size()])); + + // Save the description + try { + project.setDescription(description,null); + } catch (CoreException e){ + ProcessingLog.logError(e); + } + } + } diff --git a/editor/org.processing.editor/src/org/processing/editor/ProcessingEditorPlugin.java b/editor/org.processing.editor/src/org/processing/editor/ProcessingEditorPlugin.java index 45fa8dc55..a1b82285e 100644 --- a/editor/org.processing.editor/src/org/processing/editor/ProcessingEditorPlugin.java +++ b/editor/org.processing.editor/src/org/processing/editor/ProcessingEditorPlugin.java @@ -31,7 +31,7 @@ import org.processing.editor.util.ProcessingColorProvider; */ public class ProcessingEditorPlugin extends AbstractUIPlugin { - public static final String PLUGIN_ID = "org.processing.ProcessingEditor"; + public static final String PLUGIN_ID = "org.processing.editor"; //public static final String JAVA_PARTITIONING= "__java_example_partitioning"; //$NON-NLS-1$ public static final String PROCESSING_PARTITIONING= "__processing_partitioning"; //$NON-NLS-1$ diff --git a/editor/org.processing.editor/src/org/processing/wizards/NewSketchWizard.java b/editor/org.processing.editor/src/org/processing/wizards/NewSketchWizard.java index e52a3bddd..120ac021a 100644 --- a/editor/org.processing.editor/src/org/processing/wizards/NewSketchWizard.java +++ b/editor/org.processing.editor/src/org/processing/wizards/NewSketchWizard.java @@ -17,14 +17,13 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.actions.WorkspaceModifyOperation; -import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; +import org.processing.builder.ProcessingSketchNature; /** * A wizard to create a new Processing sketch project. @@ -38,13 +37,11 @@ public class NewSketchWizard extends Wizard implements INewWizard { /** The single page in the wizard */ private NewSketchWizardPage page; - - private IWorkbench workbench; + /** The project to be created */ private IProject project; /** Constructor */ public NewSketchWizard(){ - // TODO implement the dialog settings stuff // IDialogSettings processingSettings = ProcessingEditorPlugin.getDefault().getDialogSettings(); // IDialogSettings wizardSettings = processingSettings.getSection("NewSketchWizard"); // if (wizardSettings == null) @@ -89,8 +86,6 @@ public class NewSketchWizard extends Wizard implements INewWizard { return false; } - // TODO update Perspective(config); - // TODO re-enable this when the bigger problem is fixed BasicNewResourceWizard.selectAndReveal(project, workbench.getActiveWorkbenchWindow()); return true; } @@ -134,13 +129,14 @@ public class NewSketchWizard extends Wizard implements INewWizard { if (monitor.isCanceled()){throw new OperationCanceledException();} //create the main file - addFileToProject(container, new Path(project.getName() + ".pde"), null, new SubProgressMonitor(monitor, 100)); - - - + addFileToContainer(container, new Path(project.getName() + ".pde"), null, new SubProgressMonitor(monitor, 100)); } finally{ monitor.done(); } + + // this is a new project + ProcessingSketchNature.addNature(proj); + } /** @@ -152,7 +148,7 @@ public class NewSketchWizard extends Wizard implements INewWizard { * @param monitor report the progress back to the user * @throws CoreException if there are problems with the resource */ - private void addFileToProject(IContainer container, Path path, InputStream contentStream, IProgressMonitor monitor) throws CoreException{ + private void addFileToContainer(IContainer container, Path path, InputStream contentStream, IProgressMonitor monitor) throws CoreException{ final IFile file = container.getFile(path); if (contentStream == null){ contentStream = new ByteArrayInputStream(" void setup(){} \n void draw(){} ".getBytes());