Browse Source

DragMoveMouseGesture bugfix: use coordinates relative to design panel because MoveLogic expects those.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4774 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
fb3be54913
  1. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/WindowClone.cs
  2. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs
  3. 14
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs
  4. 92
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MoveLogic.cs
  5. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  6. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs
  7. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceContainer.cs
  8. 62
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceRequiredException.cs
  9. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj

20
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/WindowClone.cs

@ -164,49 +164,45 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
set { SetValue(Window.WindowStyleProperty, value); } set { SetValue(Window.WindowStyleProperty, value); }
} }
#pragma warning disable 0067
// disable "event is never used" warning
/// <summary> /// <summary>
/// This event is never raised. (for compatibility with <see cref="Window"/> only). /// This event is never raised. (for compatibility with <see cref="Window"/> only).
/// </summary> /// </summary>
public event EventHandler Activated; public event EventHandler Activated { add {} remove {} }
/// <summary> /// <summary>
/// This event is never raised. (for compatibility with <see cref="Window"/> only). /// This event is never raised. (for compatibility with <see cref="Window"/> only).
/// </summary> /// </summary>
public event EventHandler Closed; public event EventHandler Closed { add {} remove {} }
/// <summary> /// <summary>
/// This event is never raised. (for compatibility with <see cref="Window"/> only). /// This event is never raised. (for compatibility with <see cref="Window"/> only).
/// </summary> /// </summary>
public event EventHandler Closing; public event EventHandler Closing { add {} remove {} }
/// <summary> /// <summary>
/// This event is never raised. (for compatibility with <see cref="Window"/> only). /// This event is never raised. (for compatibility with <see cref="Window"/> only).
/// </summary> /// </summary>
public event EventHandler ContentRendered; public event EventHandler ContentRendered { add {} remove {} }
/// <summary> /// <summary>
/// This event is never raised. (for compatibility with <see cref="Window"/> only). /// This event is never raised. (for compatibility with <see cref="Window"/> only).
/// </summary> /// </summary>
public event EventHandler Deactivated; public event EventHandler Deactivated { add {} remove {} }
/// <summary> /// <summary>
/// This event is never raised. (for compatibility with <see cref="Window"/> only). /// This event is never raised. (for compatibility with <see cref="Window"/> only).
/// </summary> /// </summary>
public event EventHandler LocationChanged; public event EventHandler LocationChanged { add {} remove {} }
/// <summary> /// <summary>
/// This event is never raised. (for compatibility with <see cref="Window"/> only). /// This event is never raised. (for compatibility with <see cref="Window"/> only).
/// </summary> /// </summary>
public event EventHandler SourceInitialized; public event EventHandler SourceInitialized { add {} remove {} }
/// <summary> /// <summary>
/// This event is never raised. (for compatibility with <see cref="Window"/> only). /// This event is never raised. (for compatibility with <see cref="Window"/> only).
/// </summary> /// </summary>
public event EventHandler StateChanged; public event EventHandler StateChanged { add {} remove {} }
#pragma warning restore
} }
/// <summary> /// <summary>

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs

@ -39,6 +39,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public virtual Rect GetPosition(PlacementOperation operation, DesignItem item) public virtual Rect GetPosition(PlacementOperation operation, DesignItem item)
{ {
if (item.View == null)
return Rect.Empty;
var p = item.View.TranslatePoint(new Point(), operation.CurrentContainer.View); var p = item.View.TranslatePoint(new Point(), operation.CurrentContainer.View);
return new Rect(p, item.View.RenderSize); return new Rect(p, item.View.RenderSize);
} }

14
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs

