Example #1
0
        protected virtual void UpdateType(JSC.JSValue manifest)
        {
            this._manifest = manifest;

            string       nv   = null;
            int          attr = 0;
            BitmapSource ni   = null;

            if (_manifest != null && _manifest.ValueType == JSC.JSValueType.Object && _manifest.Value != null)
            {
                var    vv = _manifest["editor"];
                string tmp_s;
                if (vv.ValueType == JSC.JSValueType.String && !string.IsNullOrEmpty(tmp_s = vv.Value as string))
                {
                    nv = tmp_s;
                }
                var iv = _manifest["icon"];
                if (iv.ValueType == JSC.JSValueType.String && !string.IsNullOrEmpty(tmp_s = iv.Value as string))
                {
                    ni = App.GetIcon(tmp_s);
                }
                JSC.JSValue js_attr;
                if ((js_attr = _manifest["attr"]).IsNumber)
                {
                    attr = (int)js_attr;
                }
            }
            IsReadonly = (attr & 2) != 0;
            IsRequired = (attr & 1) != 0;
            if (nv == null)
            {
                nv = DTopic.JSV2Type(value);
            }
            if (ni == null)
            {
                if (value.ValueType == JSC.JSValueType.Object && value.Value == null)
                {
                    ni = App.GetIcon((this is InTopic) ? string.Empty : "Null"); // Folder or Null
                }
            }
            if (ni == null)
            {
                ni = App.GetIcon(nv);
            }

            if (ni != icon)
            {
                icon = ni;
                PropertyChangedReise("icon");
            }
            if (nv != _editorName)
            {
                _editorName = nv;
                editor      = InspectorForm.GetEditor(_editorName, this, _manifest);
                PropertyChangedReise("editor");
            }
            this.editor.TypeChanged(_manifest);
        }
Example #2
0
        private void UpdateData(JSC.JSValue val)
        {
            bool o_hc = HasChildren;

            _value = val;
            if (_value.ValueType == JSC.JSValueType.Object)
            {
                InValue vc;
                int     i;
                foreach (var kv in _value.OrderBy(z => z.Key))
                {
                    vc = _items.OfType <InValue>().FirstOrDefault(z => z.name == kv.Key);
                    if (vc != null)
                    {
                        vc.UpdateData(kv.Value);
                    }
                    else
                    {
                        for (i = _items.Count - 1; i >= 0; i--)
                        {
                            if (string.Compare(_items[i].name, kv.Key) < 0)
                            {
                                break;
                            }
                        }
                        JSC.JSValue cs;
                        {
                            JSC.JSValue pr;
                            if (_manifest == null || (pr = _manifest["Fields"]).ValueType != JSC.JSValueType.Object || (cs = pr[kv.Key]).ValueType != JSC.JSValueType.Object)
                            {
                                cs = null;
                            }
                        }
                        var ni = new InValue(_data, this, kv.Key, kv.Value, cs, _collFunc);
                        _items.Insert(i + 1, ni);
                        if (_isVisible && _isExpanded)
                        {
                            _collFunc(ni, true);
                        }
                    }
                }
                var keys = _value.Select(z => z.Key).ToArray();
                for (i = _items.Count - 1; i >= 0; i--)
                {
                    if (!keys.Contains(_items[i].name))
                    {
                        if (_isVisible && _isExpanded)
                        {
                            _items[i].Deleted();
                        }
                        _items.RemoveAt(i);
                    }
                }
            }
            if (editor == null)
            {
                editor = InspectorForm.GetEditor(_editorName, this, _manifest);
                PropertyChangedReise("editor");
            }
            else
            {
                editor.ValueChanged(_value);
            }
            if (o_hc != this.HasChildren)
            {
                PropertyChangedReise("HasChildren");
            }
        }