Skip to content

Editor refactor fixup #5528

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

Merged
merged 8 commits into from
Nov 9, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
6 changes: 5 additions & 1 deletion app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,7 @@ public void rebuildExamplesMenu(JMenu menu) {
}

private static String priorPlatformFolder;
private static boolean newLibraryImported;

public void onBoardOrPortChange() {
BaseNoGui.onBoardOrPortChange();
Expand All @@ -1303,10 +1304,11 @@ public void onBoardOrPortChange() {
TargetPlatform tp = BaseNoGui.getTargetPlatform();
if (tp != null) {
String platformFolder = tp.getFolder().getAbsolutePath();
if (priorPlatformFolder == null || !priorPlatformFolder.equals(platformFolder)) {
if (priorPlatformFolder == null || !priorPlatformFolder.equals(platformFolder) || newLibraryImported) {
pdeKeywords = new PdeKeywords();
pdeKeywords.reload();
priorPlatformFolder = platformFolder;
newLibraryImported = false;
for (Editor editor : editors) {
editor.updateKeywords(pdeKeywords);
}
Expand Down Expand Up @@ -1346,6 +1348,7 @@ protected void onIndexesUpdated() throws Exception {
// Manager dialog is modal, waits here until closed

//handleAddLibrary();
newLibraryImported = true;
onBoardOrPortChange();
rebuildImportMenu(Editor.importMenu);
rebuildExamplesMenu(Editor.examplesMenu);
Expand Down Expand Up @@ -2303,6 +2306,7 @@ public void handleAddLibrary() {
// FIXME error when importing. ignoring :(
} finally {
// delete zip created temp folder, if exists
newLibraryImported = true;
FileUtils.recursiveDelete(tmpFolder);
}
}
Expand Down
23 changes: 23 additions & 0 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,24 @@ public void createTabs() {
selectTab(0);
}

private static final Comparator<EditorTab> CODE_DOCS_COMPARATOR = new Comparator<EditorTab>() {
@Override
public int compare(EditorTab x, EditorTab y) {
if (x.getSketchFile().isPrimary() && !y.getSketchFile().isPrimary())
return -1;
if (y.getSketchFile().isPrimary() && !x.getSketchFile().isPrimary())
return 1;
return x.getSketchFile().getFileName().compareTo(y.getSketchFile().getFileName());
}
};

/**
* Reorders tabs as per current sketch's files order
*/
public void reorderTabs() {
Collections.sort(tabs, CODE_DOCS_COMPARATOR);
}

/**
* Add a new tab.
*
Expand All @@ -1706,6 +1724,11 @@ protected void addTab(SketchFile file, String contents) throws IOException {
tabs.add(tab);
}

protected void removeTab(SketchFile file) throws IOException {
int index = findTabIndex(file);
tabs.remove(index);
}

// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

void handleFindReference(ActionEvent e) {
Expand Down
1 change: 1 addition & 0 deletions app/src/processing/app/EditorHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ public void rebuildMenu() {
if (sketch != null) {
menu.addSeparator();

editor.reorderTabs();
int i = 0;
for (EditorTab tab : editor.getTabs()) {
SketchFile file = tab.getSketchFile();
Expand Down
2 changes: 2 additions & 0 deletions app/src/processing/app/SketchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ public void handleDeleteCode() throws IOException {
return;
}

editor.removeTab(current);

// just set current tab to the main tab
editor.selectTab(0);

Expand Down
10 changes: 6 additions & 4 deletions arduino-core/src/processing/app/BaseNoGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,14 @@ static public PreferencesMap getBoardPreferences() {

// Add all tools dependencies from the (possibily) referenced core
String core = prefs.get("build.core");
if (core.contains(":")) {
if (core != null && core.contains(":")) {
String split[] = core.split(":");
TargetPlatform referenced = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
ContributedPlatform referencedPlatform = indexer.getContributedPlaform(referenced);
if (referencedPlatform != null)
requiredTools.addAll(referencedPlatform.getResolvedTools());
if (referenced != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't an error be given when a referenced core does not exist?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmh, good idea 😄
Compilation would fail anyway, so the problem should be solved by the maintainer (Arrow SAMD boards and Win10 IoT core are affected). However a message is ok, I'm pushing it tomorrow

ContributedPlatform referencedPlatform = indexer.getContributedPlaform(referenced);
if (referencedPlatform != null)
requiredTools.addAll(referencedPlatform.getResolvedTools());
}
}

String prefix = "runtime.tools.";
Expand Down