示例#1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="document"></param>
        public void Add(Document document)
        {
            if (document == null)
                return;

            document.PropertyChanged += DocumentObserver;

            Verbose("Add Document: " + document.Name);

            if (document.Containers != null)
            {
                foreach (var container in document.Containers)
                {
                    Add(container);
                }
            }
        }
示例#2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="item"></param>
 public void OnCopy(object item)
 {
     if (item is Container)
     {
         var container = item as Container;
         _containerToCopy = container;
         _documentToCopy = default(Document);
     }
     else if (item is Document)
     {
         var document = item as Document;
         _containerToCopy = default(Container);
         _documentToCopy = document;
     }
     else if (item is EditorContext || item == null)
     {
         OnCopy();
     }
 }
示例#3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="document"></param>
        public void Remove(Document document)
        {
            if (document == null)
                return;

            document.PropertyChanged -= DocumentObserver;

            Verbose("Remove Document: " + document.Name);

            if (document.Containers != null)
            {
                foreach (var container in document.Containers)
                {
                    Remove(container);
                }
            }
        }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        public Document Clone(Document document)
        {
            try
            {
                var templates = document.Containers.Select(c => c.Template).ToArray();
                var json = _serializer.Serialize(document);
                if (!string.IsNullOrEmpty(json))
                {
                    var clone = _serializer.Deserialize<Document>(json);
                    if (clone != null)
                    {
                        for (int i = 0; i < clone.Containers.Length; i++)
                        {
                            var container = clone.Containers[i];
                            var shapes = container.Layers.SelectMany(l => l.Shapes);
                            TryToRestoreStyles(shapes);
                            TryToRestoreRecords(shapes);
                            container.Template = templates[i];
                        }
                        return clone;
                    }
                }
            }
            catch (Exception ex)
            {
                if (_editor.Log != null)
                {
                    _editor.Log.LogError("{0}{1}{2}",
                        ex.Message,
                        Environment.NewLine,
                        ex.StackTrace);
                }
            }

            return null;
        }