Пример #1
0
        /// <summary>
        /// Edits the value of the specified object.
        /// </summary>
        /// <param name="ctx">An <see cref="ITypeDescriptorContext"/> that can be used to gain additional context information.</param>
        /// <param name="provider">An <see cref="IServiceProvider"/> through which editing services may be obtained.</param>
        /// <param name="value">An instance of the value being edited.</param>
        /// <returns>A string containing the new value of the object.</returns>
        override public object EditValue(ITypeDescriptorContext ctx, IServiceProvider provider, object value)
        {
            object instance;
            FlexDesignerHostServices services;

            if (!Util.EditableModelHelper.GetInstanceAndServices(ctx, out instance, out services))
            {
                return(value);
            }

            IGetReportsService   grs = services.GetGetReportService();
            IScriptEditorService ses = services.GetScriptEditorService();

            if (grs == null || ses == null)
            {
                return(value);
            }

            var report = grs.Report;

            if (report == null)
            {
                return(value);
            }

            // guess script context
            string dataSourceName;
            ScriptEditorContextKind contextKind;

            EditorScriptContextBase.GuessContextName(report, instance, ctx.PropertyDescriptor.Name, out dataSourceName, out contextKind);

            // Run the editor:
            object result;

            if (ses.EditScript(report, dataSourceName, contextKind, instance, ctx.PropertyDescriptor.Name, null, IsExpression, out result))
            {
                return(result);
            }

            // editor was cancelled - return original value
            return(value);
        }
Пример #2
0
        override public object EditValue(ITypeDescriptorContext ctx, IServiceProvider provider, object value)
        {
            // sanity
            if (provider == null)
            {
                return(value);
            }

            object instance;
            FlexDesignerHostServices services;

            if (!Util.EditableModelHelper.GetInstanceAndServices(ctx, out instance, out services))
            {
                return(value);
            }

            IGetReportsService grs = services.GetGetReportService();

            if (grs == null)
            {
                return(value);
            }

            C1FlexReport report = grs.Report;

            if (report == null)
            {
                return(value);
            }

            // show the list
            _edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if (_edSvc == null)
            {
                return(value);
            }
            FillListBox(report, instance);
            _edSvc.DropDownControl(_listBox);
            _edSvc = null;

            return(_listBox.SelectedItem);
        }
Пример #3
0
        /// <summary>
        /// Edits the value of the specified object.
        /// </summary>
        /// <param name="ctx">An <see cref="ITypeDescriptorContext"/> that can be used to gain additional context information.</param>
        /// <param name="provider">An <see cref="IServiceProvider"/> through which editing services may be obtained.</param>
        /// <param name="value">An instance of the value being edited.</param>
        /// <returns>A string containing the new value of the object.</returns>
        public override object EditValue(ITypeDescriptorContext ctx, IServiceProvider provider, object value)
        {
            // sanity
            if (provider == null)
            {
                return(value);
            }

            object instance;
            FlexDesignerHostServices services;

            if (!Util.EditableModelHelper.GetInstanceAndServices(ctx, out instance, out services))
            {
                return(value);
            }

            IGetReportsService   grs = services.GetGetReportService();
            IScriptEditorService ses = services.GetScriptEditorService();

            if (grs == null || ses == null)
            {
                return(value);
            }

            C1FlexReport report = grs.Report;

            if (report == null)
            {
                return(value);
            }

            // Handle both string and ScriptStringValue properties:
            Type targetType = ctx != null && ctx.PropertyDescriptor != null ? ctx.PropertyDescriptor.PropertyType : typeof(string);

            // script editor call:
            Func <object, object> doEdit = (v_) =>
            {
                string dataSourceName;
                ScriptEditorContextKind contextKind;
                EditorScriptContextBase.GuessContextName(report, instance, ctx.PropertyDescriptor.Name, out dataSourceName, out contextKind);
                object result;
                if (ses.EditScript(report, dataSourceName, contextKind, instance, ctx.PropertyDescriptor.Name, null, true, out result))
                {
                    return(result);
                }
                else
                {
                    return(v_);
                }
            };

            // select editor style
            UITypeEditorEditStyle style = GetEditStyle(ctx);
            object retValue;

            switch (style)
            {
            case UITypeEditorEditStyle.None:
                retValue = value;
                break;

            case UITypeEditorEditStyle.Modal:
                retValue = doEdit(value);
                break;

            case UITypeEditorEditStyle.DropDown:
                _edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (_edSvc != null)
                {
                    // show the list
                    _edSvc.DropDownControl(_listBox);
                    _edSvc = null;
                    IScriptValueListItem selectedItem = _listBox.GetSelectedItem();
                    if (selectedItem == null)
                    {
                        retValue = value;
                    }
                    else if (selectedItem.IsScriptEditor)
                    {
                        retValue = doEdit(value);
                    }
                    else if (selectedItem.IsValue)
                    {
                        retValue = Util.ScriptValueHelper.TextToObject(selectedItem.Text, targetType, selectedItem.IsExpression);
                    }
                    else
                    {
                        retValue = value;
                    }
                }
                else
                {
                    retValue = value;
                }
                break;

            default:
                System.Diagnostics.Debug.Assert(false);
                retValue = null;
                break;
            }
            // return whatever we got
            return(retValue);
        }