mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
i18n and formatting of code related to import lib auto-install
This commit is contained in:
@@ -251,9 +251,9 @@ public class AvailableContribution extends Contribution {
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
category = sb.toString();
|
||||
}
|
||||
|
||||
|
||||
String specifiedImport = "";
|
||||
List<String> importsList = parseImports(properties.get("imports"));
|
||||
List<String> importsList = parseImports(properties.get("imports"));
|
||||
if (importsList == null || importsList.isEmpty()) {
|
||||
specifiedImport = getImportStr();
|
||||
} else {
|
||||
|
||||
@@ -92,18 +92,18 @@ abstract public class Contribution {
|
||||
|
||||
|
||||
protected String getImportStr() {
|
||||
if (specifiedImports == null || specifiedImports.isEmpty())
|
||||
if (specifiedImports == null || specifiedImports.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String importName : specifiedImports) {
|
||||
sb.append(importName);
|
||||
sb.append(',');
|
||||
}
|
||||
sb.deleteCharAt(sb.length()-1); // delete last comma
|
||||
sb.deleteCharAt(sb.length() - 1); // delete last comma
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected boolean hasImport(String importName) {
|
||||
if (specifiedImports != null && importName != null) {
|
||||
for (String c : specifiedImports) {
|
||||
@@ -267,13 +267,13 @@ abstract public class Contribution {
|
||||
*/
|
||||
static List<String> parseImports(String importStr) {
|
||||
List<String> outgoing = new ArrayList<String>();
|
||||
|
||||
|
||||
if (importStr != null) {
|
||||
String[] importList = PApplet.trim(PApplet.split(importStr, ','));
|
||||
for (String importName : importList) {
|
||||
outgoing.add(importName);
|
||||
outgoing.add(importName);
|
||||
}
|
||||
}
|
||||
return (outgoing.size() > 0) ? outgoing : null;
|
||||
return (outgoing.size() > 0) ? outgoing : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public class ContributionListing {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (oldLib.getImports() != null) {
|
||||
for (String importName : oldLib.getImports()) {
|
||||
librariesByImportHeader.replace(importName, newLib);
|
||||
|
||||
@@ -110,8 +110,9 @@ public class ContributionManager {
|
||||
// Hiding stack trace. An error has been shown where needed.
|
||||
// ioe.printStackTrace();
|
||||
}
|
||||
if (progress != null)
|
||||
if (progress != null) {
|
||||
progress.finished();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -154,8 +155,9 @@ public class ContributionManager {
|
||||
contribListing.replaceContribution(ad, contribution);
|
||||
if (contribution.getType() == ContributionType.MODE) {
|
||||
ArrayList<ModeContribution> contribModes = editor.getBase().getModeContribs();
|
||||
if (!contribModes.contains(contribution))
|
||||
if (!contribModes.contains(contribution)) {
|
||||
contribModes.add((ModeContribution) contribution);
|
||||
}
|
||||
}
|
||||
refreshInstalled(editor);
|
||||
}
|
||||
@@ -232,8 +234,9 @@ public class ContributionManager {
|
||||
contribModes.add((ModeContribution) contribution);
|
||||
}
|
||||
}
|
||||
if (base.getActiveEditor() != null)
|
||||
if (base.getActiveEditor() != null) {
|
||||
refreshInstalled(base.getActiveEditor());
|
||||
}
|
||||
}
|
||||
|
||||
contribZip.delete();
|
||||
@@ -243,13 +246,12 @@ public class ContributionManager {
|
||||
} catch (Exception e) {
|
||||
// Chuck the stack trace. The user might have no idea why it is appearing, or what (s)he did wrong...
|
||||
// e.printStackTrace();
|
||||
System.out.println("Error during download and install of "
|
||||
+ ad.getName());
|
||||
String arg = "contrib.startup.errors.download_install";
|
||||
System.err.println(Language.interpolate(arg, ad.getName()));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err
|
||||
.println("Could not write to temporary directory during download and install of "
|
||||
+ ad.getName());
|
||||
String arg = "contrib.startup.errors.temp_dir";
|
||||
System.err.println(Language.interpolate(arg, ad.getName()));
|
||||
}
|
||||
}
|
||||
}, "Contribution Installer").start();
|
||||
@@ -288,8 +290,8 @@ public class ContributionManager {
|
||||
} catch (IOException e) {
|
||||
// Again, forget about the stack trace. The user ain't done wrong
|
||||
// e.printStackTrace();
|
||||
System.err.println("The unupdated contribution marker seems to not like "
|
||||
+ ac.getName() + ". You may have to install it manually to update...");
|
||||
String arg = "contrib.startup.errors.new_marker";
|
||||
System.err.println(Language.interpolate(arg, ac.getName()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -311,12 +313,17 @@ public class ContributionManager {
|
||||
// during pre-processing
|
||||
base.getActiveEditor().getTextArea().setEditable(false);
|
||||
base.getActiveEditor().getConsole().clear();
|
||||
|
||||
|
||||
ArrayList<String> installedLibList = new ArrayList<String>();
|
||||
|
||||
// boolean variable to check if previous lib was installed successfully,
|
||||
// to give the user an idea about progress being made.
|
||||
boolean isPrevDone = false;
|
||||
|
||||
for (AvailableContribution ad : aList) {
|
||||
if (ad.getType() != ContributionType.LIBRARY)
|
||||
if (ad.getType() != ContributionType.LIBRARY) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
URL url = new URL(ad.link);
|
||||
String filename = url.getFile();
|
||||
@@ -332,55 +339,63 @@ public class ContributionManager {
|
||||
// one install is completed and the next download has begun without
|
||||
// interfereing with occur status messages that may arise in the meanwhile
|
||||
String statusMsg = base.getActiveEditor().getStatusMessage();
|
||||
if (statusMsg.contains("has been installed"))
|
||||
base.getActiveEditor().statusNotice(statusMsg + " "
|
||||
+ "Downloading "
|
||||
+ ad.name + "...");
|
||||
else
|
||||
base.getActiveEditor().statusNotice("Downloading " + ad.name
|
||||
+ "...");
|
||||
if (isPrevDone) {
|
||||
String status = statusMsg + " "
|
||||
+ Language.interpolate("contrib.import.progress.download", ad.name);
|
||||
base.getActiveEditor().statusNotice(status);
|
||||
}
|
||||
else {
|
||||
String arg = "contrib.import.progress.download";
|
||||
String status = Language.interpolate(arg, ad.name);
|
||||
base.getActiveEditor().statusNotice(status);
|
||||
}
|
||||
|
||||
isPrevDone = false;
|
||||
|
||||
download(url, contribZip, null);
|
||||
|
||||
base.getActiveEditor()
|
||||
.statusNotice("Installing " + ad.name + "...");
|
||||
String arg = "contrib.import.progress.install";
|
||||
base.getActiveEditor().statusNotice(Language.interpolate(arg,ad.name));
|
||||
LocalContribution contribution = ad.install(base, contribZip,
|
||||
false, null);
|
||||
|
||||
if (contribution != null) {
|
||||
contribListing.replaceContribution(ad, contribution);
|
||||
if (base.getActiveEditor() != null)
|
||||
if (base.getActiveEditor() != null) {
|
||||
refreshInstalled(base.getActiveEditor());
|
||||
}
|
||||
}
|
||||
|
||||
contribZip.delete();
|
||||
|
||||
installedLibList.add(ad.name);
|
||||
base.getActiveEditor().statusNotice(ad.name
|
||||
+ " has been installed.");
|
||||
isPrevDone = true;
|
||||
|
||||
arg = "contrib.import.progress.done";
|
||||
base.getActiveEditor().statusNotice(Language.interpolate(arg,ad.name));
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error during download and install of "
|
||||
+ ad.getName());
|
||||
String arg = "contrib.startup.errors.download_install";
|
||||
System.err.println(Language.interpolate(arg, ad.getName()));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err
|
||||
.println("Could not write to temporary directory during download and install of "
|
||||
+ ad.getName());
|
||||
String arg = "contrib.startup.errors.temp_dir";
|
||||
System.err.println(Language.interpolate(arg,ad.getName()));
|
||||
}
|
||||
} catch (MalformedURLException e1) {
|
||||
System.err.println("Error: The library " + ad.getName()
|
||||
+ " has a weird looking download link.");
|
||||
System.err.println(Language.interpolate("contrib.import.errors.link",
|
||||
ad.getName()));
|
||||
}
|
||||
}
|
||||
base.getActiveEditor().getTextArea().setEditable(true);
|
||||
base.getActiveEditor().statusEmpty();
|
||||
System.out.println("The following libraries have been installed:");
|
||||
System.out.println(Language.text("contrib.import.progress.final_list"));
|
||||
for (String l : installedLibList) {
|
||||
System.out.println(" • " + l);
|
||||
System.out.println(" * " + l);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public void refreshInstalled(Editor e) {
|
||||
|
||||
Iterator<Editor> iter = e.getBase().getEditors().iterator();
|
||||
|
||||
@@ -338,8 +338,9 @@ delete.messages.is_read_only.description = Some files are marked \"read-only\",
|
||||
|
||||
|
||||
# ---------------------------------------
|
||||
# Contribution Panel
|
||||
# Contributions
|
||||
|
||||
# Contribution Panel
|
||||
contrib = Contribution Manager
|
||||
contrib.manager_title.update = Update Manager
|
||||
contrib.manager_title.mode = Mode Manager
|
||||
@@ -384,6 +385,20 @@ contrib.progress.downloading = Downloading
|
||||
contrib.download_error = An error occured while downloading the contribution.
|
||||
contrib.unsupported_operating_system = Your operating system does not appear to be supported. You should visit the %s\'s library for more info.
|
||||
|
||||
# Install on Startup
|
||||
contrib.startup.errors.download_install = Error during download and install of %s
|
||||
contrib.startup.errors.temp_dir = Could not write to temporary directory during download and install of %s
|
||||
contrib.startup.errors.new_marker = The unupdated contribution marker seems to not like %s. You may have to install it manually to update...
|
||||
|
||||
# Install on Import
|
||||
contrib.import.dialog.title = Missing Libraries Available
|
||||
contrib.import.dialog.primary_text = The following imported libraries are available for download, but have not been installed.
|
||||
contrib.import.dialog.secondary_text = Would you like to install them now?
|
||||
contrib.import.progress.download = Downloading %s...
|
||||
contrib.import.progress.install = Installing %s...
|
||||
contrib.import.progress.done = %s has been installed.
|
||||
contrib.import.progress.final_list = The following libraries have been installed:
|
||||
contrib.import.errors.link = Error: The library %s has a strange looking download link.
|
||||
|
||||
# ---------------------------------------
|
||||
# Warnings
|
||||
|
||||
@@ -1853,11 +1853,12 @@ public class JavaEditor extends Editor {
|
||||
super.prepareRun();
|
||||
downloadImports();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Downloads libraries that have been imported, that aren't available as a
|
||||
* LocalContribution, but that have an AvailableContribution associated with
|
||||
* them.
|
||||
* Downloads libraries that have been imported, that aren't available as a
|
||||
* LocalContribution, but that have an AvailableContribution associated with
|
||||
* them.
|
||||
*/
|
||||
protected void downloadImports() {
|
||||
String importRegex = errorCheckerService.importRegexp;
|
||||
@@ -1867,7 +1868,7 @@ public class JavaEditor extends Editor {
|
||||
tabCode = sc.getProgram();
|
||||
|
||||
String[][] pieces = PApplet.matchAll(tabCode, importRegex);
|
||||
|
||||
|
||||
if (pieces != null) {
|
||||
ArrayList<String> importHeaders = new ArrayList<String>();
|
||||
for (String[] importStatement : pieces) {
|
||||
@@ -1879,24 +1880,26 @@ public class JavaEditor extends Editor {
|
||||
for (AvailableContribution ac : installLibsHeaders) {
|
||||
libList.append("\n • " + ac.getName());
|
||||
}
|
||||
int option = Base
|
||||
.showYesNoQuestion(this, "Missing Libraries Available",
|
||||
"The following imported libraries are available for download, but have not been installed.",
|
||||
libList.toString());
|
||||
int option = Base.showYesNoQuestion(this,
|
||||
Language.text("contrib.import.dialog.title"),
|
||||
Language.text("contrib.import.dialog.primary_text"),
|
||||
libList.toString());
|
||||
|
||||
if (option == JOptionPane.YES_OPTION) {
|
||||
ContributionManager.downloadAndInstallOnImport(base,
|
||||
installLibsHeaders);
|
||||
}
|
||||
if (option == JOptionPane.YES_OPTION) {
|
||||
ContributionManager.downloadAndInstallOnImport(base,
|
||||
installLibsHeaders);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a list of AvailableContributions of those libraries that the user wants imported,
|
||||
* but that are not installed.
|
||||
* Returns a list of AvailableContributions of those libraries that the user
|
||||
* wants imported, but that are not installed.
|
||||
*
|
||||
* @param importHeaders
|
||||
*/
|
||||
private ArrayList<AvailableContribution> getNotInstalledAvailableLibs(ArrayList<String> importHeadersList) {
|
||||
@@ -1917,19 +1920,24 @@ public class JavaEditor extends Editor {
|
||||
library = this.getMode().getLibrary(entry);
|
||||
if (library == null) {
|
||||
Contribution c = importMap.get(importHeaders);
|
||||
if (c!=null && c instanceof AvailableContribution)
|
||||
libList.add((AvailableContribution)c);//System.out.println(importHeaders + "not found");
|
||||
if (c != null && c instanceof AvailableContribution) {
|
||||
libList.add((AvailableContribution) c);// System.out.println(importHeaders
|
||||
// + "not found");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Not gonna happen (hopefully)
|
||||
Contribution c = importMap.get(importHeaders);
|
||||
if (c!=null && c instanceof AvailableContribution)
|
||||
libList.add((AvailableContribution)c);//System.out.println(importHeaders + "not found");
|
||||
if (c != null && c instanceof AvailableContribution) {
|
||||
libList.add((AvailableContribution) c);// System.out.println(importHeaders
|
||||
// + "not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
return libList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Displays a JDialog prompting the user to save when the user hits
|
||||
* run/present/etc.
|
||||
|
||||
Reference in New Issue
Block a user