Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Few fixes & addons for WPF Designer #690

Merged
merged 10 commits into from
Jun 29, 2015
Original file line number Diff line number Diff line change
@@ -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()
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ protected override void OnKeyUp(KeyEventArgs e)

protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{
if (!pan && e.MiddleButton == MouseButtonState.Pressed)
{
pan = true;
Mouse.UpdateCursor();
}

if (pan && !e.Handled) {
if (Mouse.Capture(this)) {
isMouseDown = true;
Expand All @@ -106,6 +112,12 @@ protected override void OnPreviewMouseMove(MouseEventArgs e)

protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
{
if (pan && e.MiddleButton != MouseButtonState.Pressed && !Keyboard.IsKeyDown(Key.Space))
{
pan = false;
Mouse.UpdateCursor();
}

if (isMouseDown) {
isMouseDown = false;
ReleaseMouseCapture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
Expand Down Expand Up @@ -46,7 +47,7 @@ namespace ICSharpCode.WpfDesign.Designer
/// </summary>
[TemplatePart(Name = "PART_DesignContent", Type = typeof(ContentControl))]
[TemplatePart(Name = "PART_Zoom", Type = typeof(ZoomControl))]
public partial class DesignSurface : ContentControl
public partial class DesignSurface : ContentControl, INotifyPropertyChanged
{
private FocusNavigator _focusNav;

Expand All @@ -68,6 +69,17 @@ public DesignSurface()
this.AddCommandHandler(ApplicationCommands.Paste, Paste, CanPaste);
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.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Ideal);

Expand All @@ -86,6 +98,8 @@ public override void OnApplyTemplate()

this.ZoomControl = this.Template.FindName("PART_Zoom", this) as ZoomControl;

OnPropertyChanged("ZoomControl");

base.OnApplyTemplate();
}

Expand Down Expand Up @@ -173,6 +187,8 @@ void InitializeDesigner(DesignContext context)
context.Services.AddService(typeof(IKeyBindingService), new DesignerKeyBindings(this));
_focusNav=new FocusNavigator(this);
_focusNav.Start();

OnPropertyChanged("DesignContext");
}

/// <summary>
Expand Down Expand Up @@ -356,5 +372,18 @@ static List<DesignItem> GetLiveElements(ICollection<DesignItem> items)
}

#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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,7 @@ public string Name
{
get
{
if (string.IsNullOrEmpty(DesignItem.Name)) {
return DesignItem.ComponentType.Name;
}
return DesignItem.ComponentType.Name + " (" + DesignItem.Name + ")";
return DesignItem.Services.GetService<IOutlineNodeNameService>().GetOutlineNodeName(DesignItem);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override bool ShouldItemBeVisible(DragTreeViewItem dragTreeViewitem)
{
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ArrangeDirection.cs" />
<Compile Include="Commands.cs" />
<Compile Include="Controls\NullableComboBox.cs" />
<Compile Include="Controls\RenderTransformOriginThumb.cs" />
<Compile Include="Controls\Thumbs\PointThumb.cs" />
Expand Down Expand Up @@ -135,6 +136,7 @@
</Compile>
<Compile Include="Extensions\WrapItemsContextMenuExtension.cs" />
<Compile Include="MarkupExtensions\DesignItemBinding.cs" />
<Compile Include="OutlineView\OutlineNodeNameService.cs" />
<Compile Include="OutlineView\OutlineNodeBase.cs" />
<Compile Include="Extensions\WrapItemContextMenuExtension.cs" />
<Compile Include="Extensions\WrapItemsContextMenu.xaml.cs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Reflection;
using System.Xml;
using ICSharpCode.WpfDesign.XamlDom;
using ICSharpCode.WpfDesign.Designer.OutlineView;
using ICSharpCode.WpfDesign.Designer.Services;
using ICSharpCode.WpfDesign.Designer.Extensions;
using ICSharpCode.WpfDesign.Extensions;
Expand Down Expand Up @@ -73,6 +74,7 @@ public XamlDesignContext(XmlReader xamlReader, XamlLoadSettings loadSettings)
this.Services.AddService(typeof(IToolService), new DefaultToolService(this));
this.Services.AddService(typeof(UndoService), new UndoService());
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(OptionService), new OptionService());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ public override string TextValue
return null;
}
}


internal void SetValueOnInstance(object value)
{
_property.ValueOnInstance = value;
}

// There may be multiple XamlModelProperty instances for the same property,
// so this class may not have any mutable fields / events - instead,
// we forward all event handlers to the XamlProperty.
Expand Down Expand Up @@ -195,7 +200,7 @@ public override string TextValue
_property.IsSetChanged -= value;
}
}

public override void SetValue(object value)
{
XamlPropertyValue newValue;
Expand Down Expand Up @@ -251,6 +256,7 @@ public sealed class PropertyChangeAction : ITransactionItem
{
readonly XamlModelProperty property;
readonly XamlPropertyValue oldValue;
readonly object oldValueOnInstance;
XamlPropertyValue newValue;
readonly bool oldIsSet;
bool newIsSet;
Expand All @@ -264,6 +270,7 @@ public PropertyChangeAction(XamlModelProperty property, XamlPropertyValue newVal

oldIsSet = property._property.IsSet;
oldValue = property._property.PropertyValue;
oldValueOnInstance = property._property.ValueOnInstance;

if (oldIsSet && oldValue == null && property.IsCollection) {
collectionTransactionItem = property._collectionElements.CreateResetTransaction();
Expand Down Expand Up @@ -300,8 +307,18 @@ public void Undo()
property.SetValueInternal(oldValue);
}
}
else
else {
if (property.DependencyProperty == null) {
try
{
property.SetValueOnInstance(oldValueOnInstance);
}
catch(Exception)
{ }
}

property.ResetInternal();
}
}

public System.Collections.Generic.ICollection<DesignItem> AffectedElements {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ internal XamlTextValue(XamlDocument document, XmlAttribute attribute)
internal XamlTextValue(XamlDocument document, string textValue)
{
this.document = document;
if (textValue.StartsWith("{"))
textValue = "{}" + textValue;
this.textValue = textValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ public void AddService(Type serviceInterface, object serviceInstance)
}
}

/// <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>
/// Gets the service object of the specified type.
/// Returns null when the service is not available.
Expand Down
13 changes: 13 additions & 0 deletions src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ public interface IPropertyDescriptionService
}
#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
/// <summary>
/// Service for showing error UI.
Expand Down
Binary file modified src/Libraries/WPFExtendedToolkit/Xceed.Wpf.Toolkit.dll
Binary file not shown.