コード例 #1
0
        public override void InitStyles(Selector selector, StyleTable styles)
        {
            var components = GetComponentsMatchingSelector(selector);

            foreach (Component component in components)
            {
                // 2. for additions, set the style
                foreach (KeyValuePair <string, object> pair in styles)
                {
                    MemberWrapper wrapper = new MemberWrapper(component.GetType(), pair.Key);
                    wrapper.SetValue(component, pair.Value);
                }
            }
        }
コード例 #2
0
        public override void UpdateStyles(Selector selector, DictionaryDelta delta)
        {
            // nothing yet
            //Debug.Log("UpdateStyles: " + delta);
            var components = GetComponentsMatchingSelector(selector);

            delta.Process();

            foreach (Component component in components)
            {
                // TODO: find out which property changed and its value
                //var changedProp = _modifiedPropertyName;
                //component.SetStyle("paddingLeft", 30);

                // 1. for removals, clear the style
                foreach (string removal in delta.Removals.Keys)
                {
                    // TODO: set the default value (if exists)
                    // (default values should be implemented via the attribute)
                    //Debug.Log("Removing -> " + removal);
                    MemberWrapper wrapper = new MemberWrapper(component.GetType(), removal);

                    object value      = null;
                    var    attributes = CoreReflector.GetMemberAttributes <StyleAttribute>(wrapper.MemberInfo);
                    if (attributes.Count > 0)
                    {
                        value = attributes[0].GetDefault();
                    }

                    wrapper.SetValue(component, value);
                }
                // 2. for additions, set the style
                foreach (KeyValuePair <string, object> addition in delta.Additions)
                {
                    MemberWrapper wrapper = new MemberWrapper(component.GetType(), addition.Key);
                    wrapper.SetValue(component, addition.Value);
                }

                // 3. for updates, set the style
                foreach (KeyValuePair <string, object> update in delta.Updates)
                {
                    MemberWrapper wrapper = new MemberWrapper(component.GetType(), update.Key);
                    wrapper.SetValue(component, update.Value);
                }

                UnityComponentStylingGizmo.Show(components);
            }
        }
コード例 #3
0
        private void EditButtonClicked()
        {
            Debug.Assert(m_currentValue != null, "m_currentValue != null");

            Type editorType = ((CellEditorData)m_currentValue.Tag).GetEditorType(EditorManager);

            Debug.Assert(editorType != null, "Edit button clicked, but there is no editor for value type '"
                         + m_currentValue.ValueTypeName + "'.");

            if (m_editorDialog == null)
            {
                m_editorDialog = new EditorDialog(MessageBoxButtons.OKCancel);
            }
            if (m_editorDialogSettings != null)
            {
                m_editorDialogSettings.ApplyToWindow(m_editorDialog);
            }
            m_editorDialog.ReadOnly          = IsReallyReadOnly(m_currentValue);
            m_editorDialog.CurrentEditorType = editorType;

            // Keep the value in the remote AppDomain, if the editor supports this.

            if (m_editorDialog.IsRemoteEditor)
            {
                m_editorDialog.DisplayRemoteValue(m_currentValue.CreateWrapper());
            }
            else
            {
                m_editorDialog.DisplayValue(m_currentValue.GetValue());
            }

            m_editorDialog.FocusOnEditor();             // Set focus to the editor every time the dialog is shown.

            if (m_editorDialog.ShowDialog(DataGridTableStyle.DataGrid) == DialogResult.OK)
            {
                m_currentValue.SetValue(m_editorDialog.GetValue());
                OnEditorCommitted(new MemberWrapperEventArgs(m_currentValue));
            }

            if (m_editorDialogSettings == null)
            {
                m_editorDialogSettings = new WindowSettings();
            }
            m_editorDialogSettings.ReadFromWindow(m_editorDialog);
        }
コード例 #4
0
ファイル: CouchDocumentWrapper.cs プロジェクト: grueni/Divan
 public void ReadJson(JObject obj)
 {
     instance = (T)serializer.Deserialize(new JTokenReader(obj), typeof(T));
     id.SetValue(instance, obj["_id"].Value <string>());
     rev.SetValue(instance, obj["_rev"].Value <string>());
 }
コード例 #5
0
        private void FindSkinParts()
        {
            if (null == _thisType)
            {
                _thisType = GetType();
            }

            var parts = SkinParts.Keys;

            foreach (var id in parts)
            {
                object part = null;

                /**
                 * 1. If this is a mapper skin,
                 * */
                if (_isMapperSkin)
                {
                    part = Skin.GetChildComponent(id);
                    //if (null != part)
                    //    Debug.Log("Found mapper skin part: " + part);
                    //else
                    //    Debug.Log(Skin + " -> Couldn't find mapper skin part: " + id);
                }

                else
                {
                    if (CoreReflector.HasMember(Skin, id))
                    {
                        try
                        {
                            part = CoreReflector.GetValue(Skin, id);
                        }
                        catch (InvalidCastException /* ex*/)
                        {
                            Debug.LogError(string.Format("Cannot cast the skin part to InteractiveComponent. Skin: {0}; Part: {1}", Skin, id));
                        }
                    }

                    //else
                    //    Debug.LogWarning("Couldn't find member: " + id);
                }

                if (SkinParts[id]) // == true (required part)
                {
                    if (null == part)
                    {
                        throw new Exception("Required skin part not found: " + id);
                    }
                }

                if (null != part)
                {
                    /**
                     * Note: we've been having a hard-core bug here (20131216)!
                     * The system FREEZED when using Panel with children in designer
                     * For instance, a panel had a single button child as a content child (not tool or control bar child)
                     * This is also the source of bug whereever we add a child prior to adding itself to the display list (both designer and code)
                     * I think it might be related to styles and StyleProtoChain process (?)
                     * This shoould - of course - be fixed
                     * The problem with designer was in ComponentAdapter ("Produce" method):
                     * _component.AddEventListener(FrameworkEvent.PREINITIALIZE, InitializeHandler)
                     * During the PREINITILIZE, child components have not yet been created - so the skin wasn't created
                     * When I changed it to INITILIZE, it started to work properly:
                     * _component.AddEventListener(FrameworkEvent.INITIALIZE, InitializeHandler)                     *
                     * */

                    /*if (id == "ContentGroup")
                     *  Debug.LogWarning("ContentGroup: " + part);*/

                    //CoreReflector.SetValue(this, id, part);
                    MemberWrapper wrapper = new MemberWrapper(GetType(), id);
                    wrapper.SetValue(this, part);

                    // If the assigned part has already been instantiated, call partAdded() here,
                    // but only for static parts.

                    try
                    {
                        /* Note: this fails, because the wrapper wraps around the Skin's property, not the Panel's */
                        //var p = CoreReflector.GetValue(this, id);
                        wrapper = new MemberWrapper(GetType(), id);
                        var p = wrapper.GetValue(this);

                        // TODO: we should get the value silently here, because not to disturb the DoubleGroup.Modified flag
                        //Debug.Log("Just added: " + p);

                        // If the assigned part has already been instantiated, call partAdded() here,
                        // but only for static parts.
                        if (null != p && !(p is IFactory))
                        {
                            PartAdded(id, p);
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        throw ex;
                    }
                }
            }
        }