mirror of
https://github.com/processing/processing4.git
synced 2026-02-13 18:35:37 +01:00
Modes now can be removed without restart
This commit is contained in:
@@ -162,6 +162,7 @@ public abstract class Mode {
|
||||
}
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -329,14 +329,12 @@ public abstract class LocalContribution extends Contribution {
|
||||
}
|
||||
|
||||
|
||||
void remove(final Editor editor,
|
||||
final ProgressMonitor pm,
|
||||
final StatusPanel status,
|
||||
final ContributionListing contribListing) {
|
||||
void remove(final Editor editor, final ProgressMonitor pm,
|
||||
final StatusPanel status, final ContributionListing contribListing) {
|
||||
pm.startTask("Removing", ProgressMonitor.UNKNOWN);
|
||||
|
||||
boolean doBackup = Preferences.getBoolean("contribution.backup.on_remove");
|
||||
if (getType().requiresRestart()) {
|
||||
if (getType().requiresRestart() && getType() != ContributionType.MODE) {
|
||||
if (!doBackup || (doBackup && backup(editor, false, status))) {
|
||||
if (setDeletionFlag(true)) {
|
||||
contribListing.replaceContribution(this, this);
|
||||
@@ -344,6 +342,27 @@ public abstract class LocalContribution extends Contribution {
|
||||
}
|
||||
} else {
|
||||
boolean success = false;
|
||||
if (getType() == ContributionType.MODE) {
|
||||
boolean isModeActive = false;
|
||||
ModeContribution m = (ModeContribution) this;
|
||||
for (Editor e : editor.getBase().getEditors())
|
||||
if (e.getMode().equals(m.getMode())) {
|
||||
isModeActive = true;
|
||||
break;
|
||||
}
|
||||
if (!isModeActive)
|
||||
m.clearClassLoader(editor.getBase());
|
||||
else {
|
||||
if (!doBackup || (doBackup && backup(editor, false, status))) {
|
||||
if (setDeletionFlag(true)) {
|
||||
contribListing.replaceContribution(this, this);
|
||||
}
|
||||
}
|
||||
ContributionManager.refreshInstalled(editor);
|
||||
pm.finished();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (doBackup) {
|
||||
success = backup(editor, true, status);
|
||||
} else {
|
||||
@@ -352,8 +371,8 @@ public abstract class LocalContribution extends Contribution {
|
||||
}
|
||||
|
||||
if (success) {
|
||||
Contribution advertisedVersion =
|
||||
contribListing.getAvailableContribution(this);
|
||||
Contribution advertisedVersion = contribListing
|
||||
.getAvailableContribution(this);
|
||||
|
||||
if (advertisedVersion == null) {
|
||||
contribListing.removeContribution(this);
|
||||
|
||||
@@ -21,11 +21,19 @@
|
||||
*/
|
||||
package processing.app.contrib;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.*;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JRadioButtonMenuItem;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.Editor;
|
||||
import processing.app.Mode;
|
||||
|
||||
|
||||
@@ -71,7 +79,6 @@ public class ModeContribution extends LocalContribution {
|
||||
private ModeContribution(Base base, File folder,
|
||||
String className) throws Exception {
|
||||
super(folder);
|
||||
|
||||
className = initLoader(className);
|
||||
if (className != null) {
|
||||
Class<?> modeClass = loader.loadClass(className);
|
||||
@@ -84,6 +91,35 @@ public class ModeContribution extends LocalContribution {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to close the ClassLoader so that the archives are no longer "locked" and
|
||||
* a mode can be removed without restart.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user