示例#1
0
        private void SaveTreeItem(StreamWriter Writer, TreeViewItem Item, int Depth)
        {
            // LocationData
            LocationData Data = DataHandler.GetLocationByTreeViewId(Item.Name);

            if (Data != null)
            {
                AddSpaces(Writer, Depth);   Writer.WriteLine("<LocationData>");
                AddSpaces(Writer, Depth + 1);   Writer.WriteLine("<TreeViewId>" + Data.TreeViewId + "</TreeViewId>");
                AddSpaces(Writer, Depth + 1);   Writer.WriteLine("<Guid>" + Data.Guid + "</Guid>");
                AddSpaces(Writer, Depth + 1);   Writer.WriteLine("<Description>" + Data.Description + "</Description>");
                AddSpaces(Writer, Depth + 1);   Writer.WriteLine("<Decisions>");
                foreach (LocationDecision Decision in Data.Decisions)
                {
                    if (Decision.Text != "" && Decision.LocationLink != "")
                    {
                        AddSpaces(Writer, Depth + 2); Writer.WriteLine("<LocationDecision>");
                        AddSpaces(Writer, Depth + 3); Writer.WriteLine("<Text>" + Decision.Text + "</Text>");
                        AddSpaces(Writer, Depth + 3); Writer.WriteLine("<LocationLink>" + Decision.LocationLink + "</LocationLink>");
                        if (Decision.Condition != null && Decision.Condition != "")
                        {
                            AddSpaces(Writer, Depth + 3);
                            Writer.WriteLine("<Condition>" + Decision.Condition + "</Condition>");
                        }
                        if (Decision.Action != null && Decision.Action != "")
                        {
                            AddSpaces(Writer, Depth + 3);
                            Writer.WriteLine("<Action>" + Decision.Action + "</Action>");
                        }
                        AddSpaces(Writer, Depth + 2); Writer.WriteLine("</LocationDecision>");
                    }
                }
                AddSpaces(Writer, Depth + 1);   Writer.WriteLine("</Decisions>");
                AddSpaces(Writer, Depth);   Writer.WriteLine("</LocationData>");
            }
            // LocationSelector
            LocationSelector Selector = DataHandler.GetSelectorByTreeViewId(Item.Name);

            if (Selector != null)
            {
                AddSpaces(Writer, Depth); Writer.WriteLine("<LocationSelector>");
                AddSpaces(Writer, Depth + 1); Writer.WriteLine("<TreeViewId>" + Selector.TreeViewId + "</TreeViewId>");
                AddSpaces(Writer, Depth + 1); Writer.WriteLine("<Guid>" + Selector.Guid + "</Guid>");
                AddSpaces(Writer, Depth + 1); Writer.WriteLine("<Options>");
                foreach (LocationSelectorEntry Option in Selector.Options)
                {
                    if (Option.Link != "")
                    {
                        AddSpaces(Writer, Depth + 2); Writer.WriteLine("<SelectorOption>");
                        AddSpaces(Writer, Depth + 3); Writer.WriteLine("<Link>" + Option.Link + "</Link>");
                        AddSpaces(Writer, Depth + 3); Writer.WriteLine("<Chance>" + Option.Chance + "</Chance>");
                        if (Option.Condition != null && Option.Condition != "")
                        {
                            AddSpaces(Writer, Depth + 3);
                            Writer.WriteLine("<Condition>" + Option.Condition + "</Condition>");
                        }
                        if (Option.Action != null && Option.Action != "")
                        {
                            AddSpaces(Writer, Depth + 3);
                            Writer.WriteLine("<Action>" + Option.Action + "</Action>");
                        }
                        AddSpaces(Writer, Depth + 2); Writer.WriteLine("</SelectorOption>");
                    }
                }
                AddSpaces(Writer, Depth + 1); Writer.WriteLine("</Options>");
                AddSpaces(Writer, Depth); Writer.WriteLine("</LocationSelector>");
            }

            if (Data == null && Selector == null)
            {
                AddSpaces(Writer, Depth); Writer.WriteLine("<Folder>");
                AddSpaces(Writer, Depth + 1); Writer.WriteLine("<Name>" + Item.Name + "</Name>");
                AddSpaces(Writer, Depth + 1); Writer.WriteLine("<Header>" + Item.Header + "</Header>");
                foreach (TreeViewItem Child in Item.Items)
                {
                    SaveTreeItem(Writer, Child, Depth + 1);
                }
                AddSpaces(Writer, Depth); Writer.WriteLine("</Folder>");
            }
        }
