Skip to content

Commit 472c136

Browse files
authored
Merge pull request #8 from openpatch/release/alpha.12
Release Studio 0.1.0-alpha.12
2 parents a00f16f + bcccf4c commit 472c136

17 files changed

Lines changed: 327 additions & 17 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Scratch for Java Studio is a desktop IDE for students moving from Scratch to
44
Java. It builds projects with [Scratch for Java](https://github.com/openpatch/scratch-for-java)
55
and keeps them as ordinary Java source files that also work in BlueJ and VS Code.
66

7-
**Status: 0.1.0-alpha.11.** The IDE and its
7+
**Status: 0.1.0-alpha.12.** The IDE and its
88
project format may change while we test it with students and teachers.
99

1010
![Scratch for Java Studio with the code editor and the visual stage designer side by side](docs/screenshot.png)

‎app/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.openpatch.scratch4j</groupId>
99
<artifactId>scratch4j-ide</artifactId>
10-
<version>0.1.0-alpha.11</version>
10+
<version>0.1.0-alpha.12</version>
1111
</parent>
1212

1313
<artifactId>app</artifactId>

‎core/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.openpatch.scratch4j</groupId>
99
<artifactId>scratch4j-ide</artifactId>
10-
<version>0.1.0-alpha.11</version>
10+
<version>0.1.0-alpha.12</version>
1111
</parent>
1212

1313
<artifactId>core</artifactId>

‎export/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.openpatch.scratch4j</groupId>
99
<artifactId>scratch4j-ide</artifactId>
10-
<version>0.1.0-alpha.11</version>
10+
<version>0.1.0-alpha.12</version>
1111
</parent>
1212

1313
<artifactId>export</artifactId>

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.openpatch.scratch4j</groupId>
88
<artifactId>scratch4j-ide</artifactId>
9-
<version>0.1.0-alpha.11</version>
9+
<version>0.1.0-alpha.12</version>
1010
<packaging>pom</packaging>
1111

1212
<name>Scratch for Java Studio</name>

‎runner/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.openpatch.scratch4j</groupId>
99
<artifactId>scratch4j-ide</artifactId>
10-
<version>0.1.0-alpha.11</version>
10+
<version>0.1.0-alpha.12</version>
1111
</parent>
1212

1313
<artifactId>runner</artifactId>

‎sound/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.openpatch.scratch4j</groupId>
99
<artifactId>scratch4j-ide</artifactId>
10-
<version>0.1.0-alpha.11</version>
10+
<version>0.1.0-alpha.12</version>
1111
</parent>
1212

1313
<artifactId>sound</artifactId>

‎ui/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.openpatch.scratch4j</groupId>
99
<artifactId>scratch4j-ide</artifactId>
10-
<version>0.1.0-alpha.11</version>
10+
<version>0.1.0-alpha.12</version>
1111
</parent>
1212

1313
<artifactId>ui</artifactId>

‎ui/src/main/java/org/openpatch/scratch4j/ui/CodeEditor.java‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ org.openpatch.scratch4j.core.compile.Completions.Result complete(Path file, Stri
9494
});
9595

9696
private static final String INDENT = " ";
97+
/** A method snippet from the block palette (an event block): its name. */
98+
private static final java.util.regex.Pattern EVENT_METHOD = java.util.regex.Pattern.compile(
99+
"^(?:public |protected |private )?void (\\w+)\\([^)]*\\) \\{\n");
97100
private static final Pattern IDENTIFIER = Pattern.compile("[A-Za-z_][A-Za-z0-9_]*$");
98101
private static final Pattern WORD = Pattern.compile("\\b[A-Za-z_][A-Za-z0-9_]{2,}\\b");
99102
private static final Pattern IMAGE_STRING = Pattern.compile(
@@ -536,6 +539,27 @@ void insertBlock(String snippet) {
536539
}
537540
String body = snippet.substring(0, snippet.length() - 1);
538541
boolean multiLine = body.contains("\n");
542+
var method = EVENT_METHOD.matcher(body);
543+
if (method.find()) {
544+
// an event block is a method: it goes into the class body, not into a method
545+
int current = area.getCurrentParagraph();
546+
int lineEnd = area.getAbsolutePosition(current, area.getParagraph(current).length());
547+
var place = MemberPlacement.place(area.getText(), lineEnd, method.group(1));
548+
if (place != null && place.existing()) {
549+
// the class already reacts to this event: go there instead of a second copy
550+
area.moveTo(place.offset());
551+
int open = area.getCurrentParagraph();
552+
if (open + 1 < area.getParagraphs().size()
553+
&& !area.getParagraph(open + 1).getText().strip().startsWith("}")) {
554+
open++; // the method's first line
555+
}
556+
area.moveTo(open, area.getParagraph(open).length());
557+
area.requestFollowCaret();
558+
area.requestFocus();
559+
return;
560+
}
561+
if (place != null) area.moveTo(place.offset());
562+
}
539563
int paragraph = area.getCurrentParagraph();
540564
String line = area.getParagraph(paragraph).getText();
541565
boolean blank = line.isBlank();
@@ -545,8 +569,10 @@ void insertBlock(String snippet) {
545569
boolean prevIsBlank = blank
546570
? paragraph == 0 || area.getParagraph(paragraph - 1).getText().isBlank()
547571
: false;
572+
// a closing brace below needs no blank line before it either
548573
boolean nextIsBlank = paragraph + 1 >= area.getParagraphs().size()
549-
|| area.getParagraph(paragraph + 1).getText().isBlank();
574+
|| area.getParagraph(paragraph + 1).getText().isBlank()
575+
|| area.getParagraph(paragraph + 1).getText().strip().startsWith("}");
550576
int lineStart = area.getAbsolutePosition(paragraph, 0);
551577
// multi-line snippets (method overrides) keep a blank line on both sides
552578
String before = blank ? (multiLine && !prevIsBlank ? "\n" : "")

‎ui/src/main/java/org/openpatch/scratch4j/ui/ImageEditorView.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ private record Snapshot(List<WritableImage> layers, List<Boolean> visible, int a
197197
HBox bottom = new HBox(8, status, spacer, credits);
198198
bottom.getStyleClass().add("editor-status");
199199
setBottom(bottom);
200+
// Ctrl+Z / Ctrl+Y (Cmd on macOS) anywhere in the editor; text fields keep their own
201+
addEventHandler(javafx.scene.input.KeyEvent.KEY_PRESSED, e -> {
202+
if (!e.isShortcutDown()
203+
|| e.getTarget() instanceof javafx.scene.control.TextInputControl) return;
204+
if (e.getCode() == javafx.scene.input.KeyCode.Z) {
205+
if (e.isShiftDown()) redo(); else undo();
206+
e.consume();
207+
} else if (e.getCode() == javafx.scene.input.KeyCode.Y) {
208+
redo();
209+
e.consume();
210+
}
211+
});
200212
updateApplyButton();
201213
updateStatus();
202214
redrawOverlay();

0 commit comments

Comments
 (0)