add model renaming

This commit is contained in:
Stewart Allen 2022-01-20 17:40:10 -05:00
commit 3df81d48c7
4 changed files with 33 additions and 1 deletions

View file

@ -287,6 +287,7 @@ function space_init(data) {
case 'KeyV': case 'KeyV':
return selection.focus(); return selection.focus();
case 'KeyN': case 'KeyN':
if (shiftKey) return estop(evt, api.tool.rename());
return api.normals(); return api.normals();
case 'KeyW': case 'KeyW':
return api.wireframe(); return api.wireframe();

View file

@ -330,6 +330,31 @@ let tool = {
} }
}, },
rename(models) {
models = fallback(models, true);
let model = models[0];
if (!model) {
return;
}
if (models.length > 1) {
return api.log.emit('rename requires a single selection');
}
let onclick = onkeydown = (ev) => {
if (ev.code && ev.code !== 'Enter') {
return;
}
model.rename( $('tempedit').value.trim() );
selection.update();
api.modal.hide();
};
let { tempedit } = api.modal.show(`rename model`, h.div({ class: "rename"}, [
h.input({ id: "tempedit", value: model.file, onkeydown }),
h.button({ _: 'ok', onclick })
]));
tempedit.setSelectionRange(0,1000);
tempedit.focus();
},
analyze(models, opt = { compound: true }) { analyze(models, opt = { compound: true }) {
models = fallback(models); models = fallback(models);
api.log.emit('analyzing mesh(es)...').pin(); api.log.emit('analyzing mesh(es)...').pin();

View file

@ -195,6 +195,12 @@ mesh.model = class MeshModel extends mesh.object {
this.normals({refresh: true}); this.normals({refresh: true});
} }
rename(file) {
this.file = file;
// persist in db so it can be restored on page load
mapp.db.space.put(this.id, { file, mesh: this.attributes.position.array });
}
get group() { get group() {
return this._group; return this._group;
} }

View file

@ -513,7 +513,7 @@ button.selected:hover {
color: #fff !important; color: #fff !important;
} }
.tempedit { .tempedit, .rename {
gap: 3px; gap: 3px;
} }