Browse Source

- removed x-support from XamlResolver

- added XamlNamespacePrefix to XamlContext
- fixed invalid placement handling in GridPlacementSupport

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4818 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 17 years ago
parent
commit
ffa6cf7b41
  1. 50
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs
  2. 5
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs
  3. 26
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs
  4. 2
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlContext.cs
  5. 5
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs
  6. 99
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs

50
src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs

@ -91,6 +91,7 @@ namespace ICSharpCode.XamlBinding
List<AXmlElement> ancestors = new List<AXmlElement>(); List<AXmlElement> ancestors = new List<AXmlElement>();
Dictionary<string, string> xmlns = new Dictionary<string, string>(); Dictionary<string, string> xmlns = new Dictionary<string, string>();
List<string> ignored = new List<string>(); List<string> ignored = new List<string>();
string xamlNamespacePrefix = string.Empty;
var item = currentData; var item = currentData;
@ -106,7 +107,10 @@ namespace ICSharpCode.XamlBinding
} }
if (attr.LocalName == "Ignorable" && attr.Namespace == MarkupCompatibilityNamespace) if (attr.LocalName == "Ignorable" && attr.Namespace == MarkupCompatibilityNamespace)
ignored.Add(attr.Value); ignored.AddRange(attr.Value.Split(' ', '\t'));
if (string.IsNullOrEmpty(xamlNamespacePrefix) && attr.Value == XamlNamespace)
xamlNamespacePrefix = attr.LocalName;
} }
} }
@ -172,18 +176,19 @@ namespace ICSharpCode.XamlBinding
var xAttribute = currentData as AXmlAttribute; var xAttribute = currentData as AXmlAttribute;
var context = new XamlContext() { var context = new XamlContext() {
Description = description, Description = description,
ActiveElement = (active == null) ? null : active.ToWrapper(), ActiveElement = (active == null) ? null : active.ToWrapper(),
ParentElement = (parent == null) ? null : parent.ToWrapper(), ParentElement = (parent == null) ? null : parent.ToWrapper(),
Ancestors = ancestors.Select(ancestor => ancestor.ToWrapper()).ToList(), Ancestors = ancestors.Select(ancestor => ancestor.ToWrapper()).ToList(),
Attribute = (xAttribute != null) ? xAttribute.ToWrapper() : null, Attribute = (xAttribute != null) ? xAttribute.ToWrapper() : null,
InRoot = isRoot, InRoot = isRoot,
AttributeValue = value, AttributeValue = value,
RawAttributeValue = attributeValue, RawAttributeValue = attributeValue,
ValueStartOffset = offsetFromValueStart, ValueStartOffset = offsetFromValueStart,
XmlnsDefinitions = xmlns, XmlnsDefinitions = xmlns,
ParseInformation = info, ParseInformation = info,
IgnoredXmlns = ignored.AsReadOnly() IgnoredXmlns = ignored.AsReadOnly(),
XamlNamespacePrefix = xamlNamespacePrefix
}; };
return context; return context;
@ -233,7 +238,7 @@ namespace ICSharpCode.XamlBinding
var list = new List<ICompletionItem>(); var list = new List<ICompletionItem>();
string xamlPrefix = Utils.GetXamlNamespacePrefix(context); string xamlPrefix = context.XamlNamespacePrefix;
string xKey = string.IsNullOrEmpty(xamlPrefix) ? "" : xamlPrefix + ":"; string xKey = string.IsNullOrEmpty(xamlPrefix) ? "" : xamlPrefix + ":";
if (xamlBuiltInTypes.Concat(XamlNamespaceAttributes).Select(s => xKey + s).Contains(lastElement.Name)) if (xamlBuiltInTypes.Concat(XamlNamespaceAttributes).Select(s => xKey + s).Contains(lastElement.Name))
@ -413,16 +418,14 @@ namespace ICSharpCode.XamlBinding
if (itemClass != null) if (itemClass != null)
result.Add(new XamlCodeCompletionItem(itemClass, last.Prefix)); result.Add(new XamlCodeCompletionItem(itemClass, last.Prefix));
} }
string xamlPrefix = Utils.GetXamlNamespacePrefix(context);
var xamlItems = XamlNamespaceAttributes.AsEnumerable(); var xamlItems = XamlNamespaceAttributes.AsEnumerable();
if (EnableXaml2009) if (EnableXaml2009)
xamlItems = xamlBuiltInTypes.Concat(XamlNamespaceAttributes); xamlItems = xamlBuiltInTypes.Concat(XamlNamespaceAttributes);
foreach (string item in xamlItems) foreach (string item in xamlItems)
result.Add(new XamlCompletionItem(xamlPrefix, XamlNamespace, item)); result.Add(new XamlCompletionItem(context.XamlNamespacePrefix, XamlNamespace, item));
return result; return result;
} }
@ -452,7 +455,7 @@ namespace ICSharpCode.XamlBinding
it.Text = text; it.Text = text;
} }
return neededItems.Cast<ICompletionItem>().Add(new XamlCompletionItem(Utils.GetXamlNamespacePrefix(context), XamlNamespace, "Reference")); return neededItems.Cast<ICompletionItem>().Add(new XamlCompletionItem(context.XamlNamespacePrefix, XamlNamespace, "Reference"));
} }
public static XamlCompletionItemList CreateListForContext(XamlCompletionContext context) public static XamlCompletionItemList CreateListForContext(XamlCompletionContext context)
@ -495,14 +498,14 @@ namespace ICSharpCode.XamlBinding
int propertyStart = element.IndexOf('.'); int propertyStart = element.IndexOf('.');
if (propertyStart != -1) if (propertyStart != -1)
className = element.Substring(0, propertyStart).TrimEnd('.'); className = element.Substring(0, propertyStart).TrimEnd('.');
TypeResolveResult trr = new XamlResolver().Resolve(new ExpressionResult(className, context), info, editor.Document.Text) as TypeResolveResult; TypeResolveResult trr = XamlResolver.Resolve(className, context) as TypeResolveResult;
IClass typeClass = (trr != null && trr.ResolvedType != null) ? trr.ResolvedType.GetUnderlyingClass() : null; IClass typeClass = (trr != null && trr.ResolvedType != null) ? trr.ResolvedType.GetUnderlyingClass() : null;
if (typeClass != null && typeClass.HasAttached(true, true)) if (typeClass != null && typeClass.HasAttached(true, true))
list.Items.AddRange(GetListOfAttached(context, className, ns, true, true)); list.Items.AddRange(GetListOfAttached(context, className, ns, true, true));
} else { } else {
QualifiedNameWithLocation last = context.ActiveElement.ToQualifiedName(); QualifiedNameWithLocation last = context.ActiveElement.ToQualifiedName();
TypeResolveResult trr = new XamlResolver().Resolve(new ExpressionResult(last.Name, context), info, editor.Document.Text) as TypeResolveResult; TypeResolveResult trr = XamlResolver.Resolve(last.Name, context) as TypeResolveResult;
IClass typeClass = (trr != null && trr.ResolvedType != null) ? trr.ResolvedType.GetUnderlyingClass() : null; IClass typeClass = (trr != null && trr.ResolvedType != null) ? trr.ResolvedType.GetUnderlyingClass() : null;
list.Items.AddRange(CreateAttributeList(context, true)); list.Items.AddRange(CreateAttributeList(context, true));
list.Items.AddRange(standardAttributes); list.Items.AddRange(standardAttributes);
@ -746,9 +749,8 @@ namespace ICSharpCode.XamlBinding
if (type is ConstructedReturnType && type.TypeArgumentCount > 0 && c.FullyQualifiedName == "System.Nullable") { if (type is ConstructedReturnType && type.TypeArgumentCount > 0 && c.FullyQualifiedName == "System.Nullable") {
ConstructedReturnType rt = type as ConstructedReturnType; ConstructedReturnType rt = type as ConstructedReturnType;
string nullExtensionName = "Null"; string nullExtensionName = "Null";
string prefix = Utils.GetXamlNamespacePrefix(context); if (!string.IsNullOrEmpty(context.XamlNamespacePrefix))
if (!string.IsNullOrEmpty(prefix)) nullExtensionName = context.XamlNamespacePrefix + ":" + nullExtensionName;
nullExtensionName = prefix + ":" + nullExtensionName;
yield return new SpecialCompletionItem("{" + nullExtensionName + "}"); yield return new SpecialCompletionItem("{" + nullExtensionName + "}");
c = rt.TypeArguments.First().GetUnderlyingClass(); c = rt.TypeArguments.First().GetUnderlyingClass();
if (c == null) if (c == null)

5
src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs

@ -53,11 +53,6 @@ namespace ICSharpCode.XamlBinding
static char[] whitespace = new char[] {' ', '\t', '\n', '\r'}; static char[] whitespace = new char[] {' ', '\t', '\n', '\r'};
public static string GetXamlNamespacePrefix(XamlContext context)
{
return GetNamespacePrefix(CompletionDataHelper.XamlNamespace, context);
}
public static string GetNamespacePrefix(string namespaceUri, XamlContext context) public static string GetNamespacePrefix(string namespaceUri, XamlContext context)
{ {
var item = context.XmlnsDefinitions.FirstOrDefault(i => i.Value == namespaceUri); var item = context.XmlnsDefinitions.FirstOrDefault(i => i.Value == namespaceUri);

26
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs

@ -233,19 +233,23 @@ namespace ICSharpCode.XamlBinding
void ColorizeMember(HighlightingInfo info, DocumentLine line, IMember member) void ColorizeMember(HighlightingInfo info, DocumentLine line, IMember member)
{ {
try { try {
if (info.Context.IgnoredXmlns.Any(item => info.Token.StartsWith(item + ":", StringComparison.OrdinalIgnoreCase))) { if (info.Token.StartsWith(info.Context.XamlNamespacePrefix + ":", StringComparison.Ordinal)) {
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightIgnored); ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightProperty);
} else { } else {
if (member != null) { if (info.Context.IgnoredXmlns.Any(item => info.Token.StartsWith(item + ":", StringComparison.Ordinal))) {
if (member is IEvent) ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightIgnored);
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightEvent);
else
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightProperty);
} else { } else {
if (info.Token.StartsWith("xmlns", StringComparison.OrdinalIgnoreCase) || info.Token.StartsWith(Utils.GetNamespacePrefix(CompletionDataHelper.MarkupCompatibilityNamespace, info.Context) + ":", StringComparison.OrdinalIgnoreCase)) if (member != null) {
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightNamespaceDeclaration); if (member is IEvent)
else ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightEvent);
Core.LoggingService.Debug(info.Token + " not highlighted; line " + line.LineNumber); else
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightProperty);
} else {
if (info.Token.StartsWith("xmlns", StringComparison.OrdinalIgnoreCase) || info.Token.StartsWith(Utils.GetNamespacePrefix(CompletionDataHelper.MarkupCompatibilityNamespace, info.Context) + ":", StringComparison.OrdinalIgnoreCase))
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightNamespaceDeclaration);
else
Core.LoggingService.Debug(info.Token + " not highlighted; line " + line.LineNumber);
}
} }
} }
} catch (ArgumentOutOfRangeException) {} } catch (ArgumentOutOfRangeException) {}

