Example #1
0
        private void DesignPanel_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down)
            {
                e.Handled = true;

                if (placementOp != null)
                {
                    placementOp.Commit();
                    placementOp = null;
                }
            }
            //pass the key event to the underlying objects if they have implemented IKeyUp interface
            //OBS!!!! this call needs to be here, after the placementOp.Commit().
            //In case the underlying object has a operation of its own this operation needs to be commited first
            foreach (DesignItem di in Context.Services.Selection.SelectedItems.Reverse())
            {
                foreach (Extension ext in di.Extensions)
                {
                    var keyUp = ext as IKeyUp;
                    if (keyUp != null)
                    {
                        keyUp.KeyUpAction(sender, e);
                    }
                }
            }
        }
Example #2
0
        private void DesignPanel_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down)
            {
                e.Handled = true;

                if (placementOp != null)
                {
                    placementOp.Commit();
                    placementOp = null;
                }
            }
        }
        protected override void OnMouseUp(object sender, MouseButtonEventArgs e)
        {
            if (hasDragStarted)
            {
                if (operation != null)
                {
                    operation.Commit();
                    operation = null;
                }
            }
            else
            {
                CreateComponentTool.AddItemWithDefaultSize(container, createdItem, e.GetPosition(positionRelativeTo));
            }
            if (changeGroup != null)
            {
                changeGroup.Commit();
                changeGroup = null;
            }

            if (designPanel.Context.Services.Component is XamlComponentService)
            {
                ((XamlComponentService)designPanel.Context.Services.Component).RaiseComponentRegisteredAndAddedToContainer(createdItem);
            }

            base.OnMouseUp(sender, e);
        }
 void drag_Completed(DragListener drag)
 {
     if (operation != null)
     {
         if (drag.IsCanceled)
         {
             operation.Abort();
         }
         else
         {
             operation.Commit();
         }
         operation = null;
     }
     else
     {
         if (drag.IsCanceled)
         {
             changeGroup.Abort();
         }
         else
         {
             changeGroup.Commit();
         }
         changeGroup = null;
     }
     _isResizing = false;
     HideSizeAndShowHandles();
 }
Example #5
0
 public void Stop()
 {
     if (operation != null)
     {
         operation.Commit();
         operation = null;
     }
 }
        internal static void Resize(Rect rect, params DesignItem[] items)
        {
            PlacementOperation operation = PlacementOperation.Start(items, PlacementType.Resize);

            foreach (var info in operation.PlacedItems)
            {
                info.Bounds = rect;
                operation.CurrentContainerBehavior.SetPosition(info);
            }
            operation.Commit();
        }
        internal static void Move(Vector v, params DesignItem[] items)
        {
            PlacementOperation operation = PlacementOperation.Start(items, PlacementType.Move);

            foreach (PlacementInformation info in operation.PlacedItems)
            {
                info.Bounds = new Rect(info.OriginalBounds.Left + v.X,
                                       info.OriginalBounds.Top + v.Y,
                                       info.OriginalBounds.Width,
                                       info.OriginalBounds.Height);
                operation.CurrentContainerBehavior.SetPosition(info);
            }
            operation.Commit();
        }
        private bool AddItemsWithCustomSize(DesignItem container, DesignItem[] createdItems, IList <Rect> positions)
        {
            PlacementOperation operation = null;

            while (operation == null && container != null)
            {
                operation = PlacementOperation.TryStartInsertNewComponents(
                    container,
                    createdItems,
                    positions,
                    PlacementType.AddItem
                    );

                if (operation != null)
                {
                    break;
                }

                try
                {
                    if (container.Parent != null)
                    {
                        var rel = container.View.TranslatePoint(new Point(0, 0), container.Parent.View);
                        for (var index = 0; index < positions.Count; index++)
                        {
                            positions[index] = new Rect(new Point(positions[index].X + rel.X, positions[index].Y + rel.Y), positions[index].Size);
                        }
                    }
                }
                catch (Exception)
                { }

                container = container.Parent;
            }

            if (operation != null)
            {
                container.Services.Selection.SetSelectedComponents(createdItems);
                operation.Commit();
                return(true);
            }
            else
            {
                return(false);
            }
        }
        internal static bool AddItemWithCustomSize(DesignItem container, DesignItem createdItem, Point position, Size size)
        {
            PlacementOperation operation = PlacementOperation.TryStartInsertNewComponents(
                container,
                new DesignItem[] { createdItem },
                new Rect[] { new Rect(position, size).Round() },
                PlacementType.AddItem
                );

            if (operation != null)
            {
                container.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem });
                operation.Commit();
                return(true);
            }
            else
            {
                return(false);
            }
        }
        internal static bool AddItemsWithCustomSize(DesignItem container, DesignItem[] createdItems, IList <Rect> positions)
        {
            PlacementOperation operation = PlacementOperation.TryStartInsertNewComponents(
                container,
                createdItems,
                positions,
                PlacementType.AddItem
                );

            if (operation != null)
            {
                container.Services.Selection.SetSelectedComponents(createdItems);
                operation.Commit();
                return(true);
            }
            else
            {
                return(false);
            }
        }
 protected override void OnMouseUp(object sender, MouseButtonEventArgs e)
 {
     if (hasDragStarted)
     {
         if (operation != null)
         {
             operation.Commit();
             operation = null;
         }
     }
     else
     {
         CreateComponentTool.AddItemWithDefaultSize(container, createdItem, e.GetPosition(positionRelativeTo));
     }
     if (changeGroup != null)
     {
         changeGroup.Commit();
         changeGroup = null;
     }
     base.OnMouseUp(sender, e);
 }
 void drag_Rotate_Completed(ICSharpCode.WpfDesign.Designer.Controls.DragListener drag)
 {
     operation.Commit();
 }