示例#2
0
        void LoadTreeStructure(String Filename)
        {
            ClearTreeView(Tree_Hierarchy);
            DataHandler.LocationList.Clear();
            WindowTitle.RemoveStar(this);

            bool                 ParsingData           = false;
            bool                 ParsingDecision       = false;
            bool                 ParsingSelector       = false;
            bool                 ParsingSelectorOption = false;
            TreeViewItem         Folder        = null;
            TreeViewItem         LocationItem  = null;
            LocationData         LocationEntry = null;
            LocationSelector     Selector      = null;
            Stack <TreeViewItem> Parent        = new Stack <TreeViewItem>();

            StreamReader Reader = new StreamReader(Filename, System.Text.Encoding.UTF8);

            while (!Reader.EndOfStream)
            {
                String Line = Reader.ReadLine();
                // Parsing location data
                if (Line.Contains("<LocationData>") == true)
                {
                    ParsingData   = true;
                    LocationItem  = DataHandler.AddLocation(this, Folder);
                    LocationEntry = new LocationData();
                    DataHandler.LocationList.Add(LocationEntry);
                }
                else if (Line.Contains("TreeViewId") == true && ParsingData)
                {
                    int StartIndex = Line.IndexOf("<TreeViewId>") + 12;
                    int EndIndex   = Line.IndexOf("</TreeViewId>");
                    LocationItem.Name             = Line.Substring(StartIndex, EndIndex - StartIndex);
                    LocationItem.ContextMenu.Name = LocationItem.Name;
                    LocationEntry.TreeViewId      = LocationItem.Name;
                }
                else if (Line.Contains("<Guid>") == true && ParsingData)
                {
                    int StartIndex = Line.IndexOf("<Guid>") + 6;
                    int EndIndex   = Line.IndexOf("</Guid>");
                    LocationEntry.Guid  = Line.Substring(StartIndex, EndIndex - StartIndex);
                    LocationItem.Header = LocationEntry.Guid;
                    if (LocationItem.Header.ToString().Length == 0)
                    {
                        LocationItem.Header = "Unnamed";
                    }
                }
                else if (Line.Contains("<Description>") == true && ParsingData)
                {
                    int StartIndex = Line.IndexOf("<Description>") + 13;
                    int EndIndex   = Line.IndexOf("</Description>");
                    LocationEntry.Description = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("<LocationDecision>") == true && ParsingData)
                {
                    ParsingDecision = true;
                    LocationEntry.Decisions.Add(new LocationDecision());
                }
                else if (Line.Contains("<Text>") == true && ParsingDecision)
                {
                    int StartIndex = Line.IndexOf("<Text>") + 6;
                    int EndIndex   = Line.IndexOf("</Text>");
                    LocationEntry.Decisions[LocationEntry.Decisions.Count - 1].Text = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("<LocationLink>") == true && ParsingDecision)
                {
                    int StartIndex = Line.IndexOf("<LocationLink>") + 14;
                    int EndIndex   = Line.IndexOf("</LocationLink>");
                    LocationEntry.Decisions[LocationEntry.Decisions.Count - 1].LocationLink = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("<Condition>") == true && ParsingDecision)
                {
                    int StartIndex = Line.IndexOf("<Condition>") + 11;
                    int EndIndex   = Line.IndexOf("</Condition>");
                    LocationEntry.Decisions[LocationEntry.Decisions.Count - 1].Condition = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("<Action>") == true && ParsingDecision)
                {
                    int StartIndex = Line.IndexOf("<Action>") + 8;
                    int EndIndex   = Line.IndexOf("</Action>");
                    LocationEntry.Decisions[LocationEntry.Decisions.Count - 1].Action = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("/LocationDecision>") == true)
                {
                    ParsingDecision = false;
                }
                else if (Line.Contains("</LocationData>") == true)
                {
                    LocationItem = null;
                    ParsingData  = false;
                }
                // Parsing location selector data
                else if (Line.Contains("<LocationSelector>") == true)
                {
                    ParsingSelector = true;
                    LocationItem    = DataHandler.AddSelector(this, Folder);
                    Selector        = new LocationSelector();
                    DataHandler.SelectorList.Add(Selector);
                }
                else if (Line.Contains("TreeViewId") == true && ParsingSelector)
                {
                    int StartIndex = Line.IndexOf("<TreeViewId>") + 12;
                    int EndIndex   = Line.IndexOf("</TreeViewId>");
                    LocationItem.Name             = Line.Substring(StartIndex, EndIndex - StartIndex);
                    LocationItem.ContextMenu.Name = LocationItem.Name;
                    Selector.TreeViewId           = LocationItem.Name;
                }
                else if (Line.Contains("<Guid>") == true && ParsingSelector)
                {
                    int StartIndex = Line.IndexOf("<Guid>") + 6;
                    int EndIndex   = Line.IndexOf("</Guid>");
                    Selector.Guid       = Line.Substring(StartIndex, EndIndex - StartIndex);
                    LocationItem.Header = Selector.Guid;
                    if (LocationItem.Header.ToString().Length == 0)
                    {
                        LocationItem.Header = "Unnamed";
                    }
                }
                else if (Line.Contains("<SelectorOption>") == true && ParsingSelector)
                {
                    ParsingSelectorOption = true;
                    Selector.Options.Add(new LocationSelectorEntry());
                }
                else if (Line.Contains("<Link>") == true && ParsingSelectorOption)
                {
                    int StartIndex = Line.IndexOf("<Link>") + 6;
                    int EndIndex   = Line.IndexOf("</Link>");
                    Selector.Options[Selector.Options.Count - 1].Link = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("<Chance>") == true && ParsingSelectorOption)
                {
                    int StartIndex = Line.IndexOf("<Chance>") + 8;
                    int EndIndex   = Line.IndexOf("</Chance>");
                    Selector.Options[Selector.Options.Count - 1].Chance = Int32.Parse(Line.Substring(StartIndex, EndIndex - StartIndex));
                }
                else if (Line.Contains("<Condition>") == true && ParsingSelectorOption)
                {
                    int StartIndex = Line.IndexOf("<Condition>") + 11;
                    int EndIndex   = Line.IndexOf("</Condition>");
                    Selector.Options[Selector.Options.Count - 1].Condition = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("<Action>") == true && ParsingSelectorOption)
                {
                    int StartIndex = Line.IndexOf("<Action>") + 8;
                    int EndIndex   = Line.IndexOf("</Action>");
                    Selector.Options[Selector.Options.Count - 1].Action = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("/SelectorOption>") == true)
                {
                    ParsingDecision = false;
                }
                else if (Line.Contains("</LocationSelector>") == true)
                {
                    LocationItem    = null;
                    ParsingSelector = false;
                }
                // Parsing folder data
                else if (Line.Contains("<Folder>") == true)
                {
                    if (Folder != null)
                    {
                        TreeViewItem LastParent = Folder;
                        Parent.Push(LastParent);
                        Folder = DataHandler.AddFolderFull(this, LastParent);
                    }
                    else
                    {
                        Folder = DataHandler.AddFolderFull(this, null);
                    }
                }
                else if (Line.Contains("<Name>"))
                {
                    int StartIndex = Line.IndexOf("<Name>") + 6;
                    int EndIndex   = Line.IndexOf("</Name>");
                    Folder.Name             = Line.Substring(StartIndex, EndIndex - StartIndex);
                    Folder.ContextMenu.Name = Folder.Name;
                }
                else if (Line.Contains("<Header>"))
                {
                    int StartIndex = Line.IndexOf("<Header>") + 8;
                    int EndIndex   = Line.IndexOf("</Header>");
                    Folder.Header = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("</Folder>"))
                {
                    if (Parent.Count == 0)
                    {
                        Folder = null;
                    }
                    else
                    {
                        Folder = Parent.Pop();
                    }
                }
            }
        }
