Skip to content

Commit 63fd953

Browse files
author
jantje
committed
performance boost open project. Only search for examples when selected
1 parent 27a2497 commit 63fd953

File tree

2 files changed

+37
-34
lines changed

2 files changed

+37
-34
lines changed

io.sloeber.ui/src/io/sloeber/ui/wizard/newsketch/NewSketchWizard.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ public void addPages() {
6767
//
6868
// settings for template file location
6969
//
70-
this.mNewArduinoSketchWizardCodeSelectionPage.setTitle(Messages.ui_new_sketch_sketch_template_folder);
71-
this.mNewArduinoSketchWizardCodeSelectionPage
70+
mNewArduinoSketchWizardCodeSelectionPage.setTitle(Messages.ui_new_sketch_sketch_template_folder);
71+
mNewArduinoSketchWizardCodeSelectionPage
7272
.setDescription(Messages.ui_new_sketch_error_folder_must_contain_sketch_cpp);
73-
73+
mNewArduinoSketchWizardCodeSelectionPage.setSketchWizardPage(mArduinoPage);
7474
//
7575
// actually add the pages to the wizard
7676
//

io.sloeber.ui/src/io/sloeber/ui/wizard/newsketch/NewSketchWizardCodeSelectionPage.java

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.eclipse.swt.widgets.Composite;
1515
import org.eclipse.swt.widgets.Event;
1616
import org.eclipse.swt.widgets.Listener;
17-
import org.eclipse.swt.widgets.Shell;
1817

1918
import io.sloeber.core.api.BoardDescription;
2019
import io.sloeber.core.api.CodeDescription;
@@ -24,33 +23,23 @@
2423

2524
public class NewSketchWizardCodeSelectionPage extends WizardPage {
2625

27-
final Shell shell = new Shell();
26+
// final Shell shell = new Shell();
2827
private Composite myParentComposite = null;
29-
protected LabelCombo myCodeSourceOptionsCombo;
28+
protected LabelCombo myCodeSourceOptionsCombo;
3029
protected DirectoryFieldEditor myTemplateFolderEditor;
3130
protected SampleSelector myExampleEditor = null;
3231
protected Button myCheckBoxUseCurrentLinkSample;
33-
private BoardDescription myBoardDescriptor = null;
32+
private BoardDescription myCurrentBoardDesc = null;
3433
private CodeDescription myCodedescriptor = CodeDescription.createLastUsed();
34+
private NewSketchWizardBoardPage myArduinoPage;
3535

36-
// TOFIX disabled the push boarddescriptor
37-
38-
// public void setBoardDescriptor(BoardDescription boardDescriptor) {
39-
// if (myBoardDescriptor == null) {
40-
// myBoardDescriptor = boardDescriptor;
41-
// }
42-
// handleBoarDescriptorChange();
43-
// }
44-
45-
public void handleBoarDescriptorChange() {
46-
47-
if (myExampleEditor != null) {
48-
myExampleEditor.AddAllExamples(myBoardDescriptor, myCodedescriptor.getExamples());
49-
}
50-
36+
@Override
37+
public void setVisible(boolean visible) {
38+
super.setVisible(visible);
5139
validatePage();
5240
}
5341

42+
5443
public NewSketchWizardCodeSelectionPage(String pageName) {
5544
super(pageName);
5645
setPageComplete(true);
@@ -112,18 +101,16 @@ public void handleEvent(Event event) {
112101
SetControls();// set the controls according to the setting
113102

114103
validatePage();// validate the page
115-
handleBoarDescriptorChange();
116-
117104
setControl(composite);
118105

119106
}
120107

121108
/**
122-
* @name SetControls() Enables or disables the controls based on the
123-
* Checkbox settings
109+
* @name SetControls() Enables or disables the controls based on the Checkbox
110+
* settings
124111
*/
125112
protected void SetControls() {
126-
switch (CodeTypes.values()[Math.max(0, myCodeSourceOptionsCombo.getSelectionIndex())]) {
113+
switch (getCodeType()) {
127114
case None:
128115
myTemplateFolderEditor.setEnabled(false, myParentComposite);
129116
myExampleEditor.setEnabled(false);
@@ -155,14 +142,12 @@ protected void SetControls() {
155142
}
156143

157144
/**
158-
* @name validatePage() Check if the user has provided all the info to
159-
* create the project. If so enable the finish button.
145+
* @name validatePage() Check if the user has provided all the info to create
146+
* the project. If so enable the finish button.
160147
*/
161148
protected void validatePage() {
162-
if (myCodeSourceOptionsCombo == null) {
163-
return;
164-
}
165-
switch (CodeTypes.values()[Math.max(0, myCodeSourceOptionsCombo.getSelectionIndex())]) {
149+
150+
switch (getCodeType()) {
166151
case None:
167152
case defaultIno:
168153
case defaultCPP:
@@ -177,6 +162,12 @@ protected void validatePage() {
177162
setPageComplete(existFile);
178163
break;
179164
case sample:
165+
BoardDescription mySelectedBoardDesc = myArduinoPage.getBoardDescriptor();
166+
if (!mySelectedBoardDesc.equals(myCurrentBoardDesc)) {
167+
myCurrentBoardDesc = new BoardDescription(mySelectedBoardDesc);
168+
myExampleEditor.AddAllExamples(myCurrentBoardDesc, myCodedescriptor.getExamples());
169+
170+
}
180171
setPageComplete(myExampleEditor.isSampleSelected());
181172
break;
182173
default:
@@ -202,7 +193,7 @@ private void restoreAllSelections() {
202193

203194
public CodeDescription getCodeDescription() {
204195

205-
switch (CodeTypes.values()[myCodeSourceOptionsCombo.getSelectionIndex()]) {
196+
switch (getCodeType()) {
206197
case None:
207198
return CodeDescription.createNone();
208199
case defaultIno:
@@ -248,4 +239,16 @@ public static String[] getCodeTypeDescriptions() {
248239
return ret;
249240
}
250241

242+
private CodeTypes getCodeType() {
243+
if (myCodeSourceOptionsCombo == null) {
244+
return CodeTypes.None;
245+
}
246+
return CodeTypes.values()[Math.max(0, myCodeSourceOptionsCombo.getSelectionIndex())];
247+
}
248+
249+
public void setSketchWizardPage(NewSketchWizardBoardPage arduinoPage) {
250+
myArduinoPage = arduinoPage;
251+
252+
}
253+
251254
}

0 commit comments

Comments
 (0)