Skip to content

Adds new Processing sketch templates to enhance the user's initial coding experience in the Processing IDE. #1020

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

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,9 @@ public JMenu initDefaultFileMenu() {
item.addActionListener(e -> handleNew());
defaultFileMenu.add(item);

item = Toolkit.newJMenuItem(Language.text("menu.file.open"), 'O');
item.addActionListener(e -> handleOpenPrompt());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realised that the file->open menu item certainly should not be deleted here

defaultFileMenu.add(item);
// item = Toolkit.newJMenuItem(Language.text("menu.file.open"), 'O');
// item.addActionListener(e -> handleOpenPrompt());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clean up any comments and unused code left in your Pull Request

// defaultFileMenu.add(item);

item = Toolkit.newJMenuItemShift(Language.text("menu.file.sketchbook"), 'K');
item.addActionListener(e -> showSketchbookFrame());
Expand All @@ -598,6 +598,10 @@ public JMenu initDefaultFileMenu() {
item.addActionListener(e -> thinkDifferentExamples());
defaultFileMenu.add(item);

item = Toolkit.newJMenuItem(Language.text("menu.file.templates"), 'T');
//item.addActionListener(e -> handleTemplates());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more comment

defaultFileMenu.add(item);

return defaultFileMenu;
}

Expand Down Expand Up @@ -1288,6 +1292,8 @@ private void openContribBundle(String path) {
});
}

// Open templates to start with any work
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another



/**
* Return true if it's an obvious sketch folder: only .pde files,
Expand Down
37 changes: 37 additions & 0 deletions app/src/processing/app/ui/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,13 @@ protected JMenu buildFileMenu(JMenuItem[] exportItems) {
item.addActionListener(e -> handleSaveAs());
fileMenu.add(item);

item = Toolkit.newJMenuItemShift(Language.text("menu.file.templates"), 'T');
//JMenuItem finalItem = item;
item.addActionListener(e -> handleTemplate());
fileMenu.add(item);



if (exportItems != null) {
for (JMenuItem ei : exportItems) {
fileMenu.add(ei);
Expand Down Expand Up @@ -761,6 +768,36 @@ protected JMenu buildFileMenu(JMenuItem[] exportItems) {
}
return fileMenu;
}
// Define the handleTemplate method to show different templates
private void handleTemplate() {
// Create a popup menu for templates
JPopupMenu templatesMenu = new JPopupMenu("Templates");

JMenuItem template1 = new JMenuItem("Animation Sketch");
template1.addActionListener(e -> insertTemplateCode(Template.animationSketchCode));
templatesMenu.add(template1);

JMenuItem template2 = new JMenuItem("Interactive Sketch");
template2.addActionListener(e -> insertTemplateCode(Template.interactiveSketchCode));
templatesMenu.add(template2);

JMenuItem template3 = new JMenuItem("Fullscreen Sketch");
template3.addActionListener(e -> insertTemplateCode(Template.fullscreenSketchCode));
templatesMenu.add(template3);

JMenuItem template4 = new JMenuItem("Resizeable Sketch");
template4.addActionListener(e -> insertTemplateCode(Template.resizeableSketchCode));
templatesMenu.add(template4);

// Show the popup menu at the location where the "Templates" menu item was clicked
templatesMenu.show(this, 0, 0);
}

// Add this method to insert template code into the editor
private void insertTemplateCode(String templateCode) {
textarea.setText("");
insertText(templateCode);
}


protected JMenu buildEditMenu() {
Expand Down
50 changes: 50 additions & 0 deletions app/src/processing/app/ui/Template.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package processing.app.ui;

public class Template {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer used correct?


// New templates
public static final String animationSketchCode =
"void setup() {\n" +
" size(500, 500);\n" +
" // write code that will be called once in this function\n" +
"}\n\n" +
"void draw() {\n" +
" // write code that will be called for every frame here\n" +
"}";

public static final String interactiveSketchCode =
"void setup() {\n" +
" size(500, 500);\n" +
" // write code that will be called once in this function\n" +
"}\n\n" +
"void draw() {\n" +
" // write code that will be called for every frame here\n" +
"}\n\n" +
"void mousePressed() {\n" +
" ellipse(mouseX, mouseY, 20, 20);\n" +
" // write code that will run when you click\n" +
"}";

public static final String fullscreenSketchCode =
"void setup() {\n" +
" fullScreen(); // create a fullscreen canvas\n" +
"}\n\n" +
"void draw() {\n" +
" circle(width / 2, height / 2, height * 0.5);\n" +
"}";

public static final String resizeableSketchCode =
"void setup() {\n" +
" size(500, 500);\n" +
" windowResizable(true);\n" +
" // allow the window to be resized\n" +
"}\n\n" +
"void draw() {\n" +
" circle(width / 2, height / 2, min(width, height) * 0.5);\n" +
" // draw a circle that resizes with the window\n" +
"}\n\n" +
"void windowResized() {\n" +
" println(\"Window resized to: \" + width + \"x\" + height);\n" +
" // this function is called whenever the window is resized\n" +
"}";
}