示例#3
0
        //==========================================================================================
        // Editing
        //==========================================================================================
        public void Location_Selected(object sender, RoutedEventArgs e)
        {
            TabControl_Main.SelectedIndex = 1;
            e.Handled = true;
            TreeViewItem Sender = sender as TreeViewItem;

            ChangeEventsDisabled = true;
            SetControlStatusToLocation();
            foreach (LocationData Data in DataHandler.LocationList)
            {
                if (Sender.Name == Data.TreeViewId)
                {
                    SelectedLocation = Data;
                    SelectedSelector = null;
                    Text_Guid.Text   = Data.Guid;
                    // Parse description
                    Text_Description.Document.Blocks.Clear();
                    // Simple parse - no markup
                    if (Data.Description == null || Data.Description.IndexOf("<p>") == -1)
                    {
                        Text_Description.Document.Blocks.Add(new Paragraph(new Run(Data.Description)));
                    }
                    // True parse
                    else
                    {
                        String Descr = new String(Data.Description.ToArray());
                        while (Descr.IndexOf("<p>") != -1)
                        {
                            int    StartIndex = Descr.IndexOf("<p>") + 3;
                            int    EndIndex   = Descr.IndexOf("</p>");
                            String Substring  = Descr.Substring(StartIndex, EndIndex - StartIndex);
                            Substring = Substring.Replace("<br>", "\r\n");
                            Text_Description.Document.Blocks.Add(new Paragraph(new Run(Substring)));
                            Descr = Descr.Remove(StartIndex - 3, 3);
                            Descr = Descr.Remove(EndIndex - 3, 4);
                        }
                    }
                    // End of parse
                    for (int i = 0; i < Data.Decisions.Count; i++)
                    {
                        String Index = i.ToString();
                        if (i < 10)
                        {
                            Index = "0" + Index;
                        }
                        TextBox Box = DecisionContainer.FindName("Text_DecisionText" + Index) as TextBox;
                        Box.Text = Data.Decisions[i].Text;
                        Box      = DecisionContainer.FindName("Text_DecisionLink" + Index) as TextBox;
                        Box.Text = Data.Decisions[i].LocationLink;
                        Box      = DecisionContainer.FindName("Text_DecisionCondition" + Index) as TextBox;
                        Box.Text = Data.Decisions[i].Condition;
                        Box      = DecisionContainer.FindName("Text_DecisionAction" + Index) as TextBox;
                        Box.Text = Data.Decisions[i].Action;
                    }
                    // Check amount of decisions to unfold
                    int DecisionCount = 0;
                    for (int i = 0; i < Data.Decisions.Count; i++)
                    {
                        if ((Data.Decisions[i].Text != null && Data.Decisions[i].Text != "") ||
                            (Data.Decisions[i].LocationLink != null && Data.Decisions[i].LocationLink != ""))
                        {
                            DecisionCount = i + 1;
                        }
                    }
                    UnfoldDecisions(DecisionCount);
                    break;
                }
            }
            ChangeEventsDisabled = false;
        }