|
1 | 1 | package io.sloeber.ui.project.properties;
|
2 | 2 |
|
3 | 3 | import java.io.File;
|
4 |
| -import java.util.ArrayList; |
5 | 4 | import java.util.HashMap;
|
6 | 5 | import java.util.Map;
|
7 |
| -import java.util.StringJoiner; |
8 | 6 | import java.util.TreeMap;
|
9 | 7 |
|
10 | 8 | import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
|
13 | 11 | import org.eclipse.cdt.ui.newui.AbstractCPropertyTab;
|
14 | 12 | import org.eclipse.cdt.ui.newui.AbstractPage;
|
15 | 13 | import org.eclipse.cdt.ui.newui.ICPropertyProvider;
|
| 14 | +import org.eclipse.core.runtime.IPath; |
16 | 15 | import org.eclipse.core.runtime.IStatus;
|
| 16 | +import org.eclipse.core.runtime.Path; |
17 | 17 | import org.eclipse.core.runtime.Status;
|
18 | 18 | import org.eclipse.jface.dialogs.Dialog;
|
19 | 19 | import org.eclipse.swt.SWT;
|
@@ -130,11 +130,9 @@ public void handleEvent(Event e) {
|
130 | 130 | }
|
131 | 131 | };
|
132 | 132 |
|
133 |
| - private int mNumBoardsFiles; |
134 |
| - |
135 | 133 | private Composite mComposite;
|
136 | 134 |
|
137 |
| - private String[] mAllBoardsFileNames; |
| 135 | + private TreeMap<String, String> mAllBoardsFiles = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); |
138 | 136 |
|
139 | 137 | @Override
|
140 | 138 | public void createControls(Composite parent, ICPropertyProvider provider) {
|
@@ -167,39 +165,36 @@ public void draw(Composite composite) {
|
167 | 165 | this.myBoardID = BoardDescriptor.makeBoardDescriptor(getConfdesc());
|
168 | 166 | }
|
169 | 167 | ICConfigurationDescription confdesc = getConfdesc();
|
| 168 | + |
| 169 | + String[] allBoardsFileNames = BoardsManager.getAllBoardsFiles(); |
| 170 | + for (String curBoardFile : allBoardsFileNames) { |
| 171 | + this.mAllBoardsFiles.put(tidyUpLength(curBoardFile), curBoardFile); |
| 172 | + } |
| 173 | + |
170 | 174 | this.mComposite = composite;
|
171 | 175 |
|
172 | 176 | GridLayout theGridLayout = new GridLayout();
|
173 | 177 | theGridLayout.numColumns = this.ncol;
|
174 | 178 | composite.setLayout(theGridLayout);
|
175 | 179 |
|
176 | 180 | GridData theGriddata;
|
177 |
| - this.mAllBoardsFileNames = BoardsManager.getAllBoardsFiles(); |
178 |
| - this.mNumBoardsFiles = this.mAllBoardsFileNames.length; |
179 |
| - if (this.mAllBoardsFileNames.length == 0) { |
180 |
| - Activator.log(new Status(IStatus.ERROR, Activator.getId(), |
181 |
| - "ArduinoHelpers.getBoardsFiles() returns null.\nThis should not happen.\nIt looks like the download of the boards failed.")); //$NON-NLS-1$ |
182 |
| - } |
183 | 181 |
|
184 |
| - switch (this.mAllBoardsFileNames.length) { |
185 |
| - case 0: |
| 182 | + if (this.mAllBoardsFiles.isEmpty()) { |
| 183 | + |
186 | 184 | Activator.log(new Status(IStatus.ERROR, Activator.getId(), Messages.error_no_platform_files_found, null));
|
187 |
| - break; |
188 |
| - default: { |
189 |
| - // create a combo to select the boards |
190 |
| - createLabel(composite, this.ncol, "The boards.txt file you want to use"); //$NON-NLS-1$ |
191 |
| - new Label(composite, SWT.NONE).setText("Boards.txt file:"); //$NON-NLS-1$ |
192 | 185 | }
|
193 | 186 |
|
194 |
| - } |
| 187 | + // create a combo to select the boards |
| 188 | + createLabel(composite, this.ncol, "The platform you want to use"); //$NON-NLS-1$ |
| 189 | + new Label(composite, SWT.NONE).setText("Platform folder:"); //$NON-NLS-1$ |
195 | 190 |
|
196 | 191 | this.mControlBoardsTxtFile = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
|
197 | 192 | theGriddata = new GridData();
|
198 | 193 | theGriddata.horizontalAlignment = SWT.FILL;
|
199 | 194 | theGriddata.horizontalSpan = (this.ncol - 1);
|
200 | 195 | this.mControlBoardsTxtFile.setLayoutData(theGriddata);
|
201 | 196 | this.mControlBoardsTxtFile.setEnabled(false);
|
202 |
| - this.mControlBoardsTxtFile.setItems(tidyUpLength(this.mAllBoardsFileNames)); |
| 197 | + this.mControlBoardsTxtFile.setItems(this.mAllBoardsFiles.keySet().toArray(new String[0])); |
203 | 198 |
|
204 | 199 | createLine(composite, this.ncol);
|
205 | 200 | // -------
|
@@ -252,43 +247,25 @@ public void draw(Composite composite) {
|
252 | 247 | this.mFeedbackControl.setLayoutData(theGriddata);
|
253 | 248 | // End of special controls
|
254 | 249 |
|
255 |
| - this.mControlBoardsTxtFile.select(0); |
256 |
| - this.boardFileModifyListener.handleEvent(null); |
257 | 250 | setValues(confdesc);
|
258 | 251 |
|
259 | 252 | this.mcontrolBoardName.addListener(SWT.Modify, this.boardModifyListener);
|
260 | 253 | this.mControlBoardsTxtFile.addListener(SWT.Modify, this.boardFileModifyListener);
|
261 | 254 |
|
262 |
| - // force update to first |
263 |
| - |
264 | 255 | enableControls();
|
265 | 256 | Dialog.applyDialogFont(composite);
|
266 | 257 | }
|
267 | 258 |
|
268 |
| - private static String[] tidyUpLength(String[] pLongNames) { |
269 |
| - final String separator = "/"; //$NON-NLS-1$ |
270 |
| - ArrayList<String> shortNames = new ArrayList<>(); |
271 |
| - for (String longName : pLongNames) { |
272 |
| - String[] pathParts = longName.split(separator); |
273 |
| - if (pathParts.length > 10) { |
274 |
| - StringJoiner sj = new StringJoiner(separator); |
275 |
| - sj.add(pathParts[0]); |
276 |
| - sj.add(pathParts[1]); |
277 |
| - sj.add(pathParts[2]); |
278 |
| - sj.add(pathParts[3]); |
279 |
| - sj.add("..."); //$NON-NLS-1$ |
280 |
| - sj.add(pathParts[pathParts.length - 5]); |
281 |
| - sj.add(pathParts[pathParts.length - 4]); |
282 |
| - sj.add(pathParts[pathParts.length - 3]); |
283 |
| - sj.add(pathParts[pathParts.length - 2]); |
284 |
| - sj.add(pathParts[pathParts.length - 1]); |
285 |
| - shortNames.add(sj.toString()); |
286 |
| - } else { |
287 |
| - shortNames.add(longName); |
288 |
| - } |
| 259 | + private static String tidyUpLength(String longName) { |
| 260 | + IPath longPath = new Path(longName).removeLastSegments(1); |
| 261 | + IPath tidyPath = longPath; |
| 262 | + int segments = longPath.segmentCount(); |
| 263 | + if (segments > 7) { |
| 264 | + tidyPath = longPath.removeLastSegments(segments - 2); |
| 265 | + tidyPath = tidyPath.append("..."); //$NON-NLS-1$ |
| 266 | + tidyPath = tidyPath.append(longPath.removeFirstSegments(segments - 4)); |
289 | 267 | }
|
290 |
| - |
291 |
| - return shortNames.toArray(new String[0]); |
| 268 | + return tidyPath.toString(); |
292 | 269 | }
|
293 | 270 |
|
294 | 271 | public boolean isPageComplete() {
|
@@ -320,7 +297,7 @@ protected void enableControls() {
|
320 | 297 | this.mcontrolBoardName.setEnabled(true);
|
321 | 298 | this.mControlUploadPort.setEnabled(true);
|
322 | 299 | this.mControlUploadProtocol.setEnabled(true);
|
323 |
| - this.mControlBoardsTxtFile.setEnabled((this.mNumBoardsFiles > 1)); |
| 300 | + this.mControlBoardsTxtFile.setEnabled(true); |
324 | 301 | for (LabelCombo curLabelCombo : this.mBoardOptionCombos) {
|
325 | 302 | curLabelCombo.setVisible(true);
|
326 | 303 | }
|
@@ -356,8 +333,8 @@ protected void updateButtons() {
|
356 | 333 |
|
357 | 334 | private void setValues(ICConfigurationDescription confdesc) {
|
358 | 335 |
|
359 |
| - this.mControlBoardsTxtFile.setText(this.myBoardID.getBoardsFile()); |
360 |
| - // // if no boards file is selected select the first |
| 336 | + this.mControlBoardsTxtFile.setText(tidyUpLength(this.myBoardID.getBoardsFile())); |
| 337 | + // if no boards file is selected select the first |
361 | 338 | // if (this.mControlBoardsTxtFile.getText().isEmpty()) {
|
362 | 339 | // this.mControlBoardsTxtFile.setText(this.mControlBoardsTxtFile.getItem(0));
|
363 | 340 | // this.myBoardID.setBoardsFile(this.mAllBoardsFiles[0]);
|
@@ -451,9 +428,12 @@ protected File getSelectedBoardsFile() {
|
451 | 428 | if (this.mControlBoardsTxtFile == null) {
|
452 | 429 | return null;
|
453 | 430 | }
|
454 |
| - int index = this.mControlBoardsTxtFile.getSelectionIndex(); |
455 |
| - return new File(this.mAllBoardsFileNames[index]); |
456 |
| - // return new File(this.mControlBoardsTxtFile.getText().trim()); |
| 431 | + String selectedText = this.mControlBoardsTxtFile.getText().trim(); |
| 432 | + String longText = this.mAllBoardsFiles.get(selectedText); |
| 433 | + if (longText == null) { |
| 434 | + return null;// this should not happen |
| 435 | + } |
| 436 | + return new File(longText); |
457 | 437 | }
|
458 | 438 |
|
459 | 439 | private String getUpLoadPort() {
|
|
0 commit comments