protected override SceneNode InternalCreateRawInstance(ITypeId instanceType) { IType type = this.ViewModel.ProjectContext.ResolveType(instanceType); if (type != null && type.RuntimeType != (System.Type)null) { ToolboxExampleAttribute attribute = TypeUtilities.GetAttribute <ToolboxExampleAttribute>(type.RuntimeType); if (attribute != null) { IToolboxExampleFactory toolboxExampleFactory = Activator.CreateInstance(attribute.ToolboxExampleFactoryType) as IToolboxExampleFactory; if (toolboxExampleFactory != null && toolboxExampleFactory.Examples != null) { IToolboxExample[] toolboxExampleArray = Enumerable.ToArray <IToolboxExample>(toolboxExampleFactory.Examples); if (this.exampleInfo.Index < toolboxExampleArray.Length) { IToolboxExample toolboxExample = toolboxExampleArray[this.exampleInfo.Index]; if (toolboxExample != null) { ISceneNodeModelItem sceneNodeModelItem = toolboxExample.CreateExample(this.ViewModel.ExtensibilityManager.EditingContext) as ISceneNodeModelItem; if (sceneNodeModelItem != null && sceneNodeModelItem.SceneNode != null) { return(sceneNodeModelItem.SceneNode); } } } } } } return(base.InternalCreateRawInstance(instanceType)); }
public string CreateNameId(ModelItem item, string name) { ISceneNodeModelItem sceneNodeModelItem = item as ISceneNodeModelItem; if (sceneNodeModelItem != null) { return(this.importContext.CreateNameId(sceneNodeModelItem.SceneNode, name)); } return(name); }
public override ModelItem SetValue(object value) { using (SceneEditTransaction editTransaction = this.CreateEditTransaction()) { ModelItem modelItem = value as ModelItem; if (modelItem != null) { ISceneNodeModelItem sceneNodeModelItem = value as ISceneNodeModelItem; value = sceneNodeModelItem == null?modelItem.GetCurrentValue() : (object)sceneNodeModelItem.SceneNode.DocumentNode; } string text = value as string; if (text != null) { bool flag = true; if (text.StartsWith("{", StringComparison.Ordinal)) { if (text.StartsWith("{}", StringComparison.Ordinal)) { text = text.Substring(2); } else { XamlDocument document = (XamlDocument)this.parent.SceneNode.ViewModel.XamlDocument; DocumentNode parentNode = this.parent.SceneNode.DocumentNode; if (parentNode.DocumentRoot == null) { parentNode = document.RootNode; } IList <XamlParseError> errors; DocumentNode expressionFromString = XamlExpressionSerializer.GetExpressionFromString(text, document, parentNode, this.PropertyType, out errors); if (errors == null || errors.Count == 0) { flag = false; value = (object)expressionFromString; } } } if (flag) { value = (object)this.parent.SceneNode.DocumentContext.CreateNode((ITypeId)this.property.PropertyType, (IDocumentNodeValue) new DocumentNodeStringValue(text)); } } if (value != null && !(value is DocumentNode) && this.parent.SceneNode.ProjectContext.GetType(value.GetType()) == null) { throw new InvalidOperationException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, ExceptionStringTable.TypeIsNotResolveableWithinProject, new object[1] { (object)value.GetType().FullName })); } this.parent.SceneNode.SetValue((IPropertyId)this.property, value); editTransaction.Commit(); } return(this.Value); }
public override IEnumerable <ModelItem> Find(ModelItem startingItem, Predicate <Type> match) { ISceneNodeModelItem root = startingItem as ISceneNodeModelItem; if (root != null) { SearchPath path = new SearchPath(new SearchStep[1] { new SearchStep(SearchAxis.DocumentSelfAndDescendant, (ISearchPredicate) new DelegatePredicate((Predicate <SceneNode>)(node => match(node.TargetType)), SearchScope.NodeTreeSelf)) }); foreach (SceneNode sceneNode in path.Query(root.SceneNode)) { yield return((ModelItem)sceneNode.ModelItem); } } }
public override ModelItem FromName(ModelItem scope, string name, StringComparison comparison) { ISceneNodeModelItem sceneNodeModelItem = (scope ?? this.Root) as ISceneNodeModelItem; if (sceneNodeModelItem != null) { SceneNode sceneNode = new SearchPath(new SearchStep[1] { new SearchStep(SearchAxis.DocumentSelfAndDescendant, (ISearchPredicate) new DelegatePredicate((Predicate <SceneNode>)(node => string.Compare(name, node.Name, comparison) == 0), SearchScope.NodeTreeSelf)) }).QueryFirst(sceneNodeModelItem.SceneNode); if (sceneNode != null) { return((ModelItem)sceneNode.ModelItem); } } return((ModelItem)null); }
private void OnUserSelectionChanged(Microsoft.Windows.Design.Interaction.Selection selection) { if (this.settingSelection) { return; } try { this.settingSelection = true; using (SceneEditTransaction editTransaction = this.viewModel.CreateEditTransaction(StringTable.UndoUnitSetSelection)) { List <SceneElement> list = new List <SceneElement>(); SceneElement primarySelection = (SceneElement)null; foreach (ModelItem modelItem in selection.SelectedObjects) { ISceneNodeModelItem sceneNodeModelItem = modelItem as ISceneNodeModelItem; if (sceneNodeModelItem != null) { SceneElement sceneElement = sceneNodeModelItem.SceneNode as SceneElement; if (sceneElement != null) { list.Add(sceneElement); if (modelItem == selection.PrimarySelection) { primarySelection = sceneElement; } } } } if (list.Count == 0) { this.viewModel.ElementSelectionSet.Clear(); } else { this.viewModel.ElementSelectionSet.SetSelection((ICollection <SceneElement>)list, primarySelection); } editTransaction.Commit(); } } finally { this.settingSelection = false; } }
private void ValueTranslationServicePropertyInvalidated(object sender, PropertyInvalidatedEventArgs e) { ISceneNodeModelItem sceneNodeModelItem = e.Item as ISceneNodeModelItem; if (sceneNodeModelItem == null || sceneNodeModelItem.SceneNode == null) { return; } SceneNode sceneNode = sceneNodeModelItem.SceneNode; ReferenceStep referenceStep = sceneNode.Type.GetMember(MemberType.Property, e.InvalidatedProperty.Name, MemberAccessTypes.All) as ReferenceStep; if (sceneNode.ViewObject != null && sceneNode.ViewObject.PlatformSpecificObject != null && referenceStep != null) { DesignModeValueProviderService.RunDesignModeValueProvider(sceneNode.ViewObject.PlatformSpecificObject, this.platform, this.ValueTranslationService, sceneNode.Type, sceneNode.TrueTargetType, e.InvalidatedProperty, referenceStep, false); } else { sceneNode.ViewModel.DefaultView.InstanceBuilderContext.ViewNodeManager.Invalidate(sceneNode.DocumentNode, InstanceState.Invalid); } }