mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
Available boards are updated right after closing "Boards Installer"
Boards menu list has been moved into Base class where it looks a more appropriate place to reduce interactions between Editor class and Base class. Probably shared menus can be moved in a separate, specific, class.
This commit is contained in:
parent
0783f40ba5
commit
75d1cb874d
@ -86,6 +86,11 @@ public class Base {
|
|||||||
List<Editor> editors = Collections.synchronizedList(new ArrayList<Editor>());
|
List<Editor> editors = Collections.synchronizedList(new ArrayList<Editor>());
|
||||||
Editor activeEditor;
|
Editor activeEditor;
|
||||||
|
|
||||||
|
// these menus are shared so that the board and serial port selections
|
||||||
|
// are the same for all windows (since the board and serial port that are
|
||||||
|
// actually used are determined by the preferences, which are shared)
|
||||||
|
static List<JMenu> boardsCustomMenus;
|
||||||
|
|
||||||
static public void main(String args[]) throws Exception {
|
static public void main(String args[]) throws Exception {
|
||||||
System.setProperty("awt.useSystemAAFontSettings", "on");
|
System.setProperty("awt.useSystemAAFontSettings", "on");
|
||||||
System.setProperty("swing.aatext", "true");
|
System.setProperty("swing.aatext", "true");
|
||||||
@ -238,6 +243,7 @@ public class Base {
|
|||||||
splashScreenHelper.splashText(_("Initializing packages..."));
|
splashScreenHelper.splashText(_("Initializing packages..."));
|
||||||
BaseNoGui.initPackages();
|
BaseNoGui.initPackages();
|
||||||
splashScreenHelper.splashText(_("Preparing boards..."));
|
splashScreenHelper.splashText(_("Preparing boards..."));
|
||||||
|
rebuildBoardsMenu();
|
||||||
|
|
||||||
// Setup board-dependent variables.
|
// Setup board-dependent variables.
|
||||||
onBoardOrPortChange();
|
onBoardOrPortChange();
|
||||||
@ -1114,37 +1120,47 @@ public class Base {
|
|||||||
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor) {
|
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor) {
|
||||||
@Override
|
@Override
|
||||||
protected void onIndexesUpdated() throws Exception {
|
protected void onIndexesUpdated() throws Exception {
|
||||||
BaseNoGui.reloadAllHardware();
|
BaseNoGui.initPackages();
|
||||||
|
rebuildBoardsMenu();
|
||||||
setIndexer(BaseNoGui.indexer);
|
setIndexer(BaseNoGui.indexer);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
managerUI.setIndexer(BaseNoGui.indexer);
|
managerUI.setIndexer(BaseNoGui.indexer);
|
||||||
managerUI.setVisible(true);
|
managerUI.setVisible(true);
|
||||||
|
// Installer dialog is modal, waits here until closed
|
||||||
|
|
||||||
|
// Reload all boards (that may have been installed/updated/removed)
|
||||||
|
try {
|
||||||
|
BaseNoGui.initPackages();
|
||||||
|
rebuildBoardsMenu();
|
||||||
|
onBoardOrPortChange();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rebuildBoardsMenu(JMenu toolsMenu, Editor editor) throws Exception {
|
public void rebuildBoardsMenu() throws Exception {
|
||||||
JMenu boardsMenu = getBoardCustomMenu();
|
boardsCustomMenus = new LinkedList<JMenu>();
|
||||||
|
|
||||||
|
// The first custom menu is the "Board" selection submenu
|
||||||
|
JMenu boardMenu = new JMenu(_("Board"));
|
||||||
|
MenuScroller.setScrollerFor(boardMenu);
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
Action runInstaller = new AbstractAction("Install boards...") {
|
Action runInstaller = new AbstractAction("Install boards...") {
|
||||||
public void actionPerformed(ActionEvent actionevent) {
|
public void actionPerformed(ActionEvent actionevent) {
|
||||||
openInstallBoardDialog();
|
openInstallBoardDialog();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
boardsMenu.add(new JMenuItem(runInstaller));
|
boardMenu.add(new JMenuItem(runInstaller));
|
||||||
|
boardsCustomMenus.add(boardMenu);
|
||||||
|
|
||||||
// If there are no platforms installed skip menu creation
|
// If there are no platforms installed we are done
|
||||||
if (BaseNoGui.packages.size() == 0)
|
if (BaseNoGui.packages.size() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
boardsMenu.add(new JSeparator());
|
// Separate "Install boards..." command from installed boards
|
||||||
|
boardMenu.add(new JSeparator());
|
||||||
boolean first = true;
|
|
||||||
|
|
||||||
List<JMenuItem> menuItemsToClickAfterStartup = new LinkedList<JMenuItem>();
|
|
||||||
|
|
||||||
ButtonGroup boardsButtonGroup = new ButtonGroup();
|
|
||||||
Map<String, ButtonGroup> buttonGroupsMap = new HashMap<String, ButtonGroup>();
|
|
||||||
|
|
||||||
// Generate custom menus for all platforms
|
// Generate custom menus for all platforms
|
||||||
Set<String> titles = new HashSet<String>();
|
Set<String> titles = new HashSet<String>();
|
||||||
@ -1152,17 +1168,24 @@ public class Base {
|
|||||||
for (TargetPlatform targetPlatform : targetPackage.platforms())
|
for (TargetPlatform targetPlatform : targetPackage.platforms())
|
||||||
titles.addAll(targetPlatform.getCustomMenus().values());
|
titles.addAll(targetPlatform.getCustomMenus().values());
|
||||||
}
|
}
|
||||||
for (String title : titles)
|
for (String title : titles) {
|
||||||
makeBoardCustomMenu(toolsMenu, _(title));
|
boardsCustomMenus.add(new JMenu(_(title)));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<JMenuItem> menuItemsToClickAfterStartup = new LinkedList<JMenuItem>();
|
||||||
|
|
||||||
|
ButtonGroup boardsButtonGroup = new ButtonGroup();
|
||||||
|
Map<String, ButtonGroup> buttonGroupsMap = new HashMap<String, ButtonGroup>();
|
||||||
|
|
||||||
// Cycle through all packages
|
// Cycle through all packages
|
||||||
|
boolean first = true;
|
||||||
for (TargetPackage targetPackage : BaseNoGui.packages.values()) {
|
for (TargetPackage targetPackage : BaseNoGui.packages.values()) {
|
||||||
// For every package cycle through all platform
|
// For every package cycle through all platform
|
||||||
for (TargetPlatform targetPlatform : targetPackage.platforms()) {
|
for (TargetPlatform targetPlatform : targetPackage.platforms()) {
|
||||||
|
|
||||||
// Add a separator from the previous platform
|
// Add a separator from the previous platform
|
||||||
if (!first)
|
if (!first)
|
||||||
boardsMenu.add(new JSeparator());
|
boardMenu.add(new JSeparator());
|
||||||
first = false;
|
first = false;
|
||||||
|
|
||||||
// Add a title for each platform
|
// Add a title for each platform
|
||||||
@ -1170,7 +1193,7 @@ public class Base {
|
|||||||
if (platformLabel != null && !targetPlatform.getBoards().isEmpty()) {
|
if (platformLabel != null && !targetPlatform.getBoards().isEmpty()) {
|
||||||
JMenuItem menuLabel = new JMenuItem(_(platformLabel));
|
JMenuItem menuLabel = new JMenuItem(_(platformLabel));
|
||||||
menuLabel.setEnabled(false);
|
menuLabel.setEnabled(false);
|
||||||
boardsMenu.add(menuLabel);
|
boardMenu.add(menuLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cycle through all boards of this platform
|
// Cycle through all boards of this platform
|
||||||
@ -1178,14 +1201,14 @@ public class Base {
|
|||||||
JMenuItem item = createBoardMenusAndCustomMenus(menuItemsToClickAfterStartup,
|
JMenuItem item = createBoardMenusAndCustomMenus(menuItemsToClickAfterStartup,
|
||||||
buttonGroupsMap,
|
buttonGroupsMap,
|
||||||
board, targetPlatform, targetPackage);
|
board, targetPlatform, targetPackage);
|
||||||
boardsMenu.add(item);
|
boardMenu.add(item);
|
||||||
boardsButtonGroup.add(item);
|
boardsButtonGroup.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (menuItemsToClickAfterStartup.isEmpty()) {
|
if (menuItemsToClickAfterStartup.isEmpty()) {
|
||||||
menuItemsToClickAfterStartup.add(selectFirstEnabledMenuItem(boardsMenu));
|
menuItemsToClickAfterStartup.add(selectFirstEnabledMenuItem(boardMenu));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (JMenuItem menuItemToClick : menuItemsToClickAfterStartup) {
|
for (JMenuItem menuItemToClick : menuItemsToClickAfterStartup) {
|
||||||
@ -1265,9 +1288,10 @@ public class Base {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void filterVisibilityOfSubsequentBoardMenus(TargetBoard board, int fromIndex) {
|
private static void filterVisibilityOfSubsequentBoardMenus(TargetBoard board,
|
||||||
for (int i = fromIndex; i < Editor.boardsMenus.size(); i++) {
|
int fromIndex) {
|
||||||
JMenu menu = Editor.boardsMenus.get(i);
|
for (int i = fromIndex; i < boardsCustomMenus.size(); i++) {
|
||||||
|
JMenu menu = boardsCustomMenus.get(i);
|
||||||
for (int m = 0; m < menu.getItemCount(); m++) {
|
for (int m = 0; m < menu.getItemCount(); m++) {
|
||||||
JMenuItem menuItem = menu.getItem(m);
|
JMenuItem menuItem = menu.getItem(m);
|
||||||
menuItem.setVisible(menuItem.getAction().getValue("board").equals(board));
|
menuItem.setVisible(menuItem.getAction().getValue("board").equals(board));
|
||||||
@ -1293,19 +1317,8 @@ public class Base {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JMenu makeBoardCustomMenu(JMenu toolsMenu, String label) {
|
|
||||||
JMenu menu = new JMenu(label);
|
|
||||||
Editor.boardsMenus.add(menu);
|
|
||||||
toolsMenu.add(menu);
|
|
||||||
return menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
private JMenu getBoardCustomMenu() throws Exception {
|
|
||||||
return getBoardCustomMenu(_("Board"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private JMenu getBoardCustomMenu(String label) throws Exception {
|
private JMenu getBoardCustomMenu(String label) throws Exception {
|
||||||
for (JMenu menu : Editor.boardsMenus)
|
for (JMenu menu : boardsCustomMenus)
|
||||||
if (label.equals(menu.getText()))
|
if (label.equals(menu.getText()))
|
||||||
return menu;
|
return menu;
|
||||||
throw new Exception("Custom menu not found!");
|
throw new Exception("Custom menu not found!");
|
||||||
@ -1760,6 +1773,10 @@ public class Base {
|
|||||||
return BaseNoGui.getBoardPreferences();
|
return BaseNoGui.getBoardPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<JMenu> getBoardsCustomMenus() {
|
||||||
|
return boardsCustomMenus;
|
||||||
|
}
|
||||||
|
|
||||||
static public File getPortableFolder() {
|
static public File getPortableFolder() {
|
||||||
return BaseNoGui.getPortableFolder();
|
return BaseNoGui.getPortableFolder();
|
||||||
}
|
}
|
||||||
|
@ -109,10 +109,6 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
static JMenu examplesMenu;
|
static JMenu examplesMenu;
|
||||||
static JMenu importMenu;
|
static JMenu importMenu;
|
||||||
|
|
||||||
// these menus are shared so that the board and serial port selections
|
|
||||||
// are the same for all windows (since the board and serial port that are
|
|
||||||
// actually used are determined by the preferences, which are shared)
|
|
||||||
static List<JMenu> boardsMenus;
|
|
||||||
static JMenu serialMenu;
|
static JMenu serialMenu;
|
||||||
|
|
||||||
static AbstractMonitor serialMonitor;
|
static AbstractMonitor serialMonitor;
|
||||||
@ -195,7 +191,7 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
fileMenu.insert(examplesMenu, 3);
|
fileMenu.insert(examplesMenu, 3);
|
||||||
sketchMenu.insert(importMenu, 4);
|
sketchMenu.insert(importMenu, 4);
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
for (JMenu menu : boardsMenus) {
|
for (JMenu menu : Base.getBoardsCustomMenus()) {
|
||||||
toolsMenu.insert(menu, numTools + offset);
|
toolsMenu.insert(menu, numTools + offset);
|
||||||
offset++;
|
offset++;
|
||||||
}
|
}
|
||||||
@ -209,7 +205,7 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
fileMenu.remove(sketchbookMenu);
|
fileMenu.remove(sketchbookMenu);
|
||||||
fileMenu.remove(examplesMenu);
|
fileMenu.remove(examplesMenu);
|
||||||
sketchMenu.remove(importMenu);
|
sketchMenu.remove(importMenu);
|
||||||
for (JMenu menu : boardsMenus) {
|
for (JMenu menu : Base.getBoardsCustomMenus()) {
|
||||||
toolsMenu.remove(menu);
|
toolsMenu.remove(menu);
|
||||||
}
|
}
|
||||||
toolsMenu.remove(serialMenu);
|
toolsMenu.remove(serialMenu);
|
||||||
@ -684,53 +680,41 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
|
|
||||||
protected JMenu buildToolsMenu() throws Exception {
|
protected JMenu buildToolsMenu() throws Exception {
|
||||||
toolsMenu = new JMenu(_("Tools"));
|
toolsMenu = new JMenu(_("Tools"));
|
||||||
JMenu menu = toolsMenu;
|
|
||||||
JMenuItem item;
|
|
||||||
|
|
||||||
addInternalTools(menu);
|
addInternalTools(toolsMenu);
|
||||||
|
|
||||||
item = newJMenuItemShift(_("Serial Monitor"), 'M');
|
JMenuItem item = newJMenuItemShift(_("Serial Monitor"), 'M');
|
||||||
item.addActionListener(new ActionListener() {
|
item.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
handleSerial();
|
handleSerial();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menu.add(item);
|
toolsMenu.add(item);
|
||||||
|
|
||||||
addTools(menu, Base.getToolsFolder());
|
addTools(toolsMenu, Base.getToolsFolder());
|
||||||
File sketchbookTools = new File(Base.getSketchbookFolder(), "tools");
|
File sketchbookTools = new File(Base.getSketchbookFolder(), "tools");
|
||||||
addTools(menu, sketchbookTools);
|
addTools(toolsMenu, sketchbookTools);
|
||||||
|
|
||||||
menu.addSeparator();
|
toolsMenu.addSeparator();
|
||||||
|
|
||||||
numTools = menu.getItemCount();
|
numTools = toolsMenu.getItemCount();
|
||||||
|
|
||||||
// XXX: DAM: these should probably be implemented using the Tools plugin
|
// XXX: DAM: these should probably be implemented using the Tools plugin
|
||||||
// API, if possible (i.e. if it supports custom actions, etc.)
|
// API, if possible (i.e. if it supports custom actions, etc.)
|
||||||
|
|
||||||
if (boardsMenus == null) {
|
for (JMenu menu : Base.getBoardsCustomMenus()) {
|
||||||
boardsMenus = new LinkedList<JMenu>();
|
toolsMenu.add(menu);
|
||||||
|
|
||||||
JMenu boardsMenu = new JMenu(_("Board"));
|
|
||||||
MenuScroller.setScrollerFor(boardsMenu);
|
|
||||||
Editor.boardsMenus.add(boardsMenu);
|
|
||||||
toolsMenu.add(boardsMenu);
|
|
||||||
|
|
||||||
base.rebuildBoardsMenu(toolsMenu, this);
|
|
||||||
//Debug: rebuild imports
|
|
||||||
importMenu.removeAll();
|
|
||||||
base.rebuildImportMenu(importMenu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serialMenu == null)
|
if (serialMenu == null)
|
||||||
serialMenu = new JMenu(_("Port"));
|
serialMenu = new JMenu(_("Port"));
|
||||||
populatePortMenu();
|
populatePortMenu();
|
||||||
menu.add(serialMenu);
|
toolsMenu.add(serialMenu);
|
||||||
menu.addSeparator();
|
toolsMenu.addSeparator();
|
||||||
|
|
||||||
JMenu programmerMenu = new JMenu(_("Programmer"));
|
JMenu programmerMenu = new JMenu(_("Programmer"));
|
||||||
base.rebuildProgrammerMenu(programmerMenu);
|
base.rebuildProgrammerMenu(programmerMenu);
|
||||||
menu.add(programmerMenu);
|
toolsMenu.add(programmerMenu);
|
||||||
|
|
||||||
item = new JMenuItem(_("Burn Bootloader"));
|
item = new JMenuItem(_("Burn Bootloader"));
|
||||||
item.addActionListener(new ActionListener() {
|
item.addActionListener(new ActionListener() {
|
||||||
@ -738,9 +722,9 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
handleBurnBootloader();
|
handleBurnBootloader();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menu.add(item);
|
toolsMenu.add(item);
|
||||||
|
|
||||||
menu.addMenuListener(new MenuListener() {
|
toolsMenu.addMenuListener(new MenuListener() {
|
||||||
public void menuCanceled(MenuEvent e) {}
|
public void menuCanceled(MenuEvent e) {}
|
||||||
public void menuDeselected(MenuEvent e) {}
|
public void menuDeselected(MenuEvent e) {}
|
||||||
public void menuSelected(MenuEvent e) {
|
public void menuSelected(MenuEvent e) {
|
||||||
@ -749,7 +733,7 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return menu;
|
return toolsMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -587,10 +587,6 @@ public class BaseNoGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public void initPackages() throws Exception {
|
static public void initPackages() throws Exception {
|
||||||
reloadAllHardware();
|
|
||||||
}
|
|
||||||
|
|
||||||
static public void reloadAllHardware() throws Exception {
|
|
||||||
indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
|
indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
|
||||||
File indexFile = indexer.getIndexFile();
|
File indexFile = indexer.getIndexFile();
|
||||||
if (!indexFile.isFile()) {
|
if (!indexFile.isFile()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user