Skip to content

Commit 2f95e05

Browse files
committed
i18n and formatting of code related to import lib auto-install
1 parent 66a991d commit 2f95e05

6 files changed

Lines changed: 103 additions & 65 deletions

File tree

app/src/processing/app/contrib/AvailableContribution.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ public boolean writePropertiesFile(File propFile) {
251251
sb.deleteCharAt(sb.length() - 1);
252252
category = sb.toString();
253253
}
254-
254+
255255
String specifiedImport = "";
256-
List<String> importsList = parseImports(properties.get("imports"));
256+
List<String> importsList = parseImports(properties.get("imports"));
257257
if (importsList == null || importsList.isEmpty()) {
258258
specifiedImport = getImportStr();
259259
} else {

app/src/processing/app/contrib/Contribution.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,18 @@ protected List<String> getImports() {
9292

9393

9494
protected String getImportStr() {
95-
if (specifiedImports == null || specifiedImports.isEmpty())
95+
if (specifiedImports == null || specifiedImports.isEmpty()) {
9696
return "";
97+
}
9798
StringBuilder sb = new StringBuilder();
9899
for (String importName : specifiedImports) {
99100
sb.append(importName);
100101
sb.append(',');
101102
}
102-
sb.deleteCharAt(sb.length()-1); // delete last comma
103+
sb.deleteCharAt(sb.length() - 1); // delete last comma
103104
return sb.toString();
104105
}
105-
106-
106+
107107
protected boolean hasImport(String importName) {
108108
if (specifiedImports != null && importName != null) {
109109
for (String c : specifiedImports) {
@@ -267,13 +267,13 @@ static List<String> parseCategories(String categoryStr) {
267267
*/
268268
static List<String> parseImports(String importStr) {
269269
List<String> outgoing = new ArrayList<String>();
270-
270+
271271
if (importStr != null) {
272272
String[] importList = PApplet.trim(PApplet.split(importStr, ','));
273273
for (String importName : importList) {
274-
outgoing.add(importName);
274+
outgoing.add(importName);
275275
}
276276
}
277-
return (outgoing.size() > 0) ? outgoing : null;
277+
return (outgoing.size() > 0) ? outgoing : null;
278278
}
279279
}

app/src/processing/app/contrib/ContributionListing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected void replaceContribution(Contribution oldLib, Contribution newLib) {
120120
}
121121
}
122122
}
123-
123+
124124
if (oldLib.getImports() != null) {
125125
for (String importName : oldLib.getImports()) {
126126
librariesByImportHeader.replace(importName, newLib);

app/src/processing/app/contrib/ContributionManager.java

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ static boolean download(URL source, File dest, ProgressMonitor progress) {
110110
// Hiding stack trace. An error has been shown where needed.
111111
// ioe.printStackTrace();
112112
}
113-
if (progress != null)
113+
if (progress != null) {
114114
progress.finished();
115+
}
115116
return success;
116117
}
117118

@@ -154,8 +155,9 @@ public void run() {
154155
contribListing.replaceContribution(ad, contribution);
155156
if (contribution.getType() == ContributionType.MODE) {
156157
ArrayList<ModeContribution> contribModes = editor.getBase().getModeContribs();
157-
if (!contribModes.contains(contribution))
158+
if (!contribModes.contains(contribution)) {
158159
contribModes.add((ModeContribution) contribution);
160+
}
159161
}
160162
refreshInstalled(editor);
161163
}
@@ -232,8 +234,9 @@ public void run() {
232234
contribModes.add((ModeContribution) contribution);
233235
}
234236
}
235-
if (base.getActiveEditor() != null)
237+
if (base.getActiveEditor() != null) {
236238
refreshInstalled(base.getActiveEditor());
239+
}
237240
}
238241

239242
contribZip.delete();
@@ -243,13 +246,12 @@ public void run() {
243246
} catch (Exception e) {
244247
// Chuck the stack trace. The user might have no idea why it is appearing, or what (s)he did wrong...
245248
// e.printStackTrace();
246-
System.out.println("Error during download and install of "
247-
+ ad.getName());
249+
String arg = "contrib.startup.errors.download_install";
250+
System.err.println(Language.interpolate(arg, ad.getName()));
248251
}
249252
} catch (IOException e) {
250-
System.err
251-
.println("Could not write to temporary directory during download and install of "
252-
+ ad.getName());
253+
String arg = "contrib.startup.errors.temp_dir";
254+
System.err.println(Language.interpolate(arg, ad.getName()));
253255
}
254256
}
255257
}, "Contribution Installer").start();
@@ -288,8 +290,8 @@ public boolean accept(File dir, String file) {
288290
} catch (IOException e) {
289291
// Again, forget about the stack trace. The user ain't done wrong
290292
// e.printStackTrace();
291-
System.err.println("The unupdated contribution marker seems to not like "
292-
+ ac.getName() + ". You may have to install it manually to update...");
293+
String arg = "contrib.startup.errors.new_marker";
294+
System.err.println(Language.interpolate(arg, ac.getName()));
293295
}
294296