@ -20,31 +20,27 @@ namespace ICSharpCode.WpfDesign.Designer.Services
sealed class DragMoveMouseGesture : ClickOrDragMouseGesture sealed class DragMoveMouseGesture : ClickOrDragMouseGesture
{ {
bool isDoubleClick; bool isDoubleClick;
MoveLogic moveLogic; MoveLogic moveLogic;
internal DragMoveMouseGesture(DesignItem clickedOn, bool isDoubleClick) internal DragMoveMouseGesture(DesignItem clickedOn, bool isDoubleClick)
{ {
Debug.Assert(clickedOn != null); Debug.Assert(clickedOn != null);
this.isDoubleClick = isDoubleClick; this.isDoubleClick = isDoubleClick;
this.positionRelativeTo = clickedOn.Services.DesignPanel;
if (clickedOn.Parent != null)
this.positionRelativeTo = clickedOn.Parent.View;
else
this.positionRelativeTo = clickedOn.View;
moveLogic = new MoveLogic(clickedOn); moveLogic = new MoveLogic(clickedOn);
} }
protected override void OnDragStarted(MouseEventArgs e) protected override void OnDragStarted(MouseEventArgs e)
{ {
moveLogic.Start(startPoint); moveLogic.Start(startPoint);
} }
protected override void OnMouseMove(object sender, MouseEventArgs e) protected override void OnMouseMove(object sender, MouseEventArgs e)
{ {
base.OnMouseMove(sender, e); // call OnDragStarted if min. drag distace is reached base.OnMouseMove(sender, e); // call OnDragStarted if min. drag distace is reached
moveLogic.Move(e.GetPosition(positionRelativeTo)); moveLogic.Move(e.GetPosition(positionRelativeTo));
} }
protected override void OnMouseUp(object sender, MouseButtonEventArgs e) protected override void OnMouseUp(object sender, MouseButtonEventArgs e)

92
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MoveLogic.cs

@ -6,49 +6,49 @@ using System.Windows;
namespace ICSharpCode.WpfDesign.Designer.Services namespace ICSharpCode.WpfDesign.Designer.Services
{ {
class MoveLogic class MoveLogic
{ {
public MoveLogic(DesignItem clickedOn) public MoveLogic(DesignItem clickedOn)
{ {
this.clickedOn = clickedOn; this.clickedOn = clickedOn;
selectedItems = clickedOn.Services.Selection.SelectedItems; selectedItems = clickedOn.Services.Selection.SelectedItems;
if (!selectedItems.Contains(clickedOn)) if (!selectedItems.Contains(clickedOn))
selectedItems = SharedInstances.EmptyDesignItemArray; selectedItems = SharedInstances.EmptyDesignItemArray;
} }
DesignItem clickedOn; DesignItem clickedOn;
PlacementOperation operation; PlacementOperation operation;
ICollection<DesignItem> selectedItems; ICollection<DesignItem> selectedItems;
Point startPoint; Point startPoint;
public DesignItem ClickedOn { public DesignItem ClickedOn {
get { return clickedOn; } get { return clickedOn; }
} }
public PlacementOperation Operation { public PlacementOperation Operation {
get { return operation; } get { return operation; }
} }
public IDesignPanel DesignPanel { public IDesignPanel DesignPanel {
get { return clickedOn.Services.DesignPanel; } get { return clickedOn.Services.DesignPanel; }
} }
public void Start(Point p) public void Start(Point p)
{ {
startPoint = p; startPoint = p;
IPlacementBehavior b = PlacementOperation.GetPlacementBehavior(selectedItems); IPlacementBehavior b = PlacementOperation.GetPlacementBehavior(selectedItems);
if (b != null && b.CanPlace(selectedItems, PlacementType.Move, PlacementAlignment.TopLeft)) { if (b != null && b.CanPlace(selectedItems, PlacementType.Move, PlacementAlignment.TopLeft)) {
List<DesignItem> sortedSelectedItems = new List<DesignItem>(selectedItems); List<DesignItem> sortedSelectedItems = new List<DesignItem>(selectedItems);
sortedSelectedItems.Sort(ModelTools.ComparePositionInModelFile); sortedSelectedItems.Sort(ModelTools.ComparePositionInModelFile);
selectedItems = sortedSelectedItems; selectedItems = sortedSelectedItems;
operation = PlacementOperation.Start(selectedItems, PlacementType.Move); operation = PlacementOperation.Start(selectedItems, PlacementType.Move);
} }
} }
public void Move(Point p) public void Move(Point p)
{ {
if (operation != null) { if (operation != null) {
// try to switch the container // try to switch the container
if (operation.CurrentContainerBehavior.CanLeaveContainer(operation)) { if (operation.CurrentContainerBehavior.CanLeaveContainer(operation)) {
@ -60,45 +60,45 @@ namespace ICSharpCode.WpfDesign.Designer.Services
info.Bounds = new Rect(info.OriginalBounds.Left + v.X, info.Bounds = new Rect(info.OriginalBounds.Left + v.X,
info.OriginalBounds.Top + v.Y, info.OriginalBounds.Top + v.Y,
info.OriginalBounds.Width, info.OriginalBounds.Width,
info.OriginalBounds.Height); info.OriginalBounds.Height);
} }
operation.CurrentContainerBehavior.BeforeSetPosition(operation); operation.CurrentContainerBehavior.BeforeSetPosition(operation);
foreach (PlacementInformation info in operation.PlacedItems) { foreach (PlacementInformation info in operation.PlacedItems) {
operation.CurrentContainerBehavior.SetPosition(info); operation.CurrentContainerBehavior.SetPosition(info);
} }
} }
} }
public void Stop() public void Stop()
{ {
if (operation != null) { if (operation != null) {
operation.Commit(); operation.Commit();
operation = null; operation = null;
} }
} }
public void Cancel() public void Cancel()
{ {
if (operation != null) { if (operation != null) {
operation.Abort(); operation.Abort();
operation = null; operation = null;
} }
} }
// Perform hit testing on the design panel and return the first model that is not selected // Perform hit testing on the design panel and return the first model that is not selected
DesignPanelHitTestResult HitTestUnselectedModel(Point p) DesignPanelHitTestResult HitTestUnselectedModel(Point p)
{ {
DesignPanelHitTestResult result = DesignPanelHitTestResult.NoHit; DesignPanelHitTestResult result = DesignPanelHitTestResult.NoHit;
ISelectionService selection = clickedOn.Services.Selection; ISelectionService selection = clickedOn.Services.Selection;
DesignPanel.HitTest(p, false, true, delegate(DesignPanelHitTestResult r) { DesignPanel.HitTest(p, false, true, delegate(DesignPanelHitTestResult r) {
if (r.ModelHit == null) if (r.ModelHit == null)
return true; // continue hit testing return true; // continue hit testing
if (selection.IsComponentSelected(r.ModelHit)) if (selection.IsComponentSelected(r.ModelHit))
return true; // continue hit testing return true; // continue hit testing
result = r; result = r;
return false; // finish hit testing return false; // finish hit testing
}); });
return result; return result;
} }
@ -136,5 +136,5 @@ namespace ICSharpCode.WpfDesign.Designer.Services
} }
} }
} }
} }
} }

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

