Browse Source

XamlBinding:

- improved code completion
- finished "EditGridColumnsAndRowsCommand"

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4439 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 17 years ago
parent
commit
336b157935
  1. 11
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs
  2. 3
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/EditGridColumnsAndRowsCommand.cs
  3. 13
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml
  4. 700
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml.cs
  5. 14
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/XamlMenuCommand.cs
  6. 3
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs
  7. 20
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs

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

@ -431,11 +431,9 @@ namespace ICSharpCode.XamlBinding @@ -431,11 +431,9 @@ namespace ICSharpCode.XamlBinding
if (trr != null) {
var ctors = trr.ResolvedType
.GetMethods()
.Where(m => m.IsPublic && m.IsConstructor && m.Parameters.Count >= markup.PositionalArguments.Count + 1)
.Where(m => m.IsPublic && m.IsConstructor && m.Parameters.Count >= markup.PositionalArguments.Count)
.OrderBy(m => m.Parameters.Count);
yield return new MarkupExtensionInsightItem(new DefaultMethod(trr.ResolvedClass, trr.ResolvedClass.Name));
foreach (var ctor in ctors)
yield return new MarkupExtensionInsightItem(ctor);
}
@ -444,7 +442,8 @@ namespace ICSharpCode.XamlBinding @@ -444,7 +442,8 @@ namespace ICSharpCode.XamlBinding
public static ICompletionItemList CreateMarkupExtensionCompletion(XamlCompletionContext context)
{
var list = new XamlCompletionItemList();
var markup = Utils.GetMarkupExtensionAtPosition(context.AttributeValue.ExtensionValue, context.Editor.Caret.Offset);
string visibleValue = context.RawAttributeValue.Substring(0, context.ValueStartOffset);
var markup = Utils.GetInnermostMarkupExtensionInfo(MarkupExtensionParser.Parse(visibleValue));
var trr = ResolveMarkupExtensionType(markup, context);
if (trr == null) {
@ -513,7 +512,7 @@ namespace ICSharpCode.XamlBinding @@ -513,7 +512,7 @@ namespace ICSharpCode.XamlBinding
{
switch (result.ResolvedType.FullyQualifiedName) {
case "System.Windows.Thickness":
yield return new MemberInsightItem(result.ResolvedMember, "left");
yield return new MemberInsightItem(result.ResolvedMember, "uniformLength");
yield return new MemberInsightItem(result.ResolvedMember, "left, top");
yield return new MemberInsightItem(result.ResolvedMember, "left, top, right, bottom");
break;

3
src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/EditGridColumnsAndRowsCommand.cs

@ -42,7 +42,8 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands @@ -42,7 +42,8 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands
EditGridColumnsAndRowsDialog dialog = new EditGridColumnsAndRowsDialog(selectedItem);
if (dialog.ShowDialog() ?? false) {
selectedItem.ReplaceWith(dialog.GetConstructedTree());
return true;
}
return false;

13
src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml

@ -2,18 +2,21 @@ @@ -2,18 +2,21 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sd="http://icsharpcode.net/sharpdevelop/core"
Title="ICSharpCode.XamlBinding.PowerToys.Dialogs" Height="300" Width="300"
Title="Edit grid columns and rows" Height="500" Width="500"
WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow">
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Style x:Key="normal" TargetType="{x:Type Button}">
<Setter Property="Margin" Value="3" />
<Setter Property="Padding" Value="3" />
</Style>
</Window.Resources>
<DockPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom" HorizontalAlignment="Center">
<Button x:Name="btnOK" Content="{sd:Localize Global.OKButtonText}" Click="BtnOKClick" />
<Button x:Name="btnCancel" Content="{sd:Localize Global.CancelButtonText}" Click="BtnCancelClick" />
<StackPanel Orientation="Vertical" DockPanel.Dock="Bottom" HorizontalAlignment="Center">
<TextBlock x:Name="lblInstruction" Visibility="Collapsed" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button x:Name="btnOK" Content="{sd:Localize Global.OKButtonText}" Click="BtnOKClick" Style="{StaticResource normal}" />
<Button x:Name="btnCancel" Content="{sd:Localize Global.CancelButtonText}" Click="BtnCancelClick" Style="{StaticResource normal}" />
</StackPanel>
</StackPanel>
<Grid x:Name="gridDisplay" />
</DockPanel>

700
src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml.cs

@ -5,6 +5,8 @@ @@ -5,6 +5,8 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using System;
using System.Collections.Generic;
using System.Linq;
@ -25,13 +27,532 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -25,13 +27,532 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
/// </summary>
public partial class EditGridColumnsAndRowsDialog : Window
{
static readonly XName rowDefsName = XName.Get("Grid.RowDefinitions", CompletionDataHelper.WpfXamlNamespace);
static readonly XName colDefsName = XName.Get("Grid.ColumnDefinitions", CompletionDataHelper.WpfXamlNamespace);
static readonly XName rowDefName = XName.Get("RowDefinition", CompletionDataHelper.WpfXamlNamespace);
static readonly XName colDefName = XName.Get("ColumnDefinition", CompletionDataHelper.WpfXamlNamespace);
XElement gridTree;
XElement rowDefitions;
XElement colDefitions;
IList<XElement> additionalProperties;
int selectedCellX = -1, selectedCellY = -1;
bool? swap = null;
public EditGridColumnsAndRowsDialog(XElement gridTree)
{
InitializeComponent();
this.gridTree = gridTree;
this.rowDefitions = gridTree.Element(rowDefsName) ?? new XElement(rowDefsName);
this.colDefitions = gridTree.Element(colDefsName) ?? new XElement(colDefsName);
if (this.rowDefitions.Parent != null)
this.rowDefitions.Remove();
if (this.colDefitions.Parent != null)
this.colDefitions.Remove();
this.additionalProperties = gridTree.Elements().Where(e => e.Name.LocalName.Contains(".")).ToList();
this.additionalProperties.ForEach(item => { if (item.Parent != null) item.Remove(); Core.LoggingService.Debug(item); });
RebuildGrid();
}
MenuItem CreateItem(string header, Action<TextBlock> clickAction, TextBlock senderItem)
{
MenuItem item = new MenuItem();
item.Header = header;
item.Click += delegate { clickAction(senderItem); };
return item;
}
void InsertAbove(TextBlock block)
{
int row = (int)block.GetValue(Grid.RowProperty);
var newRow = new XElement(rowDefName);
newRow.SetAttributeValue(XName.Get("Height"), "Auto");
var items = rowDefitions.Elements().Skip(row);
var selItem = items.FirstOrDefault();
if (selItem != null)
selItem.AddBeforeSelf(newRow);
else
rowDefitions.Add(newRow);
var controls = gridTree
.Elements()
.Where(
element => {
var rowAttrib = element.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
int rowAttribValue = 0;
if (int.TryParse(rowAttrib.Value, out rowAttribValue))
return rowAttribValue >= row;
return false;
}
);
controls.ForEach(
item => {
var rowAttrib = item.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
item.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value) + 1);
}
);
RebuildGrid();
}
void InsertBelow(TextBlock block)
{
int row = (int)block.GetValue(Grid.RowProperty);
var newRow = new XElement(rowDefName);
newRow.SetAttributeValue(XName.Get("Height"), "Auto");
var items = rowDefitions.Elements().Skip(row);
var selItem = items.FirstOrDefault();
if (selItem != null)
selItem.AddAfterSelf(newRow);
else
rowDefitions.Add(newRow);
var controls = gridTree
.Elements()
.Where(
element => {
var rowAttrib = element.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
int rowAttribValue = 0;
if (int.TryParse(rowAttrib.Value, out rowAttribValue))
return rowAttribValue > row;
return false;
}
);
controls.ForEach(
item => {
var rowAttrib = item.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
item.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value) + 1);
}
);
RebuildGrid();
}
void MoveUp(TextBlock block)
{
int row = (int)block.GetValue(Grid.RowProperty);
if (row > 0) {
var items = rowDefitions.Elements().Skip(row);
var selItem = items.FirstOrDefault();
if (selItem == null)
return;
selItem.Remove();
items = rowDefitions.Elements().Skip(row - 1);
var before = items.FirstOrDefault();
if (before == null)
return;
before.AddBeforeSelf(selItem);
var controls = gridTree
.Elements()
.Where(
element => {
var rowAttrib = element.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
int rowAttribValue = 0;
if (int.TryParse(rowAttrib.Value, out rowAttribValue))
return rowAttribValue == row;
return false;
}
).ToList();
var controlsDown = gridTree
.Elements()
.Where(
element2 => {
var rowAttrib = element2.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
int rowAttribValue = 0;
if (int.TryParse(rowAttrib.Value, out rowAttribValue))
return rowAttribValue == (row - 1);
return false;
}
).ToList();
controls.ForEach(
item => {
var rowAttrib = item.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
item.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value) - 1);
}
);
controlsDown.ForEach(
item2 => {
var rowAttrib = item2.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
item2.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value) + 1);
}
);
RebuildGrid();
}
}
void MoveDown(TextBlock block)
{
int row = (int)block.GetValue(Grid.RowProperty);
if (row < rowDefitions.Elements().Count() - 1) {
var items = rowDefitions.Elements().Skip(row);
var selItem = items.FirstOrDefault();
if (selItem == null)
return;
selItem.Remove();
items = rowDefitions.Elements().Skip(row - 1);
var before = items.FirstOrDefault();
if (before == null)
return;
before.AddBeforeSelf(selItem);
var controls = gridTree
.Elements()
.Where(
element => {
var rowAttrib = element.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
int rowAttribValue = 0;
if (int.TryParse(rowAttrib.Value, out rowAttribValue))
return rowAttribValue == row;
return false;
}
).ToList();
var controlsUp = gridTree
.Elements()
.Where(
element2 => {
var rowAttrib = element2.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
int rowAttribValue = 0;
if (int.TryParse(rowAttrib.Value, out rowAttribValue))
return rowAttribValue == (row + 1);
return false;
}
).ToList();
controls.ForEach(
item => {
var rowAttrib = item.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
item.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value) + 1);
}
);
controlsUp.ForEach(
item2 => {
var rowAttrib = item2.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
item2.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value) - 1);
}
);
RebuildGrid();
}
}
void DeleteRow(TextBlock block)
{
int row = (int)block.GetValue(Grid.RowProperty);
var items = rowDefitions.Elements().Skip(row);
var selItem = items.FirstOrDefault();
if (selItem != null)
selItem.Remove();
var controls = gridTree
.Elements()
.Where(
element => {
var rowAttrib = element.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
int rowAttribValue = 0;
if (int.TryParse(rowAttrib.Value, out rowAttribValue))
return rowAttribValue >= row;
return false;
}
);
controls.ForEach(
item => {
var rowAttrib = item.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
item.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value) - 1);
}
);
RebuildGrid();
}
void InsertBefore(TextBlock block)
{
int column = (int)block.GetValue(Grid.ColumnProperty);
var newColumn = new XElement(colDefName);
newColumn.SetAttributeValue(XName.Get("Width"), "Auto");
var items = colDefitions.Elements().Skip(column);
var selItem = items.FirstOrDefault();
if (selItem != null)
selItem.AddBeforeSelf(newColumn);
else
colDefitions.Add(newColumn);
var controls = gridTree
.Elements()
.Where(
element => {
var colAttrib = element.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
int colAttribValue = 0;
if (int.TryParse(colAttrib.Value, out colAttribValue))
return colAttribValue >= column;
return false;
}
);
controls.ForEach(
item => {
var colAttrib = item.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
item.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value) + 1);
}
);
RebuildGrid();
}
void InsertAfter(TextBlock block)
{
int column = (int)block.GetValue(Grid.ColumnProperty);
var newColumn = new XElement(colDefName);
newColumn.SetAttributeValue(XName.Get("Width"), "Auto");
var items = colDefitions.Elements().Skip(column);
var selItem = items.FirstOrDefault();
if (selItem != null)
selItem.AddBeforeSelf(newColumn);
else
colDefitions.Add(newColumn);
var controls = gridTree
.Elements()
.Where(
element => {
var colAttrib = element.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
int colAttribValue = 0;
if (int.TryParse(colAttrib.Value, out colAttribValue))
return colAttribValue > column;
return false;
}
);
controls.ForEach(
item => {
var colAttrib = item.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
item.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value) + 1);
}
);
RebuildGrid();
}
void MoveLeft(TextBlock block)
{
int column = (int)block.GetValue(Grid.ColumnProperty);
if (column > 0) {
var items = colDefitions.Elements().Skip(column);
var selItem = items.FirstOrDefault();
if (selItem == null)
return;
selItem.Remove();
items = colDefitions.Elements().Skip(column - 1);
var before = items.FirstOrDefault();
if (before == null)
return;
before.AddBeforeSelf(selItem);
var controls = gridTree
.Elements()
.Where(
element => {
var colAttrib = element.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
int colAttribValue = 0;
if (int.TryParse(colAttrib.Value, out colAttribValue))
return colAttribValue == column;
return false;
}
).ToList();
var controlsLeft = gridTree
.Elements()
.Where(
element2 => {
var colAttrib = element2.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
int colAttribValue = 0;
if (int.TryParse(colAttrib.Value, out colAttribValue))
return colAttribValue == (column - 1);
return false;
}
).ToList();
controls.ForEach(
item => {
var colAttrib = item.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
item.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value) - 1);
}
);
controlsLeft.ForEach(
item2 => {
var colAttrib = item2.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
item2.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value) + 1);
}
);
RebuildGrid();
}
}
void MoveRight(TextBlock block)
{
int column = (int)block.GetValue(Grid.ColumnProperty);
if (column < colDefitions.Elements().Count() - 1) {
var items = colDefitions.Elements().Skip(column);
var selItem = items.FirstOrDefault();
if (selItem == null)
return;
selItem.Remove();
items = colDefitions.Elements().Skip(column - 1);
var before = items.FirstOrDefault();
if (before == null)
return;
before.AddBeforeSelf(selItem);
var controls = gridTree
.Elements()
.Where(
element => {
var colAttrib = element.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
int colAttribValue = 0;
if (int.TryParse(colAttrib.Value, out colAttribValue))
return colAttribValue == column;
return false;
}
).ToList();
var controlsRight = gridTree
.Elements()
.Where(
element2 => {
var colAttrib = element2.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
int colAttribValue = 0;
if (int.TryParse(colAttrib.Value, out colAttribValue))
return colAttribValue == (column + 1);
return false;
}
).ToList();
controls.ForEach(
item => {
var colAttrib = item.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
item.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value) + 1);
}
);
controlsRight.ForEach(
item2 => {
var colAttrib = item2.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
item2.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value) - 1);
}
);
RebuildGrid();
}
}
void DeleteColumn(TextBlock block)
{
int column = (int)block.GetValue(Grid.ColumnProperty);
var items = colDefitions.Elements().Skip(column);
var selItem = items.FirstOrDefault();
if (selItem != null)
selItem.Remove();
var controls = gridTree
.Elements()
.Where(
element => {
var colAttrib = element.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
int colAttribValue = 0;
if (int.TryParse(colAttrib.Value, out colAttribValue))
return colAttribValue >= column;
return false;
}
);
controls.ForEach(
item => {
var colAttrib = item.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
item.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value) - 1);
}
);
RebuildGrid();
}
void SwapContent(TextBlock block)
{
lblInstruction.Text = "Click on the cell you want to swap the selected cell with.";
lblInstruction.Visibility = Visibility.Visible;
this.selectedCellX = (int)block.GetValue(Grid.ColumnProperty);
this.selectedCellY = (int)block.GetValue(Grid.RowProperty);
swap = true;
}
void MoveContent(TextBlock block)
{
lblInstruction.Text = "Click on the cell you want to move the selected content to.";
lblInstruction.Visibility = Visibility.Visible;
this.selectedCellX = (int)block.GetValue(Grid.ColumnProperty);
this.selectedCellY = (int)block.GetValue(Grid.RowProperty);
swap = false;
}
void DeleteContent(TextBlock block)
{
int column = (int)block.GetValue(Grid.ColumnProperty);
int row = (int)block.GetValue(Grid.RowProperty);
gridTree.Elements()
.Where(
element => {
var colAttrib = element.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
var rowAttrib = element.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
int colAttribValue = 0, rowAttribValue = 0;
if (int.TryParse(colAttrib.Value, out colAttribValue) && int.TryParse(rowAttrib.Value, out rowAttribValue))
return colAttribValue == column && rowAttribValue == row;
return false;
}
).ForEach(item => item.Remove());
RebuildGrid();
}
@ -45,46 +566,61 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -45,46 +566,61 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
this.DialogResult = true;
}
string BuildDescriptionForCell(int row, int col)
{
StringBuilder builder = new StringBuilder();
var controls = gridTree
.Elements()
.Where(
element => {
var rowAttrib = element.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
var colAttrib = element.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
return row.ToString() == rowAttrib.Value && col.ToString() == colAttrib.Value;
}
);
foreach (var control in controls) {
var nameAttrib = control.Attribute(XName.Get("Name", CompletionDataHelper.XamlNamespace)) ?? control.Attribute(XName.Get("Name"));
if (builder.Length > 0)
builder.Append(", ");
builder.Append(control.Name.LocalName);
if (nameAttrib != null)
builder.Append(" (" + nameAttrib.Value + ")");
}
return builder.ToString();
}
void RebuildGrid()
{
this.gridDisplay.Children.Clear();
this.gridDisplay.RowDefinitions.Clear();
this.gridDisplay.ColumnDefinitions.Clear();
XName rowDefName = XName.Get("Grid.RowDefinitions", CompletionDataHelper.WpfXamlNamespace);
XName colDefName = XName.Get("Grid.ColumnDefinitions", CompletionDataHelper.WpfXamlNamespace);
var rows = (gridTree.Element(rowDefName) ?? new XElement(rowDefName)).Elements().ToList();
var cols = (gridTree.Element(colDefName) ?? new XElement(colDefName)).Elements().ToList();
int rows = rowDefitions.Elements().Count();
int cols = colDefitions.Elements().Count();
var rowDefintion = new XElement(XName.Get("RowDefinition", CompletionDataHelper.WpfXamlNamespace));
var colDefintion = new XElement(XName.Get("ColumnDefinition", CompletionDataHelper.WpfXamlNamespace));
for (int i = 0; i < cols; i++)
this.gridDisplay.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
rowDefintion.SetAttributeValue("Height", "Auto");
colDefintion.SetAttributeValue("Width", "Auto");
if (rows.Count == 0)
rows.Add(rowDefintion);
if (cols.Count == 0)
rows.Add(colDefintion);
for (int i = 0; i < rows.Count; i++) {
this.gridDisplay.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
for (int i = 0; i < rows; i++) {
this.gridDisplay.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
for (int j = 0; j < cols.Count; j++) {
this.gridDisplay.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
Rectangle displayRect = new Rectangle() {
Stroke = Brushes.Black,
StrokeThickness = 2,
Margin = new Thickness(5),
Fill = Brushes.CornflowerBlue,
VerticalAlignment = VerticalAlignment.Stretch,
HorizontalAlignment = HorizontalAlignment.Stretch
for (int j = 0; j < cols; j++) {
TextBlock displayRect = new TextBlock() {
Margin = new Thickness(5),
Background = Brushes.CornflowerBlue,
Text = BuildDescriptionForCell(i, j),
TextAlignment = TextAlignment.Center,
TextWrapping = TextWrapping.Wrap
};
displayRect.SetValue(Grid.ColumnProperty, j);
displayRect.SetValue(Grid.RowProperty, i);
displayRect.SetValue(Grid.ColumnProperty, j);
displayRect.ContextMenuOpening += new ContextMenuEventHandler(DisplayRectContextMenuOpening);
displayRect.MouseLeftButtonDown += new MouseButtonEventHandler(DisplayRectMouseLeftButtonDown);
this.gridDisplay.Children.Add(displayRect);
}
@ -92,5 +628,113 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -92,5 +628,113 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
this.InvalidateVisual();
}
void DisplayRectMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (selectedCellX > -1 && selectedCellY > -1 && swap.HasValue) {
TextBlock block = sender as TextBlock;
int targetX = (int)block.GetValue(Grid.ColumnProperty);
int targetY = (int)block.GetValue(Grid.RowProperty);
var elements = gridTree.Elements()
.Where(
element => {
var colAttrib = element.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
var rowAttrib = element.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
int colAttribValue = 0, rowAttribValue = 0;
if (int.TryParse(colAttrib.Value, out colAttribValue) && int.TryParse(rowAttrib.Value, out rowAttribValue))
return colAttribValue == targetX && rowAttribValue == targetY;
return false;
}
).ToList();
var elements2 = gridTree.Elements()
.Where(
element => {
var colAttrib = element.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0);
var rowAttrib = element.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0);
int colAttribValue = 0, rowAttribValue = 0;
if (int.TryParse(colAttrib.Value, out colAttribValue) && int.TryParse(rowAttrib.Value, out rowAttribValue))
return colAttribValue == selectedCellX && rowAttribValue == selectedCellY;
return false;
}
).ToList();
if (swap == true) {
elements.ForEach(
element => {
element.SetAttributeValue(XName.Get("Grid.Column"), selectedCellX);
element.SetAttributeValue(XName.Get("Grid.Row"), selectedCellY);
}
);
}
elements2.ForEach(
element => {
element.SetAttributeValue(XName.Get("Grid.Column"), targetX);
element.SetAttributeValue(XName.Get("Grid.Row"), targetY);
}
);
}
lblInstruction.Visibility = Visibility.Collapsed;
selectedCellX = selectedCellY = -1;
swap = null;
RebuildGrid();
}
public XElement GetConstructedTree()
{
gridTree.AddFirst(additionalProperties);
gridTree.AddFirst(colDefitions);
gridTree.AddFirst(rowDefitions);
return gridTree;
}
void DisplayRectContextMenuOpening(object sender, ContextMenuEventArgs e)
{
ContextMenu menu = new ContextMenu() {
Items = {
new MenuItem() {
Header = "Row",
Items = {
CreateItem("Insert above", InsertAbove, sender as TextBlock),
CreateItem("Insert below", InsertBelow, sender as TextBlock),
new Separator(),
CreateItem("Move up", MoveUp, sender as TextBlock),
CreateItem("Move down", MoveDown, sender as TextBlock),
new Separator(),
CreateItem("Delete", DeleteRow, sender as TextBlock)
}
},
new MenuItem() {
Header = "Column",
Items = {
CreateItem("Insert before", InsertBefore, sender as TextBlock),
CreateItem("Insert after", InsertAfter, sender as TextBlock),
new Separator(),
CreateItem("Move left", MoveLeft, sender as TextBlock),
CreateItem("Move right", MoveRight, sender as TextBlock),
new Separator(),
CreateItem("Delete", DeleteColumn, sender as TextBlock)
}
},
new MenuItem() {
Header = "Cell",
Items = {
CreateItem("Swap content", SwapContent, sender as TextBlock),
CreateItem("Move content", MoveContent, sender as TextBlock),
CreateItem("Delete content", DeleteContent, sender as TextBlock)
}
}
}
};
menu.IsOpen = true;
}
}
}

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

