6
6
import it .baeyens .arduino .tools .ArduinoHelpers ;
7
7
import it .baeyens .arduino .tools .ShouldHaveBeenInCDT ;
8
8
import it .baeyens .arduino .tools .Stream ;
9
- import it .baeyens .arduino .tools .DiskStream ;
10
9
import it .baeyens .arduino .ui .BuildConfigurationsPage .ConfigurationDescriptor ;
11
10
12
11
import java .io .File ;
13
- import java .io .InputStream ;
14
12
import java .lang .reflect .InvocationTargetException ;
15
13
import java .net .URI ;
16
14
import java .util .ArrayList ;
59
57
*/
60
58
public class NewArduinoSketchWizard extends Wizard implements INewWizard , IExecutableExtension {
61
59
62
- private WizardNewProjectCreationPage mWizardPage ; // first page of the dialog
63
- private SketchTemplatePage mSketchTemplatePage ; // add the folder for the templates
64
- private ArduinoSettingsPage mArduinoPage ; // add Arduino board and comp port
65
- private BuildConfigurationsPage mBuildCfgPage ; // build the configuration
60
+ private WizardNewProjectCreationPage mWizardPage ; // first page of the dialog
61
+ private SketchTemplatePage mSketchTemplatePage ; // add the folder for the templates
62
+ private ArduinoSettingsPage mArduinoPage ; // add Arduino board and comp port
63
+ private BuildConfigurationsPage mBuildCfgPage ; // build the configuration
66
64
private IConfigurationElement mConfig ;
67
65
private IProject mProject ;
68
66
@@ -84,31 +82,32 @@ public void addPages() {
84
82
mWizardPage .setDescription ("Create a new Arduino sketch." );
85
83
mWizardPage .setTitle ("New Arduino sketch" );
86
84
//
87
- // settings for template file location
88
- //
89
- mSketchTemplatePage = new SketchTemplatePage ("Sketch Template location" );
90
- mSketchTemplatePage .setTitle ("Provide the sketch template folder" );
91
- mSketchTemplatePage .setDescription ("The folder must contain a sketch.cpp and sketch.h" );
92
- //
93
85
// settings for Arduino board etc
94
86
//
95
87
mArduinoPage = new ArduinoSettingsPage ("Arduino information" );
96
88
mArduinoPage .setTitle ("Provide the Arduino information." );
97
89
mArduinoPage .setDescription ("These settings can be changed later." );
98
90
//
91
+ // settings for template file location
92
+ //
93
+ mSketchTemplatePage = new SketchTemplatePage ("Sketch Template location" );
94
+ mSketchTemplatePage .setTitle ("Provide the sketch template folder" );
95
+ mSketchTemplatePage .setDescription ("The folder must contain a sketch.cpp and sketch.h" );
96
+ //
99
97
// configuration page but I haven't seen it
100
98
//
101
99
mBuildCfgPage = new BuildConfigurationsPage ("Build configurations" );
102
100
mBuildCfgPage .setTitle ("Select additional build configurations for this project." );
103
101
mBuildCfgPage .setDescription ("If you are using additional tools you may want one or more of these extra configurations." );
104
102
//
105
103
// actually add the pages to the wizard
106
- ///
104
+ // /
107
105
addPage (mWizardPage );
108
- addPage (mSketchTemplatePage );
109
106
addPage (mArduinoPage );
107
+ addPage (mSketchTemplatePage );
110
108
addPage (mBuildCfgPage );
111
109
}
110
+
112
111
/**
113
112
* this method is required by IWizard otherwise nothing will actually happen
114
113
*/
@@ -171,7 +170,7 @@ protected void execute(IProgressMonitor monitor) throws CoreException {
171
170
return false ;
172
171
}
173
172
//
174
- // so the project is created we can start
173
+ // so the project is created we can start
175
174
//
176
175
mProject = projectHandle ;
177
176
@@ -259,48 +258,35 @@ void createProject(IProjectDescription description, IProject project, IProgressM
259
258
//
260
259
// Create the source files (sketch.cpp and sketch.h)
261
260
//
262
- InputStream cppTemplateFile = null ;
263
- InputStream hTemplateFile = null ;
264
-
261
+ String cppTemplateFile ;
262
+ String hTemplateFile ;
263
+ boolean isfile = true ;
264
+
265
265
if (ArduinoInstancePreferences .getLastUsedDefaultSketchSelection () == true ) {
266
266
//
267
267
// we will use the default sketch.cpp and sketch.h
268
268
//
269
- cppTemplateFile = Stream .openContentStream (project .getName (), "" , "templates/sketch.cpp" );
270
- hTemplateFile = Stream .openContentStream (project .getName (), Include , "templates/sketch.h" );
269
+ cppTemplateFile = "templates/sketch.cpp" ;
270
+ hTemplateFile = "templates/sketch.h" ;
271
+ isfile = false ;
271
272
} else {
272
273
//
273
274
// we are using our own created sketch.cpp and sketch.h. We use a different streaming mechanism
274
275
// here. Standard used relative paths (Stream class). I created a different Class (DiskStream) to
275
276
// handle absolute paths
276
277
//
277
- String folderName = ArduinoInstancePreferences .getLastTemplateFolderName ();
278
- cppTemplateFile = DiskStream .openContentStream (project .getName (), "" , folderName + "\\ sketch.cpp" );
279
- hTemplateFile = DiskStream .openContentStream (project .getName (), Include , folderName + "\\ sketch.h" );
278
+ String folderName = ArduinoInstancePreferences .getLastTemplateFolderName ();
279
+ cppTemplateFile = folderName + "\\ sketch.cpp" ;
280
+ hTemplateFile = folderName + "\\ sketch.h" ;
281
+ isfile = true ;
280
282
}
281
283
//
282
284
// add both files to the project
283
285
//
284
- ArduinoHelpers .addFileToProject (container , new Path (project .getName () + ".cpp" ), cppTemplateFile , monitor );
285
- ArduinoHelpers .addFileToProject (container , new Path (project .getName () + ".h" ), hTemplateFile , monitor );
286
-
287
- // exclude "Librarie/*/?xample from the build
288
- // ICSourceEntry[] folder;
289
- // folder = configurationDescription.getSourceEntries();
290
- // char[][] exclusions = entry.fullExclusionPatternChars();
291
- // CoreModelUtil.isExcluded(project.getFullPath(), exclusions);
292
- // folder[0].
293
- // getResourceDescription(new Path(""), true);
294
- // folder[0].createFilter(IResourceFilterDescription.EXCLUDE_ALL |
295
- // IResourceFilterDescription.FOLDERS, new
296
- // FileInfoMatcherDescription("org.eclipse.core.resources.regexFilterMatcher",
297
- // "Librarie/*/?xample"), IResource.BACKGROUND_REFRESH, monitor);
298
-
299
- // IFile file = project.getFile("Librarie/*/?xample");
300
- // Object activeConfig;
301
- // IResourceConfiguration ResConfig = configurationDescription.
302
- // .createResourceConfiguration(file);
303
- // ResConfig.setExclude(true);
286
+ ArduinoHelpers .addFileToProject (container , new Path (project .getName () + ".cpp" ),
287
+ Stream .openContentStream (project .getName (), Include , cppTemplateFile , isfile ), monitor );
288
+ ArduinoHelpers .addFileToProject (container , new Path (project .getName () + ".h" ),
289
+ Stream .openContentStream (project .getName (), Include , hTemplateFile , isfile ), monitor );
304
290
305
291
ICResourceDescription cfgd = defaultConfigDescription .getResourceDescription (new Path ("" ), true );
306
292
ICExclusionPatternPathEntry [] entries = cfgd .getConfiguration ().getSourceEntries ();
@@ -322,22 +308,6 @@ void createProject(IProjectDescription description, IProject project, IProgressM
322
308
// this should not happen
323
309
}
324
310
325
- // private void saveData() {
326
- // ICExclusionPatternPathEntry[] p = new
327
- // ICExclusionPatternPathEntry[src.size()];
328
- // Iterator<_Entry> it = src.iterator();
329
- // int i=0;
330
- // while(it.hasNext()) { p[i++] = (it.next()).ent; }
331
- // setEntries(cfgd, p);
332
- // tree.setInput(cfgd);
333
- // updateData(cfgd);
334
- // if (page instanceof AbstractPage) {
335
- // ICConfigurationDescription cfgDescription =
336
- // cfgd.getConfiguration();
337
- // ((AbstractPage)page).cfgChanged(cfgDescription);
338
- // }
339
- // }
340
-
341
311
prjDesc .setActiveConfiguration (defaultConfigDescription );
342
312
prjDesc .setCdtProjectCreated ();
343
313
CoreModel .getDefault ().getProjectDescriptionManager ().setProjectDescription (project , prjDesc , true , null );
0 commit comments