295297
}
@@ -311,12 +313,17 @@ public static void downloadAndInstallOnImport(final Base base,
311313
// during pre-processing
312314
base.getActiveEditor().getTextArea().setEditable(false);
313315
base.getActiveEditor().getConsole().clear();
314-
316+
315317
ArrayList<String> installedLibList = new ArrayList<String>();
316318

319+
// boolean variable to check if previous lib was installed successfully,
320+
// to give the user an idea about progress being made.
321+
boolean isPrevDone = false;
322+
317323
for (AvailableContribution ad : aList) {
318-
if (ad.getType() != ContributionType.LIBRARY)
324+
if (ad.getType() != ContributionType.LIBRARY) {
319325
continue;
326+
}
320327
try {
321328
URL url = new URL(ad.link);
322329
String filename = url.getFile();
@@ -332,55 +339,63 @@ public static void downloadAndInstallOnImport(final Base base,
332339
// one install is completed and the next download has begun without
333340
// interfereing with occur status messages that may arise in the meanwhile
334341
String statusMsg = base.getActiveEditor().getStatusMessage();
335-
if (statusMsg.contains("has been installed"))
336-
base.getActiveEditor().statusNotice(statusMsg + " "
337-
+ "Downloading "
338-
+ ad.name + "...");
339-
else
340-
base.getActiveEditor().statusNotice("Downloading " + ad.name
341-
+ "...");
342+
if (isPrevDone) {
343+
String status = statusMsg + " "
344+
+ Language.interpolate("contrib.import.progress.download", ad.name);
345+
base.getActiveEditor().statusNotice(status);
346+
}
347+
else {
348+
String arg = "contrib.import.progress.download";
349+
String status = Language.interpolate(arg, ad.name);
350+
base.getActiveEditor().statusNotice(status);
351+
}
352+
353+
isPrevDone = false;
342354

343355
download(url, contribZip, null);
344356

345-
base.getActiveEditor()
346-
.statusNotice("Installing " + ad.name + "...");
357+
String arg = "contrib.import.progress.install";
358+
base.getActiveEditor().statusNotice(Language.interpolate(arg,ad.name));
347359
LocalContribution contribution = ad.install(base, contribZip,
348360
false, null);
349361

350362
if (contribution != null) {
351363
contribListing.replaceContribution(ad, contribution);
352-
if (base.getActiveEditor() != null)
364+
if (base.getActiveEditor() != null) {
353365
refreshInstalled(base.getActiveEditor());
366+
}
354367
}
355368

356369
contribZip.delete();
357370

358371
installedLibList.add(ad.name);
359-
base.getActiveEditor().statusNotice(ad.name
360-
+ " has been installed.");
372+
isPrevDone = true;
373+
374+
arg = "contrib.import.progress.done";
375+
base.getActiveEditor().statusNotice(Language.interpolate(arg,ad.name));
361376

362377
} catch (Exception e) {
363-
System.out.println("Error during download and install of "
364-
+ ad.getName());
378+
String arg = "contrib.startup.errors.download_install";
379+
System.err.println(Language.interpolate(arg, ad.getName()));
365380
}
366381
} catch (IOException e) {
367-
System.err
368-
.println("Could not write to temporary directory during download and install of "
369-
+ ad.getName());
382+
String arg = "contrib.startup.errors.temp_dir";
383+
System.err.println(Language.interpolate(arg,ad.getName()));
370384
}
371385
} catch (MalformedURLException e1) {
372-
System.err.println("Error: The library " + ad.getName()
373-
+ " has a weird looking download link.");
386+
System.err.println(Language.interpolate("contrib.import.errors.link",
387+
ad.getName()));
374388
}
375389
}
376390
base.getActiveEditor().getTextArea().setEditable(true);
377391
base.getActiveEditor().statusEmpty();
378-
System.out.println("The following libraries have been installed:");
392+
System.out.println(Language.text("contrib.import.progress.final_list"));
379393
for (String l : installedLibList) {
380-
System.out.println(" " + l);
394+
System.out.println(" * " + l);
381395
}
382396
}
383397

