replace all window.prompt() with kiri.ui.prompt() for electron. open electron links in os browser

This commit is contained in:
Stewart Allen 2024-06-17 15:21:50 -04:00
commit 995b338946
6 changed files with 86 additions and 56 deletions

View file

@ -537,13 +537,14 @@ gapp.register("kiri.init", [], (root, exports) => {
api.show.alert("select object to rotate");
return;
}
let coord = (prompt("Enter X,Y,Z degrees of rotation") || '').split(','),
prod = Math.PI / 180,
x = parseFloat(coord[0] || 0.0) * prod,
y = parseFloat(coord[1] || 0.0) * prod,
z = parseFloat(coord[2] || 0.0) * prod;
api.selection.rotate(x, y, z);
api.uc.prompt("Enter X,Y,Z degrees of rotation","").then(coord => {
coord = (coord || '').split(',');
let prod = Math.PI / 180,
x = parseFloat(coord[0] || 0.0) * prod,
y = parseFloat(coord[1] || 0.0) * prod,
z = parseFloat(coord[2] || 0.0) * prod;
api.selection.rotate(x, y, z);
});
}
function positionSelection() {
@ -554,18 +555,21 @@ gapp.register("kiri.init", [], (root, exports) => {
let current = settings(),
{ device, process} = current,
center = process.ctOriginCenter || process.camOriginCenter || device.bedRound || device.originCenter,
bounds = boundsSelection(),
coord = prompt("Enter X,Y coordinates for selection").split(','),
x = parseFloat(coord[0] || 0.0),
y = parseFloat(coord[1] || 0.0),
z = parseFloat(coord[2] || 0.0);
bounds = boundsSelection();
if (!center) {
x = x - device.bedWidth/2 + (bounds.max.x - bounds.min.x)/2;
y = y - device.bedDepth/2 + (bounds.max.y - bounds.min.y)/2
}
api.uc.prompt("Enter X,Y coordinates for selection","").then(coord => {
coord = (coord || '').split(',');
let x = parseFloat(coord[0] || 0.0),
y = parseFloat(coord[1] || 0.0),
z = parseFloat(coord[2] || 0.0);
api.selection.move(x, y, z, true);
if (!center) {
x = x - device.bedWidth/2 + (bounds.max.x - bounds.min.x)/2;
y = y - device.bedDepth/2 + (bounds.max.y - bounds.min.y)/2
}
api.selection.move(x, y, z, true);
});
}
function deviceExport(exp, name) {
@ -1018,8 +1022,14 @@ gapp.register("kiri.init", [], (root, exports) => {
showDevices();
};
ui.deviceRename.onclick = function() {
const newname = prompt(`Rename "${selected}`, selected);
if (newname) updateDeviceName(newname);
api.uc.prompt(`Rename "${selected}`, selected).then(newname => {
if (newname) {
updateDeviceName(newname);
showDevices();
} else {
showDevices();
}
});
};
ui.deviceExport.onclick = function(event) {
const record = {
@ -1430,12 +1440,13 @@ gapp.register("kiri.init", [], (root, exports) => {
renm.setAttribute('title', 'rename file');
renm.innerHTML = '<i class="far fa-edit"></i>';
renm.onclick = () => {
let newname = prompt(`rename file`, short);
if (newname && newname !== short) {
catalog.rename(name, `${newname}${ext}`, then => {
catalog.refresh();
});
}
api.uc.prompt(`rename file`, short).then(newname => {
if (newname && newname !== short) {
catalog.rename(name, `${newname}${ext}`, then => {
api.modal.show('files');
});
}
});
};
load.setAttribute('load', name);

View file

@ -687,19 +687,22 @@ gapp.register("kiri.main", [], (root, exports) => {
mode = getMode(),
name = e.target.getAttribute("name"),
load = current.sproc[mode][name],
edit = prompt(`settings for "${name}"`, JSON.stringify(load));
if (edit) {
try {
current.sproc[mode][name] = JSON.parse(edit);
if (name === current.proc().processName) {
api.conf.load(null, name);
loadstr = JSON.stringify(load,null,4).split('\n');
UC.prompt(`settings for "${name}"`, loadstr).then(edit => {
if (edit) {
try {
current.sproc[mode][name] = JSON.parse(edit);
if (name === settings.proc().processName) {
api.conf.load(null, name);
}
api.conf.save();
api.settings.sync.put();
} catch (e) {
console.log({ malformed_settings: e });
UC.alert('malformed settings object');
}
api.conf.save();
api.settings.sync.put();
} catch (e) {
UC.alert('malformed settings object');
}
}
});
}
function exportSettings(e) {

View file

@ -111,9 +111,12 @@ gapp.register("kiri.ui", [], (root, exports) => {
html = opt.pre.appendAll(html);
}
let iid;
if (input !== undefined) {
if (typeof(input) === 'string') {
iid = `confirm-input-${rnd}`;
html.append(`<div><input class="grow" type="text" spellcheck="false" value="${input}" id="${iid}"/></div>`);
html.append(`<div><input class="grow" type="text" spellcheck="false" id="${iid}"/></div>`);
} else if (Array.isArray(input)) {
iid = `confirm-input-${rnd}`;
html.append(`<div><textarea rows="15" cols="40" class="grow" type="text" spellcheck="false" id="${iid}"></textarea></div>`);
}
html.append(`<div class="f-row j-end">`);
Object.entries(btns).forEach((row,i) => {
@ -129,7 +132,10 @@ gapp.register("kiri.ui", [], (root, exports) => {
setTimeout(() => { resolve(value) }, 150);
}
if (iid) {
let array = Array.isArray(input);
iid = $(iid);
iid.value = array ? input.join('\n') : input;
if (!array)
iid.onkeypress = (ev) => {
if (ev.key === 'Enter' || ev.charCode === 13) {
done(ev.target.value);

View file

@ -36,12 +36,13 @@ function rename(sel) {
return;
}
let widget = widgets[0];
const newname = prompt("new widget name", widget.meta.file);
if (newname) {
widget.meta.file = newname;
api.platform.changed();
api.space.save(true);
}
kiri.ui.prompt("new widget name", widget.meta.file || "no name").then(newname => {
if (newname) {
widget.meta.file = newname;
api.platform.changed();
api.space.save(true);
}
});
}
function replace(vertices, sel) {