From 72e724aa85aadb97251c690e1f7ce95b28d54c3e Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Thu, 1 Mar 2018 17:40:01 +0100 Subject: [PATCH] prop inheritance: make @{id.value}, @{id} and @{id._value} refer to the same thing (current value) --- CHANGELOG.md | 3 ++- resources/docs/extras/property-inheritance.md | 8 ++++---- src/browser/js/app/widgets/common/widget.js | 15 +++++++++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 623f4e3f..d8c6839c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,12 @@ - bug fixes - launcher: parse array options correctly when an item contains spaces, - - launcher: the terminal now grows and scrolls to bottom automatically + - launcher: the terminal now grows and scrolls to bottom automatically - main - add `--fullscreen` switch (default gui only, bypasses the sidepanel fullscreen button) - widgets - knob: big knobs design tweaks + - property inheritance: `@{widget_id.value}`, `@{widget_id}` and `@{widget_id._value}` now all refer to the widget's current value (the latter being kept for backward compatibility) - editor - allow selecting multiple widgets (`ctrl + click`) if they share the same parent. Context-menu and sidepanel editing actions apply to all selected widgets diff --git a/resources/docs/extras/property-inheritance.md b/resources/docs/extras/property-inheritance.md index e9c8ff8a..dfccc0af 100644 --- a/resources/docs/extras/property-inheritance.md +++ b/resources/docs/extras/property-inheritance.md @@ -21,11 +21,11 @@ If the retreived property is an object (`[] / {}`), a subset can be defined by a !!! note "" The root panel's `id` is `root`. -## Use dynamic value +## Using the value -The special property name `_value`flash_on refers to a widget's value, as opposed to its `value` property. +The special property name `value`flash_on refers to a widget's current value (which can be affected by its `value` *property*). -When omitted, the property name defaults to `_value` : `@{widgetId}` => `@{widgetId._value}` +When omitted, the property name defaults to `value` : `@{widgetId}` => `@{widgetId.value}` ## Dynamic properties @@ -37,4 +37,4 @@ Some properties have much cheaper update routines and can be considered as `dyna ## Circular references cases - container widgets can inherit their children's properties only to define `dynamic` properties -- widgets can inherit their own `_value`flash_on property only to define `dynamic` properties +- widgets can inherit their own `value`flash_on property only to define `dynamic` properties diff --git a/src/browser/js/app/widgets/common/widget.js b/src/browser/js/app/widgets/common/widget.js index 8b68e52e..ae9ecef9 100644 --- a/src/browser/js/app/widgets/common/widget.js +++ b/src/browser/js/app/widgets/common/widget.js @@ -239,10 +239,13 @@ class Widget extends EventEmitter { } else { id = id[0] - k = '_value' + k = 'value' } + // backward compat + if (k === '_value') k = 'value' + var widgets = id == 'parent' && this.parent ? [this.parent] : id == 'this' ? [this] : widgetManager.getWidgetById(id) @@ -260,7 +263,7 @@ class Widget extends EventEmitter { if (storeLinks) { - if (k == '_value') { + if (k == 'value') { if (!this.linkedPropsValue[id]) this.linkedPropsValue[id] = [] if (this.linkedPropsValue[id].indexOf(propName) == -1) this.linkedPropsValue[id].push(propName) @@ -276,13 +279,13 @@ class Widget extends EventEmitter { for (var i in widgets) { - if (widgets[i].props.hasOwnProperty(k) || k == '_value') { + if (widgets[i].props.hasOwnProperty(k) || k == 'value') { if (originalPropName == k && widgets[i].props.id == originalWidget.props.id) { return undefined } - var r = k == '_value' ? + var r = k == 'value' ? widgets[i].getValue(true) : widgets[i].resolveProp(k, undefined, storeLinks, originalWidget, originalPropName) @@ -352,7 +355,7 @@ class Widget extends EventEmitter { return this.cachedProps[propName] } - updateProps(propNames, widget, options, _value) { + updateProps(propNames, widget, options, value) { if (propNames.indexOf('value') > 0) { propNames.splice(propNames.indexOf('value'), 1) @@ -385,7 +388,7 @@ class Widget extends EventEmitter { } } - if (reCreate && this.childrenHashes.indexOf(widget.hash) == -1 && !(_value && widget == this)) { + if (reCreate && this.childrenHashes.indexOf(widget.hash) == -1 && !(value && widget == this)) { this.reCreateWidget() return true