private void TextBox_PreviewMouseUp(object sender, MouseButtonEventArgs e) { var tb = (TextBox)sender; if (tb.IsMouseCaptured) { String sel; int i_from, i_to; var tier = (TextTier)this.Tier; var igti = tier.TiersHost; while ((sel = tb.SelectedText).Length > 0 && Char.IsWhiteSpace(sel[sel.Length - 1])) tb.SelectionLength--; while (true) { i_from = tb.SelectionStart; i_to = i_from + tb.SelectionLength; if (i_from == i_to || !Char.IsWhiteSpace(tb.SelectedText[0])) break; tb.SelectionStart++; tb.SelectionLength--; } if (i_from != i_to) { var seg = TiersControl.ActiveSegmentation; if (seg == null) { TiersControl.ActiveSegmentation = seg = new SegTier { TierType = "Seg" }; igti.Add(seg); } seg.Add(new SegPart { //PartsHost = seg, SourceTier = tier, FromChar = i_from, ToChar = i_to, }); } } var tb_info = (TextBlock)((Grid)tb.Parent).Children[1]; tb_info.Text = String.Empty; }
private void menu_hide_tier(object sender, RoutedEventArgs e) { var mi = (MenuItem)sender; var cm = (ContextMenu)mi.Parent; var uib = (tier_ui_base)cm.PlacementTarget; var tier = (tier_base)uib.Tier; if (tier == ActiveSegmentation) ActiveSegmentation = null; tier.SetValue(dps.IsVisibleProperty, false); }
public SegTier Segment() { var st = new SegTier { TierType = "Seg" }; var s = this.Text; if (s.Length > 0) { var f_ws = Char.IsWhiteSpace(s[0]); var x = s.PartitionBy(ch => f_ws != (f_ws ^= Char.IsWhiteSpace(ch))).ToArray(); int i_from = 0; for (int i = 0; i < x.Length; i++) { int i_to = i_from + x[i].Count; if (!x[i].Key) { var p = new SegPart { FromChar = i_from, ToChar = i_to, SourceTier = this, }; st.Add(p); } i_from = i_to; } } TiersHost.Add(st); return st; }