From 089b1d9d81bdc092c125d67dd737484539dcc5a6 Mon Sep 17 00:00:00 2001 From: Joel Moniz Date: Sun, 17 Aug 2014 13:31:20 +0530 Subject: [PATCH] Added many, many more ways for references to be included --- app/src/processing/app/Editor.java | 9 ++++-- app/src/processing/app/Library.java | 20 +++++++++++-- .../app/contrib/ToolContribution.java | 29 ++++++++++++++++++- app/src/processing/mode/java/JavaEditor.java | 4 +-- 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 76fa82d22..0e8702652 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -1278,8 +1278,13 @@ public abstract class Editor extends JFrame implements RunnerListener { } catch (IOException e) { e.printStackTrace(); } - // Prepend with file:// and also encode spaces & other characters - Base.openURL(file.toURI().toString()); + + if (file.toString().endsWith(".txt")) + // To enable readme.txt files to open as well + Base.openFolder(file); + else + // Prepend with file:// and also encode spaces & other characters + Base.openURL(file.toURI().toString()); } diff --git a/app/src/processing/app/Library.java b/app/src/processing/app/Library.java index 8b468ec4a..9f78ebef7 100644 --- a/app/src/processing/app/Library.java +++ b/app/src/processing/app/Library.java @@ -13,7 +13,7 @@ public class Library extends LocalContribution { //protected File folder; // /path/to/shortname protected File libraryFolder; // shortname/library protected File examplesFolder; // shortname/examples - protected File referenceFile; // shortname/reference/index.html + protected File referenceFile; // shortname/reference/index.html is one possible path /** * Subfolder for grouping libraries in a menu. Basic subfolder support @@ -110,7 +110,7 @@ public class Library extends LocalContribution { libraryFolder = new File(folder, "library"); examplesFolder = new File(folder, "examples"); - referenceFile = new File(folder, "reference/index.html"); + referenceFile = loadReferenceIndexFile(folder); File exportSettings = new File(libraryFolder, "export.txt"); HashMap exportTable = Base.readSettings(exportSettings); @@ -284,6 +284,22 @@ public class Library extends LocalContribution { } + private File loadReferenceIndexFile(File folder) { + final String potentialFileList[] = { + "reference/index.html", "reference/index.htm", + "documentation/index.html", "documentation/index.htm", "docs/index.html", + "docs/index.htm", "documentation.html", "documentation.htm", + "reference.html", "reference.htm", "docs.html", "docs.htm", "readme.txt" }; + + int i = 0; + File potentialRef = new File(folder, potentialFileList[i]); + while (!potentialRef.exists() && ++i < potentialFileList.length) { + potentialRef = new File(folder, potentialFileList[i]); + } + return potentialRef; + } + + public boolean hasReference() { return referenceFile.exists(); } diff --git a/app/src/processing/app/contrib/ToolContribution.java b/app/src/processing/app/contrib/ToolContribution.java index b84dbd89c..10d7ade93 100644 --- a/app/src/processing/app/contrib/ToolContribution.java +++ b/app/src/processing/app/contrib/ToolContribution.java @@ -35,7 +35,8 @@ import processing.app.tools.Tool; public class ToolContribution extends LocalContribution implements Tool { private Tool tool; - + protected File referenceFile; // shortname/reference/index.html is one possible path + static public ToolContribution load(File folder) { try { return new ToolContribution(folder); @@ -53,6 +54,7 @@ public class ToolContribution extends LocalContribution implements Tool { private ToolContribution(File folder) throws Exception { super(folder); + referenceFile = loadReferenceIndexFile(); String className = initLoader(null); if (className != null) { @@ -153,4 +155,29 @@ public class ToolContribution extends LocalContribution implements Tool { public ContributionType getType() { return ContributionType.TOOL; } + + public File loadReferenceIndexFile() { + final String potentialFileList[] = { + "reference/index.html", "reference/index.htm", + "documentation/index.html", "documentation/index.htm", "docs/index.html", + "docs/index.htm", "documentation.html", "documentation.htm", + "reference.html", "reference.htm", "docs.html", "docs.htm", "readme.txt" }; + + int i = 0; + File potentialRef = new File(folder, potentialFileList[i]); + while (!potentialRef.exists() && ++i < potentialFileList.length) { + potentialRef = new File(folder, potentialFileList[i]); + } + return potentialRef; + } + + + public File getReferenceIndexFile() { + return referenceFile; + } + + + public boolean hasReference() { + return referenceFile.exists(); + } } \ No newline at end of file diff --git a/app/src/processing/mode/java/JavaEditor.java b/app/src/processing/mode/java/JavaEditor.java index d26e2ee13..ae8f3a400 100644 --- a/app/src/processing/mode/java/JavaEditor.java +++ b/app/src/processing/mode/java/JavaEditor.java @@ -313,8 +313,8 @@ public class JavaEditor extends Editor { Iterator iter = toolsList.iterator(); while (iter.hasNext()) { final ToolContribution toolContrib = iter.next(); - final File toolRef = new File(toolContrib.getFolder(), "reference/index.html"); - if (toolRef.exists()) { + if (toolContrib.hasReference()) { + final File toolRef = toolContrib.getReferenceIndexFile(); JMenuItem libRefItem = new JMenuItem(toolContrib.getName()); libRefItem.addActionListener(new ActionListener() {