Browse Source

Merge pull request #690:Few fixes & addons for WPF Designer

pull/637/merge
Andreas Weizel 10 years ago
parent
commit
2069129010
  1. 42
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Commands.cs
  2. 12
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ZoomControl.cs
  3. 31
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs
  4. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNodeBase.cs
  5. 44
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNodeNameService.cs
  6. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineTreeView.cs
  7. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  8. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs
  9. 23
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelProperty.cs
  10. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTextValue.cs
  11. 28
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceContainer.cs
  12. 13
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs
  13. BIN
      src/Libraries/WPFExtendedToolkit/Xceed.Wpf.Toolkit.dll

42
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Commands.cs

@ -0,0 +1,42 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Windows.Input;
namespace ICSharpCode.WpfDesign.Designer
{
/// <summary>
/// Description of Commands.
/// </summary>
public static class Commands
{
public static ICommand AlignTopCommand = new RoutedCommand();
public static ICommand AlignMiddleCommand = new RoutedCommand();
public static ICommand AlignBottomCommand = new RoutedCommand();
public static ICommand AlignLeftCommand = new RoutedCommand();
public static ICommand AlignCenterCommand = new RoutedCommand();
public static ICommand AlignRightCommand = new RoutedCommand();
public static ICommand RotateLeftCommand = new RoutedCommand();
public static ICommand RotateRightCommand = new RoutedCommand();
static Commands()
{
}
}
}

12
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ZoomControl.cs

