Skip to content

Commit dc04dec

Browse files
committed
Store view settings in localStorage
Settings are stored per (title,revision) tuple so will be reset on revision update or file name change.
1 parent fb3a623 commit dc04dec

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

InteractiveHtmlBom/ibom.html

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,23 @@
244244
///PCBDATA///
245245
///////////////////////////////////////////////
246246

247+
var storagePrefix = 'KiCad_HTML_BOM__' + pcbdata.metadata.title + '__'
248+
+ pcbdata.metadata.revision + '__';
249+
var bomsplit;
250+
var canvassplit;
247251
var frontscale = 12;
248252
var backscale = 12;
249253
var canvaslayout = "default";
250254
var bomlayout = "default";
251255

256+
function readStorage(key) {
257+
return window.localStorage.getItem(storagePrefix + '#' + key);
258+
}
259+
260+
function writeStorage(key, value) {
261+
window.localStorage.setItem(storagePrefix + '#' + key, value);
262+
}
263+
252264
function deg2rad(deg) {
253265
return deg * Math.PI / 180;
254266
}
@@ -693,9 +705,11 @@
693705
if (visible) {
694706
allcanvas.front.silk.style.display = "";
695707
allcanvas.back.silk.style.display = "";
708+
writeStorage("silkscreenVisible", true);
696709
} else {
697710
allcanvas.front.silk.style.display = "none";
698711
allcanvas.back.silk.style.display = "none";
712+
writeStorage("silkscreenVisible", false);
699713
}
700714
}
701715

@@ -723,6 +737,7 @@
723737
}
724738
}
725739
canvaslayout = layout;
740+
writeStorage("canvaslayout", layout);
726741
resizeCanvas();
727742
populateBomTable(layout);
728743
}
@@ -744,9 +759,11 @@
744759
switch (layout) {
745760
case 'BOM':
746761
document.getElementById("bom-btn").classList.add("depressed");
747-
if (["LR", "TB"].includes(bomlayout)) {
762+
if (bomsplit) {
748763
bomsplit.destroy();
764+
bomsplit = null;
749765
canvassplit.destroy();
766+
canvassplit = null;
750767
}
751768
document.getElementById("frontcanvas").style.display = "none";
752769
document.getElementById("backcanvas").style.display = "none";
@@ -761,9 +778,11 @@
761778
document.getElementById("canvasdiv").classList.remove("split-horizontal");
762779
document.getElementById("frontcanvas").classList.add("split-horizontal");
763780
document.getElementById("backcanvas").classList.add("split-horizontal");
764-
if (["LR", "TB"].includes(bomlayout)) {
781+
if (bomsplit) {
765782
bomsplit.destroy();
783+
bomsplit = null;
766784
canvassplit.destroy();
785+
canvassplit = null;
767786
}
768787
bomsplit = Split(['#bomdiv', '#canvasdiv'], {
769788
sizes: [50, 50],
@@ -786,9 +805,11 @@
786805
document.getElementById("canvasdiv").classList.add("split-horizontal");
787806
document.getElementById("frontcanvas").classList.remove("split-horizontal");
788807
document.getElementById("backcanvas").classList.remove("split-horizontal");
789-
if (["LR", "TB"].includes(bomlayout)) {
808+
if (bomsplit) {
790809
bomsplit.destroy();
810+
bomsplit = null;
791811
canvassplit.destroy();
812+
canvassplit = null;
792813
}
793814
bomsplit = Split(['#bomdiv', '#canvasdiv'], {
794815
sizes: [50, 50],
@@ -803,9 +824,8 @@
803824
});
804825
}
805826
bomlayout = layout;
806-
if (bomlayout != "BOM") {
807-
changeCanvasLayout(canvaslayout);
808-
}
827+
writeStorage("bomlayout", layout);
828+
changeCanvasLayout(canvaslayout);
809829
}
810830

811831
function removeGutterNode(node) {
@@ -836,18 +856,26 @@
836856
allcanvas.back.highlight = document.getElementById("B_hl");
837857
dbgdiv = document.getElementById("dbg");
838858
bom = document.getElementById("bombody");
839-
bomlayout = "none";
840-
canvaslayout = "FB";
859+
bomlayout = readStorage("bomlayout");
860+
if (!bomlayout) {
861+
bomlayout = "LR";
862+
}
863+
canvaslayout = readStorage("canvaslayout");
864+
if (!canvaslayout) {
865+
canvaslayout = "FB";
866+
}
841867
filter = "";
842868
reflookup = "";
843869
populateMetadata();
844-
resizeCanvas();
845-
changeBomLayout('LR');
870+
changeBomLayout(bomlayout);
871+
if (readStorage("silkscreenVisible") === "false") {
872+
document.getElementById("silkscreenCheckbox").checked = false;
873+
silkscreenVisible(false);
874+
}
846875
}
847876

848877
window.onresize = resizeCanvas;
849878
window.matchMedia("print").addListener(resizeCanvas);
850-
851879
</script>
852880
</head>
853881

@@ -856,7 +884,7 @@
856884
<div id="top" class="split" style="height: 80px; border-bottom: 2px solid black;">
857885
<div style="float: right;">
858886
<div class="hideonprint" style="float: right; margin: 10px; position: relative; top: 20px">
859-
<input type="checkbox" name="silkscreen" value="silkscreen" checked
887+
<input id="silkscreenCheckbox" type="checkbox" name="silkscreen" value="silkscreen" checked
860888
onchange="silkscreenVisible(this.checked)">Silkscreen
861889
</div>
862890
<div class="button-container hideonprint"

0 commit comments

Comments
 (0)