From 3df81d48c79ab7eef400dca80724547a3c85af48 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Thu, 20 Jan 2022 17:40:10 -0500 Subject: [PATCH] add model renaming --- src/main/mesh.js | 1 + src/mesh/api.js | 25 +++++++++++++++++++++++++ src/mesh/model.js | 6 ++++++ web/mesh/index.css | 2 +- 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/mesh.js b/src/main/mesh.js index ce21b98b..cad977fe 100644 --- a/src/main/mesh.js +++ b/src/main/mesh.js @@ -287,6 +287,7 @@ function space_init(data) { case 'KeyV': return selection.focus(); case 'KeyN': + if (shiftKey) return estop(evt, api.tool.rename()); return api.normals(); case 'KeyW': return api.wireframe(); diff --git a/src/mesh/api.js b/src/mesh/api.js index 068c8c00..6cb28e92 100644 --- a/src/mesh/api.js +++ b/src/mesh/api.js @@ -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 }) { models = fallback(models); api.log.emit('analyzing mesh(es)...').pin(); diff --git a/src/mesh/model.js b/src/mesh/model.js index 0cccbc61..16f3100a 100644 --- a/src/mesh/model.js +++ b/src/mesh/model.js @@ -195,6 +195,12 @@ mesh.model = class MeshModel extends mesh.object { 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() { return this._group; } diff --git a/web/mesh/index.css b/web/mesh/index.css index c5f1609c..307d0b5b 100644 --- a/web/mesh/index.css +++ b/web/mesh/index.css @@ -513,7 +513,7 @@ button.selected:hover { color: #fff !important; } -.tempedit { +.tempedit, .rename { gap: 3px; }