Browse Source

XamlBinding:

- fixed preselection on attached property/event completion
- improved Grid-Editor

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4556 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 16 years ago
parent
commit
d01d5f9777
  1. 19
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs
  2. 28
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml
  3. 43
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml.cs
  4. 2
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/GridLengthEditor.xaml
  5. 30
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/GridLengthEditor.xaml.cs
  6. 8
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs
  7. 11
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemList.cs

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

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.SharpDevelop;
@ -301,7 +302,7 @@ namespace ICSharpCode.XamlBinding @@ -301,7 +302,7 @@ namespace ICSharpCode.XamlBinding
if (mrr != null) {
rt = mrr.ResolvedType;
}
}
}
} else {
string fullName = string.IsNullOrEmpty(last.Prefix) ? last.Name : last.Prefix + ":" + last.Name;
@ -404,22 +405,26 @@ namespace ICSharpCode.XamlBinding @@ -404,22 +405,26 @@ namespace ICSharpCode.XamlBinding
case XamlContextDescription.InTag:
string word = context.Editor.GetWordBeforeCaretExtended();
if (context.PressedKey == '.') {
TypeResolveResult trr = new XamlResolver().Resolve(new ExpressionResult(word.TrimEnd('.'), context), info, editor.Document.Text) as TypeResolveResult;
IClass typeClass = (trr != null && trr.ResolvedType != null) ? trr.ResolvedType.GetUnderlyingClass() : null;
if (context.PressedKey == '.' || word.Contains(".")) {
string ns = "";
int pos = word.IndexOf(':');
if (pos > -1)
ns = word.Substring(0, pos);
string element = word.Substring(pos + 1, word.Length - pos - 1);
string className = element;
int propertyStart = element.IndexOf('.');
if (propertyStart != -1)
className = element.Substring(0, propertyStart).TrimEnd('.');
TypeResolveResult trr = new XamlResolver().Resolve(new ExpressionResult(className, context), info, editor.Document.Text) as TypeResolveResult;
IClass typeClass = (trr != null && trr.ResolvedType != null) ? trr.ResolvedType.GetUnderlyingClass() : null;
if (typeClass != null && typeClass.DerivesFrom("System.Windows.DependencyObject"))
list.Items.AddRange(GetListOfAttached(context, word.Substring(pos + 1, word.Length - pos - 1).TrimEnd('.'), ns, true, true));
list.Items.AddRange(GetListOfAttached(context, className, ns, true, true));
} else {
QualifiedNameWithLocation last = context.ActiveElement;
TypeResolveResult trr = new XamlResolver().Resolve(new ExpressionResult(last.Name, context), info, editor.Document.Text) as TypeResolveResult;
IClass typeClass = (trr != null && trr.ResolvedType != null) ? trr.ResolvedType.GetUnderlyingClass() : null;
list = new XamlAttributeCompletionItemList();
list.Items.AddRange(CreateAttributeList(context, true));
list.Items.AddRange(standardAttributes);
}

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

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
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="Edit grid columns and rows" Height="500" Width="500"
Title="Edit grid columns and rows"
ShowInTaskbar="False"
WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow">
<Window.Resources>
@ -45,12 +45,26 @@ @@ -45,12 +45,26 @@
<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>
<Grid DockPanel.Dock="Top" x:Name="columnWidthGrid">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Column="1" x:Name="columnWidthGrid" />
<StackPanel Grid.Column="1" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center">
<Button x:Name="btnAddRow" Content="+" Style="{StaticResource normal}" Click="BtnAddRowClick" />
</StackPanel>
<StackPanel Grid.Column="2" Grid.Row="1" Orientation="Vertical" VerticalAlignment="Center">
<Button x:Name="btnAddColumn" Content="+" Style="{StaticResource normal}" Click="BtnAddColumnClick" />
</StackPanel>
<Grid Grid.Row="1" x:Name="rowHeightGrid" />
<Grid Grid.Column="1" Grid.Row="1" x:Name="gridDisplay" ShowGridLines="True" />
</Grid>
<Grid DockPanel.Dock="Left" x:Name="rowHeightGrid">
</Grid>
<Grid x:Name="gridDisplay" ShowGridLines="True" />
</DockPanel>
</Window>

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

@ -366,7 +366,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -366,7 +366,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
UpdateUndoRedoState();
var newColumn = new XElement(colDefName);
newColumn.SetAttributeValue(XName.Get("Width"), "Auto");
newColumn.SetAttributeValue(XName.Get("Width"), "*");
var items = colDefitions.Elements().Skip(column);
var selItem = items.FirstOrDefault();
if (selItem != null)
@ -403,11 +403,11 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -403,11 +403,11 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
UpdateUndoRedoState();
var newColumn = new XElement(colDefName);
newColumn.SetAttributeValue(XName.Get("Width"), "Auto");
newColumn.SetAttributeValue(XName.Get("Width"), "*");
var items = colDefitions.Elements().Skip(column);
var selItem = items.FirstOrDefault();
if (selItem != null)
selItem.AddBeforeSelf(newColumn);
selItem.AddAfterSelf(newColumn);
else
colDefitions.Add(newColumn);
@ -636,6 +636,8 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -636,6 +636,8 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
this.columnWidthGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
GridLengthEditor editor = new GridLengthEditor(Orientation.Horizontal, i, (colDefitions.Elements().ElementAt(i).Attribute("Width") ?? new XAttribute("Width", "")).Value);
editor.SelectedValueChanged += new EventHandler<GridLengthSelectionChangedEventArgs>(EditorSelectedValueChanged);
editor.Deleted += new EventHandler<GridLengthSelectionChangedEventArgs>(EditorDeleted);
editor.Added += new EventHandler<GridLengthSelectionChangedEventArgs>(EditorAdded);
this.columnWidthGrid.Children.Add(editor);
}
@ -645,6 +647,8 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -645,6 +647,8 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
this.rowHeightGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
GridLengthEditor editor = new GridLengthEditor(Orientation.Vertical, i, (rowDefitions.Elements().ElementAt(i).Attribute("Height") ?? new XAttribute("Height", "")).Value);
editor.SelectedValueChanged += new EventHandler<GridLengthSelectionChangedEventArgs>(EditorSelectedValueChanged);
editor.Deleted += new EventHandler<GridLengthSelectionChangedEventArgs>(EditorDeleted);
editor.Added += new EventHandler<GridLengthSelectionChangedEventArgs>(EditorAdded);
this.rowHeightGrid.Children.Add(editor);
for (int j = 0; j < cols; j++) {
@ -673,11 +677,25 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -673,11 +677,25 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
this.InvalidateVisual();
}
void EditorAdded(object sender, GridLengthSelectionChangedEventArgs e)
{
if (e.Type == Orientation.Horizontal)
InsertBefore(gridDisplay.Children.OfType<StackPanel>().First(item => (int)item.GetValue(Grid.ColumnProperty) == e.Cell));
else
InsertAbove(gridDisplay.Children.OfType<StackPanel>().First(item => (int)item.GetValue(Grid.RowProperty) == e.Cell));
}
void EditorDeleted(object sender, GridLengthSelectionChangedEventArgs e)
{
if (e.Type == Orientation.Horizontal)
DeleteColumn(gridDisplay.Children.OfType<StackPanel>().First(item => (int)item.GetValue(Grid.ColumnProperty) == e.Cell));
else
DeleteRow(gridDisplay.Children.OfType<StackPanel>().First(item => (int)item.GetValue(Grid.RowProperty) == e.Cell));
}
void EditorSelectedValueChanged(object sender, GridLengthSelectionChangedEventArgs e)
{
gridLengthInvalid = colDefitions.Elements().Any(col => (col.Attribute("Width") ?? new XAttribute("Width", "*")).Value == "Invalid")
|| rowDefitions.Elements().Any(row => (row.Attribute("Height") ?? new XAttribute("Height", "*")).Value == "Invalid")
|| !e.Value.HasValue;
UpdateUndoRedoState();
string value = "Invalid";
@ -694,6 +712,9 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -694,6 +712,9 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
colDefitions.Elements().ElementAt(e.Cell).SetAttributeValue("Width", value);
else
rowDefitions.Elements().ElementAt(e.Cell).SetAttributeValue("Height", value);
gridLengthInvalid = colDefitions.Elements().Any(col => (col.Attribute("Width") ?? new XAttribute("Width", "*")).Value == "Invalid")
|| rowDefitions.Elements().Any(row => (row.Attribute("Height") ?? new XAttribute("Height", "*")).Value == "Invalid");
}
class DragDropMarkerAdorner : Adorner
@ -956,5 +977,15 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -956,5 +977,15 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
RebuildGrid();
}
void BtnAddRowClick(object sender, RoutedEventArgs e)
{
InsertBelow(gridDisplay.Children.OfType<StackPanel>().First(item => (int)item.GetValue(Grid.RowProperty) == rowDefitions.Elements().Count() - 1));
}
void BtnAddColumnClick(object sender, RoutedEventArgs e)
{
InsertAfter(gridDisplay.Children.OfType<StackPanel>().First(item => (int)item.GetValue(Grid.ColumnProperty) == colDefitions.Elements().Count() - 1));
}
}
}

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

