detect mode and library example folders for recent menu

This commit is contained in:
benfry
2012-07-24 03:05:06 +00:00
parent 60e801be85
commit 80c873bc7f
4 changed files with 64 additions and 23 deletions

View File

@@ -289,9 +289,6 @@ public class Base {
// Get the sketchbook path, and make sure it's set properly
determineSketchbookFolder();
// Needs to happen after the sketchbook folder has been located
recent = new Recent(this);
// Delete all modes and tools that have been flagged for deletion before
// they are initialized by an editor.
ArrayList<InstalledContribution> contribs = new ArrayList<InstalledContribution>();
@@ -306,6 +303,11 @@ public class Base {
buildCoreModes();
rebuildContribModes();
// Needs to happen after the sketchbook folder has been located.
// Also relies on the modes to be loaded so it knows what can be
// marked as an example.
recent = new Recent(this);
String lastModeIdentifier = Preferences.get("last.sketch.mode");
if (lastModeIdentifier == null) {
nextMode = coreModes[0];

View File

@@ -45,7 +45,7 @@ public abstract class Mode {
public ArrayList<Library> coreLibraries;
public ArrayList<Library> contribLibraries;
/** Library folder for core. (Used for OpenGL in particular.) */
protected Library coreLibrary;
@@ -150,8 +150,8 @@ public abstract class Mode {
public Library getCoreLibrary() {
return null;
}
public Library getLibrary(String pkgName) throws SketchException {
ArrayList<Library> libraries = importToLibraryTable.get(pkgName);
if (libraries == null) {

View File

@@ -112,9 +112,50 @@ public class Recent {
if (purtyPath.startsWith(sketchbookPath)) {
purtyPath = "sketchbook \u2192 " +
purtyPath.substring(sketchbookPath.length() + 1);
} else {
ArrayList<Mode> modes = base.getModeList();
for (Mode mode : modes) {
File examplesFolder = mode.getExamplesFolder();
String examplesPath = examplesFolder.getAbsolutePath();
if (purtyPath.startsWith(examplesPath)) {
String modePrefix = mode.getTitle();
if (mode.getTitle().equals("Standard")) {
modePrefix = ""; // "Standard examples" is dorky
}
purtyPath = modePrefix + "examples \u2192 " +
purtyPath.substring(examplesPath.length() + 1);
break;
}
if (mode.coreLibraries != null) {
for (Library lib : mode.coreLibraries) {
examplesFolder = lib.getExamplesFolder();
examplesPath = examplesFolder.getAbsolutePath();
if (purtyPath.startsWith(examplesPath)) {
purtyPath = lib.getName() + " examples \u2192 " +
purtyPath.substring(examplesPath.length() + 1);
break;
}
}
}
if (mode.contribLibraries != null) {
for (Library lib : mode.contribLibraries) {
examplesFolder = lib.getExamplesFolder();
examplesPath = examplesFolder.getAbsolutePath();
if (purtyPath.startsWith(examplesPath)) {
purtyPath = lib.getName() + " examples \u2192 " +
purtyPath.substring(examplesPath.length() + 1);
break;
}
}
}
}
}
JMenuItem item = new JMenuItem(rec.getName() + " | " + purtyPath);
// JMenuItem item = new JMenuItem(rec.getName() + " | " + purtyPath);
JMenuItem item = new JMenuItem(purtyPath);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Base will call handle() (below) which will cause this entry to