private IProperty GetSpecialDefaultBindingProperty(DataBindingDragDropFlags filteredDragFlags) { DataSchemaNodePath primaryAbsolutePath = this.DragModel.DataSource.PrimaryAbsolutePath; IProperty defaultBindingProperty = this.GetDefaultBindingProperty(filteredDragFlags, primaryAbsolutePath); if (!DataContextMetadata.HasDataContextAttributes(defaultBindingProperty)) { return((IProperty)null); } DataContextInfo dataContextInfo = new DataContextEvaluator().Evaluate(this.DragModel.TargetNode, (IPropertyId)defaultBindingProperty, true); if (dataContextInfo.DataSource.SourceNode != primaryAbsolutePath.Schema.DataSource.DocumentNode) { return((IProperty)null); } DataSchemaNodePath nodePathFromPath = primaryAbsolutePath.Schema.GetNodePathFromPath(dataContextInfo.DataSource.Path); if (!nodePathFromPath.IsSubpathOf(primaryAbsolutePath)) { return((IProperty)null); } DataSchemaNodePath relativeNodePath = nodePathFromPath.GetRelativeNodePath(primaryAbsolutePath); if (relativeNodePath.CollectionDepth != 0) { return((IProperty)null); } this.DragModel.TargetPropertySpecialDataContext = relativeNodePath; return(defaultBindingProperty); }
private void ApplyRulesInternal(DataBindingDragDropModel model, DataBindingDragDropFlags filteredDragFlags) { if ((filteredDragFlags & DataBindingDragDropFlags.SetBinding) == DataBindingDragDropFlags.SetBinding) { if (model.InsertionPoint.Property != null) { model.DropFlags &= ~DataBindingDragDropFlags.SetBinding; IType type = model.RelativeDropSchemaPath.Type; if (type != null && BindingPropertyHelper.GetPropertyCompatibility(model.InsertionPoint.Property, type, (ITypeResolver)model.TargetNode.ProjectContext) != BindingPropertyCompatibility.None) { model.TargetProperty = model.InsertionPoint.Property; model.DropFlags |= DataBindingDragDropFlags.SetBinding; } } else if ((filteredDragFlags & DataBindingDragDropFlags.AutoPickProperty) == DataBindingDragDropFlags.AutoPickProperty) { model.TargetProperty = this.GetSpecialDefaultBindingProperty(filteredDragFlags); if (model.TargetProperty == null) { model.TargetProperty = this.GetDefaultBindingProperty(filteredDragFlags, model.RelativeDropSchemaPath); } if (model.TargetProperty != null) { model.DropFlags |= DataBindingDragDropFlags.SetBinding; } } } if ((filteredDragFlags & DataBindingDragDropFlags.CreateElement) != DataBindingDragDropFlags.CreateElement || !PlatformTypes.Panel.IsAssignableFrom((ITypeId)model.TargetNode.Type)) { return; } if (DataBindingModeModel.Instance.NormalizedMode == DataBindingMode.Default && model.RelativeDropSchemaPath.IsCollection) { model.NewElementType = !model.RelativeDropSchemaPath.IsHierarchicalCollection ? DataBindingDragDropDefaultHandler.ItemsControlType : DataBindingDragDropDefaultHandler.TreeControlType; model.NewElementProperty = (IPropertyId)model.NewElementType.GetMember(MemberType.LocalProperty, "ItemsSource", MemberAccessTypes.Public); model.DropFlags |= DataBindingDragDropFlags.CreateElement; } List <DataSchemaNode> toCreateElements = this.GetNodesToCreateElements(); if (toCreateElements.Count < model.DataSource.Count) { return; } model.DropFlags |= DataBindingDragDropFlags.CreateElement; model.NodesToCreateElements = (IList <DataSchemaNode>)toCreateElements; if (model.NewElementType != null) { return; } IType dataType = toCreateElements[0].ResolveType(model.TargetNode.DocumentNode.TypeResolver); DataViewTemplateEntry viewTemplateEntry = DataViewFactory.GetDataViewTemplateEntry(model.Platform, dataType, DataViewCategory.Master); model.NewElementType = (ITypeId)viewTemplateEntry.FieldNode.Type; model.NewElementProperty = (IPropertyId)viewTemplateEntry.FieldValueProperty; }
private static bool CheckFlags(DataBindingDragDropFlags actualFlags, DataBindingDragDropFlags testFlags, bool exactMatch) { DataBindingDragDropFlags bindingDragDropFlags = actualFlags & testFlags; if (bindingDragDropFlags == DataBindingDragDropFlags.None) { return(false); } if (bindingDragDropFlags == testFlags) { return(true); } return(!exactMatch); }
private IProperty GetDefaultBindingProperty(DataBindingDragDropFlags filteredDragFlags, DataSchemaNodePath schemaPath) { IType type = schemaPath.Type; IProperty property; if (!schemaPath.IsCollection || schemaPath.Node.Type == (Type)null || !(schemaPath.Schema is XmlSchema)) { property = this.GetDefaultBindingProperty(filteredDragFlags, type); } else { IType dataType = this.ProjectContext.ResolveType(PlatformTypes.ICollection); property = !type.IsAssignableFrom((ITypeId)dataType) ? this.GetDefaultBindingProperty(filteredDragFlags, dataType) ?? this.GetDefaultBindingProperty(filteredDragFlags, type) : this.GetDefaultBindingProperty(filteredDragFlags, type); } return(property); }
private IProperty GetDefaultBindingProperty(DataBindingDragDropFlags filteredDragFlags, IType dataType) { if (dataType == null) { return((IProperty)null); } BindingPropertyMatchInfo bindingPropertyInfo = BindingPropertyHelper.GetDefaultBindingPropertyInfo(this.DragModel.TargetNode, dataType); if (bindingPropertyInfo.Property == null) { return((IProperty)null); } if (bindingPropertyInfo.Compatibility == BindingPropertyCompatibility.StringSpecial && !PlatformTypes.IConvertible.IsAssignableFrom((ITypeId)dataType)) { return((IProperty)null); } if (bindingPropertyInfo.Compatibility == BindingPropertyCompatibility.DataContext) { if ((filteredDragFlags & DataBindingDragDropFlags.DiscourageDataContext) == DataBindingDragDropFlags.DiscourageDataContext) { return((IProperty)null); } SceneElement sceneElement = this.DragModel.TargetNode as SceneElement; if (sceneElement == null) { return((IProperty)null); } if (!sceneElement.IsContainer && !PlatformTypes.UserControl.IsAssignableFrom((ITypeId)sceneElement.Type) && (sceneElement.Parent != null && !PlatformTypes.FrameworkTemplate.IsAssignableFrom((ITypeId)sceneElement.Parent.Type))) { return((IProperty)null); } if (PlatformTypes.IConvertible.IsAssignableFrom((ITypeId)dataType)) { return((IProperty)null); } } if (bindingPropertyInfo.Compatibility == BindingPropertyCompatibility.Assignable && bindingPropertyInfo.Property.PropertyType.RuntimeType == typeof(object) && !PlatformTypes.IConvertible.IsAssignableFrom((ITypeId)dataType)) { return((IProperty)null); } if (PlatformTypes.IEnumerable.IsAssignableFrom((ITypeId)bindingPropertyInfo.Property.PropertyType) && !PlatformTypes.String.IsAssignableFrom((ITypeId)bindingPropertyInfo.Property.PropertyType) && PlatformTypes.String.IsAssignableFrom((ITypeId)dataType)) { return((IProperty)null); } return(bindingPropertyInfo.Property); }
private void Disambiguate() { if (this.DragModel.CheckDropFlags(DataBindingDragDropFlags.SetBinding) && !this.DragModel.ViewModel.BindingEditor.CanCreateAndSetBindingOrData(this.DragModel.TargetNode, (IPropertyId)this.DragModel.TargetProperty, this.DragModel.DataSource.PrimaryAbsolutePath, true)) { this.DragModel.DropFlags &= ~DataBindingDragDropFlags.SetBinding; } this.DragModel.DropFlags &= this.DragModel.DragFlags; DataBindingDragDropFlags flags = DataBindingDragDropFlags.SetBinding | DataBindingDragDropFlags.CreateElement; if (!this.DragModel.CheckDropFlags(flags)) { return; } DataBindingDragDropFlags bindingDragDropFlags = this.DragModel.InsertionPoint.InsertIndex < 0 ? (this.DragModel.CheckDragFlags(DataBindingDragDropFlags.AutoPickProperty) ? DataBindingDragDropFlags.CreateElement : DataBindingDragDropFlags.SetBinding) : DataBindingDragDropFlags.CreateElement; this.DragModel.DropFlags &= ~flags; this.DragModel.DropFlags |= bindingDragDropFlags; }
private void ApplyRules(DataBindingDragDropFlags filteredDragFlags) { this.ApplyRulesInternal(this.DragModel, filteredDragFlags); if (!this.ShouldTryDropOnAncestorPanel(filteredDragFlags)) { return; } DataBindingDragDropModel ancestorPanelModel = this.DragModel.AncestorPanelModel; if (ancestorPanelModel == null || ancestorPanelModel == this.DragModel) { return; } DataBindingDragDropFlags filteredDragFlags1 = filteredDragFlags & ~DataBindingDragDropFlags.SetBinding; this.ApplyRulesInternal(ancestorPanelModel, filteredDragFlags1); if (!ancestorPanelModel.CheckDropFlags(DataBindingDragDropFlags.CreateElement)) { return; } this.DragModel = ancestorPanelModel; }
private bool UpdateDragModelDefault() { int collectionDepth = this.DragModel.RelativeDropSchemaPath.CollectionDepth; if (collectionDepth > 1 || collectionDepth > 0 && this.DragModel.RelativeDropSchemaPath.IsMethod) { return(false); } DataBindingDragDropFlags dragFlags = this.DragModel.DragFlags; if (this.DragModel.DataSource.Count == 1 && (collectionDepth == 0 || this.DragModel.RelativeDropSchemaPath.IsCollection)) { this.DragModel.DropFlags |= DataBindingDragDropFlags.SetBinding; } else if (this.DragModel.DataSource.Count > 1 && collectionDepth == 0) { dragFlags &= ~(DataBindingDragDropFlags.SetBinding | DataBindingDragDropFlags.AutoPickProperty); } DataSchemaNode effectiveCollectionNode = this.DragModel.RelativeDropSchemaPath.EffectiveCollectionNode; bool flag = effectiveCollectionNode != null && effectiveCollectionNode != this.DragModel.RelativeDropSchemaPath.Node; if (flag) { this.DragModel.RelativeDropSchemaPath = new DataSchemaNodePath(this.DragModel.RelativeDropSchemaPath.Schema, effectiveCollectionNode); } this.ApplyRules(dragFlags); if (this.DragModel.TargetPropertySpecialDataContext != null) { this.DragModel.RelativeDropSchemaPath = this.DragModel.TargetPropertySpecialDataContext; } else if (flag && this.DragModel.CheckDropFlags(DataBindingDragDropFlags.SetBinding) && !this.ShouldGenerateDetails(this.DragModel.TargetProperty)) { this.DragModel.TargetProperty = (IProperty)null; this.DragModel.DropFlags &= ~DataBindingDragDropFlags.SetBinding; } return(true); }
public static DataBindingDragDropModel GetDragFeedback(DataSchemaNodePathCollection information, BindingSceneInsertionPoint insertionPoint, DataBindingDragDropFlags dragFlags, ModifierKeys modifiers) { bool flag = (modifiers & ModifierKeys.Alt) == ModifierKeys.Alt; if (!DataBindingDragDropManager.isAltModifier.HasValue) { if (flag) { DataBindingModeModel.Instance.SetMode(DataBindingMode.Details, false); } } else if (DataBindingDragDropManager.isAltModifier.Value != flag) { DataBindingModeModel.Instance.SetMode(flag ? DataBindingMode.Details : DataBindingMode.Default, false); } DataBindingDragDropManager.isAltModifier = new bool?(flag); if ((modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) { dragFlags &= ~DataBindingDragDropFlags.AutoPickProperty; dragFlags &= ~DataBindingDragDropFlags.AllowRetargetElement; } if (insertionPoint.Property != null) { dragFlags &= ~DataBindingDragDropFlags.CreateElement; } if (!BindingPropertyHelper.HasBindableProperties(insertionPoint.SceneNode)) { dragFlags &= ~(DataBindingDragDropFlags.SetBinding | DataBindingDragDropFlags.AutoPickProperty); } DataBindingDragDropModel bindingDragDropModel = new DataBindingDragDropModel(information, insertionPoint, dragFlags, modifiers); if (!DataBindingDragDropModel.Equals(bindingDragDropModel, DataBindingDragDropManager.effectiveDragModel)) { PerformanceUtility.StartPerformanceSequence(PerformanceEvent.DataBindingDragModelUpdate); DataBindingDragDropManager.effectiveDragModel = DataBindingDragDropManager.UpdateDragModel(bindingDragDropModel); PerformanceUtility.EndPerformanceSequence(PerformanceEvent.DataBindingDragModelUpdate); } return(DataBindingDragDropManager.effectiveDragModel); }
private bool ShouldTryDropOnAncestorPanel(DataBindingDragDropFlags filteredDragFlags) { return((filteredDragFlags & DataBindingDragDropFlags.CreateElement) != DataBindingDragDropFlags.None && this.DragModel.CheckDragFlags(DataBindingDragDropFlags.AllowRetargetElement) && (this.DragModel.DropFlags == DataBindingDragDropFlags.None || this.DragModel.DataSource.PrimarySchemaNodePath.IsCollection && !this.DragModel.CheckDropFlags(DataBindingDragDropFlags.CreateElement) && (this.DragModel.TargetProperty == null || FrameworkElement.DataContextProperty.Equals((object)this.DragModel.TargetProperty)))); }
public bool CheckDragFlags(DataBindingDragDropFlags flags, bool exactMatch) { return(DataBindingDragDropModel.CheckFlags(this.DragFlags, flags, exactMatch)); }
public bool CheckDragFlags(DataBindingDragDropFlags flags) { return(this.CheckDragFlags(flags, true)); }
public DataBindingDragDropModel(DataSchemaNodePathCollection dataSource, BindingSceneInsertionPoint insertionPoint, DataBindingDragDropFlags dragFlags, ModifierKeys modifiers) { this.DataSource = dataSource; this.InsertionPoint = insertionPoint; this.DragFlags = dragFlags; this.Modifiers = modifiers; }