2
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlContext.cs

@ -112,6 +112,7 @@ namespace ICSharpCode.XamlBinding
public ParseInformation ParseInformation { get; set; } public ParseInformation ParseInformation { get; set; }
public bool InRoot { get; set; } public bool InRoot { get; set; }
public ReadOnlyCollection<string> IgnoredXmlns { get; set; } public ReadOnlyCollection<string> IgnoredXmlns { get; set; }
public string XamlNamespacePrefix { get; set; }
public IProjectContent ProjectContent { public IProjectContent ProjectContent {
get { get {
@ -157,6 +158,7 @@ namespace ICSharpCode.XamlBinding
this.XmlnsDefinitions = context.XmlnsDefinitions; this.XmlnsDefinitions = context.XmlnsDefinitions;
this.InRoot = context.InRoot; this.InRoot = context.InRoot;
this.IgnoredXmlns = context.IgnoredXmlns; this.IgnoredXmlns = context.IgnoredXmlns;
this.XamlNamespacePrefix = context.XamlNamespacePrefix;
} }
public char PressedKey { get; set; } public char PressedKey { get; set; }

5
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs

@ -154,10 +154,7 @@ namespace ICSharpCode.XamlBinding
IProjectContent pc = context.ProjectContent; IProjectContent pc = context.ProjectContent;
IReturnType resolvedType = XamlCompilationUnit.FindType(pc, xmlNamespace, className); IReturnType resolvedType = XamlCompilationUnit.FindType(pc, xmlNamespace, className);
if (resolvedType != null && resolvedType.GetUnderlyingClass() != null) { if (resolvedType != null && resolvedType.GetUnderlyingClass() != null) {
var result = ResolvePropertyName(resolvedType, propertyName, allowAttached); return ResolvePropertyName(resolvedType, propertyName, allowAttached);
if (result == null && CompletionDataHelper.XamlNamespaceAttributes.Contains(propertyName))
return new MemberResolveResult(null, null, new DefaultProperty(null, propertyName));
return result;
} }
return null; return null;
} }

