public EditorScriptItemCollection(C1FlexReport report, EditorScriptContextCollection contexts, C1FlexReportDesigner designer) { var ctxtName = EditorScriptContextBase.MakeContextName(report.DataSourceName, ScriptEditorContextKind.ReportScript); var context = contexts.GetContext(ctxtName); Action <EditorScriptItem> addScriptItem = (si_) => this.Add(si_.Key, si_); // global script: addScriptItem(EditorScriptItem.FromObjectProperty(report, "GlobalScripts", context, true)); // report event handlers: addScriptItem(EditorScriptItem.FromObjectProperty(report, "OnOpen", context, true)); addScriptItem(EditorScriptItem.FromObjectProperty(report, "OnClose", context, true)); addScriptItem(EditorScriptItem.FromObjectProperty(report, "OnNoData", context, true)); addScriptItem(EditorScriptItem.FromObjectProperty(report, "OnPage", context, true)); addScriptItem(EditorScriptItem.FromObjectProperty(report, "OnError", context, true)); // Sections' event handlers: foreach (Section s in report.Sections) { addScriptItem(EditorScriptItem.FromObjectProperty(s, "OnFormat", context, true)); addScriptItem(EditorScriptItem.FromObjectProperty(s, "OnPrint", context, true)); } // Report fields' expressions: foreach (FieldBase f in report.Fields) { ScriptEditorExpressionInfo fieldEditorInfo = designer.GetScriptEditorExpressionInfo(f); if (fieldEditorInfo != null) { addScriptItem(EditorScriptItem.FromObjectProperty(f, fieldEditorInfo.PropertyName, context, false)); } } }
public static EditorScriptItem FromTypeDescriptorContext( ITypeDescriptorContext typeDescriptorContext, EditorScriptContextBase scriptContext, bool isScript, string displayName = null) { if (typeDescriptorContext == null) { return(null); } var pd = typeDescriptorContext.PropertyDescriptor; var propertyOwner = typeDescriptorContext.Instance; if (propertyOwner is EditableModel) { propertyOwner = ((EditableModel)propertyOwner).Instance; } if (pd == null || propertyOwner == null) { return(null); } var value = pd.GetValue(propertyOwner); return(new EditorScriptItem(value, propertyOwner, pd.Name, isScript, scriptContext, displayName)); }
public static EditorScriptItem FromObjectProperty( object propertyOwner, string propertyName, EditorScriptContextBase scriptContext, bool isScript, string displayName = null) { if (propertyOwner is EditableModel) { propertyOwner = ((EditableModel)propertyOwner).Instance; } if (propertyOwner == null || string.IsNullOrEmpty(propertyName)) { return(null); } var pd = propertyOwner.GetType().GetProperty(propertyName); if (pd == null) { return(null); } var value = pd.GetValue(propertyOwner, null); return(new EditorScriptItem(value, propertyOwner, propertyName, isScript, scriptContext, displayName)); }
private EditorScriptItem(object value, object propOwner, string propName, bool isScript, EditorScriptContextBase context, string displayName) { System.Diagnostics.Debug.Assert(propOwner != null && !string.IsNullOrEmpty(propName)); // Key/name: _displayName = MakeName(propOwner, propName, out _key); if (!string.IsNullOrEmpty(displayName)) { _displayName = displayName; } // Is script (i.e. statements rather than an expression): _isScript = isScript; // Text value/Text mode (valid for non-scripts only), if we cannot figure it out assume false: bool?isExpression; _text = Util.ScriptValueHelper.ObjectToText(value, out isExpression); if (!isExpression.HasValue && propOwner is Field) { isExpression = ((Field)propOwner).Calculated; } if (isExpression.HasValue && !isExpression.Value) { IsTextMode = true; // this will throw exception if IsScript } // _propOwner = propOwner; _propName = propName; _context = context; }
public EditorScriptContextCollection(Forms.ScriptEditorFormEx owner, C1FlexReport report, C1FlexReportDesigner designer) { _owner = owner; _report = report; string name; foreach (var ds in report.DataSources) { // For each data source, we add 3 contexts: // - data handler // - regular report // - data filter string dsName = ds.Name; name = EditorScriptContextBase.MakeContextName(ds.Name, ScriptEditorContextKind.DataHandler); _contexts.Add(name, new EditorScriptDataHandlerContext(name, _report, ds, designer)); name = EditorScriptContextBase.MakeContextName(ds.Name, ScriptEditorContextKind.ReportScript); _contexts.Add(name, new EditorScriptReportScriptContext(name, _report, ds, designer)); name = EditorScriptContextBase.MakeContextName(ds.Name, ScriptEditorContextKind.DataView); _contexts.Add(name, new EditorScriptDataFilterContext(name, _report, ds, designer)); } // 'report-only' context (currently used for parameter's allowed values collection edits): name = EditorScriptContextBase.MakeContextName(string.Empty, ScriptEditorContextKind.ReportScript); _contexts.Add(name, new EditorScriptReportScriptContext(name, _report, null, designer)); // meta context for expressions that can only access parameters (currently only data sort definition), // also is used for cases when corresponding context was not found (patchy but will do for now): name = EditorScriptContextBase.MakeContextName(null, ScriptEditorContextKind.MetaView); _contexts.Add(name, new EditorScriptMetaViewContext(name, _report, designer)); }
/// <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); }
public EditorScriptContextBase GetContext(string name) { EditorScriptContextBase ret; _contexts.TryGetValue(name, out ret); if (ret == null) { // fallback context for invalid data source names: ret = _contexts[EditorScriptContextBase.MakeContextName(null, ScriptEditorContextKind.MetaView)]; } return(ret); }
private void DoAddSortDefinition() { if (!cAddSort.Enabled) { return; } C1FlexReport report = _flexDesigner.Report; if (report == null) { return; } var ds = _dataTree.GetCurrentDataSource(); if (ds == null) { return; } var contextName = EditorScriptContextBase.MakeContextName(ds.Name, ScriptEditorContextKind.MetaView); SortDefinition sd = null; Func <DataSource, bool> addSort = (ds_) => { sd = new SortDefinition(); ds_.SortDefinitions.Add(sd); using (Forms.AddSortDefForm addForm = new Forms.AddSortDefForm(ds)) { if (addForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { sd.Expression = addForm.SortExpression; sd.Direction = addForm.Ascending ? SortDirection.Ascending : SortDirection.Descending; return(true); } else { sd = null; return(false); } } }; DoDataSourcesAction(addSort, ds); if (sd != null) { _dataTree.GoToSortDefinition(ds, sd); } }
private void DoAddCalculatedField() { if (!cAddCalculatedField.Enabled) { return; } C1FlexReport report = _flexDesigner.Report; if (report == null) { return; } var ds = _dataTree.GetCurrentDataSource(); if (ds == null) { return; } var contextName = EditorScriptContextBase.MakeContextName(ds.Name, ScriptEditorContextKind.DataHandler); CalculatedField cf = null; Func <DataSource, bool> addField = (ds_) => { cf = new CalculatedField(); cf.Name = DesignerUtil.MakeUniqueName(ds_.CalculatedFields, "CalculatedField"); ds_.CalculatedFields.Add(cf); object result; if (EditScriptInternal(ds_.ParentReport, contextName, null, cf, "Expression", null, true, out result)) { return(true); } cf = null; return(false); }; DoDataSourcesAction(addField, ds); if (cf != null) { _dataTree.GoToCalculatedField(cf); } }
private void DoAddSortDefinition() { if (!cAddSort.Enabled) { return; } C1FlexReport report = _flexDesigner.Report; if (report == null) { return; } var ds = _dataTree.GetCurrentDataSource(); if (ds == null) { return; } var contextName = EditorScriptContextBase.MakeContextName(ds.Name, ScriptEditorContextKind.MetaView); SortDefinition sd = null; Func <DataSource, bool> addSort = (ds_) => { sd = new SortDefinition(); ds_.SortDefinitions.Add(sd); object result; if (EditScriptInternal(ds_.ParentReport, contextName, null, sd, "Expression", null, true, out result)) { return(true); } sd = null; return(false); }; DoDataSourcesAction(addSort, ds); if (sd != null) { _dataTree.GoToSortDefinition(ds, sd); } }
/// <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); }
private void DoScriptEditor() { C1FlexReport report = _flexDesigner.Report; if (report == null) { return; } var state = _flexDesigner.Undo_CreateSavedState(); object result; var contextName = EditorScriptContextBase.MakeContextName(report.DataSourceName, ScriptEditorContextKind.ReportScript); if (EditScriptInternal(report, contextName, null, report, "GlobalScripts", null, false, out result)) { _flexDesigner.Undo_PushSavedState(state); } else { _flexDesigner.Undo_DiscardSavedState(state); } }
/// <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); }
private void DoDataTreeEdit() { var dataObject = _dataTree.SelectedDataObject; if (dataObject == null) { return; } if (dataObject is DataSource) { DoDataSourcesAction((Func <DataSource, bool>)DataSources_EditDataSource, (DataSource)dataObject); return; } _dataTree.EndInPlaceEdit(); var undo = _flexDesigner.Undo_CreateSavedState(); if (dataObject is CalculatedField) { var cf = (CalculatedField)dataObject; var ds = _dataTree.GetCurrentDataSource(); var contextName = EditorScriptContextBase.MakeContextName(ds.Name, ScriptEditorContextKind.DataHandler); object result; if (EditScriptInternal(ds.ParentReport, contextName, null, dataObject, "Expression", null, true, out result)) { _flexDesigner.Undo_PushSavedState(undo); _flexDesigner.UpdateFromReport(); _dataTree.UpdateFromReport(); } else { _flexDesigner.Undo_DiscardSavedState(undo); } } else if (dataObject is SortDefinition) { #if skip_dima // simplifying... var sd = (SortDefinition)dataObject; var ds = _dataTree.GetCurrentDataSource(); var contextName = EditorScriptContextBase.MakeContextName(ds.Name, ScriptEditorContextKind.MetaView); object result; if (EditScriptInternal(ds.ParentReport, contextName, null, dataObject, "Expression", null, true, out result)) { _flexDesigner.Undo_PushSavedState(undo); _flexDesigner.UpdateFromReport(); _dataTree.UpdateFromReport(); } else { _flexDesigner.Undo_DiscardSavedState(undo); } #else var sd = (SortDefinition)dataObject; var ds = _dataTree.GetCurrentDataSource(); using (Forms.AddSortDefForm addForm = new Forms.AddSortDefForm(ds)) { addForm.SortExpression = sd.Expression; addForm.Ascending = sd.Direction.Value == SortDirection.Ascending; if (addForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { sd.Expression = addForm.SortExpression; sd.Direction = addForm.Ascending ? SortDirection.Ascending : SortDirection.Descending; _flexDesigner.Undo_PushSavedState(undo); _flexDesigner.UpdateFromReport(); _dataTree.UpdateFromReport(); } else { _flexDesigner.Undo_DiscardSavedState(undo); } } #endif } else { System.Diagnostics.Debug.Assert(false, "Do not know how to edit data object"); } UpdateUI(true, true); }
private void DoCreateField(RibbonItem item) { if (item == rbtnFieldChart) { _flexDesigner.CreateFieldInfo = item; _createInfo = null; } else if (item == rbtnFieldFlexChart) { _flexDesigner.CreateFieldInfo = item; _createInfo = null; } #if MAP else if (item == rbtnFieldMap) { _flexDesigner.CreateFieldInfo = item; _createInfo = null; } #endif else if (item == rbtnFieldDataField || item == rbtnFieldRtf || item == rbtnFieldCheckBox || item == rbtnFieldBarCode || item == rbtnFieldShape || item == rbtnFieldLegacy || item == rbtnFieldParagraph || item == rbtnFieldLegacy) { _flexDesigner.CreateFieldInfo = item; _createInfo = null; } else if (item == rbtnFieldCalculated) { ValueHolder valueHolder = new ValueHolder() { Value = string.Empty }; var contextName = EditorScriptContextBase.MakeContextName(_flexDesigner.Report.DataSourceName, ScriptEditorContextKind.ReportScript); object result; if (EditScriptInternal(_flexDesigner.Report, contextName, null, valueHolder, "Value", Strings.MainForm.NewCalcFieldExprName, true, out result)) { _createInfo = valueHolder.Value; if (!string.IsNullOrEmpty(_createInfo)) { _flexDesigner.CreateFieldInfo = item; } } else { _flexDesigner.CreateFieldInfo = null; item = rbtnFieldArrow; // to reset Pressed } } else if (item == rbtnFieldPicture) { using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.DereferenceLinks = true; dlg.Filter = Strings.MainForm.OpenImageFilter; dlg.FileName = "*.bmp;*.dib;*.ico;*.cur;*.gif;*.jpg;*.wmf;*.emf;*.png"; dlg.FilterIndex = 0; if (dlg.ShowDialog() == DialogResult.OK) { _createInfo = dlg.FileName; _flexDesigner.CreateFieldInfo = rbtnFieldPicture; } else { _flexDesigner.CreateFieldInfo = null; item = rbtnFieldArrow; // to reset Pressed } } } else if (item.Parent is RibbonDropDownBase) { _flexDesigner.CreateFieldInfo = item.Parent; _createInfo = ((RibbonButton)item).Text; } else if (item.Tag is Field) { _flexDesigner.CreateFieldInfo = item; } // NO else here on purpose: if (item == rbtnFieldArrow) { _flexDesigner.CancelMouseOperation(); _flexDesigner.CreateFieldInfo = null; _createInfo = null; } // We keep the button that caused the action pressed for the duration of adding the field // (i.e. while mouse cursor is a cross), while un-pressing all other items: UpdateCreateFieldButtons(item); // if (item != rbtnFieldArrow) { _flexDesigner.DoCreateFieldWithMouse(_flexDesigner.CreateFieldInfo); } }