public MainWindow()
        {
            InitializeComponent();
            commandInTerminal.Add("get-process");
            this.DataContext = this;

            
            ////TextBox t = new TextBox();
            ////t.Undo();
            //TextScript.Text = "get-process"; // | sort-object | force-recurce";
            //TextScript.Text = "get-childitem * -include *.csv -recurse | remove-item";

            //TextScript = new RichTextBox();

            TabItem tb = new TabItem();
            tb.Header = "untl1";
            TabControlScript.Items.Add(tb);
            ScriptTab scriptTab1 = new ScriptTab(new FlowDocument(), tb);
            scriptTabsList.Add(scriptTab1);

            TabItem tb2 = new TabItem();
            tb2.Header = "untl2";
            TabControlScript.Items.Add(tb2);
            ScriptTab scriptTab2 = new ScriptTab(new FlowDocument(), tb2);
            scriptTabsList.Add(scriptTab2);

            TabItem tb3 = new TabItem();
            tb3.Header = "untl3";
            TabControlScript.Items.Add(tb3);
            ScriptTab scriptTab3 = new ScriptTab(new FlowDocument(), tb3);
            scriptTabsList.Add(scriptTab3);

            // Создание привязки
            CommandBinding bind = new CommandBinding(ApplicationCommands.New);

            // Присоединение обработчика событий
            bind.Executed += NewScriptExecuted;

            // Регистрация привязки
            this.CommandBindings.Add(bind);

            CommandBinding bind2 = new CommandBinding(ApplicationCommands.Open);
            bind2.Executed += ShowOpenFileDialog;
            this.CommandBindings.Add(bind2);

            CommandBinding bind3 = new CommandBinding(ApplicationCommands.Save);
            bind3.Executed += SaveScript;
            this.CommandBindings.Add(bind3);

            CommandBinding bind4 = new CommandBinding(ApplicationCommands.Find);
            bind4.Executed += OpenSettings;
            this.CommandBindings.Add(bind4);

            CommandBinding bind5 = new CommandBinding(ApplicationCommands.Copy);
            bind5.Executed += CopyTextInRichbox;
            this.CommandBindings.Add(bind5);

            CommandBinding bind6 = new CommandBinding(ApplicationCommands.Paste);
            bind6.Executed += PasteTextInRichbox;
            this.CommandBindings.Add(bind6);

            CommandBinding bind7 = new CommandBinding(ApplicationCommands.Undo);
            bind7.Executed += UndoTextInRichbox;
            this.CommandBindings.Add(bind7);

            CommandBinding bind8 = new CommandBinding(ApplicationCommands.Undo);
            bind8.Executed += RedoTextInRichbox;
            this.CommandBindings.Add(bind8);

            CommandBinding bind9 = new CommandBinding(ApplicationCommands.NotACommand);
            bind9.Executed += CompileScript;
            this.CommandBindings.Add(bind9);

            CommandBinding bind10 = new CommandBinding(ApplicationCommands.Help);
            bind10.Executed += HelpPowerShell;
            this.CommandBindings.Add(bind10);


            MainWindow.Terminal = new PowerShellTerminal();//new SolidColorBrush(Colors.Aquamarine), new SolidColorBrush(Colors.HotPink));
            MainWindow.Terminal.Style = StyleFromSettingsDocument();
            SettingsForTerminal();
 
            //DataContext = terminal.Style.InputTextBoxBrush;
            // FlowDocument doc = new FlowDocument();
            // Paragraph par = new Paragraph();
            // par.Inlines.Add(new Run("get-process -name chrome"));
            //// par.Inlines.Add(new Run("get-process"));
            // doc.Blocks.Add(par);
            // TextScript.Document = doc;

            TabControlScript.SelectedIndex = 0;
            prev = TabControlScript.SelectedIndex;

            //  MessageBox.Show(MainWindow.Terminal.Style.MainColor.ToString());
            // MainColor = new SolidColorBrush(Colors.Aqua);//MainWindow.Terminal.Style.MainColor

            //MainColor = terminal.Style.MainColor;

            ////TextScript.Text += Convert.ToString((int)('9'));
            ////TextScript.Text += TextScript.Text.Length.ToString();
            //terminal.Script = this.TextScript.Text;

            //Lexer lexer = new Lexer(TextScript.Text);

            //TextScript.Text += "\n";
            ////TextScript.Text += TextScript.Text.Substring(4, 10);

            //TextRange t = new TextRange(doc.ContentStart, doc.ContentEnd);
            //for (int i = 0; i < TokenReader.TokenReaderList.Count; i++)
            //{
            //    t.Text += TokenReader.TokenReaderList.ElementAt(i).ToString() + "\n";
            //}

            //TextScript.Text += "\n";
            //TextScript.Text += "\n";

            //Parser parser = new Parser(TokenReader.TokenReaderList);
            //parser.CreateTree();
            ////parser.CheckError();

            //ScriptComNonterminalExpression test = new ScriptComNonterminalExpression(TokenReader.TokenReaderList);
            //test.CreateSyntaxTree();
            //CommandCollection collection = new CommandCollection(test);
            //object[] o = null;
            //object[] obj = collection.Excute(null,o);
            //foreach(var ob in obj)
            //{
            //if(ob!=null)

            //tbOut. += ob.ToString()+'\n';
            // }
            int f = 10;
            // BreadthFirstIterator b = new BreadthFirstIterator(test);
            //test.Interpret();


            // FlowDocument document = new FlowDocument();
            // Paragraph paragraph = new Paragraph();
            // // paragraph.Inlines.Add((new Run("текст")));//\n работает" + "И прибавления тоже" + "Удачи")));
            // //paragraph.Inlines.Add(new Run("hello-hello \n"));
            // paragraph.Inlines.Add(new Run("get-process -name chrome"));
            //// Paragraph p = new Paragraph();
            //// p.Inlines.Add("gfd");
            // //paragraph.Inlines.Add(new Run("\ngess"));
            // //paragraph.Inlines.Add(new Run("\ngerocess"));
            // //paragraph.Inlines.Add(new Run("hello -hello \n"));
            // document.Blocks.Add(paragraph);
            // paragraph = new Paragraph();
            // paragraph.Inlines.Add(new Run("get-command"));
            // document.Blocks.Add(paragraph);
            //// document.Blocks.Add(p);
            // tbOut.Document = document;

            //string[] str = GetDocumentText(tbOut.Document).Split('\n');
            //for(int i=0;i<str.Length-1;i++)
            //{
            //    Lexer lexer = new Lexer(str[i]);
            //    ScriptComNonterminalExpression test = new ScriptComNonterminalExpression(TokenReader.TokenReaderList);
            //    test.CreateSyntaxTree();
            //    CommandCollection collection = new CommandCollection(test);
            //    string o = "";
            //    string obj = collection.Excute(null, o);
            //    tb.AppendText(obj);
            //    //int numberOfParag = obj.Split('\n').Length;
            //    //for(int j=0; j< numberOfParag;j++)
            //    //{
            //        //Paragraph paragr = new Paragraph();
            //        //paragr.Inlines.Add(obj);
            //        //tbOut.Document.Blocks.Add(paragr);
            //   // }
            //    //MessageBox.Show(obj);
            //}

            //Lexer lexer = new Lexer(text.ToString());
            //ScriptComNonterminalExpression test = new ScriptComNonterminalExpression(TokenReader.TokenReaderList);
            //test.CreateSyntaxTree();
            //CommandCollection collection = new CommandCollection(test);
            //string o = "";
            //string obj = collection.Excute(null, o);
            //parag.Inlines.Add();

            //PowershellTerminal powershell = new PowershellTerminal();
            //powershell.CreateSyntaxHighlight(tbOut);
            //tbOut = powershell.CreateSyntaxHighlight(tbOut).PaintOver();
            //PowershellSyntaxHighlight power = new PowershellSyntaxHighlight(document,document.ContentStart,document.ContentEnd);
            //CmdSyntaxHighlight cmd = new CmdSyntaxHighlight(document);
            //tbOut.Document = cmd.Document;
            //CmdSyntaxHighlight cmd2 = new CmdSyntaxHighlight(doc);
            //TextScript.Document = doc;

            // TextScript.TextChanged += TextChanged;

            //tbOut.SelectAll();
            //tbOut.SelectionBrush = new SolidColorBrush(Colors.Bisque);
            //string str = tbOut.Selection.Text;



            // TextRange tr = new TextRange(tbOut.Document.ContentStart)
            // MatchCollection allIp = Regex.Matches(tbOut., @"Slovo");

            //var allText = new TextRange(tbOut.Document.ContentStart, tbOut.Document.ContentEnd);
            //allText.ClearAllProperties();
            //MatchCollection regex_results = Regex.Matches(allText.Text, @"(.*?)-(.*?)\s");
            ////MatchCollection regex_results = Regex.Matches(allText.Text, @"(.*?)-(.*?)");
            ////string res1 = regex_results[0].Groups[0].Value;
            //string res2 = regex_results[0].Groups[0].Value;

            ////// string pattern = @"hello";
            //Regex regex = new Regex(res2.Split(' ')[0], RegexOptions.IgnoreCase);

            ////// var allText = new TextRange(tbOut.Document.ContentStart, tbOut.Document.ContentEnd);
            ////// allText.ClearAllProperties();
            ////tbOut.Document.Blocks.Add(new Paragraph(new Run(regex.ToString())));
            //var start = tbOut.Document.ContentStart;
            //while (start != null && start.CompareTo(tbOut.Document.ContentEnd) < 0)
            //{
            //    if (start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
            //    {
            //        var match = regex.Match(start.GetTextInRun(LogicalDirection.Forward));
            //        // string[] matchMass = match.ToString().Split(@'(\s+)');
            //        //if (match.Value != "get-process\n" || match.Value != "get-process ")
            //        //Match m = Regex.Match(match.ToString(), @".*?$");
            //        ////string s = m.ToString().Split(' ')[0];
            //        //string[] s = match.ToString().Split(' ');
            //        if (match.ToString() == "get-process")
            //        {
            //            var textrange = new TextRange(start.GetPositionAtOffset(match.Index, LogicalDirection.Forward),
            //                start.GetPositionAtOffset(match.Index + match.Length, LogicalDirection.Backward));
            //            textrange.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(Colors.DarkBlue));
            //            if (textrange.Text == "")
            //            {
            //                int b = 0;
            //            }

            //            start = textrange.End;
            //        }
            //        //else
            //        {

            //        }
            //    }
            //    start = start.GetNextContextPosition(LogicalDirection.Forward);
            //}

            //f = 11;

            //ContentPresenter cp = TabControlScript.Template.FindName("PART_SelectedContentHost", TabControlScript) as ContentPresenter;
            //(TabControlScript.ContentTemplate.FindName("TextScript", cp) as RichTextBox).Background = new SolidColorBrush(Colors.Black);
        }
 private bool IsSaved(ScriptTab script)
 {
     if (script.Path != null)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
 private void NewScriptExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     TabItem t = new TabItem();
     t.Header = "untl"+(scriptTabsList.Count+1).ToString();
     TabControlScript.Items.Add(t);
     ScriptTab newScriptTab = new ScriptTab(new FlowDocument(), t);
     scriptTabsList.Add(newScriptTab);
 }
        private void ShowOpenFileDialog(object sender, ExecutedRoutedEventArgs e)
        {
            // Create OpenFileDialog
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            // Set filter for file extension and default file extension
            dlg.DefaultExt = ".ps1";
            dlg.Filter = "PowerShell scripts (.ps1)|*.ps1";

            // Display OpenFileDialog by calling ShowDialog method
            Nullable<bool> result = dlg.ShowDialog();

            // Get the selected file name and display in a TextBox
            if (result == true)
            {
                // Open document
                string filename = dlg.FileName;
                string[] textInFile = File.ReadAllLines(filename);
                FlowDocument doc = new FlowDocument();
                for(int i=0;i<textInFile.Length;i++)
                {
                    doc.Blocks.Add(new Paragraph(new Run(textInFile[i])));
                }
                TextRange t = new TextRange(doc.ContentStart, doc.ContentEnd);
                MessageBox.Show(t.Text);
                TabItem tab = new TabItem();
                tab.Header = filename.Split('\\')[filename.Split('\\').Length-1];
                ScriptTab scriptTab = new ScriptTab(doc, tab);
                scriptTab.Path = filename;
                scriptTab.Name = tab.Header.ToString();
                TabControlScript.Items.Add(tab);
                scriptTabsList.Add(scriptTab);
                //    FileNameTextBox.Text = filename;
            }
        }