@ -37,12 +37,14 @@ namespace ICSharpCode.XamlBinding.PowerToys @@ -37,12 +37,14 @@ namespace ICSharpCode.XamlBinding.PowerToys
XDocument document = XDocument.Load(reader, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
document.Declaration = null;
if (Refactor(provider.TextEditor, document)) {
StringWriter sWriter = new StringWriter();
XmlWriter writer = XmlWriter.Create(sWriter, CreateSettings());
document.WriteTo(writer);
writer.Flush();
provider.TextEditor.Document.Text = sWriter.ToString();
XmlView.FormatXml(provider.TextEditor);
using (provider.TextEditor.Document.OpenUndoGroup()) {
StringWriter sWriter = new StringWriter();
XmlWriter writer = XmlWriter.Create(sWriter, CreateSettings());
document.WriteTo(writer);
writer.Flush();
provider.TextEditor.Document.Text = sWriter.ToString();
XmlView.FormatXml(provider.TextEditor);
}
}
}
} catch (XmlException e) {

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

@ -118,11 +118,10 @@ namespace ICSharpCode.XamlBinding @@ -118,11 +118,10 @@ namespace ICSharpCode.XamlBinding
break;
default:
if (context.Description != XamlContextDescription.None && !char.IsWhiteSpace(ch)) {
editor.Document.Insert(editor.Caret.Offset, ch.ToString());
string word = editor.Document.Text.GetWordBeforeOffset(editor.Caret.Offset);
if (!(context.AttributeName.StartsWith("xmlns") || word.StartsWith("xmlns")))
this.CtrlSpace(editor);
return CodeCompletionKeyPressResult.EatKey;
return CodeCompletionKeyPressResult.CompletedIncludeKeyInCompletion;
}
break;
}

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