99
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs

@ -156,60 +156,55 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public override void SetPosition(PlacementInformation info) public override void SetPosition(PlacementInformation info)
{ {
base.SetPosition(info); base.SetPosition(info);
if (info.Operation.Type == PlacementType.AddItem) { int leftColumnIndex = GetColumnIndex(info.Bounds.Left);
SetColumn(info.Item, GetColumnIndex(info.Bounds.Left), 1); int rightColumnIndex = GetEndColumnIndex(info.Bounds.Right);
SetRow(info.Item, GetRowIndex(info.Bounds.Top), 1); if (rightColumnIndex < leftColumnIndex) rightColumnIndex = leftColumnIndex;
} else { SetColumn(info.Item, leftColumnIndex, rightColumnIndex - leftColumnIndex + 1);
int leftColumnIndex = GetColumnIndex(info.Bounds.Left); int topRowIndex = GetRowIndex(info.Bounds.Top);
int rightColumnIndex = GetEndColumnIndex(info.Bounds.Right); int bottomRowIndex = GetEndRowIndex(info.Bounds.Bottom);
if (rightColumnIndex < leftColumnIndex) rightColumnIndex = leftColumnIndex; if (bottomRowIndex < topRowIndex) bottomRowIndex = topRowIndex;
SetColumn(info.Item, leftColumnIndex, rightColumnIndex - leftColumnIndex + 1); SetRow(info.Item, topRowIndex, bottomRowIndex - topRowIndex + 1);
int topRowIndex = GetRowIndex(info.Bounds.Top);
int bottomRowIndex = GetEndRowIndex(info.Bounds.Bottom); Rect availableSpaceRect = new Rect(
if (bottomRowIndex < topRowIndex) bottomRowIndex = topRowIndex; new Point(GetColumnOffset(leftColumnIndex), GetRowOffset(topRowIndex)),
SetRow(info.Item, topRowIndex, bottomRowIndex - topRowIndex + 1); new Point(GetColumnOffset(rightColumnIndex + 1), GetRowOffset(bottomRowIndex + 1))
);
Rect availableSpaceRect = new Rect( if (info.Item == Services.Selection.PrimarySelection) {
new Point(GetColumnOffset(leftColumnIndex), GetRowOffset(topRowIndex)), // only for primary selection:
new Point(GetColumnOffset(rightColumnIndex + 1), GetRowOffset(bottomRowIndex + 1)) if (grayOut != null) {
); grayOut.AnimateActiveAreaRectTo(availableSpaceRect);
if (info.Item == Services.Selection.PrimarySelection) { } else {
// only for primary selection: GrayOutDesignerExceptActiveArea.Start(ref grayOut, this.Services, this.ExtendedItem.View, availableSpaceRect);
if (grayOut != null) {
grayOut.AnimateActiveAreaRectTo(availableSpaceRect);
} else {
GrayOutDesignerExceptActiveArea.Start(ref grayOut, this.Services, this.ExtendedItem.View, availableSpaceRect);
}
} }
HorizontalAlignment ha = (HorizontalAlignment)info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].ValueOnInstance;
VerticalAlignment va = (VerticalAlignment)info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].ValueOnInstance;
ha = SuggestHorizontalAlignment(info.Bounds, availableSpaceRect);
va = SuggestVerticalAlignment(info.Bounds, availableSpaceRect);
info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].SetValue(ha);
info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].SetValue(va);
Thickness margin = new Thickness(0, 0, 0, 0);
if (ha == HorizontalAlignment.Left || ha == HorizontalAlignment.Stretch)
margin.Left = info.Bounds.Left - GetColumnOffset(leftColumnIndex);
if (va == VerticalAlignment.Top || va == VerticalAlignment.Stretch)
margin.Top = info.Bounds.Top - GetRowOffset(topRowIndex);
if (ha == HorizontalAlignment.Right || ha == HorizontalAlignment.Stretch)
margin.Right = GetColumnOffset(rightColumnIndex + 1) - info.Bounds.Right;
if (va == VerticalAlignment.Bottom || va == VerticalAlignment.Stretch)
margin.Bottom = GetRowOffset(bottomRowIndex + 1) - info.Bounds.Bottom;
info.Item.Properties[FrameworkElement.MarginProperty].SetValue(margin);
if (ha == HorizontalAlignment.Stretch)
info.Item.Properties[FrameworkElement.WidthProperty].Reset();
else
info.Item.Properties[FrameworkElement.WidthProperty].SetValue(info.Bounds.Width);
if (va == VerticalAlignment.Stretch)
info.Item.Properties[FrameworkElement.HeightProperty].Reset();
else
info.Item.Properties[FrameworkElement.HeightProperty].SetValue(info.Bounds.Height);
} }
HorizontalAlignment ha = (HorizontalAlignment)info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].ValueOnInstance;
VerticalAlignment va = (VerticalAlignment)info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].ValueOnInstance;
ha = SuggestHorizontalAlignment(info.Bounds, availableSpaceRect);
va = SuggestVerticalAlignment(info.Bounds, availableSpaceRect);
info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].SetValue(ha);
info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].SetValue(va);
Thickness margin = new Thickness(0, 0, 0, 0);
if (ha == HorizontalAlignment.Left || ha == HorizontalAlignment.Stretch)
margin.Left = info.Bounds.Left - GetColumnOffset(leftColumnIndex);
if (va == VerticalAlignment.Top || va == VerticalAlignment.Stretch)
margin.Top = info.Bounds.Top - GetRowOffset(topRowIndex);
if (ha == HorizontalAlignment.Right || ha == HorizontalAlignment.Stretch)
margin.Right = GetColumnOffset(rightColumnIndex + 1) - info.Bounds.Right;
if (va == VerticalAlignment.Bottom || va == VerticalAlignment.Stretch)
margin.Bottom = GetRowOffset(bottomRowIndex + 1) - info.Bounds.Bottom;
info.Item.Properties[FrameworkElement.MarginProperty].SetValue(margin);
if (ha == HorizontalAlignment.Stretch)
info.Item.Properties[FrameworkElement.WidthProperty].Reset();
else
info.Item.Properties[FrameworkElement.WidthProperty].SetValue(info.Bounds.Width);
if (va == VerticalAlignment.Stretch)
info.Item.Properties[FrameworkElement.HeightProperty].Reset();
else
info.Item.Properties[FrameworkElement.HeightProperty].SetValue(info.Bounds.Height);
} }
public override void LeaveContainer(PlacementOperation operation) public override void LeaveContainer(PlacementOperation operation)

Loading…
Cancel
Save