Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target/
.mvn
mvnw*
docs/.obsidian
docs/.obsidian
*.jar
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
<version>main-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.github.Glimmr-Lang</groupId>
<artifactId>PiccodePlugin</artifactId>
<version>main-SNAPSHOT</version>
</dependency>

</dependencies>

<dependencyManagement>
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/editor/CanvasFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.plaf.basic.BasicGraphicsUtils;
import org.editor.theme.ThemeManager;
import org.piccode.ast.Ast;
import org.piccode.backend.Compiler;
import org.piccode.rt.Context;
Expand Down Expand Up @@ -254,12 +255,12 @@ private void drawGrid() {
gridImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = gridImage.createGraphics();
// Fill background
g2.setColor(Color.WHITE);
g2.setColor(ThemeManager.RENDER_BG);
g2.fillRect(0, 0, getWidth(), getHeight());

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

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

g2.setColor(Color.GRAY);
g2.setColor(ThemeManager.RENDER_TXT2);
int x = (-offsetX % SCALE + offsetX) / SCALE;
int y = (-offsetY % SCALE + offsetY) / SCALE;
x *= SCALE;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/editor/CodeEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaHighlighter;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rsyntaxtextarea.TextEditorPane;
import org.fife.ui.rsyntaxtextarea.Theme;
import org.fife.ui.rsyntaxtextarea.TokenMakerFactory;
import org.fife.ui.rsyntaxtextarea.templates.CodeTemplate;
import org.fife.ui.rsyntaxtextarea.templates.StaticCodeTemplate;
Expand Down Expand Up @@ -297,4 +298,15 @@ public DockKey getDockKey() {
public Component getComponent() {
return this;
}

public void setThemeMode(boolean dark) {
var themeName = dark ? "monokai" : "vs";
try {
Theme theme = Theme.load(getClass().getResourceAsStream(
"/org/fife/ui/rsyntaxtextarea/themes/" + themeName +".xml"));
theme.apply(textArea);
} catch (IOException ioe) { // Never happens
ioe.printStackTrace();
}
}
}
27 changes: 16 additions & 11 deletions src/main/java/org/editor/EditorWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.editor.panels.FileTreePanel;
import org.editor.panels.PluginsPanel;
import org.editor.panels.VCPanel;
import org.editor.theme.ThemeManager;

import org.fife.rsta.ui.CollapsibleSectionPanel;
//import org.fife.rsta.ui.DocumentMap;
Expand Down Expand Up @@ -72,8 +73,9 @@ public final class EditorWindow extends JFrame implements SearchListener {
private CollapsibleSectionPanel csp;
public static FindDialog findDialog;
public static ReplaceDialog replaceDialog;
private DockingDesktop desk = new DockingDesktop();
public static DockingDesktop desk = new DockingDesktop();
private static CodeEditor selected = null;
public static boolean dark = true;

public static EditorWindow the() {
if (win == null) {
Expand All @@ -87,17 +89,13 @@ public static EditorWindow the() {
public EditorWindow() {
super("Piccode - DashBoard");

ThemeManager.setFlatLaf(dark);
DockingUISettings.getInstance().installUI();
customizeDock();

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

try {
UIManager.setLookAndFeel(new FlatLightLaf());
} catch (Exception ex) {
System.err.println("Failed to initialize LaF");
}

new CodeEditor();
root = getRootPane();
Expand All @@ -118,7 +116,7 @@ public EditorWindow() {

if (current.getDockable() instanceof CodeEditor ed) {
if (event.getFutureState().isClosed()) {
if (removeIfDirty(ed.tabIndex, ed) == false) {
if (removeIfNotDirty(ed.tabIndex, ed) == false) {
event.cancel();
}
}
Expand Down Expand Up @@ -229,6 +227,8 @@ public EditorWindow() {

win = this;

ThemeManager.updateThemes(dark);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(width, height);
this.setLocationRelativeTo(null);
Expand All @@ -251,6 +251,8 @@ public static void addTab(ActionEvent e) {
editor.requestFocusInWindow();
current_file.setText(file != null ? file.toString() : "[NONE]");
tabEditors.put(index, editor);
ThemeManager.registerEditor(editor);
ThemeManager.updateThemes(dark);

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

ThemeManager.registerEditor(editor);
ThemeManager.updateThemes(dark);
// Add first editor normally
if (index == 0) {
win.getContentPane().add(editor);
Expand Down Expand Up @@ -339,7 +343,7 @@ private static Component makeTabHeader(JTabbedPane tabs, String title) {
int index = tabs.indexOfTabComponent(tabHeader);
if (index != -1) {
var ed = tabEditors.get(index);
removeIfDirty(index, ed);
removeIfNotDirty(index, ed);
}
});

Expand All @@ -364,21 +368,21 @@ public static void removeTab() {
return;
}

removeIfDirty(index, focused);
removeIfNotDirty(index, focused);
}

public static void removeAllTabs() {
var editors = new HashMap<>(tabEditors); // Copy to avoid ConcurrentModificationException
for (var entry : editors.entrySet()) {
removeIfDirty(entry.getKey(), entry.getValue());
removeIfNotDirty(entry.getKey(), entry.getValue());
}
}

public static int tabsCount() {
return tabEditors.size();
}

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

return true;
Expand Down
Loading