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

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

@ -53,11 +53,6 @@ namespace ICSharpCode.XamlBinding @@ -53,11 +53,6 @@ namespace ICSharpCode.XamlBinding
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)
{
var item = context.XmlnsDefinitions.FirstOrDefault(i => i.Value == namespaceUri);

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

@ -233,19 +233,23 @@ namespace ICSharpCode.XamlBinding @@ -233,19 +233,23 @@ namespace ICSharpCode.XamlBinding
void ColorizeMember(HighlightingInfo info, DocumentLine line, IMember member)
{
try {
if (info.Context.IgnoredXmlns.Any(item => info.Token.StartsWith(item + ":", StringComparison.OrdinalIgnoreCase))) {
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightIgnored);
if (info.Token.StartsWith(info.Context.XamlNamespacePrefix + ":", StringComparison.Ordinal)) {
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightProperty);
} else {
if (member != null) {
if (member is IEvent)
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightEvent);
else
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightProperty);
if (info.Context.IgnoredXmlns.Any(item => info.Token.StartsWith(item + ":", StringComparison.Ordinal))) {
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightIgnored);
} 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);
if (member != null) {
if (member is IEvent)
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightEvent);
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) {}

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

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

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

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

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

@ -156,60 +156,55 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -156,60 +156,55 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public override void SetPosition(PlacementInformation info)
{
base.SetPosition(info);
if (info.Operation.Type == PlacementType.AddItem) {
SetColumn(info.Item, GetColumnIndex(info.Bounds.Left), 1);
SetRow(info.Item, GetRowIndex(info.Bounds.Top), 1);
} else {
int leftColumnIndex = GetColumnIndex(info.Bounds.Left);
int rightColumnIndex = GetEndColumnIndex(info.Bounds.Right);
if (rightColumnIndex < leftColumnIndex) rightColumnIndex = leftColumnIndex;
SetColumn(info.Item, leftColumnIndex, rightColumnIndex - leftColumnIndex + 1);
int topRowIndex = GetRowIndex(info.Bounds.Top);
int bottomRowIndex = GetEndRowIndex(info.Bounds.Bottom);
if (bottomRowIndex < topRowIndex) bottomRowIndex = topRowIndex;
SetRow(info.Item, topRowIndex, bottomRowIndex - topRowIndex + 1);
Rect availableSpaceRect = new Rect(
new Point(GetColumnOffset(leftColumnIndex), GetRowOffset(topRowIndex)),
new Point(GetColumnOffset(rightColumnIndex + 1), GetRowOffset(bottomRowIndex + 1))
);
if (info.Item == Services.Selection.PrimarySelection) {
// only for primary selection:
if (grayOut != null) {
grayOut.AnimateActiveAreaRectTo(availableSpaceRect);
} else {
GrayOutDesignerExceptActiveArea.Start(ref grayOut, this.Services, this.ExtendedItem.View, availableSpaceRect);
}
int leftColumnIndex = GetColumnIndex(info.Bounds.Left);
int rightColumnIndex = GetEndColumnIndex(info.Bounds.Right);
if (rightColumnIndex < leftColumnIndex) rightColumnIndex = leftColumnIndex;
SetColumn(info.Item, leftColumnIndex, rightColumnIndex - leftColumnIndex + 1);
int topRowIndex = GetRowIndex(info.Bounds.Top);
int bottomRowIndex = GetEndRowIndex(info.Bounds.Bottom);
if (bottomRowIndex < topRowIndex) bottomRowIndex = topRowIndex;
SetRow(info.Item, topRowIndex, bottomRowIndex - topRowIndex + 1);
Rect availableSpaceRect = new Rect(
new Point(GetColumnOffset(leftColumnIndex), GetRowOffset(topRowIndex)),
new Point(GetColumnOffset(rightColumnIndex + 1), GetRowOffset(bottomRowIndex + 1))
);
if (info.Item == Services.Selection.PrimarySelection) {
// only for primary selection:
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)

Loading…
Cancel
Save