Skip to content

Commit c4d25b8

Browse files
esaruohoclaude
andcommitted
Show loaded filename in SRAM edit dialog
When loading SRAM contents from a binary file, the filename is now captured and displayed next to the Load button as "Loaded: filename.bin". This helps users with multiple SRAMs identify which file was loaded into each one, addressing feedback from @MatNieuw on issue #184. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d5cc528 commit c4d25b8

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/com/lushprojects/circuitjs1/client/SRAMElm.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ class SRAMElm extends ChipElm {
3232
int addressBits, dataBits;
3333
HashMap<Integer, Integer> map;
3434
HashMap<Integer, Integer> initialMap; // saved initial contents for restore on reset
35+
String loadedFileName; // remembers the last file loaded via "Load Contents From File"
3536
static final int FLAG_RELOAD_ON_RESET = 2;
3637
static String contentsOverride = null;
3738
TextArea editTextArea;
3839
boolean hexTogglePending;
40+
static String fileNameOverride = null;
3941

4042
public SRAMElm(int xx, int yy) {
4143
super(xx, yy);
@@ -139,6 +141,9 @@ public EditInfo getChipEditInfo(int n) {
139141
ei.textArea.setVisibleLines(5);
140142
String s = (contentsOverride != null) ? contentsOverride : contentsToString();
141143
contentsOverride = null;
144+
if (fileNameOverride != null)
145+
loadedFileName = fileNameOverride;
146+
fileNameOverride = null;
142147
ei.textArea.setText(s);
143148
return ei;
144149
}
@@ -148,7 +153,9 @@ public EditInfo getChipEditInfo(int n) {
148153
return ei;
149154
}
150155
if (n == 4 && SRAMLoadFile.isSupported()) {
151-
EditInfo ei = new EditInfo("", 0, -1, -1);
156+
EditInfo ei = new EditInfo(
157+
loadedFileName != null ? "Loaded: " + loadedFileName : "",
158+
0, -1, -1);
152159
ei.loadFile = new SRAMLoadFile();
153160
ei.button = new Button("Load Contents From File");
154161
ei.newDialog = true;

src/com/lushprojects/circuitjs1/client/SRAMLoadFile.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,26 @@ public final native void handle()
3030
@com.lushprojects.circuitjs1.client.EditDialogLoadFile::doErrorCallback(Ljava/lang/String;)("Cannot load: That file is too large!");
3131
return;
3232
}
33-
33+
34+
var fileName = oFiles[0].name;
3435
var reader = new FileReader();
3536
reader.onload = function(e) {
3637
var arr = new Uint8Array(reader.result);
3738
var str = "0:";
3839
for (var i = 0; i < arr.length; i++)
3940
str += " " + arr[i];
40-
@com.lushprojects.circuitjs1.client.SRAMLoadFile::doLoadCallback(Ljava/lang/String;)(str);
41+
@com.lushprojects.circuitjs1.client.SRAMLoadFile::doLoadCallback(Ljava/lang/String;Ljava/lang/String;)(str, fileName);
4142
};
42-
43+
4344
reader.readAsArrayBuffer(oFiles[0]);
4445
}
4546
}-*/;
46-
47-
static public void doLoadCallback(String data) {
47+
48+
static public void doLoadCallback(String data, String fileName) {
4849
SRAMElm.contentsOverride = data;
50+
SRAMElm.fileNameOverride = fileName;
4951
CirSim.editDialog.resetDialog();
5052
SRAMElm.contentsOverride = null;
53+
SRAMElm.fileNameOverride = null;
5154
}
5255
}

0 commit comments

Comments
 (0)