void OnIdentifierNameChanged() { string trimedName = this.IdentifierName; if (this.CheckAgainstXaml && !VBIdentifierName.IsValidXamlName(trimedName)) { this.IsValid = false; this.ErrorMessage = string.Format(CultureInfo.CurrentUICulture, SR.InvalidXamlMemberName, trimedName); } else if (!this.VBProvider.IsValidIdentifier(trimedName) || !this.CSProvider.IsValidIdentifier(trimedName)) { this.IsValid = false; this.ErrorMessage = string.Format(CultureInfo.CurrentUICulture, SR.InvalidIdentifier, trimedName); } else if (trimedName.StartsWith("[", StringComparison.Ordinal) && trimedName.EndsWith("]", StringComparison.Ordinal)) { this.IsValid = false; this.ErrorMessage = string.Format(CultureInfo.CurrentUICulture, SR.InvalidIdentifier, trimedName); } else { this.IsValid = true; this.ErrorMessage = string.Empty; } }
protected override string GetItemStatusCore() { VBIdentifierDesigner vbIdentifierDesigner = this.Owner as VBIdentifierDesigner; if (vbIdentifierDesigner != null) { VBIdentifierName vbIdentifier = vbIdentifierDesigner.Identifier; if (vbIdentifier != null) { XElement itemStatus = new XElement("VBIdentifierStatus", new XAttribute("Status", vbIdentifier.IsValid ? "Valid" : "Invalid"), new XAttribute("WarningMessage", vbIdentifier.ErrorMessage)); return(itemStatus.ToString()); } } return(base.GetItemStatusCore()); }
void SetArgumentName(VBIdentifierName identifierName) { using (ModelEditingScope scope = this.ReflectedObject.BeginEdit((string)this.Editor.FindResource("changeArgumentNameDescription"))) { this.identifierName = identifierName; string name = identifierName.IdentifierName; this.Editor.UpdateArgumentName(this, name, (string)this.ReflectedObject.Properties[ArgumentNameProperty].ComputedValue); scope.Complete(); } }
internal DesignTimeArgument(ModelItem argument, ArgumentDesigner editor) : base(argument) { this.Editor = editor; this.ReflectedObject.Properties["Attributes"].Collection.CollectionChanged += new NotifyCollectionChangedEventHandler(OnAttributesChanged); this.identifierName = new VBIdentifierName(true) { IdentifierName = (string)argument.Properties[ArgumentNameProperty].ComputedValue }; }
internal void ValidateArgumentName(VBIdentifierName identifierName, string newName, string oldName) { //Check whether there're any variables' name conflict with the old name which can be cleaned up now this.ClearCaseInsensitiveDuplicates(identifierName, oldName); //Check whether there're any duplicates with new name this.CheckCaseInsensitiveDuplicates(identifierName, newName); }
//Check duplicates with old value. When there's only one variable duplicate with the old value, //the only one variable should be valid now after the change void ClearCaseInsensitiveDuplicates(VBIdentifierName identifier, string oldName) { Func<DesignTimeArgument, bool> checkForOldNameDuplicates = new Func<DesignTimeArgument, bool>(p => string.Equals((string)p.ReflectedObject.Properties["Name"].ComputedValue, oldName, StringComparison.OrdinalIgnoreCase) && !object.Equals(p.GetArgumentName(), identifier)); IEnumerable<DesignTimeArgument> oldDuplicates = this.argumentWrapperCollection.Where<DesignTimeArgument>(checkForOldNameDuplicates); if (oldDuplicates.Count<DesignTimeArgument>() == 1) { DesignTimeArgument wrapper = oldDuplicates.First<DesignTimeArgument>(); VBIdentifierName oldDuplicate = wrapper.GetArgumentName(); oldDuplicate.IsValid = true; oldDuplicate.ErrorMessage = string.Empty; } }
//Check case-insensitive duplicates, which are not allowed in VB expressions internal void CheckCaseInsensitiveDuplicates(VBIdentifierName identifierName, string newName) { Func<DesignTimeArgument, bool> checkForDuplicates = new Func<DesignTimeArgument, bool>(p => string.Equals((string)p.ReflectedObject.Properties["Name"].ComputedValue, newName, StringComparison.OrdinalIgnoreCase) && !object.Equals(p.GetArgumentName(), identifierName)); DesignTimeArgument duplicate = this.argumentWrapperCollection.FirstOrDefault<DesignTimeArgument>(checkForDuplicates); if (duplicate != null) { identifierName.IsValid = false; identifierName.ErrorMessage = string.Format(CultureInfo.CurrentUICulture, SR.DuplicateIdentifier, newName); VBIdentifierName duplicateIdentifier = duplicate.GetArgumentName(); if (duplicateIdentifier.IsValid) { duplicateIdentifier.IsValid = false; duplicateIdentifier.ErrorMessage = string.Format(CultureInfo.CurrentUICulture, SR.DuplicateIdentifier, duplicateIdentifier.IdentifierName); } }; }
protected override void OnReflectedObjectPropertyChanged(string propertyName) { if (string.Equals(propertyName, "Type")) { //type has changed - most likely custom value editors collection would be obsolete this.RaisePropertyChangedEvent(ArgumentTypeProperty); this.RaisePropertyChangedEvent(ArgumentDirectionProperty); this.RaisePropertyChangedEvent(IsOutputArgument); this.RaisePropertyChangedEvent(ArgumentDefaultValueProperty); } else if (propertyName == ArgumentNameProperty) { //Change name may need to update the defaul value editor as well, so clean the cache string oldValue = this.identifierName.IdentifierName; string newValue = GetArgumentNameString(); //This is invoked in undo stack if (oldValue != newValue) { this.identifierName = new VBIdentifierName(true) { IdentifierName = newValue }; Editor.ValidateArgumentName(this.identifierName, newValue, oldValue); } } else if (propertyName == ArgumentDefaultValueProperty) { this.argumentExpressionChanged = true; } else if (propertyName == Annotation.AnnotationTextPropertyName) { RaisePropertyChangedEvent(AnnotationTextProperty); } }
protected override void OnReflectedObjectPropertyChanged(string propertyName) { if (propertyName == Annotation.AnnotationTextPropertyName) { RaisePropertyChangedEvent(AnnotationTextProperty); } if (propertyName == VariableNameProperty) { string oldValue = this.identifierName.IdentifierName; string newValue = GetVariableNameString(); //This is invoked in undo stack if (oldValue != newValue) { this.identifierName = new VBIdentifierName { IdentifierName = newValue }; Editor.NotifyVariableNameChanged(this.identifierName, newValue, oldValue); } } }
void SetVariableName(VBIdentifierName identifierName) { using (ModelEditingScope change = this.ReflectedObject.BeginEdit((string)this.Editor.FindResource("changeVariableNameDescription"))) { this.identifierName = identifierName; string name = this.identifierName.IdentifierName; this.Editor.NotifyVariableNameChanged(this.identifierName, name, (string)this.ReflectedObject.Properties[VariableNameProperty].ComputedValue); this.ReflectedObject.Properties[VariableNameProperty].SetValue(name); change.Complete(); } }
internal DesignTimeVariable(ModelItem modelItem, VariableDesigner editor) : base(modelItem) { this.Editor = editor; this.identifierName = new VBIdentifierName { IdentifierName = (string)modelItem.Properties[VariableNameProperty].ComputedValue }; }