Skip to content

Commit bd2dd14

Browse files
committed
Tool and Lib References now show in Help menu
Removing LocalContribWithReference.java
1 parent 449905b commit bd2dd14

3 files changed

Lines changed: 95 additions & 64 deletions

File tree

app/src/processing/app/Library.java

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
import processing.core.*;
88

99

10-
public class Library extends LocalContribWithReference {
10+
public class Library extends LocalContribution {
1111
static final String[] platformNames = PConstants.platformNames;
1212

1313
//protected File folder; // /path/to/shortname
1414
protected File libraryFolder; // shortname/library
1515
protected File examplesFolder; // shortname/examples
16-
17-
// Shifted to LocalContribWithReference
18-
// protected File referenceFile; // shortname/reference/index.html is one possible path
16+
protected File referenceFile; // shortname/reference/index.html is one possible path
1917

2018
/**
2119
* Subfolder for grouping libraries in a menu. Basic subfolder support
@@ -112,9 +110,7 @@ private Library(File folder, String groupName) {
112110

113111
libraryFolder = new File(folder, "library");
114112
examplesFolder = new File(folder, "examples");
115-
116-
// Now done in LocalContribWithReference's ctor
117-
// referenceFile = loadReferenceIndexFile(folder);
113+
referenceFile = new File(folder, "reference/index.html");
118114

119115
File exportSettings = new File(libraryFolder, "export.txt");
120116
HashMap<String,String> exportTable = Base.readSettings(exportSettings);
@@ -216,6 +212,8 @@ private Library(File folder, String groupName) {
216212

217213
// get the path for all .jar files in this code folder
218214
packageList = Base.packageListFromClassPath(getClassPath());
215+
216+
referenceFile = loadReferenceIndexFile(folder);
219217
}
220218

221219

@@ -518,4 +516,47 @@ static protected void list(File folder, ArrayList<Library> libraries) {
518516
public ContributionType getType() {
519517
return ContributionType.LIBRARY;
520518
}
519+
520+
521+
/**
522+
* @param folder
523+
* The file object representing the base folder of the contribution
524+
* @return Returns a file object representing the index file of the reference
525+
*/
526+
protected File loadReferenceIndexFile(File folder) {
527+
final String potentialFileList[] = {
528+
"reference/index.html", "reference/index.htm",
529+
"documentation/index.html", "documentation/index.htm", "docs/index.html",
530+
"docs/index.htm", "documentation.html", "documentation.htm",
531+
"reference.html", "reference.htm", "docs.html", "docs.htm", "readme.txt" };
532+
533+
int i = 0;
534+
File potentialRef = new File(folder, potentialFileList[i]);
535+
while (!potentialRef.exists() && ++i < potentialFileList.length) {
536+
potentialRef = new File(folder, potentialFileList[i]);
537+
}
538+
return potentialRef;
539+
}
540+
541+
542+
/**
543+
* Returns the object stored in the referenceFile field, which contains an
544+
* instance of the file object representing the index file of the reference
545+
*
546+
* @return referenceFile
547+
*/
548+
public File getReferenceIndexFile() {
549+
return referenceFile;
550+
}
551+
552+
553+
/**
554+
* Tests whether the reference's index file indicated by referenceFile exists.
555+
*
556+
* @return true if and only if the file denoted by referenceFile exists; false
557+
* otherwise.
558+
*/
559+
public boolean hasReference() {
560+
return referenceFile.exists();
561+
}
521562
}

app/src/processing/app/contrib/LocalContribWithReference.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

app/src/processing/app/contrib/ToolContribution.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
import processing.app.tools.Tool;
3333

3434

35-
public class ToolContribution extends LocalContribWithReference implements Tool {
35+
public class ToolContribution extends LocalContribution implements Tool {
3636
private Tool tool;
3737

38+
private File referenceFile; // shortname/reference/index.html is one possible path
3839

3940
static public ToolContribution load(File folder) {
4041
try {
@@ -59,6 +60,8 @@ private ToolContribution(File folder) throws Exception {
5960
Class<?> toolClass = loader.loadClass(className);
6061
tool = (Tool) toolClass.newInstance();
6162
}
63+
64+
referenceFile = loadReferenceIndexFile(folder);
6265
}
6366

6467

@@ -153,4 +156,47 @@ public String getMenuTitle() {
153156
public ContributionType getType() {
154157
return ContributionType.TOOL;
155158
}
159+
160+
161+
/**
162+
* @param folder
163+
* The file object representing the base folder of the contribution
164+
* @return Returns a file object representing the index file of the reference
165+
*/
166+
protected File loadReferenceIndexFile(File folder) {
167+
final String potentialFileList[] = {
168+
"reference/index.html", "reference/index.htm",
169+
"documentation/index.html", "documentation/index.htm", "docs/index.html",
170+
"docs/index.htm", "documentation.html", "documentation.htm",
171+
"reference.html", "reference.htm", "docs.html", "docs.htm", "readme.txt" };
172+
173+
int i = 0;
174+
File potentialRef = new File(folder, potentialFileList[i]);
175+
while (!potentialRef.exists() && ++i < potentialFileList.length) {
176+
potentialRef = new File(folder, potentialFileList[i]);
177+
}
178+
return potentialRef;
179+
}
180+
181+
182+
/**
183+
* Returns the object stored in the referenceFile field, which contains an
184+
* instance of the file object representing the index file of the reference
185+
*
186+
* @return referenceFile
187+
*/
188+
public File getReferenceIndexFile() {
189+
return referenceFile;
190+
}
191+
192+
193+
/**
194+
* Tests whether the reference's index file indicated by referenceFile exists.
195+
*
196+
* @return true if and only if the file denoted by referenceFile exists; false
197+
* otherwise.
198+
*/
199+
public boolean hasReference() {
200+
return referenceFile.exists();
201+
}
156202
}

0 commit comments

Comments
 (0)