/// <summary>
        /// Carga el documento pasado durante la creación del control.
        /// </summary>
        public void LoadDocument(BsonValue document)
        {
            if (document is BsonDocument)
            {
                var doc = document as BsonDocument;

                //Insertar la línea de comienzo
                var start = new DocumentViewerLine(LineType.Opening, ++LineCounter);
                stpLinesContainer.Children.Add(start);

                foreach (var line in doc)
                {
                    if (line.Value is BsonDocument)
                    {
                        var childDoc = new DocumentViewerLineGroup(line, DocumentNestingLevel + 1, ++LineCounter);
                        LineCounter          = childDoc.LoadDocument();
                        childDoc.LinesAdded += ChildDoc_LinesAdded;
                        stpLinesContainer.Children.Add(childDoc);
                    }
                    else
                    {
                        //Insertar las líneas de datos
                        var docline = new DocumentViewerLine(line, ++LineCounter);
                        docline.AddNewLine      += Children_AddNewLine;
                        docline.UpdatedLineType += Children_UpdatedLineType;
                        stpLinesContainer.Children.Add(docline);
                    }
                }

                //Insertar la línea de cierre
                DocumentViewerLine dvl = new DocumentViewerLine(LineType.Closing, ++LineCounter);
                stpLinesContainer.Children.Add(dvl);
            }
        }
        public int LoadDocument()
        {
            if (ChildDocument.Value is BsonDocument)
            {
                var doc         = ChildDocument.Value as BsonDocument;
                var tabLength   = DocumentViewerLine.DEFAULT_TAB_LENGTH;
                int bracketsTab = (DocumentNestingLevel - 1 > 0) ? (DocumentNestingLevel - 1) * tabLength : tabLength;

                isGroupFold = true;

                //Insertar la línea de comienzo
                var startLine = new DocumentViewerLine(ChildDocument, LineCounter, LineType.NestedObjectOpening, bracketsTab);
                startLine.IsGroupCollapsed     = true;
                startLine.FoldActionRequest   += FoldableStartLine_FoldActionRequest;
                startLine.InnerDocumentDelete += StartLine_InnerDocumentDelete;
                startLine.AddNewLine          += Children_AddNewLine;
                startLine.UpdatedLineType     += Children_UpdatedLineType;
                stpLinesContainer.Children.Add(startLine);

                foreach (var line in doc)
                {
                    if (line.Value is BsonDocument)
                    {
                        var childDoc = new DocumentViewerLineGroup(line, DocumentNestingLevel + 1, ++LineCounter);
                        LineCounter          = childDoc.LoadDocument();
                        childDoc.LinesAdded += ChildDoc_LinesAdded;
                        stpLinesContainer.Children.Add(childDoc);
                    }
                    else
                    {
                        //Insertar las líneas de datos
                        var docline = new DocumentViewerLine(line, ++LineCounter, DocumentNestingLevel * tabLength);
                        docline.AddNewLine      += Children_AddNewLine;
                        docline.UpdatedLineType += Children_UpdatedLineType;
                        docline.Visibility       = (DocumentNestingLevel > 1) ? Visibility.Collapsed : Visibility.Visible;
                        docline.IsGroupCollapsed = true;
                        stpLinesContainer.Children.Add(docline);
                    }
                }

                //Insertar la línea de cierre
                DocumentViewerLine dvl = new DocumentViewerLine(LineType.Closing, ++LineCounter, bracketsTab);
                dvl.Visibility       = (DocumentNestingLevel > 1) ? Visibility.Collapsed : Visibility.Visible;
                dvl.IsGroupCollapsed = true;
                stpLinesContainer.Children.Add(dvl);
            }

            return(LineCounter);
        }
        private void Children_AddNewLine(object sender, LineEventArgs e)
        {
            var line = sender as DocumentViewerLine;

            if (line != null)
            {
                var index = stpLinesContainer.Children.IndexOf(line);

                if (index > -1)
                {
                    BsonValue          value   = new BsonValue("");
                    DocumentViewerLine newLine = new DocumentViewerLine("newVariable", value, e.LineNumber + 1, DocumentNestingLevel * DocumentViewerLine.DEFAULT_TAB_LENGTH);
                    newLine.UpdatedLineType += Children_UpdatedLineType;
                    newLine.AddNewLine      += Children_AddNewLine;
                    ((DocumentEditorComponent)newLine).ActivateEdition();

                    stpLinesContainer.Children.Insert(index + 1, newLine);

                    UpdateLineNumbers();
                }
            }
        }