@ -169,7 +169,6 @@
<Compile Include="PropertyGrid\PropertyGridView.xaml.cs"> <Compile Include="PropertyGrid\PropertyGridView.xaml.cs">
<DependentUpon>PropertyGridView.xaml</DependentUpon> <DependentUpon>PropertyGridView.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="ServiceRequiredException.cs" />
<Compile Include="Services\ChooseClass.cs" /> <Compile Include="Services\ChooseClass.cs" />
<Compile Include="Services\ChooseClassDialog.xaml.cs"> <Compile Include="Services\ChooseClassDialog.xaml.cs">
<DependentUpon>ChooseClassDialog.xaml</DependentUpon> <DependentUpon>ChooseClassDialog.xaml</DependentUpon>

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

@ -116,9 +116,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
if (affectedItems == null) if (affectedItems == null)
throw new ArgumentNullException("affectedItems"); throw new ArgumentNullException("affectedItems");
UndoService undoService = this.Services.GetService<UndoService>(); UndoService undoService = this.Services.GetRequiredService<UndoService>();
if (undoService == null)
throw new ServiceRequiredException(typeof(UndoService));
UndoTransaction g = undoService.StartTransaction(affectedItems); UndoTransaction g = undoService.StartTransaction(affectedItems);
g.Title = changeGroupTitle; g.Title = changeGroupTitle;
return g; return g;

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

