Browse Source

XamlBinding:

- finished Grid Editor
- if no grid is selected Grid Editor selects the root control of the Window/UserControl, if it is a grid, otherwise an error message is displayed.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4565 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 17 years ago
parent
commit
b3436caca5
  1. 9
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/EditGridColumnsAndRowsCommand.cs
  2. 14
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml.cs
  3. 15
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/GridLengthEditor.xaml
  4. 154
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/GridLengthEditor.xaml.cs

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

@ -23,7 +23,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands @@ -23,7 +23,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands
public class EditGridColumnsAndRowsCommand : XamlMenuCommand
{
protected override bool Refactor(ITextEditor editor, XDocument document)
{
{
Location startLoc = editor.Document.OffsetToPosition(editor.SelectionStart);
Location endLoc = editor.Document.OffsetToPosition(editor.SelectionStart + editor.SelectionLength);
@ -31,8 +31,11 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands @@ -31,8 +31,11 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands
where item.IsInRange(startLoc, endLoc) select item).FirstOrDefault();
if (selectedItem == null || selectedItem.Name != XName.Get("Grid", CompletionDataHelper.WpfXamlNamespace)) {
MessageService.ShowError("Please select a Grid!");
return false;
selectedItem = document.Root.Elements().FirstOrDefault();
if (selectedItem == null || selectedItem.Name != XName.Get("Grid", CompletionDataHelper.WpfXamlNamespace)) {
MessageService.ShowError("Please select a Grid!");
return false;
}
}
EditGridColumnsAndRowsDialog dialog = new EditGridColumnsAndRowsDialog(selectedItem);

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

@ -95,8 +95,8 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -95,8 +95,8 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, delegate { UndoItemClick(null, null); }));
CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, delegate { RedoItemClick(null, null); }));
int maxCols = this.colDefitions.Elements().Count();
int maxRows = this.rowDefitions.Elements().Count();
int maxCols = Math.Max(this.colDefitions.Elements().Count(), 1);
int maxRows = Math.Max(this.rowDefitions.Elements().Count(), 1);
this.gridTree.Elements().ForEach(el => NormalizeElementGridIndices(el, maxCols, maxRows));
@ -735,14 +735,8 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -735,14 +735,8 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
string value = "Invalid";
if (e.Value.HasValue) {
if (e.Value.Value.IsAuto)
value = "Auto";
if (e.Value.Value.IsStar)
value = (e.Value.Value.Value == 1) ? "*" : e.Value.Value.Value + "*";
if (e.Value.Value.IsAbsolute)
value = e.Value.Value.Value + "px";
}
if (e.Value != null)
value = e.Value;
if (e.Type == Orientation.Horizontal)
colDefitions.Elements().ElementAt(e.Cell).SetAttributeValue("Width", value);

15
src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/GridLengthEditor.xaml

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
<UserControl
x:Class="ICSharpCode.XamlBinding.PowerToys.Dialogs.GridLengthEditor" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
x:Class="ICSharpCode.XamlBinding.PowerToys.Dialogs.GridLengthEditor" xmlns:local="clr-namespace:ICSharpCode.XamlBinding.PowerToys.Dialogs" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Border CornerRadius="15" Margin="5" Background="WhiteSmoke">
<StackPanel
x:Name="panel"
@ -12,11 +12,14 @@ @@ -12,11 +12,14 @@
Width="30"
Margin="3"
TextChanged="TxtNumericValueTextChanged" />
<Button
x:Name="btnType"
Margin="3"
Content=" * "
Click="BtnTypeClick" />
<ComboBox x:Name="cmbType" SelectionChanged="CmbTypeSelectionChanged" Margin="3">
<ComboBoxItem Content="Auto" />
<ComboBoxItem Content="*" />
<ComboBoxItem Content="Pixel" />
<ComboBoxItem Content="Point" />
<ComboBoxItem Content="Centimeter" />
<ComboBoxItem Content="Inch" />
</ComboBox>
<Button
x:Name="btnDel"
Margin="3"

