Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added examples-package as a new contribution type. #2795

Merged
merged 11 commits into from
Aug 19, 2014
41 changes: 40 additions & 1 deletion app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public class Base {
ContributionManagerDialog libraryManagerFrame;
ContributionManagerDialog toolManagerFrame;
ContributionManagerDialog modeManagerFrame;
ContributionManagerDialog exampleManagerFrame;
ContributionManagerDialog updateManagerFrame;

// set to true after the first time the menu is built.
Expand All @@ -123,6 +124,8 @@ public class Base {
private Mode[] coreModes;
//public List<ModeContribution> contribModes;
protected ArrayList<ModeContribution> modeContribs;

protected ArrayList<ExamplesPackageContribution> exampleContribs;

private JMenu sketchbookMenu;

Expand Down Expand Up @@ -339,6 +342,19 @@ void rebuildContribModes() {
}


/**
* Instantiates and adds new contributed modes to the contribModes list.
* Checks for duplicates so the same mode isn't instantiates twice. Does not
* remove modes because modes can't be removed once they are instantiated.
*/
void rebuildContribExamples() {
if (exampleContribs == null) {
exampleContribs = new ArrayList<ExamplesPackageContribution>();
}
ExamplesPackageContribution.loadMissing(this);
}


public Base(String[] args) throws Exception {
// // Get the sketchbook path, and make sure it's set properly
// determineSketchbookFolder();
Expand All @@ -356,6 +372,8 @@ public Base(String[] args) throws Exception {
ContributionManager.cleanup(this);
buildCoreModes();
rebuildContribModes();

rebuildContribExamples();

// Needs to happen after the sketchbook folder has been located.
// Also relies on the modes to be loaded so it knows what can be
Expand Down Expand Up @@ -385,6 +403,8 @@ public Base(String[] args) throws Exception {
new ContributionManagerDialog(ContributionType.TOOL);
modeManagerFrame =
new ContributionManagerDialog(ContributionType.MODE);
exampleManagerFrame =
new ContributionManagerDialog(ContributionType.EXAMPLES_PACKAGE);
updateManagerFrame =
new ContributionManagerDialog(null);

Expand Down Expand Up @@ -658,6 +678,11 @@ public ArrayList<Mode> getModeList() {
}


public ArrayList<ExamplesPackageContribution> getExampleContribs() {
return exampleContribs;
}


// Because of variations in native windowing systems, no guarantees about
// changes to the focused and active Windows can be made. Developers must
// never assume that this Window is the focused or active Window until this
Expand Down Expand Up @@ -1483,7 +1508,7 @@ public void actionPerformed(ActionEvent e) {
JMenu submenu = new JMenu(name);
// needs to be separate var otherwise would set ifound to false
boolean anything = addSketches(submenu, subfolder, replaceExisting);
if (anything) {
if (anything && !name.equals("old")) { //Don't add old contributions
menu.add(submenu);
found = true;
}
Expand Down Expand Up @@ -1651,6 +1676,14 @@ public void handleOpenModeManager() {
}


/**
* Show the examples installer window.
*/
public void handleOpenExampleManager() {
exampleManagerFrame.showFrame(activeEditor);
}


public void handleShowUpdates() {
updateManagerFrame.showFrame(activeEditor);
}
Expand Down Expand Up @@ -1923,6 +1956,7 @@ static public void locateSketchbookFolder() {
getSketchbookLibrariesFolder().mkdir();
getSketchbookToolsFolder().mkdir();
getSketchbookModesFolder().mkdir();
getSketchbookExamplesPackagesFolder().mkdir();
// System.err.println("sketchbook: " + sketchbookFolder);
}

Expand Down Expand Up @@ -1954,6 +1988,11 @@ static public File getSketchbookModesFolder() {
}


static public File getSketchbookExamplesPackagesFolder() {
return new File(sketchbookFolder, "examples-packages");
}


static protected File getDefaultSketchbookFolder() {
File sketchbookFolder = null;
try {
Expand Down
Loading