@ -96,11 +96,15 @@ namespace ICSharpCode.WpfDesign
} }
} }
T GetServiceOrThrowException<T>() where T : class /// <summary>
/// Gets a required service.
/// Never returns null; instead a ServiceRequiredException is thrown when the service cannot be found.
/// </summary>
public T GetRequiredService<T>() where T : class
{ {
T service = (T)GetService(typeof(T)); T service = (T)GetService(typeof(T));
if (service == null) { if (service == null) {
throw new DesignerException("Could not find guaranteed service " + typeof(T).FullName); throw new ServiceRequiredException(typeof(T));
} }
return service; return service;
} }
@ -111,7 +115,7 @@ namespace ICSharpCode.WpfDesign
/// </summary> /// </summary>
public ISelectionService Selection { public ISelectionService Selection {
get { get {
return GetServiceOrThrowException<ISelectionService>(); return GetRequiredService<ISelectionService>();
} }
} }
@ -121,7 +125,7 @@ namespace ICSharpCode.WpfDesign
/// </summary> /// </summary>
public IToolService Tool { public IToolService Tool {
get { get {
return GetServiceOrThrowException<IToolService>(); return GetRequiredService<IToolService>();
} }
} }
@ -131,7 +135,7 @@ namespace ICSharpCode.WpfDesign
/// </summary> /// </summary>
public IComponentService Component { public IComponentService Component {
get { get {
return GetServiceOrThrowException<IComponentService>(); return GetRequiredService<IComponentService>();
} }
} }
@ -141,7 +145,7 @@ namespace ICSharpCode.WpfDesign
/// </summary> /// </summary>
public ViewService View { public ViewService View {
get { get {
return GetServiceOrThrowException<ViewService>(); return GetRequiredService<ViewService>();
} }
} }
@ -151,7 +155,7 @@ namespace ICSharpCode.WpfDesign
/// </summary> /// </summary>
public Extensions.ExtensionManager ExtensionManager { public Extensions.ExtensionManager ExtensionManager {
get { get {
return GetServiceOrThrowException<Extensions.ExtensionManager>(); return GetRequiredService<Extensions.ExtensionManager>();
} }
} }
@ -161,7 +165,7 @@ namespace ICSharpCode.WpfDesign
/// </summary> /// </summary>
public IDesignPanel DesignPanel { public IDesignPanel DesignPanel {
get { get {
return GetServiceOrThrowException<IDesignPanel>(); return GetRequiredService<IDesignPanel>();
} }
} }
} }

62
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceRequiredException.cs

@ -0,0 +1,62 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Runtime.Serialization;
namespace ICSharpCode.WpfDesign
{
/// <summary>
/// Exception class used for designer failures.
/// </summary>
[Serializable]
public class ServiceRequiredException : DesignerException
{
/// <summary>
/// Gets the missing sevice.
/// </summary>
public Type ServiceType { get; private set; }
/// <summary>
/// Create a new ServiceRequiredException instance.
/// </summary>
public ServiceRequiredException(Type serviceType)
: this("Service " + serviceType.FullName + " is required.")
{
this.ServiceType = serviceType;
}
/// <summary>
/// Create a new ServiceRequiredException instance.
/// </summary>
public ServiceRequiredException()
{
}
/// <summary>
/// Create a new ServiceRequiredException instance.
/// </summary>
public ServiceRequiredException(string message) : base(message)
{
}
/// <summary>
/// Create a new ServiceRequiredException instance.
/// </summary>
public ServiceRequiredException(string message, Exception innerException) : base(message, innerException)
{
}
/// <summary>
/// Create a new ServiceRequiredException instance.
/// </summary>
protected ServiceRequiredException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj

@ -109,6 +109,7 @@
<Compile Include="PropertyGrid\TypeHelper.cs" /> <Compile Include="PropertyGrid\TypeHelper.cs" />
<Compile Include="ServiceContainer.cs" /> <Compile Include="ServiceContainer.cs" />
<Compile Include="DesignItem.cs" /> <Compile Include="DesignItem.cs" />
<Compile Include="ServiceRequiredException.cs" />
<Compile Include="Services.cs" /> <Compile Include="Services.cs" />
<Compile Include="Tools.cs" /> <Compile Include="Tools.cs" />
</ItemGroup> </ItemGroup>

Loading…
Cancel
Save