Skip to content

Commit 5a9bfca

Browse files
committed
Changed the order of the pages in new sketch wizard; changed default
1 parent 0c03c2d commit 5a9bfca

File tree

5 files changed

+127
-192
lines changed

5 files changed

+127
-192
lines changed

it.baeyens.arduino.common/src/it/baeyens/arduino/common/ArduinoInstancePreferences.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ public static String getGlobalValue(String key) {
6767
}
6868

6969
protected static boolean getGlobalBoolean(String key) {
70+
return getGlobalBoolean(key, false);
71+
}
72+
73+
protected static boolean getGlobalBoolean(String key, boolean def) {
7074
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(NODE_ARDUINO);
71-
return myScope.getBoolean(key, false);
75+
return myScope.getBoolean(key, def);
7276
}
7377

7478
protected static int getGlobalInt(String key) {
@@ -224,22 +228,25 @@ public static void setLastUsedScopeFilter(boolean newFilter) {
224228
setGlobalBoolean(KEY_LAST_USED_SCOPE_FILTER_MENU_OPTION, newFilter);
225229

226230
}
231+
227232
//
228233
// get/set last used "use default sketch location"
229234
//
230-
public static boolean getLastUsedDefaultSketchSelection(){
231-
return getGlobalBoolean(ENV_KEY_SKETCH_TEMPLATE_USE_DEFAULT);
235+
public static boolean getLastUsedDefaultSketchSelection() {
236+
return getGlobalBoolean(ENV_KEY_SKETCH_TEMPLATE_USE_DEFAULT, true);
232237
}
233238

234239
public static void setLastUsedDefaultSketchSelection(boolean newFilter) {
235240
setGlobalBoolean(ENV_KEY_SKETCH_TEMPLATE_USE_DEFAULT, newFilter);
236241
}
242+
237243
//
238244
// get/set last used sketch template folder parameters
239245
//
240246
public static String getLastTemplateFolderName() {
241247
return getGlobalValue(ENV_KEY_SKETCH_TEMPLATE_FOLDER);
242248
}
249+
243250
public static void setLastTemplateFolderName(String folderName) {
244251
setGlobalValue(ENV_KEY_SKETCH_TEMPLATE_FOLDER, folderName);
245252

it.baeyens.arduino.core/src/it/baeyens/arduino/tools/DiskStream.java

Lines changed: 0 additions & 47 deletions
This file was deleted.

it.baeyens.arduino.core/src/it/baeyens/arduino/tools/Stream.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.io.BufferedReader;
77
import java.io.ByteArrayInputStream;
8+
import java.io.FileInputStream;
89
import java.io.IOException;
910
import java.io.InputStream;
1011
import java.io.InputStreamReader;
@@ -23,16 +24,21 @@ public class Stream {
2324
/**
2425
* Initialize the file contents to contents of the given resource.
2526
*/
26-
public static InputStream openContentStream(String title, String Include, String Resource) throws CoreException {
27+
public static InputStream openContentStream(String title, String Include, String Resource, boolean isFile) throws CoreException {
2728

2829
/* We want to be truly OS-agnostic */
2930
final String newline = System.getProperty("line.separator");
3031

3132
String line;
3233
StringBuffer stringBuffer = new StringBuffer();
33-
34+
InputStream input = null;
3435
try {
35-
InputStream input = NewArduinoSketchWizard.class.getResourceAsStream(Resource);
36+
37+
if (isFile) {
38+
input = new FileInputStream(Resource);
39+
} else {
40+
input = NewArduinoSketchWizard.class.getResourceAsStream(Resource);
41+
}
3642
// "templates/index-xhtml-template.resource");
3743
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
3844
try {
@@ -48,9 +54,27 @@ public static InputStream openContentStream(String title, String Include, String
4854
}
4955

5056
} catch (IOException ioe) {
57+
if (input != null) {
58+
try {
59+
input.close();
60+
} catch (IOException e) {
61+
// TODO Auto-generated catch block
62+
e.printStackTrace();
63+
}
64+
}
65+
input = null;
5166
IStatus status = new Status(IStatus.ERROR, "NewFileWizard", IStatus.OK, ioe.getLocalizedMessage(), null);
5267
Common.log(status);
5368
throw new CoreException(status);
69+
} finally {
70+
if (input != null) {
71+
try {
72+
input.close();
73+
} catch (IOException e) {
74+
// TODO Auto-generated catch block
75+
e.printStackTrace();
76+
}
77+
}
5478
}
5579

5680
return new ByteArrayInputStream(stringBuffer.toString().getBytes());

it.baeyens.arduino.core/src/it/baeyens/arduino/ui/NewArduinoSketchWizard.java

Lines changed: 29 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
import it.baeyens.arduino.tools.ArduinoHelpers;
77
import it.baeyens.arduino.tools.ShouldHaveBeenInCDT;
88
import it.baeyens.arduino.tools.Stream;
9-
import it.baeyens.arduino.tools.DiskStream;
109
import it.baeyens.arduino.ui.BuildConfigurationsPage.ConfigurationDescriptor;
1110

1211
import java.io.File;
13-
import java.io.InputStream;
1412
import java.lang.reflect.InvocationTargetException;
1513
import java.net.URI;
1614
import java.util.ArrayList;
@@ -59,10 +57,10 @@
5957
*/
6058
public class NewArduinoSketchWizard extends Wizard implements INewWizard, IExecutableExtension {
6159

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
6664
private IConfigurationElement mConfig;
6765
private IProject mProject;
6866

@@ -84,31 +82,32 @@ public void addPages() {
8482
mWizardPage.setDescription("Create a new Arduino sketch.");
8583
mWizardPage.setTitle("New Arduino sketch");
8684
//
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-
//
9385
// settings for Arduino board etc
9486
//
9587
mArduinoPage = new ArduinoSettingsPage("Arduino information");
9688
mArduinoPage.setTitle("Provide the Arduino information.");
9789
mArduinoPage.setDescription("These settings can be changed later.");
9890
//
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+
//
9997
// configuration page but I haven't seen it
10098
//
10199
mBuildCfgPage = new BuildConfigurationsPage("Build configurations");
102100
mBuildCfgPage.setTitle("Select additional build configurations for this project.");
103101
mBuildCfgPage.setDescription("If you are using additional tools you may want one or more of these extra configurations.");
104102
//
105103
// actually add the pages to the wizard
106-
///
104+
// /
107105
addPage(mWizardPage);
108-
addPage(mSketchTemplatePage);
109106
addPage(mArduinoPage);
107+
addPage(mSketchTemplatePage);
110108
addPage(mBuildCfgPage);
111109
}
110+
112111
/**
113112
* this method is required by IWizard otherwise nothing will actually happen
114113
*/
@@ -171,7 +170,7 @@ protected void execute(IProgressMonitor monitor) throws CoreException {
171170
return false;
172171
}
173172
//
174-
// so the project is created we can start
173+
// so the project is created we can start
175174
//
176175
mProject = projectHandle;
177176

@@ -259,48 +258,35 @@ void createProject(IProjectDescription description, IProject project, IProgressM
259258
//
260259
// Create the source files (sketch.cpp and sketch.h)
261260
//
262-
InputStream cppTemplateFile = null;
263-
InputStream hTemplateFile = null;
264-
261+
String cppTemplateFile;
262+
String hTemplateFile;
263+
boolean isfile = true;
264+
265265
if (ArduinoInstancePreferences.getLastUsedDefaultSketchSelection() == true) {
266266
//
267267
// we will use the default sketch.cpp and sketch.h
268268
//
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;
271272
} else {
272273
//
273274
// we are using our own created sketch.cpp and sketch.h. We use a different streaming mechanism
274275
// here. Standard used relative paths (Stream class). I created a different Class (DiskStream) to
275276
// handle absolute paths
276277
//
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;
280282
}
281283
//
282284
// add both files to the project
283285
//
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);
304290

305291
ICResourceDescription cfgd = defaultConfigDescription.getResourceDescription(new Path(""), true);
306292
ICExclusionPatternPathEntry[] entries = cfgd.getConfiguration().getSourceEntries();
@@ -322,22 +308,6 @@ void createProject(IProjectDescription description, IProject project, IProgressM
322308
// this should not happen
323309
}
324310

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-
341311
prjDesc.setActiveConfiguration(defaultConfigDescription);
342312
prjDesc.setCdtProjectCreated();
343313
CoreModel.getDefault().getProjectDescriptionManager().setProjectDescription(project, prjDesc, true, null);

0 commit comments

Comments
 (0)