/// <summary> /// Gets the state object from a scintilla control /// </summary> private static StateObject GetStateObject(ScintillaControl sci) { StateObject so = new StateObject(); so.LineCount = sci.LineCount; so.Position = sci.CurrentPos; so.FileName = sci.FileName; for (Int32 i = 0; i < sci.LineCount; i++) { if (!sci.FoldExpanded(i)) { so.FoldedLines.Add(i); } if ((sci.MarkerGet(i) & (1 << 0)) != 0) { so.BookmarkedLines.Add(i); } } return(so); }
/// <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); } }