Browse Source

XamlBinding:

- added resource strings
- added code completion options
- small code completion improvements

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4378 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 17 years ago
parent
commit
46105a5b4d
  1. 62
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs
  2. 45
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs
  3. 15
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Options/CodeCompletion.xaml
  4. 50
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Options/XamlBindingOptions.cs
  5. 35
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/RemoveMarginCommand.cs
  6. 12
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/RemoveUnnecessaryAttributesCommand.cs
  7. 6
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/XamlMenuCommand.cs
  8. 8
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.addin
  9. 3
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj
  10. 7
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs
  11. 7
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs
  12. 40
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItem.cs
  13. 15
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemList.cs

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

@ -69,7 +69,9 @@ namespace ICSharpCode.XamlBinding @@ -69,7 +69,9 @@ namespace ICSharpCode.XamlBinding
if (text[offset] == '>')
description = XamlContextDescription.None;
if (elementStartIndex > -1 && (char.IsWhiteSpace(text[offset]) || !string.IsNullOrEmpty(attribute) || Extensions.Is(text[offset], '"', '\'')))
string wordBeforeIndex = text.GetWordBeforeOffset(offset);
if (elementStartIndex > -1 && (char.IsWhiteSpace(text[offset]) || !string.IsNullOrEmpty(attribute) || Extensions.Is(text[offset], '"', '\'') || !wordBeforeIndex.StartsWith("<")))
description = XamlContextDescription.InTag;
if (inAttributeValue) {
@ -78,7 +80,7 @@ namespace ICSharpCode.XamlBinding @@ -78,7 +80,7 @@ namespace ICSharpCode.XamlBinding
if (value != null && !value.IsString)
description = XamlContextDescription.InMarkupExtension;
if (attributeValue.StartsWith("{}") && attributeValue.Length > 2)
if (attributeValue.StartsWith("{}", StringComparison.Ordinal) && attributeValue.Length > 2)
description = XamlContextDescription.InAttributeValue;
}
@ -192,28 +194,18 @@ namespace ICSharpCode.XamlBinding @@ -192,28 +194,18 @@ namespace ICSharpCode.XamlBinding
public int Compare(XmlnsCompletionItem x, XmlnsCompletionItem y)
{
if (x.IsUrl && y.IsUrl)
return x.Namespace.CompareTo(y.Namespace);
return string.CompareOrdinal(x.Namespace, y.Namespace);
if (x.IsUrl)
return -1;
if (y.IsUrl)
return 1;
if (x.Assembly == y.Assembly)
return x.Namespace.CompareTo(y.Namespace);
return string.CompareOrdinal(x.Namespace, y.Namespace);
else
return x.Assembly.CompareTo(y.Assembly);
return string.CompareOrdinal(x.Assembly, y.Assembly);
}
}
static bool IsReaderAtTarget(XmlTextReader r, int caretLine, int caretColumn)
{
if (r.LineNumber > caretLine)
return true;
else if (r.LineNumber == caretLine)
return r.LinePosition >= caretColumn;
else
return false;
}
public static IList<ICompletionItem> CreateListForElement(ParseInformation parseInfo, string fileContent, int caretLine, int caretColumn, bool addOpeningBrace)
{
var items = GetClassesFromContext(parseInfo, fileContent, caretLine, caretColumn);
@ -266,7 +258,7 @@ namespace ICSharpCode.XamlBinding @@ -266,7 +258,7 @@ namespace ICSharpCode.XamlBinding
}
break;
case XamlContextDescription.AtTag:
if (editor.Document.GetCharAt(editor.Caret.Offset - 1) == '.' || context.PressedKey == '.') {
if ((editor.Caret.Offset > 0 && editor.Document.GetCharAt(editor.Caret.Offset - 1) == '.') || context.PressedKey == '.') {
var loc = editor.Document.OffsetToPosition(Utils.GetParentElementStart(editor));
var existing = Utils.GetListOfExistingAttributeNames(editor.Document.Text, loc.Line, loc.Column);
list.Items.AddRange(CreateListForAttributeName(context, existing).RemoveEvents());
@ -302,20 +294,6 @@ namespace ICSharpCode.XamlBinding @@ -302,20 +294,6 @@ namespace ICSharpCode.XamlBinding
return list;
}
static bool FilterCollectionAttributes(ICompletionItem item)
{
if (item is XamlCodeCompletionItem) {
var comItem = item as XamlCodeCompletionItem;
if (comItem.Entity is IProperty) {
var prop = comItem.Entity as IProperty;
var c = prop.ReturnType.GetUnderlyingClass();
return c != null && c.ClassInheritanceTree.Any(b => b.FullyQualifiedName == "System.Collections.IEnumerable");
}
}
return false;
}
public static IEnumerable<IInsightItem> CreateMarkupExtensionInsight(XamlCompletionContext context)
{
var markup = Utils.GetMarkupExtensionAtPosition(context.AttributeValue.ExtensionValue, context.Editor.Caret.Offset);
@ -337,7 +315,6 @@ namespace ICSharpCode.XamlBinding @@ -337,7 +315,6 @@ namespace ICSharpCode.XamlBinding
public static ICompletionItemList CreateMarkupExtensionCompletion(XamlCompletionContext context)
{
var list = new XamlCompletionItemList();
var path = XmlParser.GetActiveElementStartPathAtIndex(context.Editor.Document.Text, context.Editor.Caret.Offset);
var markup = Utils.GetMarkupExtensionAtPosition(context.AttributeValue.ExtensionValue, context.Editor.Caret.Offset);
var trr = ResolveMarkupExtensionType(markup, context);
@ -383,7 +360,8 @@ namespace ICSharpCode.XamlBinding @@ -383,7 +360,8 @@ namespace ICSharpCode.XamlBinding
if (context.AttributeValue.ExtensionValue.PositionalArguments.Count <= 1) {
list.Items.AddRange(CreateListForElement(info, editor.Document.Text, editor.Caret.Line, editor.Caret.Column, false));
AttributeValue selItem = context.AttributeValue.ExtensionValue.PositionalArguments.LastOrDefault();
if (selItem != null && selItem.IsString) {
string word = editor.GetWordBeforeCaret().TrimEnd();
if (selItem != null && selItem.IsString && word == selItem.StringValue) {
list.PreselectionLength = selItem.StringValue.Length;
}
}
@ -549,11 +527,6 @@ namespace ICSharpCode.XamlBinding @@ -549,11 +527,6 @@ namespace ICSharpCode.XamlBinding
var rr = resolver.Resolve(new ExpressionResult(value, context), context.ParseInformation, context.Editor.Document.Text);
return rr;
}
static IMethod FindCompletableCtor(IList<IMethod> ctors, int index)
{
return null;
}
public static TypeResolveResult ResolveMarkupExtensionType(MarkupExtensionInfo markup, XamlCompletionContext context)
{
@ -566,7 +539,7 @@ namespace ICSharpCode.XamlBinding @@ -566,7 +539,7 @@ namespace ICSharpCode.XamlBinding
return trr;
}
public static IReturnType ResolveType(string name, XamlCompletionContext context)
public static IReturnType ResolveType(string name, XamlContext context)
{
XamlCompilationUnit cu = context.ParseInformation.BestCompilationUnit as XamlCompilationUnit;
if (cu == null)
@ -629,19 +602,6 @@ namespace ICSharpCode.XamlBinding @@ -629,19 +602,6 @@ namespace ICSharpCode.XamlBinding
return result;
}
static string GetPrefixForNamespace(string @namespace, string fileContent, int caretLine, int caretColumn)
{
using (XmlTextReader r = Utils.CreateReaderAtTarget(fileContent, caretLine, caretColumn)) {
foreach (var item in r.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml)) {
if (item.Value == @namespace) {
return item.Key;
}
}
return string.Empty;
}
}
static IDictionary<string, IEnumerable<IClass>> GetClassesFromContext(ParseInformation parseInfo, string fileContent, int caretLine, int caretColumn)
{
using (XmlTextReader r = Utils.CreateReaderAtTarget(fileContent, caretLine, caretColumn)) {

45
src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs

@ -8,12 +8,13 @@ @@ -8,12 +8,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
using ICSharpCode.XmlEditor;
using System.Xml;
using System.Xml.Linq;
namespace ICSharpCode.XamlBinding
{
@ -40,6 +41,20 @@ namespace ICSharpCode.XamlBinding @@ -40,6 +41,20 @@ namespace ICSharpCode.XamlBinding
return false;
}
public static string Replace(this string str, int index, int length, string text)
{
if (str == null)
throw new ArgumentNullException("str");
if (index < 0 || index > str.Length)
throw new ArgumentOutOfRangeException("index", index, "Value must be between 0 and " + str.Length);
if (length < 0 || length > str.Length)
throw new ArgumentOutOfRangeException("length", length, "Value must be between 0 and " + str.Length);
if ((index + length) > str.Length)
throw new ArgumentOutOfRangeException("index + length", index + length, "Value must be between 0 and " + str.Length);
return str.Substring(0, index) + text + str.Substring(index + length);
}
public static bool Is(char value, params char[] chars)
{
foreach (var c in chars) {
@ -50,6 +65,34 @@ namespace ICSharpCode.XamlBinding @@ -50,6 +65,34 @@ namespace ICSharpCode.XamlBinding
return false;
}
public static string GetWordBeforeOffset(this string text, int startIndex)
{
if (string.IsNullOrEmpty(text))
return string.Empty;
int offset = startIndex = Math.Min(startIndex, text.Length - 1);
while (offset > -1 && char.IsWhiteSpace(text[offset]))
offset--;
while (offset > -1 && !char.IsWhiteSpace(text[offset]))
offset--;
offset = Math.Max(0, offset);
return text.Substring(offset, startIndex - offset + 1).Trim();
}
public static int GetLineNumber(this XObject item)
{
return (item as IXmlLineInfo).LineNumber;
}
public static int GetLinePosition(this XObject item)
{
return (item as IXmlLineInfo).LinePosition;
}
public static void Remove(this XmlAttributeCollection coll, string name)
{
for (int i = 0; i < coll.Count; i++) {

15
src/AddIns/BackendBindings/XamlBinding/XamlBinding/Options/CodeCompletion.xaml

@ -1,12 +1,21 @@ @@ -1,12 +1,21 @@
<gui:OptionPanel x:Class="ICSharpCode.XamlBinding.Options.CodeCompletion"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui;assembly=ICSharpCode.SharpDevelop"
xmlns:addin="clr-namespace:ICSharpCode.XamlBinding"
xmlns:sd="http://icsharpcode.net/sharpdevelop/core"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<GroupBox Header="{sd:Localize ICSharpCode.XamlBinding.Options.CodeCompletionGroupLabel}">
<CheckBox Content="{sd:Localize ICSharpCode.XamlBinding.Options.UseExtensionCompletion}"
IsChecked="{sd:OptionBinding ICSharpCode.XamlBinding.Options.XamlBindingOptions.UseExtensionCompletion}" />
<GroupBox Header="{sd:Localize AddIns.XamlBinding.Options.CodeCompletionGroupLabel}">
<StackPanel>
<CheckBox Content="{sd:Localize AddIns.XamlBinding.Options.UseExtensionCompletion}"
IsChecked="{sd:OptionBinding addin:XamlBindingOptions.UseExtensionCompletion}" />
<CheckBox Content="{sd:Localize AddIns.XamlBinding.Options.SwitchToCodeViewAfterInsertion}"
IsChecked="{sd:OptionBinding addin:XamlBindingOptions.SwitchToCodeViewAfterInsertion}" />
<DockPanel>
<Label Content="{sd:Localize AddIns.XamlBinding.Options.EventHandlerNamePattern}" />
<TextBox Text="{sd:OptionBinding addin:XamlBindingOptions.EventHandlerNamePattern}" />
</DockPanel>
</StackPanel>
</GroupBox>
</StackPanel>
</gui:OptionPanel>

50
src/AddIns/BackendBindings/XamlBinding/XamlBinding/Options/XamlBindingOptions.cs

@ -1,17 +1,45 @@ @@ -1,17 +1,45 @@
/*
* Created by SharpDevelop.
* User: Siegfried
* Date: 19.06.2009
* Time: 22:20
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
// <version>$Revision: 3731 $</version>
// </file>
using System;
using ICSharpCode.Core;
using System.Diagnostics;
namespace ICSharpCode.XamlBinding.Options
namespace ICSharpCode.XamlBinding
{
public static class XamlBindingOptions
{
public static bool UseExtensionCompletion { get; set; }
{
static Properties properties;
static XamlBindingOptions()
{
properties = PropertyService.Get("XamlBinding.Options", new Properties());
}
static Properties Properties {
get {
Debug.Assert(properties != null);
return properties;
}
}
public static bool UseExtensionCompletion {
get { return properties.Get("UseExtensionCompletion", true); }
set { properties.Set("UseExtensionCompletion", value); }
}
public static bool SwitchToCodeViewAfterInsertion {
get { return properties.Get("SwitchToCodeViewAfterInsertion", true); }
set { properties.Set("SwitchToCodeViewAfterInsertion", value); }
}
public static string EventHandlerNamePattern {
get { return properties.Get("EventHandlerNamePattern", "%Object%_%Event%"); }
set { properties.Set("EventHandlerNamePattern", value); }
}
}
}

35
src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/RemoveMarginCommand.cs

@ -5,10 +5,12 @@ @@ -5,10 +5,12 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.Core;
using ICSharpCode.XmlEditor;
using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.XamlBinding;
@ -16,31 +18,24 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands @@ -16,31 +18,24 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands
{
public class RemoveMarginCommand : XamlMenuCommand
{
protected override void Refactor(ITextEditor editor, XmlDocument document)
{
RemoveRecursive(document, "Margin");
}
protected void RemoveRecursive(XmlNode pNode, string name)
protected override void Refactor(ITextEditor editor, XDocument document)
{
foreach (XmlNode node in pNode.ChildNodes) {
node.Attributes.Remove(name);
RemoveRecursive(node, name);
}
RemoveRecursive(document.Root, "Margin");
}
protected void RemoveRecursive(XmlNode pNode, string name, string namespaceURI)
protected void RemoveRecursive(XElement element, string name)
{
foreach (XmlNode node in pNode.ChildNodes) {
node.Attributes.Remove(name, namespaceURI);
RemoveRecursive(node, name, namespaceURI);
}
foreach (XAttribute a in element.Attributes(name))
a.Remove();
foreach (XElement e in element.Elements())
RemoveRecursive(e, name);
}
}
public class GroupIntoMenuItem : XamlMenuCommand
{
protected sealed override void Refactor(ITextEditor editor, XmlDocument document)
protected sealed override void Refactor(ITextEditor editor, XDocument document)
{
if (editor.SelectionLength == 0) {
MessageService.ShowError("The selected XAML is invalid!");
@ -50,11 +45,9 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands @@ -50,11 +45,9 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands
public class ExtractPropertiesAsStyleCommand : XamlMenuCommand
{
protected override void Refactor(ITextEditor editor, XmlDocument document)
protected override void Refactor(ITextEditor editor, XDocument document)
{
string[] attributes = Utils.GetListOfExistingAttributeNames(editor.Document.Text, editor.Caret.Line, editor.Caret.Column);
XmlElementPath path = XmlParser.GetParentElementPath(editor.Document.Text.Substring(0, editor.SelectionStart));
}
}
}

12
src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/RemoveUnnecessaryAttributesCommand.cs

@ -18,13 +18,13 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands @@ -18,13 +18,13 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands
/// </summary>
public class RemoveUnnecessaryAttributesCommand : RemoveMarginCommand
{
protected override void Refactor(ICSharpCode.SharpDevelop.Editor.ITextEditor editor, System.Xml.XmlDocument document)
protected override void Refactor(ICSharpCode.SharpDevelop.Editor.ITextEditor editor, System.Xml.Linq.XDocument document)
{
RemoveRecursive(document, "Margin");
RemoveRecursive(document, "Name");
RemoveRecursive(document, "Name", CompletionDataHelper.XamlNamespace);
RemoveRecursive(document, "MinWidth");
RemoveRecursive(document, "MinHeight");
RemoveRecursive(document.Root, "Margin");
// RemoveRecursive(document, "Name");
// RemoveRecursive(document, "Name", CompletionDataHelper.XamlNamespace);
RemoveRecursive(document.Root, "MinWidth");
RemoveRecursive(document.Root, "MinHeight");
// set all row and column definitions to Auto
}
}

6
src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/XamlMenuCommand.cs

@ -9,6 +9,7 @@ using System; @@ -9,6 +9,7 @@ using System;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
@ -32,8 +33,7 @@ namespace ICSharpCode.XamlBinding.PowerToys @@ -32,8 +33,7 @@ namespace ICSharpCode.XamlBinding.PowerToys
if (provider != null) {
TextReader reader = provider.TextEditor.Document.CreateReader();
XmlDocument document = new XmlDocument();
document.Load(reader);
XDocument document = XDocument.Load(reader, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
Refactor(provider.TextEditor, document);
StringWriter sWriter = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(sWriter);
@ -47,6 +47,6 @@ namespace ICSharpCode.XamlBinding.PowerToys @@ -47,6 +47,6 @@ namespace ICSharpCode.XamlBinding.PowerToys
}
}
protected abstract void Refactor(ITextEditor editor, XmlDocument document);
protected abstract void Refactor(ITextEditor editor, XDocument document);
}
}

8
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.addin

@ -52,7 +52,7 @@ @@ -52,7 +52,7 @@
<Path name="/SharpDevelop/Dialogs/OptionsDialog/TextEditorOptions">
<OptionPanel id = "XamlCompletionPanel"
insertafter = "Markers"
label = "${res:ICSharpCode.XamlBinding.Options.Title}"
label = "${res:AddIns.XamlBinding.Options.Title}"
class = "ICSharpCode.XamlBinding.Options.CodeCompletion" />
</Path>
@ -62,13 +62,13 @@ @@ -62,13 +62,13 @@
<Condition name="ActiveContentExtension" activeextension=".xaml" />
<Condition name="WindowActive" activewindow="ICSharpCode.SharpDevelop.Editor.ITextEditorProvider" />
</And>
<MenuItem id="XamlRefactoring" insertafter="Refactor" insertbefore="Project" label="Refactor" type="Menu">
<MenuItem id="XamlRefactoring" insertafter="Refactor" insertbefore="Project" label="${res:XML.MainMenu.RefactorMenu}" type="Menu">
<MenuItem id="RemoveMargin"
class="ICSharpCode.XamlBinding.PowerToys.Commands.RemoveMarginCommand"
label="Remove Margins" />
label="${res:AddIns.XamlBinding.Menu.RemoveMargin}" />
<MenuItem id="RemoveUnnecessaryAttributes"
class="ICSharpCode.XamlBinding.PowerToys.Commands.RemoveUnnecessaryAttributesCommand"
label="Remove unnecessary attributes" />
label="${res:AddIns.XamlBinding.Menu.RemoveUnnecessaryAttributes}" />
<MenuItem type="Separator" />
<!-- <MenuItem type="Builder" class="" /> -->
</MenuItem>

3
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj

@ -49,6 +49,9 @@ @@ -49,6 +49,9 @@
<Reference Include="System.Data" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>

7
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs

@ -33,8 +33,6 @@ namespace ICSharpCode.XamlBinding @@ -33,8 +33,6 @@ namespace ICSharpCode.XamlBinding
public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
{
ParseInformation info = ParserService.GetParseInformation(editor.FileName);
XamlCompletionContext context = CompletionDataHelper.ResolveCompletionContext(editor, ch);
ICompletionItemList list;
@ -122,7 +120,8 @@ namespace ICSharpCode.XamlBinding @@ -122,7 +120,8 @@ namespace ICSharpCode.XamlBinding
default:
if (context.Description != XamlContextDescription.None && !char.IsWhiteSpace(ch)) {
editor.Document.Insert(editor.Caret.Offset, ch.ToString());
if (!context.AttributeName.StartsWith("xmlns"))
string word = editor.Document.Text.GetWordBeforeOffset(editor.Caret.Offset);
if (!(context.AttributeName.StartsWith("xmlns") || word.StartsWith("xmlns")))
this.CtrlSpace(editor);
return CodeCompletionKeyPressResult.EatKey;
}
@ -243,6 +242,8 @@ namespace ICSharpCode.XamlBinding @@ -243,6 +242,8 @@ namespace ICSharpCode.XamlBinding
static bool DoMarkupExtensionCompletion(XamlCompletionContext context)
{
if (context.Description == XamlContextDescription.InMarkupExtension && context.AttributeValue != null && !context.AttributeValue.IsString) {
if (!XamlBindingOptions.UseExtensionCompletion)
return false;
var completionList = CompletionDataHelper.CreateMarkupExtensionCompletion(context);
context.Editor.ShowCompletionWindow(completionList);
var insightList = CompletionDataHelper.CreateMarkupExtensionInsight(context);

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

@ -57,6 +57,7 @@ namespace ICSharpCode.XamlBinding @@ -57,6 +57,7 @@ namespace ICSharpCode.XamlBinding
foreach (HighlightingInfo info in infos) {
MemberResolveResult rr = resolver.Resolve(info.GetExpressionResult(), parseInfo, fileContent) as MemberResolveResult;
IMember member = (rr != null) ? rr.ResolvedMember : null;
if (member != null) {
if (member is IEvent)
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightEvent);
@ -73,12 +74,14 @@ namespace ICSharpCode.XamlBinding @@ -73,12 +74,14 @@ namespace ICSharpCode.XamlBinding
HighlightingInfo[] GetInfoForLine(DocumentLine line)
{
int index = -1;
int ltCharIndex = -1;
XamlContext context = null;
List<HighlightingInfo> infos = new List<HighlightingInfo>();
do {
index = line.Text.IndexOf('=', index + 1);
if (index > -1) {
XamlContext context = CompletionDataHelper.ResolveContext(this.fileContent, this.fileName, line.LineNumber, index + 1);
context = CompletionDataHelper.ResolveContext(this.fileContent, this.fileName, line.LineNumber, index + 1);
if (!string.IsNullOrEmpty(context.AttributeName)) {
int startIndex = line.Text.Substring(0, index).LastIndexOf(context.AttributeName);
infos.Add(new HighlightingInfo(context.AttributeName, startIndex, startIndex + context.AttributeName.Length, line.Offset, context));

40
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItem.cs

@ -5,12 +5,14 @@ @@ -5,12 +5,14 @@
// <version>$Revision: 3731 $</version>
// </file>
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
using ICSharpCode.Core;
using System;
using System.Linq;
using System.Text.RegularExpressions;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
namespace ICSharpCode.XamlBinding
{
@ -143,12 +145,11 @@ namespace ICSharpCode.XamlBinding @@ -143,12 +145,11 @@ namespace ICSharpCode.XamlBinding
public string HandlerName { get; private set; }
public NewEventCompletionItem(IEvent eventType, string targetName)
: base("<new event handler>") // TODO : replace by resource string
: base(StringParser.Parse("${res:AddIns.XamlBinding.NewEventHandlerItem}"))
{
this.eventType = eventType;
this.targetName = targetName;
// TODO : Add formatting options
this.HandlerName = this.TargetName + "_" + this.EventType.Name;
this.HandlerName = ParseNamePattern(this.TargetName, this.EventType.Name);
}
public override void Complete(CompletionContext context)
@ -157,6 +158,37 @@ namespace ICSharpCode.XamlBinding @@ -157,6 +158,37 @@ namespace ICSharpCode.XamlBinding
context.EndOffset = context.StartOffset + this.HandlerName.Length;
}
public static string ParseNamePattern(string objectName, string eventName)
{
string name = XamlBindingOptions.EventHandlerNamePattern;
foreach (Match match in Regex.Matches(name, "%[A-z0-9]*%")) {
switch (match.Value.ToLowerInvariant()) {
case "%object%":
if (char.IsUpper(match.Value[1]))
objectName = objectName.ToUpper()[0] + objectName.Substring(1, objectName.Length - 1);
else
objectName = objectName.ToLower()[0] + objectName.Substring(1, objectName.Length - 1);
name = name.Replace(match.Index, match.Length, objectName);
break;
case "%event%":
if (char.IsUpper(match.Value[1]))
eventName = eventName.ToUpper()[0] + eventName.Substring(1, eventName.Length - 1);
else
eventName = eventName.ToLower()[0] + eventName.Substring(1, eventName.Length - 1);
name = name.Replace(match.Index, match.Length, eventName);
break;
case "%%":
name = name.Replace(match.Index, match.Length, "%");
break;
default:
throw new ArgumentException("Pattern identifier invalid", match.Value);
}
}
return name;
}
}
class MarkupExtensionInsightItem : IInsightItem

15
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemList.cs

@ -135,6 +135,17 @@ namespace ICSharpCode.XamlBinding @@ -135,6 +135,17 @@ namespace ICSharpCode.XamlBinding
context.Editor.Document.Insert(context.EndOffset, "=\"\"");
context.Editor.Caret.Offset--;
}
switch (item.Text) {
case "![CDATA[":
context.Editor.Document.Insert(context.Editor.Caret.Offset, "]]>");
context.Editor.Caret.Offset -= 3;
break;
case "?":
context.Editor.Document.Insert(context.Editor.Caret.Offset, "?>");
context.Editor.Caret.Offset -= 2;
break;
}
}
static void CreateEventHandlerCode(CompletionContext context, NewEventCompletionItem completionItem)
@ -167,8 +178,8 @@ namespace ICSharpCode.XamlBinding @@ -167,8 +178,8 @@ namespace ICSharpCode.XamlBinding
node.Name = completionItem.HandlerName;
node.Modifier = Modifiers.None;
IViewContent viewContent = FileService.OpenFile(part.CompilationUnit.FileName);
IViewContent viewContent = FileService.OpenFile(part.CompilationUnit.FileName, XamlBindingOptions.SwitchToCodeViewAfterInsertion);
IFileDocumentProvider document = viewContent as IFileDocumentProvider;
if (viewContent != null || document != null) {

Loading…
Cancel
Save