@ -2,7 +2,9 @@ @@ -2,7 +2,9 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel x:Name="panel" Orientation="Horizontal" Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="btnInsertCells" Margin="3" Content="Ins" Click="BtnInsertCellsClick" />
<Button x:Name="btnType" Margin="3" Content=" * " Click="BtnTypeClick" />
<TextBox x:Name="txtNumericValue" MaxLength="10" Width="50" Margin="3" TextChanged="TxtNumericValueTextChanged" />
<Button x:Name="btnDel" Margin="3" Content="Del" Click="BtnDelClick" />
</StackPanel>
</UserControl>

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

@ -97,7 +97,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -97,7 +97,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
txtNumericValue.Visibility = Visibility.Collapsed;
break;
}
OnSelectedValueChanged(new GridLengthSelectionChangedEventArgs(this.panel.Orientation, this.cell, SelectedValue));
TxtNumericValueTextChanged(null, null);
}
public GridLength? SelectedValue {
@ -120,6 +120,24 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -120,6 +120,24 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
public event EventHandler<GridLengthSelectionChangedEventArgs> SelectedValueChanged;
public event EventHandler<GridLengthSelectionChangedEventArgs> Deleted;
public event EventHandler<GridLengthSelectionChangedEventArgs> Added;
protected virtual void OnAdded(GridLengthSelectionChangedEventArgs e)
{
if (Added != null) {
Added(this, e);
}
}
protected virtual void OnDeleted(GridLengthSelectionChangedEventArgs e)
{
if (Deleted != null) {
Deleted(this, e);
}
}
protected virtual void OnSelectedValueChanged(GridLengthSelectionChangedEventArgs e)
{
if (SelectedValueChanged != null) {
@ -144,6 +162,16 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs @@ -144,6 +162,16 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
}
OnSelectedValueChanged(new GridLengthSelectionChangedEventArgs(this.panel.Orientation, cell, SelectedValue));
}
void BtnDelClick(object sender, RoutedEventArgs e)
{
OnDeleted(new GridLengthSelectionChangedEventArgs(this.panel.Orientation, cell, SelectedValue));
}
void BtnInsertCellsClick(object sender, RoutedEventArgs e)
{
OnAdded(new GridLengthSelectionChangedEventArgs(this.panel.Orientation, cell, SelectedValue));
}
}
public class GridLengthSelectionChangedEventArgs : EventArgs

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

