private void ScrollToItem(TranscriptionElement elm)
        {
            if (_scrollViewer == null)
                return;

            listbox.SelectedItem = elm;
            listbox.ScrollIntoView(listbox.Items[listbox.SelectedIndex]);
            if (elm == Transcription.Last())
            {
                _scrollViewer.ScrollToBottom();
            }
            else
            {
                var all = listbox.VisualFindChildren<Element>();
                var visible = all.Where(itm => listbox.VisualIsVisibleChild(itm));

                Action scroll = new Action(() =>
                    {
                        all = listbox.VisualFindChildren<Element>();
                        visible = all.Where(itm => listbox.VisualIsVisibleChild(itm));
                        var element = all.First(itm => itm.ValueElement == elm);
                        var position = element.TransformToAncestor(_scrollViewer).Transform(new Point(0, element.ActualHeight));
                        _scrollViewer.ScrollToVerticalOffset(position.Y);
                        _scrollViewer.UpdateLayout();
                    });

                if (visible.Any(itm => itm.ValueElement == elm))
                    _scrollViewer.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, scroll);
            }
        }
        void l_MergeWithnextRequest(object sender, EventArgs e)
        {
            Element el = (Element)sender;
            TranscriptionElement t = el.ValueElement;
            TranscriptionElement n = el.ValueElement.Next();
            t.Parent.BeginUpdate();
            int len = t.Text.Length;
            if (t is TranscriptionParagraph && n is TranscriptionParagraph)
            {
                t.End = n.End;
                n.Children.ForEach(x => t.Children.Add(x));
                n.Parent.Remove(n);
            }

            FixPosSetFor(t);

            t.Parent.EndUpdate();
            ActiveTransctiption = t;

            this.Dispatcher.Invoke(() =>
            {
                FixPosTryRestore();
                SetCaretIn(t, len);
            }, DispatcherPriority.Background);

        }
        void l_MergeWithPreviousRequest(object sender, EventArgs e)
        {
            Element el = (Element)sender;
            TranscriptionElement t = el.ValueElement;
            TranscriptionElement p = el.ValueElement.Previous();
            var parent = t.Parent;
            parent.BeginUpdate();
            int len = p.Text.Length;
            if (t is TranscriptionParagraph && p is TranscriptionParagraph)
            {
                if (!(t.Children.Count == 1 && string.IsNullOrEmpty(t.Children[0].Text)))
                {
                    p.End = t.End;
                    t.Children.ForEach(x => p.Children.Add(x));
                }
                parent.Remove(t);

            }
            FixPosSetFor(p);
            parent.EndUpdate();
            ActiveTransctiption = p.Previous();

            this.Dispatcher.Invoke(() =>
            {
                FixPosTryRestore();
                SetCaretIn(p, len);
            }, DispatcherPriority.Background);
        }
        private void SetCaretIn(TranscriptionElement elm, int position)
        {
            if (ActiveTransctiption != elm)
                ActiveTransctiption = elm;

            listbox.ScrollIntoView(elm);
            var n = listbox.ItemContainerGenerator.ContainerFromItem(elm).VisualFindChild<Element>();
            if (!n.IsFocused)
                n.Focus();
            n.SetCaretOffset(position);
        }
        void l_MoveUpRequest(object sender, EventArgs e)
        {
            bool playing = false;
            if (RequestPlaying != null)
                RequestPlaying(out playing);

            if (playing && RequestPlayPause != null)
                RequestPlayPause();

            Element el = (Element)sender;
            TranscriptionElement tr = el.ValueElement;
            if (tr == null)
                return;
            TextViewPosition twpos = el.editor.TextArea.Caret.Position;
            var prev = tr.Previous();
            if (prev != null)
            {
                this.Dispatcher.Invoke(() =>
                {
                    listbox.ScrollIntoView(prev);
                    var n = listbox.ItemContainerGenerator.ContainerFromItem(prev).VisualFindChild<Element>();
                    Point p = el.editor.TextArea.TextView.GetVisualPosition(twpos, VisualYPosition.LineMiddle);
                    p = el.editor.PointToScreen(p);

                    VisualLine last = n.editor.TextArea.TextView.VisualLines.Last();
                    int len = last.StartOffset + last.TextLines.Sum(x => x.Length) - last.TextLines.Last().Length;

                    Point p2 = n.editor.TextArea.TextView.GetVisualPosition(new TextViewPosition(n.editor.Document.GetLocation(len)), VisualYPosition.LineMiddle);
                    p2 = n.editor.PointToScreen(p2);

                    Point loc = new Point(p.X, p2.Y);

                    p2 = n.editor.PointFromScreen(loc);
                    var tpos = n.editor.TextArea.TextView.GetPosition(p2);

                    int pos = 0;
                    if (tpos.HasValue)
                    {
                        pos = n.editor.Document.Lines[tpos.Value.Line - 1].Offset + tpos.Value.Column - 1;
                    }
                    else
                    {
                        pos = n.editor.Document.TextLength;
                    }
                    n.SetCaretOffset(pos);
                }, DispatcherPriority.Background);
            }

            if (playing && RequestPlayPause != null)
                RequestPlayPause();
        }
