mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Install works without restart for modes
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<ModeContribution> 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> editor = e.getBase().getEditors();
|
||||
for (Editor ed : editor) {
|
||||
ed.getMode().rebuildImportMenu();
|
||||
ed.getMode().resetExamples();
|
||||
ed.rebuildToolMenu();
|
||||
ed.rebuildModeMenu();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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")));
|
||||
|
||||
@@ -97,30 +97,32 @@ public class ModeContribution extends LocalContribution {
|
||||
*/
|
||||
public void clearClassLoader(Base base) {
|
||||
ArrayList<ModeContribution> contribModes = base.getModeContribs();
|
||||
contribModes.remove(contribModes.indexOf(this));
|
||||
List<Editor> 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<Editor> 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<ModeContribution> contribModes = base.getModeContribs();
|
||||
|
||||
Reference in New Issue
Block a user