Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto board selection #10721

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
The Java compilation error has been fixed
  • Loading branch information
timkoers committed Mar 20, 2018
commit 9f1dcee2c58c6aea5732b365486125e2a215c3a0
10 changes: 7 additions & 3 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
@@ -2524,9 +2524,13 @@ public void handleAddBuildSettings(){
String value = e.getText().replace(setting + ":", "").replace("\"", "").trim();
return new String[]{setting, value};
}).collect(LinkedHashMap::new, (map, menu) -> map.put(menu[0], menu[1]), LinkedHashMap::putAll);
sketch.setBuildSettings(findTab(sketch.getPrimaryFile()), settingsMap);
handleSave(true);
System.out.println("Build settings header should be added");
handleSave(true);
Optional<EditorTab> optionalEditorTab = tabs.stream().filter(tab -> tab.getSketch().getSketch().equals(sketch)).findFirst();
if(optionalEditorTab.isPresent()){
optionalEditorTab.get().setText(sketch.setBuildSettings(sketch, settingsMap));
handleSave(true);
System.out.println("Build settings header should be added");
}
}

private void handleBurnBootloader() {
1 change: 1 addition & 0 deletions app/src/processing/app/EditorTab.java
Original file line number Diff line number Diff line change
@@ -434,6 +434,7 @@ public void setText(String what) {
}
}


/**
* This method loads the build settings from the main .INO file and sets the Arduino IDE accordingly
*/
35 changes: 17 additions & 18 deletions arduino-core/src/processing/app/Sketch.java
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@

import cc.arduino.files.DeleteFilesOnShutdown;
import processing.app.helpers.FileUtils;
import processing.app.EditorTab;

import static processing.app.I18n.tr;

@@ -166,24 +165,23 @@ private static int ordinalIndexOf(String str, String substr, int n) {
return pos;
}

private void removeBuildSettingsHeader(EditorTab tab){
if(tab.getText().contains(buildToolsHeader)) {
int headerStartIndex = tab.getText().indexOf(buildToolsHeader);
int headerStopIndex = tab.getText().indexOf(buildToolsHeaderEnd);
private String removeBuildSettingsHeader(Sketch sketch){
if(sketch.getPrimaryFile().getProgram().contains(buildToolsHeader)) {
int headerStartIndex = sketch.getPrimaryFile().getProgram().indexOf(buildToolsHeader);
int headerStopIndex = sketch.getPrimaryFile().getProgram().indexOf(buildToolsHeaderEnd);
if (headerStartIndex > headerStopIndex) {
System.err.println("The build tool header is not the first comment block in your file! Please fix this.");
for (int i = 0; i < tab.getText().length(); i++) {
if (headerStartIndex < ordinalIndexOf(tab.getText(), buildToolsHeaderEnd, i)) {
headerStopIndex = ordinalIndexOf(tab.getText(), buildToolsHeaderEnd, i);
for (int i = 0; i < sketch.getPrimaryFile().getProgram().length(); i++) {
if (headerStartIndex < ordinalIndexOf(sketch.getPrimaryFile().getProgram(), buildToolsHeaderEnd, i)) {
headerStopIndex = ordinalIndexOf(sketch.getPrimaryFile().getProgram(), buildToolsHeaderEnd, i);
break;
}
}
}
String header = tab.getText().substring(headerStartIndex, headerStopIndex + buildToolsHeaderEnd.length());
tab.setText(tab.getText().replace(header, ""));
// Run this method again so we are sure that there aren't any headers left
removeBuildSettingsHeader(tab);
String header = sketch.getPrimaryFile().getProgram().substring(headerStartIndex, headerStopIndex + buildToolsHeaderEnd.length());
return sketch.getPrimaryFile().getProgram().replace(header, "");
}
return sketch.getPrimaryFile().getProgram();
}

/**
@@ -233,16 +231,17 @@ private boolean isBuildSettingsEqual(LinkedHashMap<String,String> first, LinkedH
return first.keySet().containsAll(second.keySet()) && first.values().containsAll(second.values());
}

public void setBuildSettings(EditorTab tab, LinkedHashMap<String, String> buildSettings){
if(tab.getSketch().getSketch() != this){
return;
public String setBuildSettings(Sketch sketch, LinkedHashMap<String, String> buildSettings){
if(sketch != this){
return "";
}

String customBoardSettingsHeader = buildSettings.entrySet().stream().map(entry-> String.format(" * %s: %s\n", entry.getKey(), entry.getValue())).collect(Collectors.joining("", buildToolsHeader, "*/"));
if(!isBuildSettingsEqual(getBuildSettingsFromProgram(tab.getText()),buildSettings)){
removeBuildSettingsHeader(tab);
tab.setText(customBoardSettingsHeader + ((tab.getText().charAt(0) == '\n') ? "" : "\n") + tab.getText());
if(!isBuildSettingsEqual(getBuildSettingsFromProgram(sketch.getPrimaryFile().getProgram()),buildSettings)){
String headerLessProgram = removeBuildSettingsHeader(sketch);
return customBoardSettingsHeader + ((headerLessProgram.charAt(0) == '\n') ? "" : "\n") + headerLessProgram;
}
return "";
}

public int getCodeCount() {