private void CNewChapter(object sender, ExecutedRoutedEventArgs e) { TranscriptionChapter c = new TranscriptionChapter(Properties.Strings.DefaultChapterText); TranscriptionSection s = new TranscriptionSection(Properties.Strings.DefaultSectionText); TranscriptionParagraph p = new TranscriptionParagraph(); p.Add(new TranscriptionPhrase()); Transcription.Add(c); c.Add(s); s.Add(p); VirtualizingListBox.ActiveTransctiption = c; }
public async Task<bool> NewTranscription() { if (!await TrySaveUnsavedChanges()) return false; var source = new WPFTranscription(); source.BeginUpdate(false); var c = new TranscriptionChapter(Properties.Strings.DefaultChapterText); var s = new TranscriptionSection(Properties.Strings.DefaultSectionText); var p = new TranscriptionParagraph(); p.Add(new TranscriptionPhrase()); c.Add(s); s.Add(p); source.Add(c); Transcription = source; SynchronizeSpeakers(); VirtualizingListBox.ActiveTransctiption = p; TranscriptionList.Clear(); source.ClearUndo(); source.EndUpdate(); Transcription.Saved = true; return true; }
/// <summary> /// V2 deserialization beware of local variable names /// </summary> /// <param name="e"></param> /// <param name="isStrict"></param> /// <returns></returns> public static TranscriptionParagraph DeserializeV2(XElement e, bool isStrict) { TranscriptionParagraph par = new TranscriptionParagraph(); par._internalID = int.Parse(e.Attribute(isStrict ? "speakerid" : "s").Value); par.AttributeString = (e.Attribute(isStrict ? "attributes" : "a") ?? EmptyAttribute).Value; par.Elements = e.Attributes().ToDictionary(a => a.Name.ToString(), a => a.Value); par.Elements.Remove(isStrict ? "begin" : "b"); par.Elements.Remove(isStrict ? "end" : "e"); par.Elements.Remove(isStrict ? "attributes" : "a"); par.Elements.Remove(isStrict ? "speakerid" : "s"); e.Elements(isStrict ? "phrase" : "p").Select(p => (TranscriptionElement)TranscriptionPhrase.DeserializeV2(p, isStrict)).ToList().ForEach(p => par.Add(p)); ; if (e.Attribute(isStrict ? "attributes" : "a") != null) par.AttributeString = e.Attribute(isStrict ? "attributes" : "a").Value; if (e.Attribute(isStrict ? "begin" : "b") != null) { string val = e.Attribute(isStrict ? "begin" : "b").Value; int ms; if (int.TryParse(val, out ms)) par.Begin = TimeSpan.FromMilliseconds(ms); else par.Begin = XmlConvert.ToTimeSpan(val); } else { var ch = par._children.FirstOrDefault(); par.Begin = ch == null ? TimeSpan.Zero : ch.Begin; } if (e.Attribute(isStrict ? "end" : "e") != null) { string val = e.Attribute(isStrict ? "end" : "e").Value; int ms; if (int.TryParse(val, out ms)) par.End = TimeSpan.FromMilliseconds(ms); else par.End = XmlConvert.ToTimeSpan(val); } else { var ch = par._children.LastOrDefault(); par.End = ch == null ? TimeSpan.Zero : ch.Begin; } return par; }
void l_SplitRequest(object sender, EventArgs e) { Element el = (Element)sender; if (el.ValueElement is TranscriptionParagraph) { TranscriptionParagraph par = (TranscriptionParagraph)el.ValueElement; par.Parent.BeginUpdate(); TimeSpan end = par.End; TranscriptionParagraph par2 = new TranscriptionParagraph(); TranscriptionParagraph par1 = new TranscriptionParagraph(); par1.AttributeString = par2.AttributeString = par.AttributeString; par1.Speaker = par2.Speaker = par.Speaker; par1.Begin = par.Begin; par2.End = end; int where = el.editor.CaretOffset; int sum = 0; for (int i = 0; i < par.Phrases.Count; i++) { TranscriptionPhrase p = par.Phrases[i]; if (sum + p.Text.Length <= where) //patri do prvniho { par1.Add(new TranscriptionPhrase(p)); } else if (sum >= where) { par2.Add(new TranscriptionPhrase(p)); } else if (sum <= where && sum + p.Text.Length > where) //uvnitr fraze { int offs = where - sum; double ratio = offs / (double)p.Text.Length; TimeSpan length = p.End - p.Begin; TimeSpan l1 = new TimeSpan((long)(ratio * length.Ticks)); TranscriptionPhrase p1 = new TranscriptionPhrase(); p1.Text = p.Text.Substring(0, offs); p1.Begin = p.Begin; p1.End = p1.Begin + l1; //if (p1.End <= par.Begin) // p1.End = par.Begin + TimeSpan.FromMilliseconds(100); //pojistka kvuli nezarovnanejm textum int idx = i; par1.Add(p1); TranscriptionPhrase p2 = new TranscriptionPhrase(); p2.Text = p.Text.Substring(offs); p2.Begin = p1.End; p2.End = p.End; par2.Add(p2); par2.Begin = p2.Begin; par1.End = p1.End; } sum += p.Text.Length; }//for if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control))//TODO: the keyboard check should be somewhere else? { if (RequestTimePosition != null) { TimeSpan pos; RequestTimePosition(out pos); par1.End = pos; par2.Begin = pos; } } var parent = par.Parent; int indx = par.ParentIndex; FixPosSetFor(par.Previous()); parent.Remove(par); parent.Insert(indx, par2); parent.Insert(indx, par1); parent.EndUpdate(); ActiveTransctiption = par2; this.Dispatcher.Invoke(() => { FixPosTryRestore(); SetCaretIn(par2, 0); }, DispatcherPriority.Background); } }
void l_NewRequest(object sender, EventArgs e) { Element el = (Element)sender; TranscriptionParagraph p = new TranscriptionParagraph(); p.Add(new TranscriptionPhrase()); if (el.ValueElement is TranscriptionParagraph) { TimeSpan pos; RequestTimePosition(out pos); el.ValueElement.End = pos; if ((el.ValueElement.End - el.ValueElement.Begin) < TimeSpan.FromMilliseconds(100)) { el.ValueElement.End = el.ValueElement.Begin + TimeSpan.FromMilliseconds(100); } if (el.ValueElement.Parent.End < el.ValueElement.End) el.ValueElement.Parent.End = el.ValueElement.End; p.Begin = el.ValueElement.Parent.End; p.Speaker = ((TranscriptionParagraph)el.ValueElement).Speaker; el.ValueElement.Parent.Insert(el.ValueElement.ParentIndex + 1, p); } else if (el.ValueElement is TranscriptionSection) { el.ValueElement.Parent.Insert(0, p); } else if (el.ValueElement is TranscriptionChapter) { el.ValueElement.Children[0].Insert(0, p); } FixPosSetFor(el.ValueElement); ActiveTransctiption = p; this.Dispatcher.Invoke(() => { FixPosTryRestore(); SetCaretIn(p, 0); }, DispatcherPriority.Background); }
void l_SplitRequest(object sender, EventArgs e) { Element el = (Element)sender; if (el.ValueElement is TranscriptionParagraph) { TranscriptionParagraph par = (TranscriptionParagraph)el.ValueElement; par.Parent.BeginUpdate(); TimeSpan end = par.End; TranscriptionParagraph par2 = new TranscriptionParagraph(); TranscriptionParagraph par1 = new TranscriptionParagraph(); par1.AttributeString = par2.AttributeString = par.AttributeString; par1.Speaker = par2.Speaker = par.Speaker; par2.End = end; int where = el.editor.CaretOffset; int sum = 0; for (int i = 0; i < par.Phrases.Count; i++) { TranscriptionPhrase p = par.Phrases[i]; if (sum + p.Text.Length <= where) //patri do prvniho { par1.Add(new TranscriptionPhrase(p)); } else if (sum >= where) { par2.Add(new TranscriptionPhrase(p)); } else if (sum <= where && sum + p.Text.Length > where) //uvnitr fraze { int offs = where - sum; double ratio = offs / (double)p.Text.Length; TimeSpan length = p.End - p.Begin; TimeSpan l1 = new TimeSpan((long)(ratio * length.Ticks)); TranscriptionPhrase p1 = new TranscriptionPhrase(); p1.Text = p.Text.Substring(0, offs); p1.Begin = p.Begin; p1.End = p1.Begin + l1; if (p1.End <= par.Begin) p1.End = par.Begin + TimeSpan.FromMilliseconds(100); //pojistka kvuli nezarovnanejm textum int idx = i; par1.Add(p1); TranscriptionPhrase p2 = new TranscriptionPhrase(); p2.Text = p.Text.Substring(offs); p2.Begin = p1.End; p2.End = p.End; par2.Add(p2); par2.Begin = p2.Begin; par1.End = p1.End; } sum += p.Text.Length; }//for if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control))//TODO: hodit to nejak jinak do funkci... :P { if (RequestTimePosition != null) { TimeSpan pos; RequestTimePosition(out pos); par1.End = pos; par2.Begin = pos; } } //SpeakerChanged(); var parent = par.Parent; int indx = par.ParentIndex; parent.Remove(par); parent.Insert(indx, par2); parent.Insert(indx, par1); parent.EndUpdate(); ActiveTransctiption = par2; } }
void l_NewRequest(object sender, EventArgs e) { Element el = (Element)sender; TranscriptionParagraph p = new TranscriptionParagraph(); p.Add(new TranscriptionPhrase()); if (el.ValueElement is TranscriptionParagraph) { TimeSpan pos; RequestTimePosition(out pos); el.ValueElement.End = pos; if ((el.ValueElement.End - el.ValueElement.Begin) < TimeSpan.FromMilliseconds(100)) { el.ValueElement.End = el.ValueElement.Begin + TimeSpan.FromMilliseconds(100); } if (el.ValueElement.Parent.End < el.ValueElement.End) el.ValueElement.Parent.End = el.ValueElement.End; p.Begin = el.ValueElement.Parent.End; p.Speaker = ((TranscriptionParagraph)el.ValueElement).Speaker; el.ValueElement.Parent.Insert(el.ValueElement.ParentIndex + 1, p); } else if (el.ValueElement is TranscriptionSection) { el.ValueElement.Parent.Insert(0, p); } else if (el.ValueElement is TranscriptionChapter) { el.ValueElement.Children[0].Insert(0, p); } ActiveTransctiption = p; }