Skip to content

Commit 0438a64

Browse files
committed
Improvement for #367
Added the number of included examples Checked the parents so the preselected are easier to find Tried to open the selected but that does not work when at the 3th level
1 parent d24b24d commit 0438a64

File tree

3 files changed

+113
-186
lines changed

3 files changed

+113
-186
lines changed

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

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ public NewSketchWizard() {
8888

8989
@Override
9090
/**
91-
* adds pages to the wizard. We are using the standard project wizard of
92-
* Eclipse
91+
* adds pages to the wizard. We are using the standard project wizard of Eclipse
9392
*/
9493
public void addPages() {
9594
//
@@ -109,11 +108,9 @@ public void addPages() {
109108
//
110109
// settings for template file location
111110
//
112-
this.mNewArduinoSketchWizardCodeSelectionPage = new NewSketchWizardCodeSelectionPage(
113-
Messages.ui_new_sketch_sketch_template_location);
111+
this.mNewArduinoSketchWizardCodeSelectionPage = new NewSketchWizardCodeSelectionPage(Messages.ui_new_sketch_sketch_template_location);
114112
this.mNewArduinoSketchWizardCodeSelectionPage.setTitle(Messages.ui_new_sketch_sketch_template_folder);
115-
this.mNewArduinoSketchWizardCodeSelectionPage
116-
.setDescription(Messages.ui_new_sketch_error_folder_must_contain_sketch_cpp);
113+
this.mNewArduinoSketchWizardCodeSelectionPage.setDescription(Messages.ui_new_sketch_error_folder_must_contain_sketch_cpp);
117114
//
118115
// configuration page but I haven't seen it
119116
//
@@ -170,8 +167,7 @@ public boolean performFinish() {
170167
desc.setLocationURI(projectURI);
171168

172169
/*
173-
* Just like the ExampleWizard, but this time with an operation
174-
* object that modifies workspaces.
170+
* Just like the ExampleWizard, but this time with an operation object that modifies workspaces.
175171
*/
176172
WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
177173
@Override
@@ -184,9 +180,7 @@ protected void execute(IProgressMonitor monitor) throws CoreException {
184180
};
185181

186182
/*
187-
* This isn't as robust as the code in the
188-
* BasicNewProjectResourceWizard class. Consider beefing this up to
189-
* improve error handling.
183+
* This isn't as robust as the code in the BasicNewProjectResourceWizard class. Consider beefing this up to improve error handling.
190184
*/
191185
getContainer().run(false, true, op);
192186
} catch (InterruptedException e) {
@@ -224,8 +218,7 @@ protected void execute(IProgressMonitor monitor) throws CoreException {
224218
* @param monitor
225219
* @throws OperationCanceledException
226220
*/
227-
void createProject(IProjectDescription description, IProject project, IProgressMonitor monitor)
228-
throws OperationCanceledException {
221+
void createProject(IProjectDescription description, IProject project, IProgressMonitor monitor) throws OperationCanceledException {
229222

230223
monitor.beginTask(Const.EMPTY_STRING, 2000);
231224
try {
@@ -242,8 +235,7 @@ void createProject(IProjectDescription description, IProject project, IProgressM
242235
ArrayList<ConfigurationDescriptor> cfgNamesAndTCIds = this.mBuildCfgPage.getBuildConfigurationDescriptors();
243236

244237
// Creates the .cproject file with the configurations
245-
ICProjectDescription prjCDesc = ShouldHaveBeenInCDT.setCProjectDescription(project, cfgNamesAndTCIds, true,
246-
monitor);
238+
ICProjectDescription prjCDesc = ShouldHaveBeenInCDT.setCProjectDescription(project, cfgNamesAndTCIds, true, monitor);
247239

248240
// Add the C C++ AVR and other needed Natures to the project
249241
Helpers.addTheNatures(description);
@@ -252,11 +244,9 @@ void createProject(IProjectDescription description, IProject project, IProgressM
252244
Helpers.createNewFolder(project, Const.ARDUINO_CODE_FOLDER_NAME, null);
253245

254246
for (int i = 0; i < cfgNamesAndTCIds.size(); i++) {
255-
ICConfigurationDescription configurationDescription = prjCDesc
256-
.getConfigurationByName(cfgNamesAndTCIds.get(i).Name);
247+
ICConfigurationDescription configurationDescription = prjCDesc.getConfigurationByName(cfgNamesAndTCIds.get(i).Name);
257248
this.mArduinoPage.saveAllSelections(configurationDescription);
258-
Helpers.setTheEnvironmentVariables(project, configurationDescription,
259-
cfgNamesAndTCIds.get(i).DebugCompilerSettings);
249+
Helpers.setTheEnvironmentVariables(project, configurationDescription, cfgNamesAndTCIds.get(i).DebugCompilerSettings);
260250
}
261251

262252
// Set the path variables
@@ -265,8 +255,7 @@ void createProject(IProjectDescription description, IProject project, IProgressM
265255
// Intermediately save or the adding code will fail
266256
// Release is the active config (as that is the "IDE" Arduino
267257
// type....)
268-
ICConfigurationDescription defaultConfigDescription = prjCDesc
269-
.getConfigurationByName(cfgNamesAndTCIds.get(0).Name);
258+
ICConfigurationDescription defaultConfigDescription = prjCDesc.getConfigurationByName(cfgNamesAndTCIds.get(0).Name);
270259
prjCDesc.setActiveConfiguration(defaultConfigDescription);
271260

272261
// Insert The Arduino Code
@@ -278,13 +267,8 @@ void createProject(IProjectDescription description, IProject project, IProgressM
278267
// add the correct files to the project
279268
//
280269
this.mNewArduinoSketchWizardCodeSelectionPage.createFiles(project, monitor);
281-
//
282-
// add the libraries to the project if needed
283-
//
284-
this.mNewArduinoSketchWizardCodeSelectionPage.importLibraries(project, prjCDesc.getActiveConfiguration());
285270

286-
ICResourceDescription cfgd = defaultConfigDescription.getResourceDescription(new Path(Const.EMPTY_STRING),
287-
true);
271+
ICResourceDescription cfgd = defaultConfigDescription.getResourceDescription(new Path(Const.EMPTY_STRING), true);
288272
ICExclusionPatternPathEntry[] entries = cfgd.getConfiguration().getSourceEntries();
289273
if (entries.length == 1) {
290274
Path exclusionPath[] = new Path[5];
@@ -312,8 +296,7 @@ void createProject(IProjectDescription description, IProject project, IProgressM
312296
// set warning levels default on
313297
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
314298
IContributedEnvironment contribEnv = envManager.getContributedEnvironment();
315-
IEnvironmentVariable var = new EnvironmentVariable(Const.ENV_KEY_JANTJE_WARNING_LEVEL,
316-
Const.ENV_KEY_WARNING_LEVEL_ON);
299+
IEnvironmentVariable var = new EnvironmentVariable(Const.ENV_KEY_JANTJE_WARNING_LEVEL, Const.ENV_KEY_WARNING_LEVEL_ON);
317300
contribEnv.addVariable(var, cfgd.getConfiguration());
318301

319302
prjCDesc.setActiveConfiguration(defaultConfigDescription);
@@ -323,8 +306,7 @@ void createProject(IProjectDescription description, IProject project, IProgressM
323306
monitor.done();
324307

325308
} catch (CoreException e) {
326-
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
327-
Messages.ui_new_sketch_error_failed_to_create_project + project.getName(), e));
309+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.ui_new_sketch_error_failed_to_create_project + project.getName(), e));
328310
throw new OperationCanceledException();
329311
}
330312

@@ -336,8 +318,7 @@ public void init(IWorkbench workbench, IStructuredSelection selection) {
336318
}
337319

338320
@Override
339-
public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
340-
throws CoreException {
321+
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
341322
// snipped...
342323
this.mConfig = config;
343324

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

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.File;
44
import java.io.IOException;
55

6-
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
76
import org.eclipse.core.resources.IProject;
87
import org.eclipse.core.runtime.CoreException;
98
import org.eclipse.core.runtime.IPath;
@@ -13,7 +12,6 @@
1312
import org.eclipse.jface.resource.ImageDescriptor;
1413
import org.eclipse.jface.wizard.WizardPage;
1514
import org.eclipse.swt.SWT;
16-
import org.eclipse.swt.layout.GridData;
1715
import org.eclipse.swt.layout.GridLayout;
1816
import org.eclipse.swt.widgets.Button;
1917
import org.eclipse.swt.widgets.Composite;
@@ -29,9 +27,8 @@
2927
public class NewSketchWizardCodeSelectionPage extends WizardPage {
3028

3129
final Shell shell = new Shell();
32-
private final int ncol = 4;
33-
String[] codeOptions = { Messages.ui_new_sketch_default_ino, Messages.ui_new_sketch_default_cpp,
34-
Messages.ui_new_sketch_custom_template, Messages.ui_new_sketch_sample_sketch };
30+
String[] codeOptions = { Messages.ui_new_sketch_default_ino, Messages.ui_new_sketch_default_cpp, Messages.ui_new_sketch_custom_template,
31+
Messages.ui_new_sketch_sample_sketch };
3532
private static final int defaultIno = 0;
3633
private static final int defaultCPP = 1;
3734
private static final int CustomTemplate = 2;
@@ -70,18 +67,11 @@ public void createControl(Composite parent) {
7067

7168
Composite composite = new Composite(parent, SWT.NULL);
7269
this.mParentComposite = composite;
73-
GridLayout theGridLayout; // references the layout
74-
GridData theGriddata; // references a grid
7570

76-
//
77-
// create the grid layout and add it to the composite
78-
//
79-
theGridLayout = new GridLayout();
80-
theGridLayout.numColumns = this.ncol; // 4 columns
71+
GridLayout theGridLayout = new GridLayout();
72+
theGridLayout.numColumns = 4;
8173
composite.setLayout(theGridLayout);
82-
//
83-
// check box Use default
84-
//
74+
8575
Listener comboListener = new Listener() {
8676

8777
@Override
@@ -91,19 +81,20 @@ public void handleEvent(Event event) {
9181

9282
}
9383
};
94-
this.mCodeSourceOptionsCombo = new LabelCombo(composite, Messages.ui_new_sketch_selecy_code, this.ncol,
95-
Const.EMPTY_STRING, true);
84+
this.mCodeSourceOptionsCombo = new LabelCombo(composite, Messages.ui_new_sketch_selecy_code, 4, Const.EMPTY_STRING, true);
9685
this.mCodeSourceOptionsCombo.addListener(comboListener);
9786

9887
this.mCodeSourceOptionsCombo.setItems(this.codeOptions);
9988

10089
this.mTemplateFolderEditor = new DirectoryFieldEditor("temp1", Messages.ui_new_sketch_custom_template_location, //$NON-NLS-1$
10190
composite);
102-
this.mExampleEditor = new SampleSelector(composite, SWT.NONE,
103-
Messages.ui_new_sketch_select_example_code);
104-
// GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
105-
// gd.horizontalSpan = ncol;
106-
// mExampleEditor.setLayoutData(gd);
91+
92+
this.mExampleEditor = new SampleSelector(composite, SWT.FILL, Messages.ui_new_sketch_select_example_code, 4);
93+
// GridData theGriddata = new GridData();
94+
// theGriddata.horizontalSpan = 4;// (ncol - 1);
95+
// theGriddata.horizontalAlignment = SWT.FILL;
96+
// this.mExampleEditor.setLayoutData(theGriddata);
97+
10798
this.mExampleEditor.addchangeListener(new Listener() {
10899

109100
@Override
@@ -118,12 +109,6 @@ public void handleEvent(Event event) {
118109

119110
this.mCheckBoxUseCurrentLinkSample = new Button(composite, SWT.CHECK);
120111
this.mCheckBoxUseCurrentLinkSample.setText(Messages.ui_new_sketch_link_to_sample_code);
121-
theGriddata = new GridData();
122-
theGriddata.horizontalSpan = this.ncol;
123-
theGriddata.horizontalAlignment = SWT.LEAD;
124-
theGriddata.grabExcessHorizontalSpace = false;
125-
this.mCheckBoxUseCurrentLinkSample.setLayoutData(theGriddata);
126-
//
127112

128113
//
129114
// End of special controls
@@ -139,8 +124,7 @@ public void handleEvent(Event event) {
139124
}
140125

141126
/**
142-
* @name SetControls() Enables or disables the controls based on the
143-
* Checkbox settings
127+
* @name SetControls() Enables or disables the controls based on the Checkbox settings
144128
*/
145129
protected void SetControls() {
146130
switch (this.mCodeSourceOptionsCombo.mCombo.getSelectionIndex()) {
@@ -170,8 +154,7 @@ protected void SetControls() {
170154
}
171155

172156
/**
173-
* @name validatePage() Check if the user has provided all the info to
174-
* create the project. If so enable the finish button.
157+
* @name validatePage() Check if the user has provided all the info to create the project. If so enable the finish button.
175158
*/
176159
protected void validatePage() {
177160
switch (this.mCodeSourceOptionsCombo.mCombo.getSelectionIndex()) {
@@ -197,8 +180,7 @@ protected void validatePage() {
197180
}
198181

199182
/**
200-
* @name restoreAllSelections() Restore all necessary variables into the
201-
* respective controls
183+
* @name restoreAllSelections() Restore all necessary variables into the respective controls
202184
*/
203185
private void restoreAllSelections() {
204186
//
@@ -209,14 +191,12 @@ private void restoreAllSelections() {
209191
//
210192
this.mTemplateFolderEditor.setStringValue(InstancePreferences.getLastTemplateFolderName());
211193
this.mCodeSourceOptionsCombo.mCombo.select(InstancePreferences.getLastUsedDefaultSketchSelection());
212-
this.mExampleEditor.setLastUsedExamples();
213194
}
214195

215196
public void createFiles(IProject project, IProgressMonitor monitor) throws CoreException {
216197

217198
InstancePreferences.setLastTemplateFolderName(this.mTemplateFolderEditor.getStringValue());
218-
InstancePreferences
219-
.setLastUsedDefaultSketchSelection(this.mCodeSourceOptionsCombo.mCombo.getSelectionIndex());
199+
InstancePreferences.setLastUsedDefaultSketchSelection(this.mCodeSourceOptionsCombo.mCombo.getSelectionIndex());
220200
this.mExampleEditor.saveLastUsedExamples();
221201

222202
String Include = "Arduino.h"; //$NON-NLS-1$
@@ -245,8 +225,7 @@ public void createFiles(IProject project, IProgressMonitor monitor) throws CoreE
245225
Stream.openContentStream(project.getName(), Include, inoFile.toString(), true), monitor);
246226
} else {
247227
Helpers.addFileToProject(project, new Path(project.getName() + ".cpp"), //$NON-NLS-1$
248-
Stream.openContentStream(project.getName(), Include, cppTemplateFile.toString(), true),
249-
monitor);
228+
Stream.openContentStream(project.getName(), Include, cppTemplateFile.toString(), true), monitor);
250229
Helpers.addFileToProject(project, new Path(project.getName() + ".h"), //$NON-NLS-1$
251230
Stream.openContentStream(project.getName(), Include, hTemplateFile.toString(), true), monitor);
252231
}
@@ -272,21 +251,4 @@ public void AddAllExamples() {
272251

273252
}
274253

275-
public void importLibraries(IProject project, ICConfigurationDescription configurationDescription) {
276-
switch (this.mCodeSourceOptionsCombo.mCombo.getSelectionIndex()) {
277-
case defaultIno:
278-
case defaultCPP:
279-
case CustomTemplate:
280-
// no need to attach libraries here
281-
break;
282-
case sample:
283-
this.mExampleEditor.importSelectedLibraries(project, configurationDescription);
284-
break;
285-
default:
286-
287-
break;
288-
}
289-
290-
}
291-
292254
}

0 commit comments

Comments
 (0)