@ -83,6 +83,12 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
protected override void OnPreviewMouseDown(MouseButtonEventArgs e) protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{ {
if (!pan && e.MiddleButton == MouseButtonState.Pressed)
{
pan = true;
Mouse.UpdateCursor();
}
if (pan && !e.Handled) { if (pan && !e.Handled) {
if (Mouse.Capture(this)) { if (Mouse.Capture(this)) {
isMouseDown = true; isMouseDown = true;
@ -106,6 +112,12 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
protected override void OnPreviewMouseUp(MouseButtonEventArgs e) protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
{ {
if (pan && e.MiddleButton != MouseButtonState.Pressed && !Keyboard.IsKeyDown(Key.Space))
{
pan = false;
Mouse.UpdateCursor();
}
if (isMouseDown) { if (isMouseDown) {
isMouseDown = false; isMouseDown = false;
ReleaseMouseCapture(); ReleaseMouseCapture();

31
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs

@ -18,6 +18,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
@ -46,7 +47,7 @@ namespace ICSharpCode.WpfDesign.Designer
/// </summary> /// </summary>
[TemplatePart(Name = "PART_DesignContent", Type = typeof(ContentControl))] [TemplatePart(Name = "PART_DesignContent", Type = typeof(ContentControl))]
[TemplatePart(Name = "PART_Zoom", Type = typeof(ZoomControl))] [TemplatePart(Name = "PART_Zoom", Type = typeof(ZoomControl))]
public partial class DesignSurface : ContentControl public partial class DesignSurface : ContentControl, INotifyPropertyChanged
{ {
private FocusNavigator _focusNav; private FocusNavigator _focusNav;
@ -68,6 +69,17 @@ namespace ICSharpCode.WpfDesign.Designer
this.AddCommandHandler(ApplicationCommands.Paste, Paste, CanPaste); this.AddCommandHandler(ApplicationCommands.Paste, Paste, CanPaste);
this.AddCommandHandler(ApplicationCommands.SelectAll, SelectAll, CanSelectAll); this.AddCommandHandler(ApplicationCommands.SelectAll, SelectAll, CanSelectAll);
this.AddCommandHandler(Commands.AlignTopCommand, () => ModelTools.ArrangeItems(this.DesignContext.Services.Selection.SelectedItems, ArrangeDirection.Top), () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
this.AddCommandHandler(Commands.AlignMiddleCommand, () => ModelTools.ArrangeItems(this.DesignContext.Services.Selection.SelectedItems, ArrangeDirection.VerticalMiddle), () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
this.AddCommandHandler(Commands.AlignBottomCommand, () => ModelTools.ArrangeItems(this.DesignContext.Services.Selection.SelectedItems, ArrangeDirection.Bottom), () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
this.AddCommandHandler(Commands.AlignLeftCommand, () => ModelTools.ArrangeItems(this.DesignContext.Services.Selection.SelectedItems, ArrangeDirection.Left), () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
this.AddCommandHandler(Commands.AlignCenterCommand, () => ModelTools.ArrangeItems(this.DesignContext.Services.Selection.SelectedItems, ArrangeDirection.HorizontalMiddle), () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
this.AddCommandHandler(Commands.AlignRightCommand, () => ModelTools.ArrangeItems(this.DesignContext.Services.Selection.SelectedItems, ArrangeDirection.Right), () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
//Todo
//this.AddCommandHandler(Commands.RotateLeftCommand, () => , () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
//this.AddCommandHandler(Commands.RotateRightCommand, () => , () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
_sceneContainer = new Border() { AllowDrop = false, UseLayoutRounding = true }; _sceneContainer = new Border() { AllowDrop = false, UseLayoutRounding = true };
_sceneContainer.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Ideal); _sceneContainer.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Ideal);
@ -86,6 +98,8 @@ namespace ICSharpCode.WpfDesign.Designer
this.ZoomControl = this.Template.FindName("PART_Zoom", this) as ZoomControl; this.ZoomControl = this.Template.FindName("PART_Zoom", this) as ZoomControl;
OnPropertyChanged("ZoomControl");
base.OnApplyTemplate(); base.OnApplyTemplate();
} }
@ -173,6 +187,8 @@ namespace ICSharpCode.WpfDesign.Designer
context.Services.AddService(typeof(IKeyBindingService), new DesignerKeyBindings(this)); context.Services.AddService(typeof(IKeyBindingService), new DesignerKeyBindings(this));
_focusNav=new FocusNavigator(this); _focusNav=new FocusNavigator(this);
_focusNav.Start(); _focusNav.Start();
OnPropertyChanged("DesignContext");
} }
/// <summary> /// <summary>
@ -356,5 +372,18 @@ namespace ICSharpCode.WpfDesign.Designer
} }
#endregion #endregion
#region INotifyPropertyChanged implementation
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
var ev = PropertyChanged;
if (ev != null)
ev(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
} }
} }

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNodeBase.cs

@ -154,10 +154,7 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
{ {
get get
{ {
if (string.IsNullOrEmpty(DesignItem.Name)) { return DesignItem.Services.GetService<IOutlineNodeNameService>().GetOutlineNodeName(DesignItem);
return DesignItem.ComponentType.Name;
}
return DesignItem.ComponentType.Name + " (" + DesignItem.Name + ")";
} }
} }

44
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNodeNameService.cs

@ -0,0 +1,44 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
namespace ICSharpCode.WpfDesign.Designer.OutlineView
{
/// <summary>
/// Description of OulineNodeNameService.
/// </summary>
public class OutlineNodeNameService : IOutlineNodeNameService
{
public OutlineNodeNameService()
{
}
#region IOutlineNodeNameService implementation
public string GetOutlineNodeName(DesignItem designItem)
{
if (string.IsNullOrEmpty(designItem.Name)) {
return designItem.ComponentType.Name;
}
return designItem.ComponentType.Name + " (" + designItem.Name + ")";
}
#endregion
}
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineTreeView.cs

@ -54,7 +54,7 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
{ {
var node = dragTreeViewitem.DataContext as IOutlineNode; var node = dragTreeViewitem.DataContext as IOutlineNode;
return string.IsNullOrEmpty(Filter) || node.Name.ToLower().Contains(Filter.ToLower()); return string.IsNullOrEmpty(Filter) || node.DesignItem.Services.GetService<IOutlineNodeNameService>().GetOutlineNodeName(node.DesignItem).ToLower().Contains(Filter.ToLower());
} }
protected override void SelectOnly(DragTreeViewItem item) protected override void SelectOnly(DragTreeViewItem item)

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

@ -87,6 +87,7 @@
<Link>Configuration\GlobalAssemblyInfo.cs</Link> <Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile> </Compile>
<Compile Include="ArrangeDirection.cs" /> <Compile Include="ArrangeDirection.cs" />
<Compile Include="Commands.cs" />
<Compile Include="Controls\NullableComboBox.cs" /> <Compile Include="Controls\NullableComboBox.cs" />
<Compile Include="Controls\RenderTransformOriginThumb.cs" /> <Compile Include="Controls\RenderTransformOriginThumb.cs" />
<Compile Include="Controls\Thumbs\PointThumb.cs" /> <Compile Include="Controls\Thumbs\PointThumb.cs" />
@ -135,6 +136,7 @@
</Compile> </Compile>
<Compile Include="Extensions\WrapItemsContextMenuExtension.cs" /> <Compile Include="Extensions\WrapItemsContextMenuExtension.cs" />
<Compile Include="MarkupExtensions\DesignItemBinding.cs" /> <Compile Include="MarkupExtensions\DesignItemBinding.cs" />
<Compile Include="OutlineView\OutlineNodeNameService.cs" />
<Compile Include="OutlineView\OutlineNodeBase.cs" /> <Compile Include="OutlineView\OutlineNodeBase.cs" />
<Compile Include="Extensions\WrapItemContextMenuExtension.cs" /> <Compile Include="Extensions\WrapItemContextMenuExtension.cs" />
<Compile Include="Extensions\WrapItemsContextMenu.xaml.cs"> <Compile Include="Extensions\WrapItemsContextMenu.xaml.cs">

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs

@ -21,6 +21,7 @@ using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using System.Xml; using System.Xml;
using ICSharpCode.WpfDesign.XamlDom; using ICSharpCode.WpfDesign.XamlDom;
using ICSharpCode.WpfDesign.Designer.OutlineView;
using ICSharpCode.WpfDesign.Designer.Services; using ICSharpCode.WpfDesign.Designer.Services;
using ICSharpCode.WpfDesign.Designer.Extensions; using ICSharpCode.WpfDesign.Designer.Extensions;
using ICSharpCode.WpfDesign.Extensions; using ICSharpCode.WpfDesign.Extensions;
@ -73,6 +74,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
this.Services.AddService(typeof(IToolService), new DefaultToolService(this)); this.Services.AddService(typeof(IToolService), new DefaultToolService(this));
this.Services.AddService(typeof(UndoService), new UndoService()); this.Services.AddService(typeof(UndoService), new UndoService());
this.Services.AddService(typeof(IErrorService), new DefaultErrorService(this)); this.Services.AddService(typeof(IErrorService), new DefaultErrorService(this));
this.Services.AddService(typeof(IOutlineNodeNameService), new OutlineNodeNameService());
this.Services.AddService(typeof(ViewService), new DefaultViewService(this)); this.Services.AddService(typeof(ViewService), new DefaultViewService(this));
this.Services.AddService(typeof(OptionService), new OptionService()); this.Services.AddService(typeof(OptionService), new OptionService());

23
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelProperty.cs

@ -132,7 +132,12 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
return null; return null;
} }
} }
internal void SetValueOnInstance(object value)
{
_property.ValueOnInstance = value;
}
// There may be multiple XamlModelProperty instances for the same property, // There may be multiple XamlModelProperty instances for the same property,
// so this class may not have any mutable fields / events - instead, // so this class may not have any mutable fields / events - instead,
// we forward all event handlers to the XamlProperty. // we forward all event handlers to the XamlProperty.
@ -195,7 +200,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
_property.IsSetChanged -= value; _property.IsSetChanged -= value;
} }
} }
public override void SetValue(object value) public override void SetValue(object value)
{ {
XamlPropertyValue newValue; XamlPropertyValue newValue;
@ -251,6 +256,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
{ {
readonly XamlModelProperty property; readonly XamlModelProperty property;
readonly XamlPropertyValue oldValue; readonly XamlPropertyValue oldValue;
readonly object oldValueOnInstance;
XamlPropertyValue newValue; XamlPropertyValue newValue;
readonly bool oldIsSet; readonly bool oldIsSet;
bool newIsSet; bool newIsSet;
@ -264,6 +270,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
oldIsSet = property._property.IsSet; oldIsSet = property._property.IsSet;
oldValue = property._property.PropertyValue; oldValue = property._property.PropertyValue;
oldValueOnInstance = property._property.ValueOnInstance;
if (oldIsSet && oldValue == null && property.IsCollection) { if (oldIsSet && oldValue == null && property.IsCollection) {
collectionTransactionItem = property._collectionElements.CreateResetTransaction(); collectionTransactionItem = property._collectionElements.CreateResetTransaction();
@ -300,8 +307,18 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
property.SetValueInternal(oldValue); property.SetValueInternal(oldValue);
} }
} }
else else {
if (property.DependencyProperty == null) {
try
{
property.SetValueOnInstance(oldValueOnInstance);
}
catch(Exception)
{ }
}
property.ResetInternal(); property.ResetInternal();
}
} }
public System.Collections.Generic.ICollection<DesignItem> AffectedElements { public System.Collections.Generic.ICollection<DesignItem> AffectedElements {

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTextValue.cs

@ -48,6 +48,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
internal XamlTextValue(XamlDocument document, string textValue) internal XamlTextValue(XamlDocument document, string textValue)
{ {
this.document = document; this.document = document;
if (textValue.StartsWith("{"))
textValue = "{}" + textValue;
this.textValue = textValue; this.textValue = textValue;
} }

28
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceContainer.cs

@ -65,6 +65,34 @@ namespace ICSharpCode.WpfDesign
} }
} }
/// <summary>
/// Adds a new service to the container or Replaces a existing one.
/// </summary>
/// <param name="serviceInterface">
/// The type of the service interface to use as a key for the service.
/// </param>
/// <param name="serviceInstance">
/// The service instance implementing that interface.
/// </param>
public void AddOrReplaceService(Type serviceInterface, object serviceInstance)
{
if (serviceInterface == null)
throw new ArgumentNullException("serviceInterface");
if (serviceInstance == null)
throw new ArgumentNullException("serviceInstance");
if (_services.ContainsKey(serviceInterface))
_services.Remove(serviceInterface);
_services.Add(serviceInterface, serviceInstance);
Delegate subscriber;
if (_waitingSubscribers.TryGetValue(serviceInterface, out subscriber)) {
_waitingSubscribers.Remove(serviceInterface);
subscriber.DynamicInvoke(serviceInstance);
}
}
/// <summary> /// <summary>
/// Gets the service object of the specified type. /// Gets the service object of the specified type.
/// Returns null when the service is not available. /// Returns null when the service is not available.

13
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs

@ -173,6 +173,19 @@ namespace ICSharpCode.WpfDesign
} }
#endregion #endregion
#region IOutlineNodeNameService
/// <summary>
/// Used to get a description for the Outline Node.
/// </summary>
public interface IOutlineNodeNameService
{
/// <summary>
/// Gets a the Name for display in the Ouline Node.
/// </summary>
string GetOutlineNodeName(DesignItem designItem);
}
#endregion
#region IErrorService #region IErrorService
/// <summary> /// <summary>
/// Service for showing error UI. /// Service for showing error UI.

BIN
src/Libraries/WPFExtendedToolkit/Xceed.Wpf.Toolkit.dll

Binary file not shown.
Loading…
Cancel
Save