예제 #6
0
        public void FindNext(string pattern, bool isregex, bool CaseSensitive, bool searchinspeakers)
        {
            //foreach (Element e in VirtualizingListBox.gridstack.Children)
            //{
            //    e.editor.SelectionLength = 0;
            //}

            if (VirtualizingListBox.ActiveTransctiption == null)
            {
                if (_transcription.Chapters.Count > 0)
                {
                    VirtualizingListBox.ActiveTransctiption = _transcription.Chapters[0];
                }
                else
                {
                    return;
                }
            }
            TranscriptionElement tag = VirtualizingListBox.ActiveTransctiption;

            TranscriptionElement pr = tag;

            if (pr == null)
            {
                tag = Transcription.Chapters[0];
            }

            int len;

            if (Transcription.FindNext(ref tag, ref searchtextoffset, out len, pattern, isregex, CaseSensitive, searchinspeakers))
            {
                TranscriptionElement p = tag;
                waveform1.CaretPosition = p.Begin;
                VirtualizingListBox.ActiveTransctiption = p;

                if (VirtualizingListBox.ActiveElement != null)
                {
                    VirtualizingListBox.ActiveElement.SetSelection(searchtextoffset, len, 0);
                    searchtextoffset += len;
                }
            }
            else
            {
                if (MessageBox.Show(Properties.Strings.MessageBoxSearchTryFromBegining, Properties.Strings.MessageBoxSearchCaption, MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.OK)
                {
                    var first = _transcription.First();
                    VirtualizingListBox.ActiveTransctiption = first;
                    FindNext(pattern, isregex, CaseSensitive, searchinspeakers);
                }
            }
        }
        void l_MoveDownRequest(object sender, EventArgs e)
        {
            bool playing = false;
            if (RequestPlaying != null)
                RequestPlaying(out playing);

            if (playing && RequestPlayPause != null)
                RequestPlayPause();

            Element el = (Element)sender;
            TranscriptionElement tr = el.ValueElement;

            if (tr == null)
                return;
            TextViewPosition twpos = el.editor.TextArea.Caret.Position;

            var next = tr.Next();
            if (next != null)
            {
                this.Dispatcher.Invoke(() =>
                {
                    listbox.ScrollIntoView(next);
                    var n = listbox.ItemContainerGenerator.ContainerFromItem(next).VisualFindChild<Element>();
                    el = GetVisualForTransctiption(tr);
                    Point p = el.editor.TextArea.TextView.GetVisualPosition(twpos, VisualYPosition.LineMiddle);

                    p = el.editor.PointToScreen(p);

                    Point p2 = n.editor.TextArea.TextView.GetVisualPosition(new TextViewPosition(1, 1), VisualYPosition.LineMiddle);
                    p2 = n.editor.PointToScreen(p2);

                    Point loc = new Point(p.X, p2.Y);

                    p2 = n.editor.PointFromScreen(loc);
                    var tpos = n.editor.TextArea.TextView.GetPosition(p2);

                    int pos = 0;
                    if (tpos.HasValue)
                        pos = n.editor.Document.Lines[tpos.Value.Line - 1].Offset + tpos.Value.Column - 1;
                    else
                        pos = n.editor.Document.TextLength;

                    n.SetCaretOffset(pos);
                }, DispatcherPriority.Background);
            }

            if (playing && RequestPlayPause != null)
                RequestPlayPause();
        }
        private void Vizualizer_PreviewKeyDown(object sender, KeyEventArgs e)
        {

            if (e.Key == Key.Tab)
            {
                if (PlayPauseRequest != null)
                    PlayPauseRequest(this, new EventArgs());
                e.Handled = true;

                return;
            }

            if (ActiveElement == null)
                return;

            var trans = ActiveElement.TransformToAncestor(listbox);
            var topleft = trans.Transform(new Point(5, 5));

            if (e.Key == Key.PageDown)
            {
                e.Handled = true;
                _scrollViewer.PageDown();

                Dispatcher.Invoke(() =>
                {
                    TranscriptionElement elm = null;
                    var elmc = listbox.ItemContainerGenerator.ContainerFromItem(Transcription.Last()) as ListBoxItem;

                    if (elmc != null)
                    {
                        var pnt = elmc.TransformToAncestor(listbox).Transform(new Point(0, 0));
                        if (pnt.Y < listbox.ActualHeight)
                            elm = Transcription.Last();
                    }

                    if (elm == null)
                        elm = listbox.GetObjectAtPoint<ListBoxItem>(topleft) as TranscriptionElement;

                    if (elm == null)
                        elm = listbox.GetObjectAtPoint<ListBoxItem>(new Point(5, 5)) as TranscriptionElement;

                    if (elm != null)
                    {
                        ActiveTransctiption = elm;
                        ActiveElement.SetCaretOffset(0);
                    }

                }, DispatcherPriority.Background);

            }
            else if (e.Key == Key.PageUp)
            {
                e.Handled = true;
                _scrollViewer.PageUp();

                Dispatcher.Invoke(() =>
                {
                    TranscriptionElement elm = null;
                    var elmc = listbox.ItemContainerGenerator.ContainerFromItem(Transcription.First()) as ListBoxItem;

                    if (elmc != null)
                    {
                        var pnt = elmc.TransformToAncestor(listbox).Transform(new Point(elmc.ActualWidth - 1, elmc.ActualHeight - 1));
                        if (pnt.Y > 0)
                            elm = Transcription.First();
                    }

                    if (elm == null)
                        elm = listbox.GetObjectAtPoint<ListBoxItem>(topleft) as TranscriptionElement;

                    if (elm == null)
                        elm = listbox.GetObjectAtPoint<ListBoxItem>(new Point(5, 5)) as TranscriptionElement;

                    if (elm != null)
                    {
                        ActiveTransctiption = elm;
                        ActiveElement.SetCaretOffset(0);
                    }

                }, DispatcherPriority.Background);
            }
        }
 public Element GetVisualForTransctiption(TranscriptionElement el)
 {
     return listbox.ItemContainerGenerator.ContainerFromItem(el).VisualFindChild<Element>();
 }
 private void FixPosSetFor(TranscriptionElement elm)
 {
     _FixPosElm = elm;
     var prevc = listbox.ItemContainerGenerator.ContainerFromItem(elm) as ListBoxItem;
     _FixPosElmPos = prevc.TransformToAncestor(_scrollViewer).Transform(new Point(0, 0));
 }
예제 #11
0
        private void CPlayPauseExecute(object sender, ExecutedRoutedEventArgs e)
        {
            if (MWP == null)
            {
                InitializeAudioPlayer();
            }

            if (MWP == null)
            {
                return;
            }

            if (_playing)
            {
                if (videoAvailable)
                {
                    meVideo.Pause();
                }
                PlayingSelection = false;
                Playing          = false;

                waveform1.CaretPosition = MWP.PausedAt;
            }
            else
            {
                // waveform1.Invalidate();
                bool adjustspeed = false;
                if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift || ToolBar2BtnSlow.IsChecked == true)
                {
                    adjustspeed        = true;
                    meVideo.SpeedRatio = Settings.Default.SlowedPlaybackSpeed;
                }
                else
                {
                    meVideo.SpeedRatio = 1.0;
                }

                if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                {
                    if (waveform1.WaveBegin > waveform1.SelectionEnd || waveform1.WaveEnd < waveform1.SelectionBegin)
                    {
                        waveform1.SelectionBegin = VirtualizingListBox.ActiveTransctiption.Begin;
                        waveform1.SelectionEnd   = VirtualizingListBox.ActiveTransctiption.End;
                    }


                    PlayingSelection = true;
                    oldms            = TimeSpan.Zero;


                    if ((waveform1.SelectionBegin - waveform1.SelectionEnd).Duration() > TimeSpan.FromMilliseconds(100))
                    {
                        SetCaretPosition(waveform1.SelectionBegin);
                    }
                    else
                    {
                        TranscriptionElement par   = VirtualizingListBox.ActiveTransctiption;
                        TimeSpan             konec = par.End + TimeSpan.FromMilliseconds(5);
                        SetCaretPosition(konec);
                        waveform1.SelectionBegin = konec;
                        waveform1.SelectionEnd   = konec + TimeSpan.FromMilliseconds(120000);
                    }
                }

                meVideo.Position = waveform1.CaretPosition;
                if (videoAvailable)
                {
                    meVideo.Play();
                }
                //spusteni prehravani pomoci tlacitka-kvuli nacteni primeho prehravani

                Playing = true; //TODO: MWP and Playing are not properly linked - you have to set Playing to true before calling play

                if (adjustspeed)
                {
                    MWP.Play(Settings.Default.SlowedPlaybackSpeed);
                }
                else
                {
                    MWP.Play();
                }
            }
        }