Exemplo n.º 1
0
        public async Task RestoreFromClipboard(int posx, int posy)
        {
            DataPackageView dataPackage = Clipboard.GetContent();

            if (dataPackage != null)
            {
                if (dataPackage.Contains(StandardDataFormats.Text))
                {
                    String NodeText = await dataPackage.GetTextAsync();

                    MindNode clipNode = filemanager.RestoreNode(NodeText);
                    //string test = "";
                    if (clipNode.height > 0 && clipNode.width > 0)
                    {
                        clipNode.SetPosition(posx, posy, true);
                        clipNode.updateRepresentation();
                        clipNode.ReIDChilds();
                        GlobalNodeHandler.viewNode.AddChild(clipNode, false);
                        GlobalNodeHandler.actionLog.AddAction(new MindNodeAction(0, "CreateNode", clipNode));
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void UndoLast()
        {
            if (undoactions.Count >= 1)
            {
                MindNodeAction action = undoactions.Last();
                undoactions.Remove(action);
                switch (action.name)
                {
                case "CreateNode":
                    if (action.involvedNodes.Count >= 1)
                    {
                        MindNode createdNode = action.involvedNodes.Pop();
                        redoactions.Add(new MindNodeAction(1, "DeleteNode", createdNode));
                        createdNode.DeleteNode();
                    }
                    break;

                case "DeleteNode":
                    if (action.involvedNodes.Count >= 1)
                    {
                        MindNode deletednode = action.involvedNodes.Pop();
                        redoactions.Add(new MindNodeAction(0, "CreateNode", deletednode));
                        if (deletednode.parent != null)
                        {
                            deletednode.parent.AddChildNoStyle(deletednode, false);
                        }
                        // Refresh Pivot Representation after reinstating node
                        deletednode.UpdatePivots();
                    }
                    break;

                case "MoveNodes":
                    if (action.involvedNodes.Count >= 1)
                    {
                        MindNodeAction newaction = new MindNodeAction(2, "MoveNodes");
                        foreach (MindNode movedNode in action.involvedNodes)
                        {
                            newaction.involvedNodes.Push(movedNode);
                            newaction.startpoint.Push(new CalcPoint(movedNode.xpos, movedNode.ypos));

                            if (action.startpoint.Count > 0)
                            {
                                CalcPoint oldPos = action.startpoint.Pop();

                                movedNode.SetPosition(oldPos.X, oldPos.Y, false);
                            }
                            // Refresh Pivot Representation after moving node
                            movedNode.UpdatePivots();
                        }
                        redoactions.Add(newaction);
                    }
                    break;

                case "ConnectNodes":
                    if (action.involvedNodes.Count >= 2)
                    {
                        MindNodeAction newAction = new MindNodeAction(3, "DeleteConnections");
                        for (int i = 0; i < action.involvedNodes.Count / 2; i++)
                        {
                            MindNode rightnode = action.involvedNodes.Pop();
                            MindNode leftnode  = action.involvedNodes.Pop();

                            newAction.involvedNodes.Push(leftnode);
                            newAction.involvedNodes.Push(rightnode);

                            leftnode.DeleteConnection(rightnode);
                        }
                        redoactions.Add(newAction);
                    }
                    break;

                case "DeleteConnections":
                    if (action.involvedNodes.Count >= 2)
                    {
                        MindNodeAction newAction = new MindNodeAction(3, "ConnectNodes");
                        for (int i = 0; i < action.involvedNodes.Count / 2; i++)
                        {
                            MindNode rightnode = action.involvedNodes.Pop();
                            MindNode leftnode  = action.involvedNodes.Pop();

                            newAction.involvedNodes.Push(leftnode);
                            newAction.involvedNodes.Push(rightnode);

                            leftnode.AddConnection(rightnode);

                            // Refresh Pivot Representation after reinstating connection
                            leftnode.UpdatePivots();
                        }

                        redoactions.Add(newAction);
                    }
                    break;

                case "ChangeText":
                    if (action.involvedNodes.Count >= 1)
                    {
                        MindNodeAction newaction = new MindNodeAction(4, "ChangeText");

                        MindNode changedNode = action.involvedNodes.Pop();
                        newaction.text = changedNode.text;
                        newaction.involvedNodes.Push(changedNode);

                        changedNode.SetText(action.text);

                        redoactions.Add(newaction);
                    }
                    else if (action.involvedLabel != null)
                    {
                        MindNodeAction newaction = new MindNodeAction(4, "ChangeText");

                        NodeLabel changedLabel = action.involvedLabel;
                        newaction.text          = changedLabel.GetText();
                        newaction.involvedLabel = changedLabel;

                        changedLabel.SetText(action.text);

                        redoactions.Add(newaction);
                    }
                    break;

                case "Transform":
                    if (action.involvedNodes.Count >= 1)
                    {
                        MindNodeAction newaction = new MindNodeAction(5, "Transform");

                        MindNode changedNode = action.involvedNodes.Pop();
                        newaction.sourceSize.X = changedNode.width;
                        newaction.sourceSize.Y = changedNode.height;
                        newaction.startpoint.Push(new CalcPoint(changedNode.xpos, changedNode.ypos));
                        newaction.involvedNodes.Push(changedNode);

                        if (action.sourceSize.X != -1)
                        {
                            changedNode.width = action.sourceSize.X;
                            changedNode.SetScaled(false);
                        }
                        if (action.sourceSize.Y != -1)
                        {
                            changedNode.height = action.sourceSize.Y;
                            changedNode.SetScaled(false);
                        }

                        CalcPoint oldPos = action.startpoint.Pop();
                        if (oldPos != null)
                        {
                            changedNode.SetPosition(oldPos.X, oldPos.Y, false);
                        }

                        // Refresh Pivot Representation after resetting transformation
                        changedNode.UpdatePivots();
                        changedNode.updateRepresentation();

                        redoactions.Add(newaction);
                    }
                    break;
                }
            }
        }
Exemplo n.º 3
0
        public async Task ReadFile(String path, IStorageFile fiel)
        {
            try
            {
                MindNode newMasterNode = new MindNode(0, 0, 0, 0, 0, false);

                string fullText = await Windows.Storage.FileIO.ReadTextAsync(fiel, Windows.Storage.Streams.UnicodeEncoding.Utf8);

                System.Xml.Linq.XDocument xmlFile = null;
                try
                {
                    xmlFile = System.Xml.Linq.XDocument.Parse(fullText);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("No valid XML File falling back to text parser!");
                }

                if (xmlFile == null)
                {
                    IList <String> text = await Windows.Storage.FileIO.ReadLinesAsync(fiel, Windows.Storage.Streams.UnicodeEncoding.Utf8);

                    String[] FileLines    = text.ToArray();
                    MindNode selectedNode = null;

                    Stack <MindNode> Selnodes   = new Stack <MindNode>();
                    Stack <int>      connIds    = new Stack <int>();
                    Stack <Color>    conncolors = new Stack <Color>();
                    Stack <String>   connnames  = new Stack <String>();

                    for (int i = 0; i < FileLines.Length; i++)
                    {
                        String[] atts = FileLines[i].Split(':', '/');
                        switch (atts[0])
                        {
                        case "ID":
                            selectedNode = newMasterNode.GetExistingNode(int.Parse(atts[1]));
                            break;

                        case "TextPos":
                            if (selectedNode != null)
                            {
                                selectedNode.textpos.X = int.Parse(atts[1]);
                                selectedNode.textpos.Y = int.Parse(atts[2]);
                            }
                            break;

                        case "TextFormat":
                            if (selectedNode != null)
                            {
                                CanvasTextFormat newFormat = new CanvasTextFormat();
                                newFormat.FontSize   = int.Parse(atts[1]);
                                newFormat.FontFamily = atts[2];
                                if (atts[3].Equals("Italic"))
                                {
                                    newFormat.FontStyle = Windows.UI.Text.FontStyle.Italic;
                                }
                                else
                                {
                                    newFormat.FontStyle = Windows.UI.Text.FontStyle.Normal;
                                }
                                if (atts[4].Equals("Bold"))
                                {
                                    newFormat.FontWeight = FontWeights.Bold;
                                }
                                else
                                {
                                    newFormat.FontWeight = FontWeights.Normal;
                                }

                                selectedNode.SetTextStyle(newFormat);
                                selectedNode.TextColor = GetColorFromHexString(atts[5]);
                            }
                            break;

                        case "Name":
                            if (selectedNode != null)
                            {
                                selectedNode.SetText(atts[1]);
                            }
                            break;

                        case "NodeStyle":
                            if (selectedNode != null)
                            {
                                selectedNode.NodeDrawingStyle = DrawingStyle.ELLIPSE;

                                if ((atts[1]).Equals(DrawingStyle.BUTTON.ToString()))
                                {
                                    selectedNode.NodeDrawingStyle = DrawingStyle.BUTTON;
                                }
                                if ((atts[1]).Equals(DrawingStyle.CIRCLE.ToString()))
                                {
                                    selectedNode.NodeDrawingStyle = DrawingStyle.CIRCLE;
                                }
                                if ((atts[1]).Equals(DrawingStyle.ELLIPSEEDGE.ToString()))
                                {
                                    selectedNode.NodeDrawingStyle = DrawingStyle.ELLIPSEEDGE;
                                }
                                if ((atts[1]).Equals(DrawingStyle.RECTANGLE.ToString()))
                                {
                                    selectedNode.NodeDrawingStyle = DrawingStyle.RECTANGLE;
                                }
                            }
                            break;

                        case "Color":
                            if (selectedNode != null)
                            {
                                selectedNode.TextColor   = GetColorFromHexString(atts[1]);
                                selectedNode.BorderColor = GetColorFromHexString(atts[2]);
                                selectedNode.NodeColor   = GetColorFromHexString(atts[3]);
                            }
                            break;

                        case "Bounds":
                            if (selectedNode != null)
                            {
                                selectedNode.width  = int.Parse(atts[3]);
                                selectedNode.height = int.Parse(atts[4]);
                                selectedNode.SetPosition(int.Parse(atts[1]), int.Parse(atts[2]), false);
                            }
                            break;

                        case "Scaled":
                            if (selectedNode != null)
                            {
                                selectedNode.SetScaled(true);
                            }
                            break;

                        case "ConnNodes":
                            for (int c = 1; c < atts.Length; c++)
                            {
                                if (atts[c].Length >= 1)
                                {
                                    Selnodes.Push(selectedNode);
                                    connIds.Push(int.Parse(atts[c]));
                                }
                            }
                            break;

                        case "ConnColors":
                            for (int c = 1; c < atts.Length; c++)
                            {
                                if (atts[c].Length >= 1)
                                {
                                    conncolors.Push(GetColorFromHexString(atts[c]));
                                }
                            }
                            break;

                        case "ConnNames":
                            for (int c = 1; c < atts.Length; c++)
                            {
                                if (atts[c].Length >= 1)
                                {
                                    connnames.Push(atts[c]);
                                }
                            }
                            break;

                        case "Childs":
                            for (int c = 1; c < atts.Length; c++)
                            {
                                if (atts[c].Length >= 1)
                                {
                                    MindNode newNode = newMasterNode.GetExistingNode(int.Parse(atts[c]));
                                    if (newNode == null)
                                    {
                                        newNode = new MindNode(int.Parse(atts[c]), 0, 0, 0, 0, false);
                                    }
                                    selectedNode.AddChild(newNode, true);
                                }
                            }

                            break;
                        }
                    }

                    MindNode m;
                    String   connText;
                    Color    ncolor;
                    while (Selnodes.Count > 0)
                    {
                        m        = newMasterNode.GetExistingNode(connIds.Pop());
                        connText = connnames.Pop();
                        ncolor   = conncolors.Pop();
                        MindNode selectednode = Selnodes.Pop();
                        selectednode.AddConnection(m, ncolor, connText);
                    }
                }

                GlobalNodeHandler.masterNode = newMasterNode;

                if (xmlFile != null)
                {
                    GlobalNodeHandler.masterNode.FromRepresentation(xmlFile);
                }

                GlobalNodeHandler.masterNode.UpdateAllWidths();
            }
            catch
            {
            }
        }