@ -112,16 +112,19 @@ namespace ICSharpCode.XamlBinding @@ -112,16 +112,19 @@ namespace ICSharpCode.XamlBinding
index = LineText.IndexOfAny(index + 1, '=', '.');
if (index > -1) {
context = CompletionDataHelper.ResolveContext(FileContent, FileName, LineNumber, index - 1);
context = CompletionDataHelper.ResolveContext(FileContent, FileName, LineNumber, index);
string elementName = context.ActiveElement.Name;
int propertyNameIndex = elementName.IndexOf('.');
string attribute = context.AttributeName;
if (string.IsNullOrEmpty(attribute) && elementName.Contains(".")) {
if (attribute.Contains(".")) {
int tmp = attribute.IndexOf('.');
index += attribute.Substring(tmp).Length;
} else if (string.IsNullOrEmpty(attribute) && elementName.Contains(".")) {
attribute = elementName;
index += attribute.Substring(propertyNameIndex).Length;
}
if (context.Description != XamlContextDescription.InComment && !string.IsNullOrEmpty(attribute)) {
int startIndex = LineText.Substring(0, index).LastIndexOf(attribute);
int startIndex = LineText.Substring(0, Math.Min(index, LineText.Length)).LastIndexOf(attribute);
if (propertyNameIndex > -1)
infos.Add(new HighlightingInfo(attribute.TrimStart('/'), startIndex + propertyNameIndex + 1, startIndex + attribute.Length, Offset, context));
else
@ -248,6 +251,17 @@ namespace ICSharpCode.XamlBinding @@ -248,6 +251,17 @@ namespace ICSharpCode.XamlBinding
public HighlightingInfo(string token, int startOffset, int endOffset, int lineOffset, XamlContext context)
{
if (token == null)
throw new ArgumentNullException("token");
if (startOffset < 0)
throw new ArgumentOutOfRangeException("startOffset", startOffset, "Value must be greater 0");
if (endOffset < 0)
throw new ArgumentOutOfRangeException("endOffset", endOffset, "Value must be greater 0");
if (lineOffset < 0)
throw new ArgumentOutOfRangeException("lineOffset", lineOffset, "Value must be greater 0");
if (context == null)
throw new ArgumentNullException("context");
this.token = token;
this.startOffset = startOffset;
this.endOffset = endOffset;

Loading…
Cancel
Save