private bool LoadText(string location) { FileStream fs; location = saveLocation + location + ".txt"; if (File.Exists(location)) { fs = new FileStream ( location, FileMode.Open, FileAccess.Read ); using (fs) { TextRange tr = new TextRange ( MainTextArea.Document.ContentStart, MainTextArea.Document.ContentEnd ); tr.Load(fs, DataFormats.Text); } FormatExisting(); MainTextArea.Focus(); MainTextArea.CaretPosition = MainTextArea.Document.ContentEnd; mainCaretPosition = MainTextArea.CaretPosition; return(true); } else { mainCaretPosition = MainTextArea.Document.ContentEnd; return(false); } }
private void FindText() { String text = OperationTextArea.Text; if (OperationTextArea.Visibility == Visibility.Hidden) { FindInitialise(false); Keyboard.Focus(OperationTextArea); return; } if (OperationTextArea.Text == "") { AddMessage(Lang.nullOperation); return; } BEGIN: foreach (Block b in MainTextArea.Document.Blocks) { TextRange tr = new TextRange(b.ContentStart, b.ContentEnd); int index = 0; if (tr.Start.GetOffsetToPosition(findStart) > 0) { index = tr.Start.GetOffsetToPosition(findStart); } if (index >= tr.Text.Length) { goto NEXT; } index = tr.Text.IndexOf(text, index); if (index == -1) { goto NEXT; } if (tr.Start.GetPositionAtOffset(index).GetOffsetToPosition(findStart) <= 0) { MainTextArea.Focus(); MainTextArea.Selection.Select ( tr.Start.GetPositionAtOffset(index), tr.Start.GetPositionAtOffset(index + text.Length) ); findStart = tr.Start.GetPositionAtOffset(index + 1); AddMessage(Lang.found); return; } NEXT: ; } if (findStart != MainTextArea.Document.ContentStart) { findStart = MainTextArea.Document.ContentStart; goto BEGIN; } AddMessage(Lang.notFound); }
private void TogglePlan() { if (PlanTextArea.Visibility == Visibility.Hidden) { mainCaretPosition = MainTextArea.CaretPosition; MainTextArea.Visibility = Visibility.Hidden; PlanTextArea.Visibility = Visibility.Visible; PlanTextArea.Focus(); PlanTextArea.CaretPosition = planCaretPosition; } else { planCaretPosition = PlanTextArea.CaretPosition; PlanTextArea.Visibility = Visibility.Hidden; MainTextArea.Visibility = Visibility.Visible; MainTextArea.Focus(); MainTextArea.CaretPosition = mainCaretPosition; } }