private void EditValueMI_Click(object sender, EventArgs e)
        {
            try
            {
                ContentFilterElement element = SelectedTag as ContentFilterElement;

                if (element == null)
                {
                    return;
                }

                List<FilterOperand> operands = element.GetOperands();

                if (operands.Count != 2)
                {
                    return;                    
                }

                LiteralOperand literal = operands[1] as LiteralOperand;

                if (literal == null)
                {
                    return;
                }

                // get the current value.
                object currentValue = literal.Value.Value;

                if (currentValue == null)
                {
                    currentValue = String.Empty;
                }

                // edit the value.
                object value = new SimpleValueEditDlg().ShowDialog(currentValue, currentValue.GetType());

                if (value == null)
                {
                    return;
                }

                // update value.
                literal.Value = new Variant(value);
                ContentFilter filter = GetFilter();
                Update(filter);
            }
            catch (Exception exception)
            {
				GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Exemplo n.º 2
0
        private void EditMI_Click(object sender, EventArgs e)
        {
            try
            {
                if (ItemsLV.SelectedItems.Count != 1)
                {
                    return;
                }

                ValueState state = ItemsLV.SelectedItems[0].Tag as ValueState;

                if (!IsEditableType(state.Component))
                {
                    return;
                }

                object value = new SimpleValueEditDlg().ShowDialog(state.Component, state.Component.GetType());

                if (value == null)
                {
                    return;
                }

                if (state.Value is IEncodeable)
                {
                    PropertyInfo property = (PropertyInfo)state.ComponentId;
                    
                    MethodInfo[] accessors = property.GetAccessors();

                    for (int ii = 0; ii < accessors.Length; ii++)
                    {
                        if (accessors[ii].ReturnType == typeof(void))
                        {
                            accessors[ii].Invoke(state.Value, new object[] { value });
                            state.Component = value;
                            break;
                        }
                    }
                }
                
                DataValue datavalue = state.Value as DataValue;

                if (datavalue != null)
                {
                    int component = (int)state.ComponentId;

                    switch (component)
                    {
                        case 0: { datavalue.Value = value; break; }
                    }
                }

                if (state.Value is IList)
                {
                    int ii = (int)state.ComponentId;
                    ((IList)state.Value)[ii] = value;
                    state.Component = value;
                }
                
                m_expanding = false;
                int index = 0;
                bool overwrite = true;
                ShowValue(ref index, ref overwrite, state.Value);                
            }
            catch (Exception exception)
            {
				GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }