Example #1
0
        public void FolderRemove_Click(object sender, RoutedEventArgs e)
        {
            TreeViewItem ClickedItem = Utility.GetClickedTreeViewItem(sender, Tree_Hierarchy);

            DataHandler.RemoveFolder(ClickedItem.Name);
            WindowTitle.AddStar(this);
        }
Example #2
0
        public void FolderPasteTo_Click(object sender, RoutedEventArgs e)
        {
            TreeViewItem ClickedItem = Utility.GetClickedTreeViewItem(sender, Tree_Hierarchy);

            CopyPaster.PasteTo(this, Tree_Hierarchy, ClickedItem.Name);
            WindowTitle.AddStar(this);
        }
Example #3
0
        //==========================================================================================
        //==========================================================================================
        // Core
        //==========================================================================================
        //==========================================================================================
        public MainWindow()
        {
            InitializeComponent();
            WindowTitle.MakeDefault(this);
            DataHandler.SetTree(Tree_Hierarchy);

            ContextMenu LocationMenu     = new ContextMenu();
            MenuItem    LocationAddEntry = new MenuItem()
            {
                Header = "Создать локацию"
            };
            MenuItem LocationAddSelector = new MenuItem()
            {
                Header = "Создать разветвление"
            };
            MenuItem LocationAddFolder = new MenuItem()
            {
                Header = "Создать папку"
            };

            LocationAddEntry.Click    += LocationAddEntry_Click;
            LocationAddSelector.Click += LocationAddSelector_Click;
            LocationAddFolder.Click   += LocationAddFolder_Click;
            LocationMenu.Items.Add(LocationAddEntry);
            LocationMenu.Items.Add(LocationAddSelector);
            LocationMenu.Items.Add(LocationAddFolder);
            LocationMenu.Name          = null;
            Tree_Hierarchy.ContextMenu = LocationMenu;

            (TabControl_Main.Items[0] as TabItem).Visibility = System.Windows.Visibility.Collapsed;
            (TabControl_Main.Items[1] as TabItem).Visibility = System.Windows.Visibility.Collapsed;
            (TabControl_Main.Items[2] as TabItem).Visibility = System.Windows.Visibility.Collapsed;
            InitializeDecisionButtons();
            InitializeDecisionButtonContextMenu();
        }
Example #4
0
 private void CheckUnsavedChanges(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (WindowTitle.HasUnsavedChanges() && (DataHandler.LocationList.Count > 0 || DataHandler.SelectorList.Count > 0))
     {
         UnsavedChangesDialog dlg = new UnsavedChangesDialog();
         if (WindowState == WindowState.Maximized)
         {
             dlg.Left = SystemParameters.VirtualScreenWidth / 2 - 175;
             dlg.Top  = SystemParameters.VirtualScreenHeight / 2 - 65;
         }
         else
         {
             dlg.Left = Left + Width / 2 - 175;
             dlg.Top  = Top + Height / 2 - 65;
         }
         dlg.ResizeMode = System.Windows.ResizeMode.NoResize;
         dlg.Owner      = this;
         dlg.SetFileName(WindowTitle.GetOpenFileName());
         dlg.ShowDialog();
         if (UnsavedChangesDialog.ReturnResponse == "Cancel")
         {
             e.Cancel = true;
         }
         else if (UnsavedChangesDialog.ReturnResponse == "Save")
         {
             SaveCommand_Executed(sender, null);
         }
     }
 }
Example #5
0
        //==========================================================================================
        // Add new folder
        //==========================================================================================
        public void LocationAddFolder_Click(object sender, RoutedEventArgs e)
        {
            MenuItem     ClickedButton = sender as MenuItem;
            ContextMenu  ClickedMenu   = ClickedButton.Parent as ContextMenu;
            TreeViewItem ClickedItem   = Utility.FindNodeByName(ClickedMenu.Name, Tree_Hierarchy.Items);

            DataHandler.AddFolderFull(this, ClickedItem);
            WindowTitle.AddStar(this);
        }
Example #6
0
 private void SaveCommand_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     if (LastSavePath == null || LastSavePath.Length == 0)
     {
         SaveAsCommand_Executed(sender, e);
         return;
     }
     //Exporter.ToXML(Dogs, LastSavePath);
     SaveTreeStructure(Tree_Hierarchy, LastSavePath);
     WindowTitle.RemoveStar(this);
 }
Example #7
0
 //==========================================================================================
 //==========================================================================================
 // Save/load
 //==========================================================================================
 //==========================================================================================
 public void SaveTreeStructure(TreeView Tree, String Filename)
 {
     try
     {
         StreamWriter Writer = new StreamWriter(Filename, false, System.Text.Encoding.UTF8);
         foreach (TreeViewItem Item in Tree.Items)
         {
             SaveTreeItem(Writer, Item, 0);
         }
         Writer.Close();
         WindowTitle.RemoveStar(this);
     }
     catch (Exception) { MessageBox.Show("Сохранение не удалось", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); }
 }
