예제 #1
0
 private static void WriteTitle(NodeBase node, XContainer topic)
 {
     if (!string.IsNullOrWhiteSpace(node.Text))
     {
         topic.Add(new XElement(Namespaces.Content("title"), node.Text));
     }
 }
예제 #2
0
        public static IEnumerable <ImportResult> ReadContent(XDocument content, IReadOnlyDictionary <string, XMindStyle> stylesById)
        {
            var sheets = content.Root.Elements(Namespaces.Content("sheet"));

            foreach (var sheet in sheets)
            {
                var title = sheet.Element(Namespaces.Content("title"))?.Value;

                var document = new Document(Guid.NewGuid());

                var root = sheet.Element(Namespaces.Content("topic"));

                if (root == null)
                {
                    continue;
                }

                ReadNode(root, document.Root, stylesById);

                if (string.IsNullOrWhiteSpace(title))
                {
                    title = document.Root.Text ?? "Untitled";
                }

                yield return(new ImportResult(document, title));
            }
        }
예제 #3
0
        private static void WriteChildrenBoundaries(IReadOnlyList <Node> children, XContainer topic, string timestamp)
        {
            if (!children.Any(x => x.IsShowingHull))
            {
                return;
            }

            var boundaries = new XElement(Namespaces.Content("boundaries"));

            for (var i = 0; i < children.Count; i++)
            {
                var child = children[i];

                if (child.IsShowingHull)
                {
                    boundaries.Add(
                        new XElement(Namespaces.Content("boundary"),
                                     new XAttribute("id", Guid.NewGuid()),
                                     new XAttribute("range", $"({i}, {i})"),
                                     new XAttribute("timestamp", timestamp)));
                }
            }

            topic.Add(boundaries);
        }
예제 #4
0
        private static void ReadTitle(this XContainer topic, NodeBase node)
        {
            var title = topic.ElementValue(Namespaces.Content("title"));

            if (!string.IsNullOrWhiteSpace(title))
            {
                node.ChangeTextTransactional(title);
            }
        }
예제 #5
0
        private static void WriteChildren(IReadOnlyCollection <Node> children, XContainer topic, string timestamp)
        {
            if (children.Count <= 0)
            {
                return;
            }

            var topics = new XElement(Namespaces.Content("topics"), new XAttribute("type", "attached"));

            foreach (var child in children)
            {
                topics.Add(CreateTopic(timestamp, child, child.Children));
            }

            topic.Add(new XElement(Namespaces.Content("children"), topics));
        }
예제 #6
0
        public static void WriteContent(Document document, XDocument content)
        {
            var timestamp = ((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString(CultureInfo.InvariantCulture);

            var allChildren = document.Root.RightChildren.Union(document.Root.LeftChildren).ToList();

            var root =
                new XElement(Namespaces.Content("xmap-content"),
                             new XAttribute("version", "2.0"),
                             new XAttribute("timestamp", timestamp),
                             new XElement(Namespaces.Content("sheet"),
                                          new XAttribute("id", Guid.NewGuid()),
                                          new XAttribute("timestamp", timestamp),
                                          new XElement(Namespaces.Content("title"), document.Root.Text),
                                          CreateTopic(timestamp, document.Root, allChildren)));

            content.Add(root);
        }
예제 #7
0
        private static void WriteMarker(NodeBase node, XContainer topic)
        {
            var keyIcon = node.Icon as KeyIcon;

            if (keyIcon == null)
            {
                return;
            }

            var marker = MarkerMapping.ResolveXmind(keyIcon.Key);

            if (marker != null)
            {
                topic.Add(
                    new XElement(Namespaces.Content("marker-refs"),
                                 new XElement(Namespaces.Content("marker-ref"),
                                              new XAttribute("marker-id", marker))));
            }
        }
예제 #8
0
        private static void ReadBounds(this XContainer topic, IReadOnlyList <NodeBase> children)
        {
            var boundaries = topic.Element(Namespaces.Content("boundaries"));

            if (boundaries == null)
            {
                return;
            }

            foreach (var boundary in boundaries.Elements(Namespaces.Content("boundary")))
            {
                var range = boundary.AttributeValue("range");

                if (range == null)
                {
                    continue;
                }

                range = range.Trim(' ', '(', ')');

                var parts = range.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                if (parts.Length != 2)
                {
                    continue;
                }

                int s;
                int e;

                if (!int.TryParse(parts[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out s) ||
                    !int.TryParse(parts[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out e))
                {
                    continue;
                }

                if (s == e && s >= 0 && s <= children.Count - 1)
                {
                    children[s].ToggleHullTransactional();
                }
            }
        }
예제 #9
0
        private static void ReadChildren(this XContainer topic, NodeBase node, IReadOnlyDictionary <string, XMindStyle> stylesById)
        {
            var children = new List <NodeBase>();

            var topics = topic.Element(Namespaces.Content("children"))?.Element(Namespaces.Content("topics"));

            if (topics != null && topics.IsAttributeEquals("type", "attached"))
            {
                foreach (var subtopic in topics.Elements(Namespaces.Content("topic")))
                {
                    var child = node.AddChildTransactional();

                    ReadNode(subtopic, child, stylesById);

                    children.Add(child);
                }
            }

            ReadBounds(topic, children);
        }
예제 #10
0
        private static XElement CreateTopic(string timestamp, NodeBase node, IReadOnlyList <Node> children)
        {
            var topic =
                new XElement(Namespaces.Content("topic"),
                             new XAttribute("id", node.Id),
                             new XAttribute("timestamp", timestamp),
                             new XAttribute("style-id", "s" + node.Id));

            if (node is RootNode)
            {
                topic.Add(new XAttribute("structure-class", "org.xmind.ui.map"));
            }

            WriteTitle(node, topic);
            WriteFolded(node, topic);
            WriteMarker(node, topic);
            WriteChildren(children, topic, timestamp);
            WriteChildrenBoundaries(children, topic, timestamp);

            return(topic);
        }
예제 #11
0
        private static void ReadMarker(this XContainer topic, NodeBase node)
        {
            var markerRefs = topic.Element(Namespaces.Content("marker-refs"));

            if (markerRefs == null)
            {
                return;
            }

            var markerId = markerRefs.Elements(Namespaces.Content("marker-ref")).Select(x => x.Attribute("marker-id")?.Value).FirstOrDefault(x => x != null);

            if (string.IsNullOrWhiteSpace(markerId))
            {
                return;
            }

            var icon = MarkerMapping.ResolveMindapp(markerId);

            if (icon != null)
            {
                node.ChangeIconTransactional(new KeyIcon(icon));
            }
        }