mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 13:49:18 +01:00
Merge pull request #3896 from JakubValtar/cm-update-count
CM: Send update count to Editors
This commit is contained in:
@@ -342,6 +342,9 @@ public class Base {
|
||||
|
||||
// check for updates
|
||||
new UpdateCheck(this);
|
||||
|
||||
ContributionListing cl = ContributionListing.getInstance();
|
||||
cl.downloadAvailableList(this, new ContribProgressMonitor() { });
|
||||
}
|
||||
|
||||
|
||||
@@ -520,6 +523,15 @@ public class Base {
|
||||
}
|
||||
|
||||
|
||||
public void setUpdatesAvailable(int n) {
|
||||
synchronized (editors) {
|
||||
for (Editor e : editors) {
|
||||
e.setUpdatesAvailable(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ package processing.app.contrib;
|
||||
// This code seems like it's adapted from old example code found on the web.
|
||||
// https://github.com/processing/processing/issues/3176
|
||||
|
||||
abstract class ContribProgressMonitor {
|
||||
public abstract class ContribProgressMonitor {
|
||||
static final int UNKNOWN = -1;
|
||||
boolean canceled = false;
|
||||
boolean error = false;
|
||||
|
||||
@@ -397,8 +397,8 @@ public class ContributionListing {
|
||||
* Starts a new thread to download the advertised list of contributions.
|
||||
* Only one instance will run at a time.
|
||||
*/
|
||||
protected void downloadAvailableList(final Base base,
|
||||
final ContribProgressMonitor progress) {
|
||||
public void downloadAvailableList(final Base base,
|
||||
final ContribProgressMonitor progress) {
|
||||
|
||||
// TODO: replace with SwingWorker [jv]
|
||||
new Thread(new Runnable() {
|
||||
@@ -436,6 +436,7 @@ public class ContributionListing {
|
||||
@Override
|
||||
public void run() {
|
||||
setAdvertisedList(listingFile);
|
||||
base.setUpdatesAvailable(countUpdates(base));
|
||||
}
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
@@ -141,7 +141,7 @@ public class ContributionManager {
|
||||
* old version of a contribution that is being updated). Must not be
|
||||
* null.
|
||||
*/
|
||||
static void downloadAndInstall(final Editor editor,
|
||||
static void downloadAndInstall(final Base base,
|
||||
final URL url,
|
||||
final AvailableContribution ad,
|
||||
final ContribProgressBar downloadProgress,
|
||||
@@ -162,7 +162,7 @@ public class ContributionManager {
|
||||
if (!downloadProgress.isCanceled() && !downloadProgress.isError()) {
|
||||
installProgress.startTask(Language.text("contrib.progress.installing"), ContribProgressMonitor.UNKNOWN);
|
||||
final LocalContribution contribution =
|
||||
ad.install(editor.getBase(), contribZip, false, status);
|
||||
ad.install(base, contribZip, false, status);
|
||||
|
||||
if (contribution != null) {
|
||||
try {
|
||||
@@ -171,6 +171,16 @@ public class ContributionManager {
|
||||
@Override
|
||||
public void run() {
|
||||
listing.replaceContribution(ad, contribution);
|
||||
/*
|
||||
if (contribution.getType() == ContributionType.MODE) {
|
||||
List<ModeContribution> contribModes = editor.getBase().getModeContribs();
|
||||
if (!contribModes.contains(contribution)) {
|
||||
contribModes.add((ModeContribution) contribution);
|
||||
}
|
||||
}
|
||||
*/
|
||||
base.refreshContribs(contribution.getType());
|
||||
base.setUpdatesAvailable(listing.countUpdates(base));
|
||||
}
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
@@ -178,15 +188,6 @@ public class ContributionManager {
|
||||
} catch (InvocationTargetException e) {
|
||||
throw (Exception) e.getCause();
|
||||
}
|
||||
/*
|
||||
if (contribution.getType() == ContributionType.MODE) {
|
||||
List<ModeContribution> contribModes = editor.getBase().getModeContribs();
|
||||
if (!contribModes.contains(contribution)) {
|
||||
contribModes.add((ModeContribution) contribution);
|
||||
}
|
||||
}
|
||||
*/
|
||||
editor.getBase().refreshContribs(contribution.getType());
|
||||
}
|
||||
installProgress.finished();
|
||||
}
|
||||
@@ -269,6 +270,7 @@ public class ContributionManager {
|
||||
public void run() {
|
||||
listing.replaceContribution(ad, contribution);
|
||||
base.refreshContribs(contribution.getType());
|
||||
base.setUpdatesAvailable(listing.countUpdates(base));
|
||||
}
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
@@ -365,7 +367,7 @@ public class ContributionManager {
|
||||
// to give the user an idea about progress being made.
|
||||
boolean isPrevDone = false;
|
||||
|
||||
for (AvailableContribution contrib : list) {
|
||||
for (final AvailableContribution contrib : list) {
|
||||
if (contrib.getType() != ContributionType.LIBRARY) {
|
||||
continue;
|
||||
}
|
||||
@@ -400,12 +402,29 @@ public class ContributionManager {
|
||||
|
||||
String arg = "contrib.import.progress.install";
|
||||
editor.statusNotice(Language.interpolate(arg,contrib.name));
|
||||
LocalContribution contribution =
|
||||
final LocalContribution contribution =
|
||||
contrib.install(base, contribZip, false, null);
|
||||
|
||||
if (contribution != null) {
|
||||
listing.replaceContribution(contrib, contribution);
|
||||
base.refreshContribs(contribution.getType());
|
||||
try {
|
||||
EventQueue.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listing.replaceContribution(contrib, contribution);
|
||||
base.refreshContribs(contribution.getType());
|
||||
base.setUpdatesAvailable(listing.countUpdates(base));
|
||||
}
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof RuntimeException) {
|
||||
throw (RuntimeException) cause;
|
||||
} else {
|
||||
cause.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
contribZip.delete();
|
||||
|
||||
@@ -619,7 +619,7 @@ class DetailPanel extends JPanel {
|
||||
}
|
||||
};
|
||||
|
||||
ContributionManager.downloadAndInstall(listPanel.contributionTab.editor,
|
||||
ContributionManager.downloadAndInstall(listPanel.contributionTab.editor.getBase(),
|
||||
downloadUrl, ad,
|
||||
downloadProgress, installProgress,
|
||||
listPanel.contributionTab.statusPanel);
|
||||
@@ -871,7 +871,7 @@ class DetailPanel extends JPanel {
|
||||
}
|
||||
};
|
||||
((LocalContribution) contrib)
|
||||
.removeContribution(listPanel.contributionTab.editor,
|
||||
.removeContribution(listPanel.contributionTab.editor.getBase(),
|
||||
progress, listPanel.contributionTab.statusPanel);
|
||||
} else {
|
||||
updateButton.setEnabled(false);
|
||||
@@ -939,7 +939,7 @@ class DetailPanel extends JPanel {
|
||||
};
|
||||
ContributionTab contributionTab = listPanel.contributionTab;
|
||||
LocalContribution localContrib = (LocalContribution) contrib;
|
||||
localContrib.removeContribution(contributionTab.editor, monitor, contributionTab.statusPanel);
|
||||
localContrib.removeContribution(contributionTab.editor.getBase(), monitor, contributionTab.statusPanel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ public abstract class LocalContribution extends Contribution {
|
||||
|
||||
if (oldContrib.getType().requiresRestart()) {
|
||||
// XXX: We can't replace stuff, soooooo.... do something different
|
||||
if (!oldContrib.backup(editor, false, status)) {
|
||||
if (!oldContrib.backup(false, status)) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
@@ -277,7 +277,7 @@ public abstract class LocalContribution extends Contribution {
|
||||
"has been found in your sketchbook. Clicking “Yes”<br>"+
|
||||
"will move the existing library to a backup folder<br>" +
|
||||
"in <i>libraries/old</i> before replacing it.");
|
||||
if (result != JOptionPane.YES_OPTION || !oldContrib.backup(editor, true, status)) {
|
||||
if (result != JOptionPane.YES_OPTION || !oldContrib.backup(true, status)) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
@@ -292,7 +292,7 @@ public abstract class LocalContribution extends Contribution {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((doBackup && !oldContrib.backup(editor, true, status)) ||
|
||||
if ((doBackup && !oldContrib.backup(true, status)) ||
|
||||
(!doBackup && !oldContrib.getFolder().delete())) {
|
||||
return null;
|
||||
}
|
||||
@@ -349,7 +349,7 @@ public abstract class LocalContribution extends Contribution {
|
||||
* true if the file should be moved to the directory, false if it
|
||||
* should instead be copied, leaving the original in place
|
||||
*/
|
||||
boolean backup(Editor editor, boolean deleteOriginal, StatusPanel status) {
|
||||
boolean backup(boolean deleteOriginal, StatusPanel status) {
|
||||
File backupFolder = getType().createBackupFolder(status);
|
||||
|
||||
boolean success = false;
|
||||
@@ -379,13 +379,13 @@ public abstract class LocalContribution extends Contribution {
|
||||
/**
|
||||
* Non-blocking call to remove a contribution in a new thread.
|
||||
*/
|
||||
void removeContribution(final Editor editor,
|
||||
void removeContribution(final Base base,
|
||||
final ContribProgressMonitor pm,
|
||||
final StatusPanel status) {
|
||||
// TODO: replace with SwingWorker [jv]
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
remove(editor,
|
||||
remove(base,
|
||||
pm,
|
||||
status,
|
||||
ContributionListing.getInstance());
|
||||
@@ -394,7 +394,7 @@ public abstract class LocalContribution extends Contribution {
|
||||
}
|
||||
|
||||
|
||||
void remove(final Editor editor,
|
||||
void remove(final Base base,
|
||||
final ContribProgressMonitor pm,
|
||||
final StatusPanel status,
|
||||
final ContributionListing contribListing) {
|
||||
@@ -412,7 +412,7 @@ public abstract class LocalContribution extends Contribution {
|
||||
if (getType() == ContributionType.MODE) {
|
||||
boolean isModeActive = false;
|
||||
ModeContribution m = (ModeContribution) this;
|
||||
Iterator<Editor> iter = editor.getBase().getEditors().iterator();
|
||||
Iterator<Editor> iter = base.getEditors().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Editor e = iter.next();
|
||||
if (e.getMode().equals(m.getMode())) {
|
||||
@@ -421,7 +421,7 @@ public abstract class LocalContribution extends Contribution {
|
||||
}
|
||||
}
|
||||
if (!isModeActive) {
|
||||
m.clearClassLoader(editor.getBase());
|
||||
m.clearClassLoader(base);
|
||||
} else {
|
||||
pm.cancel();
|
||||
Messages.showMessage("Mode Manager",
|
||||
@@ -442,12 +442,12 @@ public abstract class LocalContribution extends Contribution {
|
||||
t.clearClassLoader(editor.getBase());
|
||||
*/
|
||||
// menu will be rebuilt below with the refreshContribs() call
|
||||
editor.getBase().clearToolMenus();
|
||||
base.clearToolMenus();
|
||||
((ToolContribution) this).clearClassLoader();
|
||||
}
|
||||
|
||||
if (doBackup) {
|
||||
success = backup(editor, true, status);
|
||||
success = backup(true, status);
|
||||
} else {
|
||||
Util.removeDir(getFolder());
|
||||
success = !getFolder().exists();
|
||||
@@ -473,6 +473,8 @@ public abstract class LocalContribution extends Contribution {
|
||||
} else {
|
||||
contribListing.replaceContribution(LocalContribution.this, advertisedVersion);
|
||||
}
|
||||
base.refreshContribs(LocalContribution.this.getType());
|
||||
base.setUpdatesAvailable(contribListing.countUpdates(base));
|
||||
}
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
@@ -488,7 +490,7 @@ public abstract class LocalContribution extends Contribution {
|
||||
|
||||
} else {
|
||||
// There was a failure backing up the folder
|
||||
if (!doBackup || (doBackup && backup(editor, false, status))) {
|
||||
if (!doBackup || (doBackup && backup(false, status))) {
|
||||
if (setDeletionFlag(true)) {
|
||||
try {
|
||||
// TODO: run this in SwingWorker done() [jv]
|
||||
@@ -497,6 +499,8 @@ public abstract class LocalContribution extends Contribution {
|
||||
public void run() {
|
||||
contribListing.replaceContribution(LocalContribution.this,
|
||||
LocalContribution.this);
|
||||
base.refreshContribs(LocalContribution.this.getType());
|
||||
base.setUpdatesAvailable(contribListing.countUpdates(base));
|
||||
}
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
@@ -514,7 +518,6 @@ public abstract class LocalContribution extends Contribution {
|
||||
status.setErrorMessage("Could not delete the contribution's files");
|
||||
}
|
||||
}
|
||||
editor.getBase().refreshContribs(this.getType());
|
||||
if (success) {
|
||||
pm.finished();
|
||||
} else {
|
||||
|
||||
@@ -225,16 +225,16 @@ public class UpdateListPanel extends ListPanel {
|
||||
if (newPanel == null) {
|
||||
newPanel = new DetailPanel(UpdateListPanel.this);
|
||||
}
|
||||
if (!panelByContribution.containsKey(contribution)) {
|
||||
synchronized (panelByContribution) {
|
||||
synchronized (panelByContribution) {
|
||||
if (!panelByContribution.containsKey(contribution)) {
|
||||
panelByContribution.put(contribution, newPanel);
|
||||
}
|
||||
}
|
||||
if (newPanel != null) {
|
||||
newPanel.setContribution(contribution);
|
||||
add(newPanel);
|
||||
updatePanelOrdering(panelByContribution.keySet());
|
||||
updateColors(); // XXX this is the place
|
||||
if (newPanel != null) {
|
||||
newPanel.setContribution(contribution);
|
||||
add(newPanel);
|
||||
updatePanelOrdering(panelByContribution.keySet());
|
||||
updateColors(); // XXX this is the place
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1090,6 +1090,16 @@ public abstract class Editor extends JFrame implements RunnerListener {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates update count in the UI. Called on EDT.
|
||||
* @param n number of available updates
|
||||
*/
|
||||
public void setUpdatesAvailable(int n) {
|
||||
// TODO: refresh UI and remove the debug message
|
||||
PApplet.println("setting update count to", n);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Override this if you want a special menu for your particular 'mode'.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user