/// <summary>
 /// Applies the state object to a scintilla control
 /// </summary>
 private static void ApplyStateObject(ScintillaControl sci, StateObject so, Boolean restorePosition)
 {
     if (so.LineCount != sci.LineCount)
     {
         return;
     }
     sci.Refresh(); // Update the scintilla control state
     for (Int32 i = 0; i < so.FoldedLines.Count; i++)
     {
         Int32 foldedLine = so.FoldedLines[i];
         Int32 parentFold = sci.FoldParent(foldedLine);
         if (parentFold != -1)
         {
             sci.ToggleFold(foldedLine);
         }
         else
         {
             sci.FoldExpanded(foldedLine, false);
         }
     }
     if (so.BookmarkedLines != null)
     {
         for (Int32 i = 0; i < so.BookmarkedLines.Count; i++)
         {
             Int32 bookmarkedLine = so.BookmarkedLines[i];
             sci.MarkerAdd(bookmarkedLine, 0);
         }
         sci.Refresh(); // Update again
     }
     if (restorePosition)
     {
         Int32 line = sci.LineFromPosition(so.Position);
         sci.SetSel(so.Position, so.Position);
         sci.EnsureVisible(line);
     }
 }