398+
384399
static public void refreshInstalled(Editor e) {
385400

386401
Iterator<Editor> iter = e.getBase().getEditors().iterator();

build/shared/lib/languages/PDE.properties

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,9 @@ delete.messages.is_read_only.description = Some files are marked \"read-only\",
338338

339339

340340
# ---------------------------------------
341-
# Contribution Panel
341+
# Contributions
342342

343+
# Contribution Panel
343344
contrib = Contribution Manager
344345
contrib.manager_title.update = Update Manager
345346
contrib.manager_title.mode = Mode Manager
@@ -384,6 +385,20 @@ contrib.progress.downloading = Downloading
384385
contrib.download_error = An error occured while downloading the contribution.
385386
contrib.unsupported_operating_system = Your operating system does not appear to be supported. You should visit the %s\'s library for more info.
386387

388+
# Install on Startup
389+
contrib.startup.errors.download_install = Error during download and install of %s
390+
contrib.startup.errors.temp_dir = Could not write to temporary directory during download and install of %s
391+
contrib.startup.errors.new_marker = The unupdated contribution marker seems to not like %s. You may have to install it manually to update...
392+
393+
# Install on Import
394+
contrib.import.dialog.title = Missing Libraries Available
395+
contrib.import.dialog.primary_text = The following imported libraries are available for download, but have not been installed.
396+
contrib.import.dialog.secondary_text = Would you like to install them now?
397+
contrib.import.progress.download = Downloading %s...
398+
contrib.import.progress.install = Installing %s...
399+
contrib.import.progress.done = %s has been installed.
400+
contrib.import.progress.final_list = The following libraries have been installed:
401+
contrib.import.errors.link = Error: The library %s has a strange looking download link.
387402

388403
# ---------------------------------------
389404
# Warnings

java/src/processing/mode/java/JavaEditor.java

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,11 +1853,12 @@ public void prepareRun() {
18531853
super.prepareRun();
18541854
downloadImports();
18551855
}
1856-
1856+
1857+
18571858
/**
1858-
* Downloads libraries that have been imported, that aren't available as a
1859-
* LocalContribution, but that have an AvailableContribution associated with
1860-
* them.
1859+
* Downloads libraries that have been imported, that aren't available as a
1860+
* LocalContribution, but that have an AvailableContribution associated with
1861+
* them.
18611862
*/
18621863
protected void downloadImports() {
18631864
String importRegex = errorCheckerService.importRegexp;
@@ -1867,7 +1868,7 @@ protected void downloadImports() {
18671868
tabCode = sc.getProgram();
18681869

18691870
String[][] pieces = PApplet.matchAll(tabCode, importRegex);
1870-
1871+
18711872
if (pieces != null) {
18721873
ArrayList<String> importHeaders = new ArrayList<String>();
18731874
for (String[] importStatement : pieces) {
@@ -1879,24 +1880,26 @@ protected void downloadImports() {
18791880
for (AvailableContribution ac : installLibsHeaders) {
18801881
libList.append("\n • " + ac.getName());
18811882
}
1882-
int option = Base
1883-
.showYesNoQuestion(this, "Missing Libraries Available",
1884-
"The following imported libraries are available for download, but have not been installed.",
1885-
libList.toString());
1886-
1887-
if (option == JOptionPane.YES_OPTION) {
1888-
ContributionManager.downloadAndInstallOnImport(base,
1889-
installLibsHeaders);
1890-
}
1883+
int option = Base.showYesNoQuestion(this,
1884+
Language.text("contrib.import.dialog.title"),
1885+
Language.text("contrib.import.dialog.primary_text"),
1886+
libList.toString());
1887+
1888+
if (option == JOptionPane.YES_OPTION) {
1889+
ContributionManager.downloadAndInstallOnImport(base,
1890+
installLibsHeaders);
1891+
}
18911892
}
18921893
}
18931894
}
18941895
}
18951896
}
1896-
1897+
1898+
18971899
/**
1898-
* Returns a list of AvailableContributions of those libraries that the user wants imported,
1899-
* but that are not installed.
1900+
* Returns a list of AvailableContributions of those libraries that the user
1901+
* wants imported, but that are not installed.
1902+
*
19001903
* @param importHeaders
19011904
*/
19021905
private ArrayList<AvailableContribution> getNotInstalledAvailableLibs(ArrayList<String> importHeadersList) {
@@ -1917,19 +1920,24 @@ private ArrayList<AvailableContribution> getNotInstalledAvailableLibs(ArrayList<
19171920
library = this.getMode().getLibrary(entry);
19181921
if (library == null) {
19191922
Contribution c = importMap.get(importHeaders);
1920-
if (c!=null && c instanceof AvailableContribution)
1921-
libList.add((AvailableContribution)c);//System.out.println(importHeaders + "not found");
1923+
if (c != null && c instanceof AvailableContribution) {
1924+
libList.add((AvailableContribution) c);// System.out.println(importHeaders
1925+
// + "not found");
1926+
}
19221927
}
19231928
} catch (Exception e) {
19241929
// Not gonna happen (hopefully)
19251930
Contribution c = importMap.get(importHeaders);
1926-
if (c!=null && c instanceof AvailableContribution)
1927-
libList.add((AvailableContribution)c);//System.out.println(importHeaders + "not found");
1931+
if (c != null && c instanceof AvailableContribution) {
1932+
libList.add((AvailableContribution) c);// System.out.println(importHeaders
1933+
// + "not found");
1934+
}
19281935
}
19291936
}
19301937
return libList;
19311938
}
19321939

1940+
19331941
/**
19341942
* Displays a JDialog prompting the user to save when the user hits
19351943
* run/present/etc.

0 commit comments

Comments
 (0)