From 1685eb24fc6336c9568acf7149c00d71b2d3e48b Mon Sep 17 00:00:00 2001 From: lonnen Date: Fri, 23 Jul 2010 01:24:50 +0000 Subject: [PATCH] Added the start of a wizard that will setup a new processing sketch like the PDE and establish a new project in eclipse for that sketch. All the SWT stuff is done, but no files are actually modified. --- .../META-INF/MANIFEST.MF | 2 +- editor/org.processing.editor/build.properties | 3 +- editor/org.processing.editor/plugin.xml | 8 + .../processing/wizards/NewSketchWizard.java | 49 ++++ .../wizards/NewSketchWizardPage.java | 209 ++++++++++++++++++ 5 files changed, 269 insertions(+), 2 deletions(-) create mode 100644 editor/org.processing.editor/src/org/processing/wizards/NewSketchWizard.java create mode 100644 editor/org.processing.editor/src/org/processing/wizards/NewSketchWizardPage.java diff --git a/editor/org.processing.editor/META-INF/MANIFEST.MF b/editor/org.processing.editor/META-INF/MANIFEST.MF index 65671eaab..65cf2516f 100644 --- a/editor/org.processing.editor/META-INF/MANIFEST.MF +++ b/editor/org.processing.editor/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: org.processing.editor Bundle-SymbolicName: org.processing.editor;singleton:=true -Bundle-Version: 0.0.2 +Bundle-Version: 0.0.3 Bundle-Activator: org.processing.editor.ProcessingEditorPlugin Require-Bundle: org.eclipse.core.runtime, org.eclipse.ui, diff --git a/editor/org.processing.editor/build.properties b/editor/org.processing.editor/build.properties index 8c4fc98bc..73c4ed737 100644 --- a/editor/org.processing.editor/build.properties +++ b/editor/org.processing.editor/build.properties @@ -11,5 +11,6 @@ bin.includes = plugin.xml,\ libs/core.jar,\ libs/ecj.jar,\ libs/jna.jar,\ - libs/pde.jar + libs/pde.jar,\ + src/ source.. = src/ diff --git a/editor/org.processing.editor/plugin.xml b/editor/org.processing.editor/plugin.xml index 530a33bc3..437ef2745 100644 --- a/editor/org.processing.editor/plugin.xml +++ b/editor/org.processing.editor/plugin.xml @@ -74,4 +74,12 @@ natureId="org.processing.editor.processingSketchNature"> + + + + diff --git a/editor/org.processing.editor/src/org/processing/wizards/NewSketchWizard.java b/editor/org.processing.editor/src/org/processing/wizards/NewSketchWizard.java new file mode 100644 index 000000000..d4c598f27 --- /dev/null +++ b/editor/org.processing.editor/src/org/processing/wizards/NewSketchWizard.java @@ -0,0 +1,49 @@ +package org.processing.wizards; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; + +/** + * A wizard to create a new Processing sketch project. + *

+ * Contains a single page the requests the name of the sketch + * and the sketch book folder to put the sketch in. + * + * @author lonnen + */ +public class NewSketchWizard extends Wizard implements INewWizard { + + /** The single page in the wizard */ + private NewSketchWizardPage page; + + /** Constructor */ + public NewSketchWizard(){ + + + } + + public void init(IWorkbench workbench, IStructuredSelection selection) { + // init code + } + + /** + * Called when the 'Finish' button is pressed in the wizard. + */ + public boolean performFinish() { + // shit it down + return true; + } + + /** + * Initializes the single page and adds it to the wizard. + */ + public void addPages(){ + setWindowTitle("New Sketch Wizard"); + page = new NewSketchWizardPage(); + + addPage(page); + } + +} diff --git a/editor/org.processing.editor/src/org/processing/wizards/NewSketchWizardPage.java b/editor/org.processing.editor/src/org/processing/wizards/NewSketchWizardPage.java new file mode 100644 index 000000000..9b9d496a5 --- /dev/null +++ b/editor/org.processing.editor/src/org/processing/wizards/NewSketchWizardPage.java @@ -0,0 +1,209 @@ +package org.processing.wizards; + +import java.io.File; + +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + + +public class NewSketchWizardPage extends WizardPage { + + /** field containg the name of the sketch to be created */ + private Text sketchNameField; + /** field containing path of the sketch book folder that will contain the sketch */ + private Text sketchbookPathField; // TODO get the default from the plugin preferences + /** the actual path of the sketch book folder */ + private IPath initialSketchbookPath; + + public NewSketchWizardPage() { + super("selectFiles"); + setTitle("New Sketch Wizard"); + setDescription("Create a new Processing Sketch"); + } + + public void createControl(Composite parent) { + Composite container = new Composite(parent, SWT.NULL); + final GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 3; + container.setLayout(gridLayout); + setControl(container); + + final Label label = new Label(container, SWT.NONE); + final GridData gridData = new GridData(); + gridData.horizontalSpan = 3; + label.setLayoutData(gridData); + label.setText("Select a name for the new sketch."); + + final Label label_1 = new Label(container, SWT.NONE); + final GridData gridData_1 = new GridData(GridData.HORIZONTAL_ALIGN_END); + label_1.setLayoutData(gridData_1); + label_1.setText("Sketch Name:"); + + sketchNameField = new Text(container, SWT.BORDER); + sketchNameField.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e){ + updatePageComplete(); + } + }); + sketchNameField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + final Label label_2 = new Label(container, SWT.NONE); + final GridData gridData_2 = new GridData(); + gridData_2.horizontalSpan = 3; + label_2.setLayoutData(gridData_2); + + final Label label_3 = new Label(container, SWT.NONE); + final GridData gridData_3 = new GridData(); + gridData_3.horizontalSpan = 3; + label_3.setLayoutData(gridData_3); + label_3.setLayoutData(gridData_3); + label_3.setText("Select the sketchbook folder that will contain the sketch:"); + + final Label label_4 = new Label(container, SWT.NONE); + final GridData gridData_4 = new GridData(); + gridData_4.horizontalIndent = 20; + label_4.setLayoutData(gridData_4); + label_4.setText("Sketchbook Folder:"); + + sketchbookPathField = new Text(container, SWT.BORDER); + sketchbookPathField.addModifyListener( + new ModifyListener() { + public void modifyText(ModifyEvent e){ + updatePageComplete(); + } + }); + sketchbookPathField.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); + + final Button button_1 = new Button(container, SWT.NONE); + button_1.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e){browseForDestinationFolder(); + } + }); + button_1.setText("Browse..."); + + initContents(); + } + + /** initialize the contents of the sketch book path */ + private void initContents() { + if (initialSketchbookPath == null){ + setPageComplete(false); + return; + } + // see if the sketchbook path has been set in the prefs +// IPreferenceStore prefs = ProcessingEditorPlugin.getDefault().getPreferenceStore(); +// +// IPath rootLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation(); + + } + + /** + * Browse button functionality to find a destination folder + *

+ * Prettifies the file path if it happens to be in the workspace + */ + protected void browseForDestinationFolder() { + IPath path = browse(getSketchbookLoc()); + if (path == null) + return; + IPath rootLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation(); + if (rootLoc.isPrefixOf(path)) + path = path.setDevice(null).removeFirstSegments(rootLoc.segmentCount()); + sketchbookPathField.setText(path.toString()); + } + + /** + * Sets up a dialog box allowing you to select a directory to use for the sketchbook + * + * @param path the path to be investigated + * @return the path chosen in the dialog box + */ + private IPath browse(IPath path){ + DirectoryDialog dialog = new DirectoryDialog(getShell()); + if (path != null){ + if(path.segmentCount() > 1) + dialog.setFilterPath(path.toOSString()); + } + String result = dialog.open(); + if (result == null) + return null; + return new Path(result); + } + + /** + * Verifies that the sketchbook path exists and does not already contain a sketch with that name. + */ + private void updatePageComplete() { + setPageComplete(false); + + // check the sketchbook path first + IPath sketchbookLoc = getSketchbookLoc(); + if (sketchbookLoc == null || !sketchbookLoc.toFile().exists()){ + setMessage(null); + setErrorMessage("Please specify a sketchbook folder."); + return; + } + + // ensure the sketch isn't already present in the sketchbook + String sketchName = getSketchName(); + System.out.println(sketchName); + for( File child : sketchbookLoc.toFile().listFiles()){ + if (child.isDirectory() && child.getName().equals(sketchName)){ + System.out.println(child.getName() + " is a conflict!"); + setMessage(null); + setErrorMessage("A sketch with that name already exists. Please choose another."); + return; + } + } + + // if nothing was caught, enable the finish button + setPageComplete(true); + setMessage(null); + setErrorMessage(null); + } + + /** + * Trims and returns the sketchNameField contents + * + * @return the contents of the sketchNameField as a string or null + */ + private String getSketchName() { + String text = sketchNameField.getText().trim(); + if (text.length() == 0) + return null; + return text; + } + + /** + * Tries to resolve the contents of the sketch book path field to an IPath, and returns it. + * If the field contains a relative path it will be resolved relative to the Eclipse workspace folder. + * + * @return an absolute IPath handle to the contents of the sketchbookPathField or null + */ + private IPath getSketchbookLoc() { + String text = sketchbookPathField.getText().trim(); + if (text.length() == 0) + return null; + IPath path = new Path(text); + if (!path.isAbsolute()) // relative paths are relative to the Eclipse workspace + path = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(path); + return path; + } + +}