From 46ba4115af775f79468f41024d95b358fdc5cbd3 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sat, 12 Feb 2022 12:16:29 +0100 Subject: [PATCH] widgets/editor: add lock property --- CHANGELOG.md | 3 +++ resources/docs/docs/remote-control.md | 2 +- resources/docs/docs/user-interface/editor.md | 4 ++++ src/client/editor/index.js | 25 ++++++++++++++++++++ src/client/ui/ui-inspector-field.js | 2 +- src/client/ui/ui-inspector.js | 4 +++- src/client/ui/ui-tree.js | 2 +- src/client/widgets/common/widget.js | 1 + src/scss/ui/inspector.scss | 13 ++++++++++ src/scss/ui/tree.scss | 7 ++++++ 10 files changed, 59 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ca448e6..c13d09fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ - bug fixes - editor: prevent accessing non-editable widgets with right arrow +- widgets + - add `lock` property to all widgets + ## 1.14.6 - bug fixes diff --git a/resources/docs/docs/remote-control.md b/resources/docs/docs/remote-control.md index bec57fd4..1184f3a6 100644 --- a/resources/docs/docs/remote-control.md +++ b/resources/docs/docs/remote-control.md @@ -11,7 +11,7 @@ When osc messages are received, the default behavior is to update the value of a #### `/EDIT id properties options` -Apply a set of options to an existing widget by replacing the old ones with the new ones. +Apply a set of options to an existing widget by replacing the old ones with the new ones. This ignores the widget's `lock` property. - `id`: `string`, widget's `id` diff --git a/resources/docs/docs/user-interface/editor.md b/resources/docs/docs/user-interface/editor.md index 406ee1a2..551efb66 100644 --- a/resources/docs/docs/user-interface/editor.md +++ b/resources/docs/docs/user-interface/editor.md @@ -42,6 +42,8 @@ Selected widget's properties are displayed and can be modified in the inspector. Some properties (for example `onValue`) have a special code editor with syntax hilighting and many keyboard shortcuts (available by clicking on the "Help" button). In this properties, pressing `enter` will not submit pending changes and instead insert a new line at the cursor position (as you would expect in a regular editor). To submit pending changes, press ++ctrl+enter++ (or ++cmd+enter== on Mac) or click outside the editor. +Widgets can be locked for edition by enabling their `lock` property. When locked, a widget can't be modified by the editor but it remains possible to delete it or to move it from a container to another in the project tree. + ## Project tree @@ -49,6 +51,8 @@ The project tree displays the whole widget structure of the session. Widgets can The "Filter" input allows filtering displayed widgets by their `id`. It's also possible to only display a single type of widget by typing `type:fader` for example. +Invisible widgets are displayed with a lower opacity and their name in italic. Locked widgets are displayed with a lock icon after their name. + ## Widget resizing / dragging Selected widget can be resized using its south, south-east and east handles. It can be dragged with its north-west handle (holding ++alt++ extends this handle to the widget's size to ease dragging). If the widget's position/size was written in percents, the editor will try to keep using percents. diff --git a/src/client/editor/index.js b/src/client/editor/index.js index aa6807a5..d4573521 100644 --- a/src/client/editor/index.js +++ b/src/client/editor/index.js @@ -33,6 +33,11 @@ class Editor { newWidgets = [], error = false + if (this.selectedWidgets.some(w=>w.getProp('lock')) && propName !== 'lock') { + this.select(this.selectedWidgets) + return + } + for (var w of this.selectedWidgets) { let previousValue = w.props[propName] @@ -557,6 +562,16 @@ class Editor { } + var parent = this.selectedWidgets[0].parent, + parentLock = false + while (parent !== widgetManager) { + if (parent.getProp('lock')) { + this.selectedWidgets = [parent] + parentLock = true + } + parent = parent.parent + } + if (options.fromLasso && !options.lassoEnd) return this.unselect() @@ -818,6 +833,11 @@ class Editor { if (!this.selectedWidgets.length) return + if (this.selectedWidgets.some(w=>w.getProp('lock'))) { + this.createSelectionBlock() + return + } + var newWidgets = [], area = this.widgetDragResize, changedProps = [] @@ -891,6 +911,11 @@ class Editor { if (!this.selectedWidgets.length) return + if (this.selectedWidgets.some(w=>w.getProp('lock'))) { + this.createSelectionBlock() + return + } + var newWidgets = [] for (var w of this.selectedWidgets) { diff --git a/src/client/ui/ui-inspector-field.js b/src/client/ui/ui-inspector-field.js index ede99252..70c92b1d 100644 --- a/src/client/ui/ui-inspector-field.js +++ b/src/client/ui/ui-inspector-field.js @@ -17,7 +17,7 @@ class UiInspectorField extends UiWidget { this.default = options.default this.tabIndex = options.tabIndex - this.container = html`` + this.container = html`` this.label = this.container.appendChild(html``) if (this.name === 'type' || this.name === 'widgetType') this.createTypeSelect() diff --git a/src/client/ui/ui-inspector.js b/src/client/ui/ui-inspector.js index f4e137f7..94ea8ef2 100644 --- a/src/client/ui/ui-inspector.js +++ b/src/client/ui/ui-inspector.js @@ -117,15 +117,17 @@ class UiInspector extends UiWidget { this.clearTimeout = null } - var content = html`
` var widget = widgets[0], + lock = widgets.some(w=>w.getProp('lock')), props = defaults[widget.props.type], tabIndex = 1000, codeEditorFields = [] this.widget = widget + var content = html`
` + for (let categoryName in props) { if (categoryName === 'children') continue diff --git a/src/client/ui/ui-tree.js b/src/client/ui/ui-tree.js index f9082315..fbd279fa 100644 --- a/src/client/ui/ui-tree.js +++ b/src/client/ui/ui-tree.js @@ -265,7 +265,7 @@ class UiTree extends UiWidget { id = widget.getProp('id'), node = html`
  • - ${raw(icon(widgetIcons[widget.getProp('type')] || 'root'))}${id}
  • ` + ${raw(icon(widgetIcons[widget.getProp('type')] || 'root'))}${id}${widget.getProp('lock')? raw(icon('lock')) :''}` node.depth = depth diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index 718c5156..aa1545f2 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -54,6 +54,7 @@ class Widget extends EventEmitter { var defaults = { widget: { + lock: {type: 'boolean', value: false, help: 'Set to `true` to prevent modifying this widget with the editor. This will not prevent deleting the widget or moving it from a container to another.'}, type: {type: 'string', value: 'auto', help: 'Widget type'}, id: {type: 'string', value: 'auto', help: 'Widgets sharing the same `id` will act as clones and update each other\'s value(s) without sending extra osc messages.' }, visible: {type: 'boolean', value: true, help: 'Set to `false` to hide the widget.'}, diff --git a/src/scss/ui/inspector.scss b/src/scss/ui/inspector.scss index 939654ce..0304a66a 100644 --- a/src/scss/ui/inspector.scss +++ b/src/scss/ui/inspector.scss @@ -17,6 +17,19 @@ osc-panel-container.right.editor-breakout { --widget-padding: -1rem; + .lock { + osc-inspector-field { + filter: saturate(0); + pointer-events: none; + opacity: 0.65; + } + osc-inspector-field[name=lock] { + filter: none; + pointer-events: auto; + opacity: 1.0; + } + } + } osc-inspector-field { diff --git a/src/scss/ui/tree.scss b/src/scss/ui/tree.scss index 0f2c840f..2bd9fe46 100644 --- a/src/scss/ui/tree.scss +++ b/src/scss/ui/tree.scss @@ -112,6 +112,13 @@ // right: -12rem; // } } + .fa-lock { + position: relative; + margin-left: 4rem; + top:0; + font-size: 80%; + opacity: 0.8; + } }