Example #8
0
        private void SaveAsCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();

            dlg.FileName   = "output";
            dlg.DefaultExt = ".xml";
            dlg.Filter     = "XML Files (*.xml)|*.xml|All Files|*";

            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                LastSavePath = dlg.FileName;
                WindowTitle.SetOpenFileName(this, dlg.FileName);
                SaveTreeStructure(Tree_Hierarchy, dlg.FileName);
            }
        }
Example #9
0
        private void OpenCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            dlg.DefaultExt = ".xml";
            dlg.Filter     = "XML Files (*.xml)|*.xml|All Files|*";

            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                //Dogs = Importer.FromXML(dlg.FileName);
                WindowTitle.SetOpenFileName(this, dlg.FileName);
                LastSavePath = dlg.FileName;
                LoadTreeStructure(dlg.FileName);
            }
        }
Example #10
0
        private void Text_DecisionAction_Changed(object sender, TextChangedEventArgs e)
        {
            if (ChangeEventsDisabled == true)
            {
                return;
            }

            WindowTitle.AddStar(this);
            TextBox Sender = sender as TextBox;
            int     Index  = Int32.Parse(Sender.Name.Substring(Sender.Name.Length - 2));

            if (SelectedLocation != null)
            {
                while (SelectedLocation.Decisions.Count < Index + 1)
                {
                    SelectedLocation.Decisions.Add(new LocationDecision());
                }
                SelectedLocation.Decisions[Index].Action = Sender.Text;
            }
        }
Example #11
0
        public void Folder_KeyDown(object sender, KeyEventArgs e)
        {
            e.Handled = true;
            TreeViewItem SelectedItem = sender as TreeViewItem;

            if (e.Key == Key.C && Keyboard.IsKeyDown(Key.LeftCtrl))
            {
                CopyPaster.IsCut          = false;
                CopyPaster.CopyObjectName = SelectedItem.Name;
            }
            else if (e.Key == Key.X && Keyboard.IsKeyDown(Key.LeftCtrl))
            {
                CopyPaster.IsCut          = true;
                CopyPaster.CopyObjectName = SelectedItem.Name;
            }
            else if (e.Key == Key.V && Keyboard.IsKeyDown(Key.LeftCtrl))
            {
                CopyPaster.PasteTo(this, Tree_Hierarchy, SelectedItem.Name);
                WindowTitle.AddStar(this);
            }
        }
Example #12
0
        private void Text_Description_Changed(object sender, TextChangedEventArgs e)
        {
            if (ChangeEventsDisabled == true)
            {
                return;
            }

            if (SelectedLocation != null)
            {
                WindowTitle.AddStar(this);
                //TextRange textRange = new TextRange(Text_Description.Document.ContentStart, Text_Description.Document.ContentEnd);
                var    Paragraphs = Text_Description.Document.Blocks.ToList();
                String Output     = "";
                for (int i = 0; i < Paragraphs.Count; i++)
                {
                    Output += "<p>";
                    TextRange textRange = new TextRange(Paragraphs[i].ContentStart, Paragraphs[i].ContentEnd);
                    Output += textRange.Text;
                    Output += "</p>";
                }
                Output = Output.Replace("\r\n", "<br>");
                SelectedLocation.Description = Output;
            }
        }
Example #13
0
        private void Text_Guid_Changed(object sender, TextChangedEventArgs e)
        {
            if (ChangeEventsDisabled == true)
            {
                return;
            }

            WindowTitle.AddStar(this);
            TreeViewItem SelectedItem = Tree_Hierarchy.SelectedItem as TreeViewItem;

            if (SelectedItem != null)
            {
                SelectedItem.Header = Text_Guid.Text;
            }

            if (SelectedLocation != null)
            {
                SelectedLocation.Guid = Text_Guid.Text;
            }
            else if (SelectedSelector != null)
            {
                SelectedSelector.Guid = Text_Guid.Text;
            }
        }
Example #14
0
 private void NewCommand_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     ClearTreeView(Tree_Hierarchy);
     WindowTitle.MakeDefault(this);
 }
Example #15
0
 void ClearTreeView(TreeView Tree)
 {
     WindowTitle.RemoveStar(this);
     Tree.Items.Clear();
 }
Example #16
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();
                    }
                }
            }
        }
Example #17
0
 private void DataGrid_CellChanged(object sender, EventArgs e)
 {
     WindowTitle.AddStar(this);
 }