Example #13
0
 void drag_Rotate_Completed(DragListener drag)
 {
     operation.Commit();
 }
Example #14
0
        public static Tuple <DesignItem, Rect> WrapItemsNewContainer(IEnumerable <DesignItem> items, Type containerType, bool doInsert = true)
        {
            var collection = items;

            var _context = collection.First().Context as XamlDesignContext;

            var container = collection.First().Parent;

            if (collection.Any(x => x.Parent != container))
            {
                return(null);
            }

            //Change Code to use the Placment Operation!
            var placement = container.Extensions.OfType <IPlacementBehavior>().FirstOrDefault();

            if (placement == null)
            {
                return(null);
            }

            var operation = PlacementOperation.Start(items.ToList(), PlacementType.Move);

            var        newInstance = _context.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory(containerType, null);
            DesignItem newPanel    = _context.Services.Component.RegisterComponentForDesigner(newInstance);

            List <ItemPos> itemList = new List <ItemPos>();

            foreach (var item in collection)
            {
                itemList.Add(GetItemPos(operation, item));
                //var pos = placement.GetPosition(null, item);
                if (container.Component is Canvas)
                {
                    item.Properties.GetAttachedProperty(Canvas.RightProperty).Reset();
                    item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset();
                    item.Properties.GetAttachedProperty(Canvas.TopProperty).Reset();
                    item.Properties.GetAttachedProperty(Canvas.BottomProperty).Reset();
                }
                else if (container.Component is Grid)
                {
                    item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).Reset();
                    item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).Reset();
                    item.Properties.GetProperty(FrameworkElement.MarginProperty).Reset();
                }

                var parCol = item.ParentProperty.CollectionElements;
                parCol.Remove(item);
            }

            var xmin = itemList.Min(x => x.Xmin);
            var xmax = itemList.Max(x => x.Xmax);
            var ymin = itemList.Min(x => x.Ymin);
            var ymax = itemList.Max(x => x.Ymax);

            foreach (var item in itemList)
            {
                if (newPanel.Component is Canvas)
                {
                    if (item.HorizontalAlignment == HorizontalAlignment.Right)
                    {
                        item.DesignItem.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(xmax - item.Xmax);
                    }
                    else
                    {
                        item.DesignItem.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(item.Xmin - xmin);
                    }

                    if (item.VerticalAlignment == VerticalAlignment.Bottom)
                    {
                        item.DesignItem.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(ymax - item.Ymax);
                    }
                    else
                    {
                        item.DesignItem.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(item.Ymin - ymin);
                    }

                    newPanel.ContentProperty.CollectionElements.Add(item.DesignItem);
                }
                else if (newPanel.Component is Grid)
                {
                    Thickness thickness = new Thickness(0);
                    if (item.HorizontalAlignment == HorizontalAlignment.Right)
                    {
                        item.DesignItem.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).SetValue(HorizontalAlignment.Right);
                        thickness.Right = xmax - item.Xmax;
                    }
                    else
                    {
                        item.DesignItem.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).SetValue(HorizontalAlignment.Left);
                        thickness.Left = item.Xmin - xmin;
                    }

                    if (item.VerticalAlignment == VerticalAlignment.Bottom)
                    {
                        item.DesignItem.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).SetValue(VerticalAlignment.Bottom);
                        thickness.Bottom = ymax - item.Ymax;
                    }
                    else
                    {
                        item.DesignItem.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).SetValue(VerticalAlignment.Top);
                        thickness.Top = item.Ymin - ymin;
                    }

                    item.DesignItem.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(thickness);

                    newPanel.ContentProperty.CollectionElements.Add(item.DesignItem);
                }
                else if (newPanel.Component is Viewbox)
                {
                    newPanel.ContentProperty.SetValue(item.DesignItem);
                }
            }

            if (doInsert)
            {
                PlacementOperation operation2 = PlacementOperation.TryStartInsertNewComponents(
                    container,
                    new[] { newPanel },
                    new[] { new Rect(xmin, ymin, xmax - xmin, ymax - ymin).Round() },
                    PlacementType.AddItem
                    );

                operation2.Commit();

                _context.Services.Selection.SetSelectedComponents(new[] { newPanel });
            }

            operation.Commit();

            return(new Tuple <DesignItem, Rect>(newPanel, new Rect(xmin, ymin, xmax - xmin, ymax - ymin).Round()));
        }