Skip to content

Commit 14c8f5f

Browse files
Merge pull request #41 from Glimmr-Lang/Sibusiso
I somehow lost a lot of code.
2 parents 68d922a + 4d21eee commit 14c8f5f

13 files changed

+1123
-17
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
target/
22
.mvn
33
mvnw*
4-
docs/.obsidian
4+
docs/.obsidian
5+
*.jar

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@
8484
<version>main-SNAPSHOT</version>
8585
</dependency>
8686

87+
<dependency>
88+
<groupId>com.github.Glimmr-Lang</groupId>
89+
<artifactId>PiccodePlugin</artifactId>
90+
<version>main-SNAPSHOT</version>
91+
</dependency>
92+
8793
</dependencies>
8894

8995
<dependencyManagement>

src/main/java/org/editor/CanvasFrame.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.swing.SwingUtilities;
2828
import javax.swing.Timer;
2929
import javax.swing.plaf.basic.BasicGraphicsUtils;
30+
import org.editor.theme.ThemeManager;
3031
import org.piccode.ast.Ast;
3132
import org.piccode.backend.Compiler;
3233
import org.piccode.rt.Context;
@@ -254,12 +255,12 @@ private void drawGrid() {
254255
gridImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
255256
Graphics2D g2 = gridImage.createGraphics();
256257
// Fill background
257-
g2.setColor(Color.WHITE);
258+
g2.setColor(ThemeManager.RENDER_BG);
258259
g2.fillRect(0, 0, getWidth(), getHeight());
259260

260261
if (showGrid) {
261262
// Draw grid
262-
g2.setColor(new Color(230, 230, 230));
263+
g2.setColor(ThemeManager.RENDER_GRID);
263264
for (int x = -offsetX % SCALE; x < getWidth(); x += SCALE) {
264265
g2.drawLine(x, 0, x, getHeight());
265266
}
@@ -270,7 +271,7 @@ private void drawGrid() {
270271

271272
if (showRuler) {
272273
// Draw axis numbers
273-
g2.setColor(Color.GRAY);
274+
g2.setColor(ThemeManager.RENDER_GRID);
274275
for (int x = -offsetX % SCALE; x < getWidth(); x += SCALE) {
275276
int value = (x + offsetX) / SCALE;
276277
g2.drawString(Integer.toString(value * SCALE), x + 2, 12);
@@ -286,7 +287,7 @@ private void drawGrid() {
286287
g2.setColor(Color.RED);
287288
g2.drawString("y", 8, getHeight() - 5);
288289

289-
g2.setColor(Color.GRAY);
290+
g2.setColor(ThemeManager.RENDER_TXT2);
290291
int x = (-offsetX % SCALE + offsetX) / SCALE;
291292
int y = (-offsetY % SCALE + offsetY) / SCALE;
292293
x *= SCALE;

src/main/java/org/editor/CodeEditor.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaHighlighter;
3131
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
3232
import org.fife.ui.rsyntaxtextarea.TextEditorPane;
33+
import org.fife.ui.rsyntaxtextarea.Theme;
3334
import org.fife.ui.rsyntaxtextarea.TokenMakerFactory;
3435
import org.fife.ui.rsyntaxtextarea.templates.CodeTemplate;
3536
import org.fife.ui.rsyntaxtextarea.templates.StaticCodeTemplate;
@@ -297,4 +298,15 @@ public DockKey getDockKey() {
297298
public Component getComponent() {
298299
return this;
299300
}
301+
302+
public void setThemeMode(boolean dark) {
303+
var themeName = dark ? "monokai" : "vs";
304+
try {
305+
Theme theme = Theme.load(getClass().getResourceAsStream(
306+
"/org/fife/ui/rsyntaxtextarea/themes/" + themeName +".xml"));
307+
theme.apply(textArea);
308+
} catch (IOException ioe) { // Never happens
309+
ioe.printStackTrace();
310+
}
311+
}
300312
}

src/main/java/org/editor/EditorWindow.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.editor.panels.FileTreePanel;
4444
import org.editor.panels.PluginsPanel;
4545
import org.editor.panels.VCPanel;
46+
import org.editor.theme.ThemeManager;
4647

4748
import org.fife.rsta.ui.CollapsibleSectionPanel;
4849
//import org.fife.rsta.ui.DocumentMap;
@@ -72,8 +73,9 @@ public final class EditorWindow extends JFrame implements SearchListener {
7273
private CollapsibleSectionPanel csp;
7374
public static FindDialog findDialog;
7475
public static ReplaceDialog replaceDialog;
75-
private DockingDesktop desk = new DockingDesktop();
76+
public static DockingDesktop desk = new DockingDesktop();
7677
private static CodeEditor selected = null;
78+
public static boolean dark = true;
7779

7880
public static EditorWindow the() {
7981
if (win == null) {
@@ -87,17 +89,13 @@ public static EditorWindow the() {
8789
public EditorWindow() {
8890
super("Piccode - DashBoard");
8991

92+
ThemeManager.setFlatLaf(dark);
9093
DockingUISettings.getInstance().installUI();
9194
customizeDock();
9295

9396
UIManager.put("Tree.collapsedIcon", UIManager.getIcon("Tree.collapsedIcon"));
9497
UIManager.put("Tree.expandedIcon", UIManager.getIcon("Tree.expandedIcon"));
9598

96-
try {
97-
UIManager.setLookAndFeel(new FlatLightLaf());
98-
} catch (Exception ex) {
99-
System.err.println("Failed to initialize LaF");
100-
}
10199

102100
new CodeEditor();
103101
root = getRootPane();
@@ -118,7 +116,7 @@ public EditorWindow() {
118116

119117
if (current.getDockable() instanceof CodeEditor ed) {
120118
if (event.getFutureState().isClosed()) {
121-
if (removeIfDirty(ed.tabIndex, ed) == false) {
119+
if (removeIfNotDirty(ed.tabIndex, ed) == false) {
122120
event.cancel();
123121
}
124122
}
@@ -229,6 +227,8 @@ public EditorWindow() {
229227

230228
win = this;
231229

230+
ThemeManager.updateThemes(dark);
231+
232232
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
233233
this.setSize(width, height);
234234
this.setLocationRelativeTo(null);
@@ -251,6 +251,8 @@ public static void addTab(ActionEvent e) {
251251
editor.requestFocusInWindow();
252252
current_file.setText(file != null ? file.toString() : "[NONE]");
253253
tabEditors.put(index, editor);
254+
ThemeManager.registerEditor(editor);
255+
ThemeManager.updateThemes(dark);
254256

255257
// Add first editor normally
256258
if (index == 0) {
@@ -271,6 +273,8 @@ public static void addTab(Path path, Void e) {
271273
editor.requestFocusInWindow();
272274
tabEditors.put(index, editor);
273275

276+
ThemeManager.registerEditor(editor);
277+
ThemeManager.updateThemes(dark);
274278
// Add first editor normally
275279
if (index == 0) {
276280
win.getContentPane().add(editor);
@@ -339,7 +343,7 @@ private static Component makeTabHeader(JTabbedPane tabs, String title) {
339343
int index = tabs.indexOfTabComponent(tabHeader);
340344
if (index != -1) {
341345
var ed = tabEditors.get(index);
342-
removeIfDirty(index, ed);
346+
removeIfNotDirty(index, ed);
343347
}
344348
});
345349

@@ -364,21 +368,21 @@ public static void removeTab() {
364368
return;
365369
}
366370

367-
removeIfDirty(index, focused);
371+
removeIfNotDirty(index, focused);
368372
}
369373

370374
public static void removeAllTabs() {
371375
var editors = new HashMap<>(tabEditors); // Copy to avoid ConcurrentModificationException
372376
for (var entry : editors.entrySet()) {
373-
removeIfDirty(entry.getKey(), entry.getValue());
377+
removeIfNotDirty(entry.getKey(), entry.getValue());
374378
}
375379
}
376380

377381
public static int tabsCount() {
378382
return tabEditors.size();
379383
}
380384

381-
private static boolean removeIfDirty(Integer index, CodeEditor ed) {
385+
private static boolean removeIfNotDirty(Integer index, CodeEditor ed) {
382386
if (ed.textArea.isDirty()) {
383387
int result = JOptionPane.showConfirmDialog(win, "File " + ed.filePathTruncated() + " is modified. Save?");
384388
if (result == JOptionPane.OK_OPTION) {
@@ -387,6 +391,7 @@ private static boolean removeIfDirty(Integer index, CodeEditor ed) {
387391
}
388392
win.desk.remove((Dockable) ed); // Actual removal from docking layout
389393
tabEditors.remove(index);
394+
ThemeManager.removeEditor(ed);
390395
migrateIndexes();
391396

392397
return true;

0 commit comments

Comments
 (0)