示例#1
0
        /// <summary>
        /// Gets the editor style used by the <see cref="EditValue"/> method.
        /// If there are available bindable fields, returns DropDown, otherwise Modal.
        /// </summary>
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext ctx)
        {
            object instance;
            FlexDesignerHostServices services;

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

            if (ctx.PropertyDescriptor.PropertyType == typeof(ScriptEnumValue <SortDirection>))
            {
                _listBox.FillWithSortDirections();
            }
            else
            {
                var grs = services.GetGetReportService();
                if (grs == null)
                {
                    return(UITypeEditorEditStyle.None);
                }

                C1FlexReport report = grs.Report;
                if (report == null)
                {
                    return(UITypeEditorEditStyle.None);
                }

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

                if (contextKind == ScriptEditorContextKind.DataView)
                {
                    return(UITypeEditorEditStyle.Modal);
                }

                if (contextKind == ScriptEditorContextKind.MetaView)
                {
                    dataSourceName = report.DataSourceName;
                }

                var ds = report.DataSources.FindByName(dataSourceName);
                _listBox.FillWithFields(report, ds, contextKind);
            }

            if (_listBox.Items.Count == 1) // just the expression editor
            {
                return(UITypeEditorEditStyle.Modal);
            }

            // done
            return(UITypeEditorEditStyle.DropDown);
        }
示例#2
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);
        }
示例#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);
        }