예제 #1
0
        public override bool Execute()
        {
            if (DragObjects.IsNullOrEmpty() || Target == null || DragDropMethod == DragTopicsMethod.None)
            {
                return(false);
            }

            Parents = new Dictionary <ChartObject, object>();
            Indices = new Dictionary <ChartObject, int>();

            switch (DragDropMethod)
            {
            case DragTopicsMethod.Copy:
                var data = new MapClipboardData(DragObjects);
                NewObjects     = PasteCommand.PasteObjectsTo(data, Document, Target);
                AfterSelection = NewObjects;
                return(true);

            case DragTopicsMethod.Move:
                if (DeleteCommand.DeleteObjects(DragObjects, Parents, Indices))
                {
                    foreach (var co in DragObjects)
                    {
                        co.Parent = Target;
                    }
                    AfterSelection = DragObjects;
                    return(true);
                }

                return(false);

            default:
                return(false);
            }
        }
예제 #2
0
        public static ChartObject[] PasteObjectsTo(MapClipboardData data, Document document, Topic target)
        {
            var chartObjects = data.GetChartObjects();

            if (!chartObjects.IsNullOrEmpty())
            {
                var newids = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                foreach (var co in chartObjects)
                {
                    if (co is Topic && !isTargetAllow((Topic)co, target))
                    {
                        continue;
                    }
                    if (!string.IsNullOrEmpty(co.ID))
                    {
                        string id = co.ID;
                        co.ID      = document.GetNextObjectID();
                        newids[id] = co.ID;
                    }
                }

                foreach (var co in chartObjects)
                {
                    if (co is Topic)
                    {
                        if (!isTargetAllow((Topic)co, target))
                        {
                            continue;
                        }

                        var t = (Topic)co;
                        target.Children.Add(t);

                        for (int j = t.Links.Count - 1; j >= 0; j--)
                        {
                            Link line = t.Links[j];
                            if (newids.ContainsKey(line.TargetID))
                            {
                                line.TargetID = (string)newids[line.TargetID];
                            }
                            else
                            {
                                t.Links.Remove(line);
                            }
                        }
                    }
                    else if (co is Widget)
                    {
                        target.Widgets.Add((Widget)co);
                    }
                }
            }

            return(chartObjects);
        }