154
src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/GridLengthEditor.xaml.cs

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows;
using System.Windows.Controls;
@ -17,12 +18,21 @@ using System.Windows.Media; @@ -17,12 +18,21 @@ using System.Windows.Media;
namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
{
public enum UnitType : int {
Auto = 0,
Star = 1,
Pixel = 2,
Point = 3,
Centimeter = 4,
Inch = 5
}
/// <summary>
/// Interaction logic for GridLengthEditor.xaml
/// </summary>
public partial class GridLengthEditor : UserControl
{
public GridUnitType Type { get; private set; }
{
public UnitType Unit { get; private set; }
public int Cell { get; private set; }
public Orientation Orientation { get; private set; }
@ -44,80 +54,75 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -44,80 +54,75 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
void SetValue(string value)
{
if (value.Equals("Auto", StringComparison.OrdinalIgnoreCase)) {
Type = GridUnitType.Auto;
string stringValue = value.Trim();
double numValue;
bool success = double.TryParse(stringValue.ToUpperInvariant().Trim('P', 'X', 'T', 'C', 'M', 'I', 'N'), out numValue);
if (stringValue.Equals("Auto", StringComparison.OrdinalIgnoreCase)) {
Unit = UnitType.Auto;
txtNumericValue.Text = "";
} else {
if (value.EndsWith("px", StringComparison.OrdinalIgnoreCase)) {
Type = GridUnitType.Pixel;
txtNumericValue.Text = value.Remove(value.Length - 2);
Unit = UnitType.Pixel;
txtNumericValue.Text = stringValue.Remove(value.Length - 2);
} else if (value.EndsWith("pt", StringComparison.OrdinalIgnoreCase)) {
Unit = UnitType.Point;
txtNumericValue.Text = stringValue.Remove(value.Length - 2);
} else if (value.EndsWith("cm", StringComparison.OrdinalIgnoreCase)) {
Unit = UnitType.Centimeter;
txtNumericValue.Text = stringValue.Remove(value.Length - 2);
} else if (value.EndsWith("in", StringComparison.OrdinalIgnoreCase)) {
Unit = UnitType.Inch;
txtNumericValue.Text = stringValue.Remove(value.Length - 2);
} else if (value.EndsWith("*", StringComparison.OrdinalIgnoreCase)) {
Type = GridUnitType.Star;
txtNumericValue.Text = value.Remove(value.Length - 1);
} else if (string.IsNullOrEmpty(value)) {
Type = GridUnitType.Star;
Unit = UnitType.Star;
txtNumericValue.Text = stringValue.Remove(value.Length - 1);
} else if (string.IsNullOrEmpty(stringValue)) {
Unit = UnitType.Star;
txtNumericValue.Text = "";
} else {
Type = GridUnitType.Pixel;
txtNumericValue.Text = value;
Unit = UnitType.Pixel;
txtNumericValue.Text = stringValue;
}
}
switch (Type) {
case GridUnitType.Star:
btnType.Content = " * ";
txtNumericValue.Visibility = Visibility.Visible;
break;
case GridUnitType.Pixel:
btnType.Content = "Pixel";
txtNumericValue.Visibility = Visibility.Visible;
break;
case GridUnitType.Auto:
btnType.Content = "Auto";
txtNumericValue.Visibility = Visibility.Collapsed;
break;
}
cmbType.SelectedIndex = (int)Unit;
}
void BtnTypeClick(object sender, RoutedEventArgs e)
{
switch (Type) {
case GridUnitType.Auto:
if (txtNumericValue.Text == "Invalid")
txtNumericValue.Text = "";
Type = GridUnitType.Star;
btnType.Content = " * ";
txtNumericValue.Visibility = Visibility.Visible;
break;
case GridUnitType.Star:
Type = GridUnitType.Pixel;
btnType.Content = "Pixel";
txtNumericValue.Visibility = Visibility.Visible;
break;
case GridUnitType.Pixel:
Type = GridUnitType.Auto;
btnType.Content = "Auto";
txtNumericValue.Visibility = Visibility.Collapsed;
break;
}
TxtNumericValueTextChanged(null, null);
}
public GridLength? SelectedValue {
public string SelectedValue {
get {
if (Type == GridUnitType.Star || Type == GridUnitType.Pixel) {
double value;
if (Type == GridUnitType.Star && string.IsNullOrEmpty(txtNumericValue.Text)) {
return new GridLength(1, Type);
} else {
if (double.TryParse(txtNumericValue.Text, out value))
return new GridLength(value, Type);
}
return null;
string stringValue = txtNumericValue.Text.Trim().ToUpperInvariant();
double value;
bool success = double.TryParse(stringValue.Trim('P', 'X', 'T', 'C', 'M', 'I', 'N'),
NumberStyles.Float, CultureInfo.InvariantCulture, out value);
string result = "";
switch (Unit) {
case UnitType.Auto:
return "Auto";
case UnitType.Centimeter:
result = value.ToString(CultureInfo.InvariantCulture) + "cm";
break;
case UnitType.Inch:
result = value.ToString(CultureInfo.InvariantCulture) + "in";
break;
case UnitType.Pixel:
result = value.ToString(CultureInfo.InvariantCulture) + "px";
break;
case UnitType.Point:
result = value.ToString(CultureInfo.InvariantCulture) + "pt";
break;
case UnitType.Star:
if (string.IsNullOrEmpty(stringValue))
return "*";
result = value.ToString(CultureInfo.InvariantCulture) + "*";
break;
}
return GridLength.Auto;
if (success)
return result;
else
return null;
}
}
@ -141,12 +146,13 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -141,12 +146,13 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
void TxtNumericValueTextChanged(object sender, TextChangedEventArgs e)
{
if (Type == GridUnitType.Star && string.IsNullOrEmpty(txtNumericValue.Text)) {
if (Unit == UnitType.Star && string.IsNullOrEmpty(txtNumericValue.Text)) {
txtNumericValue.ClearValue(TextBox.BackgroundProperty);
txtNumericValue.ClearValue(TextBox.ForegroundProperty);
} else {
double x;
if (!double.TryParse(txtNumericValue.Text, out x)) {
double value;
if (!double.TryParse(txtNumericValue.Text.Trim('P', 'X', 'T', 'C', 'M', 'I', 'N'),
NumberStyles.Any, CultureInfo.InvariantCulture, out value)) {
txtNumericValue.Background = Brushes.Red;
txtNumericValue.Foreground = Brushes.White;
} else {
@ -161,15 +167,27 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -161,15 +167,27 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
{
OnDeleted(new GridLengthSelectionChangedEventArgs(this.panel.Orientation, Cell, SelectedValue));
}
void CmbTypeSelectionChanged(object sender, SelectionChangedEventArgs e)
{
Unit = (UnitType)cmbType.SelectedIndex;
if (Unit == UnitType.Auto)
txtNumericValue.Visibility = Visibility.Collapsed;
else
txtNumericValue.Visibility = Visibility.Visible;
TxtNumericValueTextChanged(null, null);
}
}
public class GridLengthSelectionChangedEventArgs : EventArgs
{
public Orientation Type { get; private set; }
public int Cell { get; private set; }
public GridLength? Value { get; private set; }
public string Value { get; private set; }
public GridLengthSelectionChangedEventArgs(Orientation type, int cell, GridLength? value)
public GridLengthSelectionChangedEventArgs(Orientation type, int cell, string value)
{
this.Type = type;
this.Cell = cell;

Loading…
Cancel
Save