Skip to content

Commit df6ffc3

Browse files
cyaffledzikoysk
authored andcommitted
Added default material ui, icon, file creation, simple 'run' to run Panda's code. Updated lily-intellij-settings, code cleanup and fixes.
1 parent 81b9606 commit df6ffc3

File tree

16 files changed

+241
-112
lines changed

16 files changed

+241
-112
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Lily is a powerful lightweight IDE for Panda
22

33

4-
![Lily](https://sc-cdn.scaleengine.net/i/17d6289dc9d6f16f6afaee11ca7571983.png)
4+
![Lily](https://sc-cdn.scaleengine.net/i/3c141f925eb4ca4a99837d9668c0b12c.png)

lily-intellij-settings.jar

-6.41 KB
Binary file not shown.

pom.xml

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

55
<groupId>org.panda_lang</groupId>
66
<artifactId>lily</artifactId>
7-
<version>1.0.1-SNAPSHOT</version>
7+
<version>1.0.2-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>Lily</name>

src/main/java/org/panda_lang/lily/Lily.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,34 @@
55
import javafx.geometry.Rectangle2D;
66
import javafx.scene.Parent;
77
import javafx.scene.Scene;
8+
import javafx.scene.image.Image;
89
import javafx.stage.Screen;
910
import javafx.stage.Stage;
1011
import org.panda_lang.lily.ui.Interface;
12+
import org.panda_lang.panda.Panda;
1113

1214
public class Lily extends Application {
1315

1416
public static Lily instance;
17+
private Panda panda;
1518
private Stage stage;
1619
private Interface anInterface;
1720

1821
@Override
1922
public void start(Stage stage) throws Exception {
20-
this.stage = stage;
2123
instance = this;
2224

25+
this.stage = stage;
26+
this.panda = new Panda();
27+
2328
// Size of the screen
2429
Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
2530

2631
// Lily's ui
2732
Parent root = FXMLLoader.load(getClass().getResource("/ui/interface.fxml"));
2833
Scene scene = new Scene(root, bounds.getWidth() - 20, bounds.getHeight() * 0.5);
29-
root.getStylesheets().add("/ui/themes/dark_material.css");
34+
root.getStylesheets().add("/ui/themes/default_material.css");
35+
stage.getIcons().add(new Image("/ui/icons/icon.png"));
3036

3137
// Lily's position
3238
stage.setWidth(bounds.getWidth() - 20);
@@ -35,6 +41,7 @@ public void start(Stage stage) throws Exception {
3541
stage.setY((bounds.getHeight() - stage.getHeight()) / 2);
3642

3743
// Others
44+
panda.initializeDefaultElements();
3845
stage.setTitle("Lily the Panda IDE");
3946
stage.setScene(scene);
4047
stage.show();
@@ -52,6 +59,10 @@ public Stage getStage() {
5259
return this.stage;
5360
}
5461

62+
public Panda getPanda() {
63+
return panda;
64+
}
65+
5566

5667
public static void main(String[] args) throws Exception {
5768
launch(args);
Lines changed: 76 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.panda_lang.lily.ui;
22

33
import javafx.fxml.FXML;
4+
import javafx.fxml.FXMLLoader;
45
import javafx.fxml.Initializable;
56
import javafx.scene.control.Tab;
67
import javafx.scene.control.TabPane;
@@ -14,12 +15,14 @@
1415
import org.panda_lang.lily.Lily;
1516
import org.panda_lang.lily.util.ResourcesBuilder;
1617
import org.panda_lang.panda.util.IOUtils;
18+
import org.panda_lang.panda.util.StringUtils;
1719

1820
import java.io.File;
21+
import java.io.IOException;
1922
import java.net.URL;
2023
import java.util.ResourceBundle;
2124

22-
public class EditorTab implements Initializable {
25+
public class EditorTab extends Tab implements Initializable {
2326

2427
private static final String template;
2528

@@ -33,29 +36,28 @@ public class EditorTab implements Initializable {
3336
.replace("{imports}", resourcesBuilder.toString());
3437
}
3538

36-
@FXML private Tab tab;
3739
@FXML private WebView webView;
3840

3941
private WebEngine webEngine;
4042
private String title;
41-
private boolean changes;
43+
private boolean changed;
4244
private boolean succeeded;
4345

46+
public EditorTab() throws IOException {
47+
super();
48+
49+
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/ui/tab.fxml"));
50+
fxmlLoader.setRoot(this);
51+
fxmlLoader.setController(this);
52+
fxmlLoader.load();
53+
}
54+
4455
@Override
4556
public void initialize(URL location, ResourceBundle resources) {
4657
// Style
4758
webEngine = webView.getEngine();
4859
GridPane.setHgrow(webView, Priority.ALWAYS);
4960
GridPane.setVgrow(webView, Priority.ALWAYS);
50-
51-
// Events
52-
webView.setOnKeyPressed(key -> {
53-
if (changes) {
54-
return;
55-
}
56-
tab.setText(title + " *");
57-
changes = true;
58-
});
5961
}
6062

6163
public void run(TabPane pane, File file) {
@@ -65,27 +67,38 @@ public void run(TabPane pane, File file) {
6567

6668
// Tab Settings
6769
this.title = file.getName();
68-
tab.setText(title);
70+
setText(title);
6971

7072
// Engine settings
7173
webView.setVisible(true);
7274
webEngine.setJavaScriptEnabled(true);
7375

76+
// Load source
77+
String source = IOUtils.getContentOfFile(file);
78+
if (source == null) {
79+
source = "";
80+
}
81+
else {
82+
source = StringUtils.replace(source, " ", "\t");
83+
}
84+
7485
// Load content
75-
String source = template.replace("{code}", IOUtils.getContentOfFile(file));
76-
webEngine.loadContent(source);
86+
String content = template.replace("{code}", source);
87+
webEngine.loadContent(content);
7788
webView.setUserData(file);
7889

7990
// Tabs
80-
pane.getTabs().add(tab);
81-
pane.getSelectionModel().select(tab);
91+
pane.getTabs().add(this);
92+
pane.getSelectionModel().select(this);
8293

8394
// Accelerators
8495
webView.getScene().getAccelerators().put(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_ANY), () -> {
8596
File f = (File) webView.getUserData();
86-
IOUtils.overrideFile(f, (String) webEngine.executeScript("editor.getValue()"));
87-
tab.setText(title);
88-
changes = false;
97+
String src = (String) webEngine.executeScript("editor.getValue()");
98+
// StringUtils.replace(src, "\t", " ")
99+
IOUtils.overrideFile(f, src);
100+
setText(title);
101+
changed = false;
89102
});
90103

91104
// State listener
@@ -96,6 +109,49 @@ public void run(TabPane pane, File file) {
96109
}
97110
}
98111
});
112+
113+
// Events
114+
webView.setOnKeyPressed(key -> {
115+
if (!changed) {
116+
KeyCode keyCode = key.getCode();
117+
if (keyCode.isLetterKey() || keyCode.isDigitKey() || keyCode.isWhitespaceKey() || keyCode == KeyCode.BACK_SPACE) {
118+
setText(title + " *");
119+
changed = true;
120+
}
121+
}
122+
});
123+
}
124+
125+
public void setWebView(WebView webView) {
126+
this.webView = webView;
127+
}
128+
129+
public boolean isChanged() {
130+
return changed;
131+
}
132+
133+
public boolean isSucceeded() {
134+
return succeeded;
135+
}
136+
137+
public WebEngine getWebEngine() {
138+
return webEngine;
139+
}
140+
141+
public WebView getWebView() {
142+
return webView;
143+
}
144+
145+
public Tab getTab() {
146+
return this;
147+
}
148+
149+
public String getTitle() {
150+
return title;
151+
}
152+
153+
public static String getTemplate() {
154+
return template;
99155
}
100156

101157
}
Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.panda_lang.lily.ui;
22

33
import javafx.fxml.FXML;
4-
import javafx.fxml.FXMLLoader;
54
import javafx.fxml.Initializable;
65
import javafx.scene.control.MenuItem;
76
import javafx.scene.control.SplitPane;
@@ -10,41 +9,77 @@
109
import javafx.stage.DirectoryChooser;
1110
import javafx.stage.FileChooser;
1211
import org.panda_lang.lily.Lily;
12+
import org.panda_lang.panda.PandaScript;
13+
import org.panda_lang.panda.core.syntax.block.MethodBlock;
1314

1415
import java.io.File;
1516
import java.io.IOException;
1617
import java.net.URL;
17-
import java.util.ArrayList;
18-
import java.util.List;
1918
import java.util.ResourceBundle;
2019

2120
public class Interface implements Initializable {
2221

22+
@FXML private MenuItem menuFileNew;
2323
@FXML private MenuItem menuFileOpenFile;
2424
@FXML private MenuItem menuFileOpenFolder;
25+
@FXML public MenuItem menuFileSettings;
26+
@FXML public MenuItem menuFileSaveAll;
2527
@FXML private MenuItem menuFileExit;
28+
2629
@FXML private MenuItem menuEditUndo;
30+
@FXML public MenuItem menuEditRedo;
31+
@FXML public MenuItem menuEditCut;
32+
@FXML public MenuItem menuEditCopy;
33+
@FXML public MenuItem menuEditPaste;
34+
@FXML public MenuItem menuEditFind;
35+
@FXML public MenuItem menuEditSelectAll;
36+
@FXML public MenuItem menuEditDelete;
37+
2738
@FXML private MenuItem menuRunRun;
2839
@FXML private MenuItem menuHelpAbout;
40+
2941
@FXML private SplitPane splitPane;
3042
@FXML private TreeView<String> filesTree;
3143
@FXML private TabPane tabPane;
3244

3345
private ProjectTree tree;
34-
private List<EditorTab> tabs;
3546
private EditorTab currentTab;
3647

3748
@Override
3849
public void initialize(URL url, ResourceBundle rb) {
3950
// Initialize Interface
4051
Lily.instance.initAnInterface(this);
4152

53+
// SplitPane
54+
splitPane.setDividerPositions(0.25, 0.75);
55+
56+
// ProjectTree
57+
tree = new ProjectTree(filesTree);
58+
try {
59+
tree.open(new File("./").getCanonicalFile());
60+
} catch (IOException e) {
61+
e.printStackTrace();
62+
}
63+
4264
// Extend
4365
extend(menuFileOpenFolder);
4466
extend(menuEditUndo);
4567
extend(menuRunRun);
4668
extend(menuHelpAbout);
4769

70+
// Initialize Actions
71+
initializeActions();
72+
}
73+
74+
protected void initializeActions() {
75+
// Action: File -> New
76+
menuFileNew.setOnAction(event -> {
77+
FileChooser fileChooser = new FileChooser();
78+
fileChooser.setInitialDirectory(tree.getDirectory());
79+
fileChooser.showOpenDialog(Lily.instance.getStage());
80+
tree.open(tree.getDirectory());
81+
});
82+
4883
// Action: File -> Open
4984
menuFileOpenFile.setOnAction(event -> {
5085
FileChooser fileChooser = new FileChooser();
@@ -64,18 +99,21 @@ public void initialize(URL url, ResourceBundle rb) {
6499
// Action: File -> Exit
65100
menuFileExit.setOnAction(event -> System.exit(-1));
66101

67-
// SplitPane
68-
splitPane.setDividerPositions(0.25, 0.75);
69-
70-
// EditorTabs
71-
tabs = new ArrayList<>();
102+
// Action: Run -> Run
103+
menuRunRun.setOnAction(event -> {
104+
String source = (String) getCurrentTab().getWebEngine().executeScript("editor.getValue()");
105+
PandaScript pandaScript = Lily.instance.getPanda().getPandaLoader().loadSimpleScript(source);
106+
pandaScript.call(MethodBlock.class, "main");
107+
});
72108

73-
// ProjectTree
74-
tree = new ProjectTree(filesTree);
75-
tree.open(new File("./"));
109+
tabPane.getSelectionModel().selectedItemProperty().addListener(
110+
(ov, t, t1) -> {
111+
currentTab = (EditorTab) tabPane.getSelectionModel().getSelectedItem();
112+
}
113+
);
76114
}
77115

78-
private void extend(MenuItem menuItem) {
116+
public void extend(MenuItem menuItem) {
79117
String currentName = menuItem.getText();
80118
StringBuilder builder = new StringBuilder(currentName);
81119
int required = 50 - currentName.length();
@@ -85,25 +123,14 @@ private void extend(MenuItem menuItem) {
85123
menuItem.setText(builder.toString());
86124
}
87125

88-
public void displayFile(File file) {
89-
try {
90-
FXMLLoader loader = new FXMLLoader(getClass().getResource("/ui/tab.fxml"));
91-
loader.load();
92-
EditorTab ti = loader.getController();
93-
tabs.add(ti);
94-
ti.run(tabPane, file);
95-
currentTab = ti;
96-
} catch (IOException e) {
97-
e.printStackTrace();
98-
}
126+
public void displayFile(File file) throws IOException {
127+
EditorTab editorTab = new EditorTab();
128+
editorTab.run(tabPane, file);
129+
currentTab = editorTab;
99130
}
100131

101132
public EditorTab getCurrentTab() {
102133
return currentTab;
103134
}
104135

105-
public List<EditorTab> getTabs() {
106-
return tabs;
107-
}
108-
109136
}

0 commit comments

Comments
 (0)