示例#1
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));
        }
示例#2
0
        public static void ReadStyles(XDocument mapStyles, IDictionary <string, XMindStyle> stylesById)
        {
            var nodeStyles = mapStyles.Root.Element(Namespaces.Styles("styles"));

            if (nodeStyles == null)
            {
                return;
            }

            foreach (var style in nodeStyles.Elements(Namespaces.Styles("style")))
            {
                var id = style.AttributeValue("id");

                if (string.IsNullOrWhiteSpace(id))
                {
                    continue;
                }

                if (!style.IsAttributeEquals("type", "topic"))
                {
                    continue;
                }

                var properties = style.Element(Namespaces.Styles("topic-properties"));

                if (properties == null)
                {
                    continue;
                }

                var fillString = properties.AttributeValue(Namespaces.SVG("fill"));

                if (string.IsNullOrWhiteSpace(fillString) || !ColorRegex.IsMatch(fillString))
                {
                    continue;
                }

                int color;

                if (int.TryParse(fillString.Substring(1), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out color))
                {
                    stylesById[id] = new XMindStyle {
                        Color = color
                    };
                }
            }
        }
示例#3
0
 private static void WriteManifest(XDocument document)
 {
     document.Add(
         new XElement(Namespaces.Manifest("manifest"),
                      new XElement(Namespaces.Manifest("file-entry"),
                                   new XAttribute("full-path", "content.xml"),
                                   new XAttribute("media-type", "text/xml")),
                      new XElement(Namespaces.Manifest("file-entry"),
                                   new XAttribute("full-path", "styles.xml"),
                                   new XAttribute("media-type", "text/xml")),
                      new XElement(Namespaces.Manifest("file-entry"),
                                   new XAttribute("full-path", "META-INF"),
                                   new XAttribute("media-type", string.Empty)),
                      new XElement(Namespaces.Manifest("file-entry"),
                                   new XAttribute("full-path", "META-INF/manifest.xml"),
                                   new XAttribute("media-type", "text/xml"))));
 }
示例#4
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);
        }
示例#5
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))));
            }
        }
示例#6
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();
                }
            }
        }
示例#7
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);
        }
示例#8
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);
        }
示例#9
0
        public static void WriteContent(Document document, XDocument xMapStyles, IRenderer renderer)
        {
            var styles = new XElement(Namespaces.Styles("styles"));

            foreach (var node in document.Nodes)
            {
                var color = renderer.FindColor(node);

                if (color == null)
                {
                    continue;
                }

                var colorString = ColorsVectorHelper.ConvertToRGBString(color.Normal);

                var properties = new XElement(Namespaces.Styles("topic-properties"));

                if (node is RootNode || node.Parent is RootNode)
                {
                    properties.Add(new XAttribute(Namespaces.SVG("fill"), colorString));
                }
                else
                {
                    properties.Add(new XAttribute("border-line-color", colorString));
                    properties.Add(new XAttribute("line-color", colorString));
                }

                styles.Add(
                    new XElement(Namespaces.Styles("style"),
                                 new XAttribute("id", "s" + node.Id),
                                 new XAttribute("type", "topic"),
                                 properties));
            }

            xMapStyles.Add(
                new XElement(Namespaces.Styles("xmap-styles"),
                             new XAttribute("version", "2.0"),
                             new XAttribute(XNamespace.Xmlns + "svg", Namespaces.SVGNamespace),
                             styles));
        }
示例#10
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));
            }
        }