@ -162,8 +162,12 @@ namespace ICSharpCode.XamlBinding @@ -162,8 +162,12 @@ namespace ICSharpCode.XamlBinding
if (!XmlParser.IsInsideAttributeValue(editor.Document.Text, editor.Caret.Offset) && context.Description != XamlContextDescription.InAttributeValue) {
var list = CompletionDataHelper.CreateListForContext(context) as XamlCompletionItemList;
string starter = editor.GetWordBeforeCaretExtended().TrimStart('/');
if (context.Description != XamlContextDescription.None && !string.IsNullOrEmpty(starter))
list.PreselectionLength = starter.Length;
if (context.Description != XamlContextDescription.None && !string.IsNullOrEmpty(starter)) {
if (starter.Contains("."))
list.PreselectionLength = starter.Length - starter.IndexOf('.') - 1;
else
list.PreselectionLength = starter.Length;
}
editor.ShowCompletionWindow(list);
return true;
} else {

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

@ -18,17 +18,6 @@ using ICSharpCode.XmlEditor; @@ -18,17 +18,6 @@ using ICSharpCode.XmlEditor;
namespace ICSharpCode.XamlBinding
{
public class XamlAttributeCompletionItemList : XamlCompletionItemList
{
public override CompletionItemListKeyResult ProcessInput(char key)
{
if (key == '.')
return CompletionItemListKeyResult.NormalKey;
return base.ProcessInput(key);
}
}
public class XamlCompletionItemList : DefaultCompletionItemList
{
public override CompletionItemListKeyResult ProcessInput(char key)

Loading…
Cancel
Save