diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index d27d52ffb..28456f19d 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -435,6 +435,34 @@ public abstract class Editor extends JFrame implements RunnerListener { } + public void rebuildModeMenu() { + modeMenu = new JMenu(); + ButtonGroup modeGroup = new ButtonGroup(); + for (final Mode m : base.getModeList()) { + JRadioButtonMenuItem item = new JRadioButtonMenuItem(m.getTitle()); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + base.changeMode(m); + } + }); + modeMenu.add(item); + modeGroup.add(item); + if (mode == m) { + item.setSelected(true); + } + } + + modeMenu.addSeparator(); + JMenuItem addLib = new JMenuItem("Add Mode..."); + addLib.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + base.handleOpenModeManager(); + } + }); + modeMenu.add(addLib); + } + + public JMenu getModeMenu() { return modeMenu; } diff --git a/app/src/processing/app/contrib/AvailableContribution.java b/app/src/processing/app/contrib/AvailableContribution.java index 44ed86888..39c2940e1 100644 --- a/app/src/processing/app/contrib/AvailableContribution.java +++ b/app/src/processing/app/contrib/AvailableContribution.java @@ -143,6 +143,9 @@ class AvailableContribution extends Contribution { installedContrib.setRestartFlag(); //status.setMessage("Restart Processing to finish the installation."); } +// else if (type == ContributionType.MODE) { +// +// } // 3. Delete the newContrib, do a garbage collection, hope and pray // that Java will unlock the temp folder on Windows now diff --git a/app/src/processing/app/contrib/ContributionManager.java b/app/src/processing/app/contrib/ContributionManager.java index f39d04606..1c4204880 100644 --- a/app/src/processing/app/contrib/ContributionManager.java +++ b/app/src/processing/app/contrib/ContributionManager.java @@ -23,6 +23,8 @@ package processing.app.contrib; import java.io.*; import java.net.*; +import java.util.List; +import java.util.ArrayList; import processing.app.Base; import processing.app.Editor; @@ -130,6 +132,10 @@ public class ContributionManager { if (contribution != null) { contribListing.replaceContribution(ad, contribution); + if (contribution.getType() == ContributionType.MODE) { + ArrayList contribModes = editor.getBase().getModeContribs(); + contribModes.add((ModeContribution)contribution); + } refreshInstalled(editor); } installProgress.finished(); @@ -148,10 +154,14 @@ public class ContributionManager { } - static public void refreshInstalled(Editor editor) { - editor.getMode().rebuildImportMenu(); - editor.getMode().resetExamples(); - editor.rebuildToolMenu(); + static public void refreshInstalled(Editor e) { + List editor = e.getBase().getEditors(); + for (Editor ed : editor) { + ed.getMode().rebuildImportMenu(); + ed.getMode().resetExamples(); + ed.rebuildToolMenu(); + ed.rebuildModeMenu(); + } } diff --git a/app/src/processing/app/contrib/ContributionPanel.java b/app/src/processing/app/contrib/ContributionPanel.java index 07f76e472..57b7e7e80 100644 --- a/app/src/processing/app/contrib/ContributionPanel.java +++ b/app/src/processing/app/contrib/ContributionPanel.java @@ -208,23 +208,44 @@ class ContributionPanel extends JPanel { notificationBlock.setFont(new Font("Verdana", Font.ITALIC, 10)); // stripTextSelectionListeners(notificationBlock); - updateButton = new JButton("Update"); - updateButton.setInheritsPopupMenu(true); - Dimension updateButtonDimensions = updateButton.getPreferredSize(); - updateButtonDimensions.width = BUTTON_WIDTH; - updateButton.setMinimumSize(updateButtonDimensions); - updateButton.setPreferredSize(updateButtonDimensions); - updateButton.setOpaque(false); - updateButton.setVisible(false); - updateButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - listPanel.contribManager.status.clear(); + updateButton = new JButton("Update"); + updateButton.setInheritsPopupMenu(true); + Dimension updateButtonDimensions = updateButton.getPreferredSize(); + updateButtonDimensions.width = BUTTON_WIDTH; + updateButton.setMinimumSize(updateButtonDimensions); + updateButton.setPreferredSize(updateButtonDimensions); + updateButton.setOpaque(false); + updateButton.setVisible(false); + updateButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + listPanel.contribManager.status.clear(); + if (contrib.getType() == ContributionType.MODE) { + installRemoveButton.setEnabled(false); + installProgressBar.setVisible(true); + installProgressBar.setIndeterminate(true); + + ((LocalContribution) contrib) + .removeContribution(listPanel.contribManager.editor, + new JProgressMonitor(installProgressBar) { + public void finishedAction() { + // Finished uninstalling the library + resetInstallProgressBarState(); + updateButton.setEnabled(false); + AvailableContribution ad = contribListing + .getAvailableContribution(contrib); + String url = ad.link; + installContribution(ad, url); + } + }, listPanel.contribManager.status); + } else { updateButton.setEnabled(false); - AvailableContribution ad = contribListing.getAvailableContribution(contrib); + AvailableContribution ad = contribListing + .getAvailableContribution(contrib); String url = ad.link; installContribution(ad, url); } - }); + } + }); // add(updateButton, c); // } updateBox.add(updateButton); @@ -424,7 +445,7 @@ class ContributionPanel extends JPanel { } updateButton.setEnabled(true); - if (contrib != null && !contrib.getType().requiresRestart()) { + if (contrib != null && contrib.getType() != ContributionType.TOOL) { updateButton.setVisible(isSelected() && contribListing.hasUpdates(contrib)); } @@ -536,7 +557,7 @@ class ContributionPanel extends JPanel { // now a hyperlink, it will be opened as the mouse is released. enableHyperlinks = alreadySelected; - if (contrib != null && !contrib.getType().requiresRestart()) { + if (contrib != null && contrib.getType() != ContributionType.TOOL) { updateButton.setVisible(isSelected() && contribListing.hasUpdates(contrib)); } installRemoveButton.setVisible(isSelected() || installRemoveButton.getText().equals(Language.text("contributions.remove"))); diff --git a/app/src/processing/app/contrib/ModeContribution.java b/app/src/processing/app/contrib/ModeContribution.java index 7c4dfeb01..4be3184a4 100644 --- a/app/src/processing/app/contrib/ModeContribution.java +++ b/app/src/processing/app/contrib/ModeContribution.java @@ -97,30 +97,32 @@ public class ModeContribution extends LocalContribution { */ public void clearClassLoader(Base base) { ArrayList contribModes = base.getModeContribs(); - contribModes.remove(contribModes.indexOf(this)); - List editorList = base.getEditors(); - for (Editor editor : editorList) { - Component[] j = editor.getModeMenu().getPopupMenu().getComponents(); - for (Component component : j) { - JRadioButtonMenuItem cbmi = null; - if (component instanceof JRadioButtonMenuItem) { - cbmi = (JRadioButtonMenuItem) component; - if (cbmi.getText().equals(mode.toString())) - editor.getModeMenu().getPopupMenu().remove(component); + int botherToRemove = contribModes.indexOf(this); + if (botherToRemove != -1) { // The poor thing isn't even loaded, and we're trying to remove it... + contribModes.remove(botherToRemove); + /* List editorList = base.getEditors(); + for (Editor editor : editorList) { + Component[] j = editor.getModeMenu().getPopupMenu().getComponents(); + for (Component component : j) { + JRadioButtonMenuItem cbmi = null; + if (component instanceof JRadioButtonMenuItem) { + cbmi = (JRadioButtonMenuItem) component; + if (cbmi.getText().equals(mode.toString())) + editor.getModeMenu().getPopupMenu().remove(component); + } } + } */ + try { + ((URLClassLoader) loader).close(); + // The typecast should be safe, since the only case when loader is not of + // type URLClassLoader is when no archives were found in the first + // place... + } catch (IOException e) { + e.printStackTrace(); } } - try { - ((URLClassLoader) loader).close(); - // The typecast should be safe, since the only case when loader is not of - // type URLClassLoader is when no archives were found in the first - // place... - } catch (IOException e) { - e.printStackTrace(); - } } - static public void loadMissing(Base base) { File modesFolder = Base.getSketchbookModesFolder(); ArrayList contribModes = base.getModeContribs();