Exemplo n.º 1
0
        public static OutlineItem LoadFromClipboard()
        {
            if (Clipboard.ContainsText())
            {
                var clipboardText = Clipboard.GetText();

                try
                {
                    var xmlElement = XElement.Parse(clipboardText);

                    var item = OutlineItem.CreateFromXmlElement(xmlElement);

                    return(item);
                }
                catch (Exception)
                {
                    return(null);
                }
            }

            return(null);

            /*
             * var clipboardAdapter = new OutlineItemCollectionClipboardAdapter();
             * var itemCollection = clipboardAdapter.GetItemCollection();
             *
             * if (itemCollection != null && itemCollection.Count > 0)
             * {
             *  return itemCollection[0];
             * }
             *
             * return null;*/
        }
Exemplo n.º 2
0
        public static void ReplaceWith(this OutlineItem itemToReplace, OutlineItem item)
        {
            var parent = itemToReplace.ParentItem;
            var index  = itemToReplace.IndexInParent();

            parent.Items.RemoveAt(index);
            parent.Items.Insert(index, item);
        }
Exemplo n.º 3
0
        public static int IndexInParent(this OutlineItem item)
        {
            if (item.ParentItem != null)
            {
                return(item.ParentItem.Items.IndexOf(item));
            }

            return(-1);
        }
Exemplo n.º 4
0
        public OutlineItem Clone()
        {
            //Temporary solution. Todo: Implement  copy constructor.

            var thisItemAsXmlElement = ToXmlElement();
            var clone = OutlineItem.CreateFromXmlElement(thisItemAsXmlElement);

            return(clone);
        }
Exemplo n.º 5
0
        public static OutlineItem PreviousItem(this OutlineItem item)
        {
            var prevSibling = item.PreviousSibling();

            if (prevSibling != null)
            {
                return(prevSibling);
            }

            return(item.ParentItem);
        }
Exemplo n.º 6
0
        public static bool IsFirstChildOfParent(this OutlineItem item)
        {
            if (item.IndexInParent() == 0)
            {
                return(true);
            }

            if (item.IndexInParent() == -1)
            {
                throw new InvalidOperationException();
            }

            return(false);
        }
Exemplo n.º 7
0
        public static bool IsLastChildOfParent(this OutlineItem item)
        {
            var indexInParent = item.IndexInParent();

            if (indexInParent != -1)
            {
                if (item.ParentItem.Items.Count == indexInParent + 1)
                {
                    return(true);
                }
            }

            throw new InvalidOperationException();
        }
Exemplo n.º 8
0
        public static OutlineDocument CreateFromXmlElement(XElement xmlElement)
        {
            if (xmlElement == null)
            {
                throw new ArgumentNullException(nameof(xmlElement));
            }

            if (xmlElement.Name != "SimpleOutlineDocument")
            {
                throw new DecodingException();
            }

            if (xmlElement.Attributes().Count() > 0)
            {
                throw new DecodingException();
            }

            if (xmlElement.Elements().SingleOrDefault(e => e.Name != "Outline") != null)
            {
                throw new DecodingException();
            }

            if (xmlElement.Elements().SingleOrDefault(e => e.Name == "Outline") == null)
            {
                throw new DecodingException();
            }

            var xmlOutlineElement = xmlElement.Element("Outline");

            if (xmlOutlineElement.Attributes().Count() > 0)
            {
                throw new DecodingException();
            }

            if (xmlOutlineElement.Elements("Item").Count() != 1)
            {
                throw new DecodingException();
            }

            var thisOutlineDocument = new OutlineDocument();

            var rootItemXmlElement = xmlOutlineElement.Element("Item");
            var rootOutlineItem    = OutlineItem.CreateFromXmlElement(rootItemXmlElement);

            thisOutlineDocument.Items[0] = rootOutlineItem;

            return(thisOutlineDocument);
        }
Exemplo n.º 9
0
        public static OutlineItem PreviousSibling(this OutlineItem item)
        {
            var indexInParent = item.IndexInParent();

            if (indexInParent == -1)
            {
                return(null);
            }

            if (!item.IsFirstChildOfParent())
            {
                return(item.ParentItem.Items[indexInParent - 1]);
            }

            return(null);
        }
Exemplo n.º 10
0
        public static OutlineItem NextSibling(this OutlineItem item)
        {
            var indexInParent = item.IndexInParent();

            if (indexInParent == -1)
            {
                return(null);
            }

            if (!item.IsLastChildOfParent())
            {
                return(item.ParentItem.Items[indexInParent + 1]);
            }

            return(null);
        }
Exemplo n.º 11
0
        public static OutlineItem CreateFromXmlElement(XElement xmlElement)
        {
            if (xmlElement == null)
            {
                throw new ArgumentNullException(nameof(xmlElement));
            }

            if (xmlElement.Name != "Item")
            {
                throw new DecodingException();
            }

            if (xmlElement.Attributes().SingleOrDefault(attr => attr.Name == "Name") == null)
            {
                throw new DecodingException();
            }

            if (xmlElement.Attributes().SingleOrDefault(attr => attr.Name != "Name") != null)
            {
                throw new DecodingException();
            }

            if (xmlElement.Elements().SingleOrDefault(elem => elem.Name != "Item") != null)
            {
                throw new DecodingException();
            }

            var thisOutlineItemName = xmlElement.Attribute("Name").Value.ToString();
            var thisOutlineItem     = new OutlineItem(thisOutlineItemName);

            foreach (XElement childOutlineItemXmlElement in xmlElement.Elements("Item"))
            {
                var childOutlineItem = OutlineItem.CreateFromXmlElement(childOutlineItemXmlElement);
                thisOutlineItem.Items.Add(childOutlineItem);
            }

            return(thisOutlineItem);
        }
Exemplo n.º 12
0
        public static OutlineItem NextItem(this OutlineItem item)
        {
            if (item.Items.Count != 0)
            {
                return(item.Items[0]);
            }

            var nextSibling = item.NextSibling();

            if (nextSibling != null)
            {
                return(nextSibling);
            }

            var parentOfItem = item.ParentItem;

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

            return(parentOfItem.NextSibling());
        }