|
|
|
|
@ -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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |