/// <summary>
 /// Saves the text.
 /// </summary>
 private void SaveText()
 {
     if (originalNote != null)
     {
         originalNote.GetRichTextBox().Rtf = RichTextBox.Rtf;
         originalNote.Save();
     }
 }
        /// <summary>
        /// Builds the list. for the bookmark system
        /// </summary>
        /// <returns>
        /// The list.
        /// </returns>
        /// <param name='RichText'>
        /// Rich text.
        /// </param>
        public List<TreeItem> BuildList(NoteDataXML_RichText RichText)
        {
            System.Text.RegularExpressions.Regex Mainheading = new System.Text.RegularExpressions.Regex ("^=[^=]+=$",
                                                                                                         RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.Multiline);
            System.Text.RegularExpressions.Regex Mainheading2 = new System.Text.RegularExpressions.Regex ("^==[^=]+==$",
                                                                                                          RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.Multiline);
            System.Text.RegularExpressions.Regex Mainheading3 = new System.Text.RegularExpressions.Regex ("^===[^=]+===$",
                                                                                                          RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.Multiline);

            System.Text.RegularExpressions.Regex Mainheading4 = new System.Text.RegularExpressions.Regex ("^====[^=]+====$",
                                                                                                          RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.Multiline);

            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex ("\\[\\[~(.*?)\\]\\]",
                                                                                                   System.Text.RegularExpressions.RegexOptions.IgnoreCase |
                                                                                                   System.Text.RegularExpressions.RegexOptions.Multiline);

            //TODO: Move this into the MarkupLanguage
            List<TreeItem> items = new List<TreeItem> ();

            //For [ ] text
            System.Text.RegularExpressions.MatchCollection matches = regex.Matches (RichText.GetRichTextBox().Text, 0);
            foreach (System.Text.RegularExpressions.Match match in matches) {
                string value = match.Value;
                if (value.IndexOf("~var") > -1)
                {
                    // December 2013
                    // we don't show variable text.
                }
                else
                {
                    items.Add (new TreeItem(match.Value, 0,match.Index));
                }
            }

             matches = Mainheading.Matches (RichText.GetRichTextBox().Text, 0);

            foreach (System.Text.RegularExpressions.Match match in matches) {
                items.Add (new TreeItem(match.Value.Replace ("=",""), 0,match.Index));
            }
            matches = Mainheading2.Matches (RichText.GetRichTextBox().Text, 0);

            foreach (System.Text.RegularExpressions.Match match in matches) {
                items.Add (new TreeItem(match.Value.Replace ("=",""), 1,match.Index));
            }
            matches = Mainheading3.Matches (RichText.GetRichTextBox().Text, 0);
            foreach (System.Text.RegularExpressions.Match match in matches) {
                items.Add (new TreeItem(match.Value.Replace ("=",""), 2,match.Index));
            }

            matches = Mainheading4.Matches (RichText.GetRichTextBox().Text, 0);
            foreach (System.Text.RegularExpressions.Match match in matches) {
                items.Add (new TreeItem(match.Value.Replace ("=",""), 3,match.Index));
            }

            //need to somehow merge and sort by index
            // need to a custom fort
            items.Sort ();

            return items;
        }
        public FullScreenEditor(NoteDataXML_RichText theNote)
        {
            this.KeyPreview    = true;
            this.StartPosition = FormStartPosition.Manual;
            var screen = Screen.FromPoint(Cursor.Position);

            this.Location    = screen.Bounds.Location;
            this.WindowState = FormWindowState.Maximized;
            //this.DesktopBounds = MyWind

            if (null == theNote)
            {
                throw new Exception("theNote was invalid in FullSCreenEditor");
            }
            originalNote = theNote;

            RichTextBox      = new RichTextExtended();
            RichTextBox.Dock = DockStyle.Fill;
            this.Controls.Add(RichTextBox);
//			Panel tempToHideRTFBorder = new Panel();
//			this.Controls.Add (tempToHideRTFBorder);
//			tempToHideRTFBorder.Controls.Add (RichTextBox);
//			tempToHideRTFBorder.Dock = DockStyle.Fill;
//			tempToHideRTFBorder.BorderStyle = BorderStyle.Fixed3D;

            RichTextBox.Rtf         = theNote.Data1;
            RichTextBox.BorderStyle = BorderStyle.None;
            RichTextBox.BackColor   = theNote.GetRichTextBox().BackColor;


            // pretty up
            this.ControlBox = false;
            this.Text       = string.Empty;
            this.BackColor  = RichTextBox.BackColor;
            // this works but you see richTextBorder
            this.Padding = new System.Windows.Forms.Padding(15);
            //RichTextBox.Margin= new System.Windows.Forms.Padding(10);

            hud = new Panel();
            this.Controls.Add(hud);
            hud.Dock      = DockStyle.Bottom;
            hud.Height    = this.Height / 5;
            hud.BackColor = System.Drawing.Color.White;
            hud.ForeColor = System.Drawing.Color.Black;
            hud.BringToFront();

            Button closeButton = new Button();

            closeButton.Text = Loc.GetStr("Close");

            closeButton.Dock   = DockStyle.Bottom;
            closeButton.Click += (object sender, EventArgs e) => {
                Close();
            };
            closeButton.ForeColor = this.ForeColor;

            Button outlinerButton = new Button();

            hud.Controls.Add(outlinerButton);
            outlinerButton.Text   = Loc.GetStr("Outline");
            outlinerButton.Dock   = DockStyle.Bottom;
            outlinerButton.Click += (object sender, EventArgs e) => {
                bookMarkView.Visible = !bookMarkView.Visible;
                if (bookMarkView.Visible)
                {
                    AddBookmarkView();
                }
            };



            wordLabel      = new Label();
            startingWords  = LayoutDetails.Instance.WordSystemInUse.CountWords(RichTextBox.Text);
            wordLabel.Text = Loc.Instance.GetStringFmt("{0} words", startingWords);
            //wordLabel.BackColor = this.BackColor;
            //wordLabel.ForeColor = RichTextBox.ForeColor;
            hud.Visible = false;
            hud.Controls.Add(closeButton);
            hud.Controls.Add(wordLabel);



            // outliner

            bookMarkView = new NoteNavigation(originalNote);
            this.Controls.Add(bookMarkView);
            bookMarkView.Dock    = DockStyle.Left;
            bookMarkView.Visible = false;

            RichTextBox.BringToFront();
        }
        public void TestNavigationNote()
        {
            NoteDataXML_RichText texter = new NoteDataXML_RichText(100, 100);

            System.Windows.Forms .Form form = new System.Windows.Forms.Form ();
            _TestSingleTon.Instance._SetupForLayoutPanelTests ();

            FAKE_LayoutPanel panel = new FAKE_LayoutPanel (CoreUtilities.Constants.BLANK, false);
            form.Controls.Add (panel);
            form.Show ();

            //NOTE: For now remember that htis ADDS 1 Extra notes
            panel.NewLayout ("mynewpanel", true, null);

            panel.AddNote(texter);

            texter.GetRichTextBox().Text = "";

            NoteNavigation bookMarkView = new NoteNavigation (texter);

            // Test 1: Tests that no crash happens when we don't have a proper markup assigned
            bookMarkView.UpdateListOfBookmarks();

            LayoutDetails.Instance.SetCurrentMarkup(new iMarkupYourOtherMind());
            // Test 2: Same test. No crash still.
            bookMarkView.UpdateListOfBookmarks();
            string TestText = @"7 minutes
            Bus crash over cliff in Ecuador
            Lost style flash leading to salvation
            ddd[[f]]
            =Dog=

            =Dog 2=
            The |whatis|this|
            ===error===
            The |firstssafdfsf|day of the ghoose|
            The |linkfdfgdfgdfg|dfdgdfgedfgdnded|";
                texter.GetRichTextBox().Text = TestText;
            // test 3: some text
            bookMarkView.UpdateListOfBookmarks();

            // Main Level Node +1
            // Dog +1
            // Dog 2 + 1
            // <Make Up Node to insert between Dog 2 and Error> +1
            // Error + 1
            // Current Position (Automated Node) + 1
            // = 6
            Assert.AreEqual (6, bookMarkView.NumberOfNodes());

            texter.GetRichTextBox().Text = "[[~scene]]";
            bookMarkView.UpdateListOfBookmarks();
            Assert.AreEqual (3, bookMarkView.NumberOfNodes());
            texter.GetRichTextBox().Text = @"Hello.
            =h1=
            =h2=
            =h3=
            =h4=
            =h1=
            ";
            bookMarkView.UpdateListOfBookmarks();
            Assert.AreEqual (7, bookMarkView.NumberOfNodes());
        }