Skip to content

Commit

Permalink
Add menu commands
Browse files Browse the repository at this point in the history
  • Loading branch information
e9gille committed Feb 23, 2024
1 parent 7ce05f6 commit dc15a81
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
formatInterpreters(interpreters);
};
const createPresets = () => {
const prCr = D.prf.presetsCreated();
const prCr = [...D.prf.presetsCreated()];
const newInterpreters = interpreters.filter((x) => {
const inConns = D.conns.findIndex((y) => y.preset && y.exe === x.exe) >= 0;
const inPrCr = prCr.indexOf(x.exe) >= 0;
Expand Down Expand Up @@ -743,6 +743,12 @@
+ '\n -'
+ '\n &Quit=QIT'
+ ''
+ '\n&File'
+ '\n New configuration=CNNW'
+ '\n Clone configuration=CNCL'
+ '\n Delete configuration=CNDL'
+ '\n -'
+ '\n Re-create preset configurations=CNCP'
+ '\n&Edit'
+ '\n Undo=UND'
+ '\n Redo=RDO'
Expand Down Expand Up @@ -1044,7 +1050,7 @@
}
});
{ const [a] = q.favs.querySelectorAll('a'); a && a.focus(); }
q.neu.onclick = () => {
D.configNew = () => {
if ($(q.rhs).is(':hidden')) {
toggleConfig();
}
Expand All @@ -1053,7 +1059,8 @@
$(q.favs).list('select', $e.index());
q.fav_name.focus();
};
q.cln.onclick = () => {
q.neu.onclick = D.configNew;
D.configClone = () => {
if (sel) {
const cnf = favDOM({
...sel,
Expand All @@ -1066,7 +1073,8 @@
q.fav_name.focus();
}
};
q.del.onclick = () => {
q.cln.onclick = D.configClone;
D.configDelete = () => {
const n = $sel.length;
n && $.confirm(
`Are you sure you want to delete\nthe selected configuration${n > 1 ? 's' : ''}?`,
Expand All @@ -1075,12 +1083,15 @@
if (x) {
const i = Math.min($sel.eq(0).index(), q.favs.children.length - 1);
$sel.remove();
const connsInd = D.conns.indexOf($sel[0].cnData);
if (connsInd >= 0) D.conns.splice(connsInd, 1);
save();
$(q.favs).list('select', i);
}
},
);
};
q.del.onclick = D.configDelete;
q.go.onclick = () => { go(); return !1; };
const a = q.rhs.querySelectorAll('input,textarea');
for (let i = 0; i < a.length; i++) if (/^text(area)?$/.test(a[i].type)) D.util.elastic(a[i]);
Expand Down Expand Up @@ -1125,7 +1136,16 @@
if (autoStart) q.go.click();
}, 1);
};

D.recreatePresets = () => {
D.prf.presetsCreated([]);
const hasCreated = createPresets();
if (!hasCreated) return;
const favItems = [...q.favs.children].map((x) => x.cnData);
D.conns.forEach((x) => {
if (!favItems.includes(x)) q.favs.appendChild(favDOM(x));
});
save();
};
module.exports = () => {
D.send = (x, y) => {
if (D.ide && !D.ide.promptType
Expand Down
4 changes: 4 additions & 0 deletions src/km.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@
});
if (D.ide.dead) window.close();
},
CNNW() { D.configNew(); },
CNCL() { D.configClone(); },
CNDL() { D.configDelete(); },
CNCP() { D.recreatePresets(); },
DHI() {
openURI(D.hlp.INDEX);
},
Expand Down

0 comments on commit dc15a81

Please sign in to comment.