Beispiel #1
0
        private void Run_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ARun run = sender as ARun;

            run.Cursor = Cursors.Wait;
            switch (CurrentState)
            {
            case State.Stop:
                if (e.ClickCount == 1)
                {
                    run.Select();
                    run.PlayCachedSound();
                }
                else if (e.ClickCount == 2)
                {
                    StopSound();
                    run.Select();
                    if (run is RunWord)
                    {
                        CurrentState = State.Edit;
                    }
                }
                break;

            case State.Play:
                if (e.ClickCount == 1)
                {
                    CurrentState = State.Stop;
                    StopSound();
                    run.Select();
                    run.PlayCachedSound();
                }
                else if (e.ClickCount == 2)
                {
                    StopSound();
                    run.Select();
                    if (run is RunWord)
                    {
                        CurrentState = State.Edit;
                    }
                }
                break;

            case State.Segment:
                if (e.ClickCount == 1)
                {
                    if (run is RunImage)
                    {
                        run.Select();
                        break;
                    }

                    RunWord     curRun     = run as RunWord;
                    RichTextBox rtb        = curRun.IsImage ? ImageCaptionRTB : BookContentRTB;
                    TextPointer curPointer = rtb.GetPositionFromPoint(e.GetPosition(run), false);
                    if (curPointer == null)
                    {
                        return;
                    }

                    TextPointerContext contextPrev = curPointer.GetPointerContext(GoBackward);
                    TextPointerContext contextNext = curPointer.GetPointerContext(GoForward);

                    // MERGE
                    if (contextNext == TextPointerContext.ElementEnd)
                    {
                        curRun.MergeWithNext();
                    }
                    else if (contextPrev == TextPointerContext.ElementStart)
                    {
                        curRun.MergeWithPrev();
                    }
                    // SPLIT
                    else if (contextPrev == contextNext && contextNext == TextPointerContext.Text)
                    {
                        RunWord newRun = curRun.SplitAt(curPointer);
                        InitiateRun(newRun);
                        newRun.UpdateBackground();
                        //newRun.UpdateSegmentedBackground();
                    }
                }
                break;

            case State.Edit:
                if (e.ClickCount == 1)
                {
                    CurrentState = State.Stop;
                    run.Select();
                    run.PlayCachedSound();
                }
                else if (e.ClickCount == 2)
                {
                    run.Select();
                    if (run is RunWord)
                    {
                        CurrentState = State.Edit;
                    }
                }
                break;

            case State.Caption:
                break;
            }
            run.Cursor = Cursors.Hand;
        }
Beispiel #2
0
        private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            TreeViewItem oldTVI = e.OldValue as TreeViewItem;
            TreeViewItem newTVI = e.NewValue as TreeViewItem;

            //Console.WriteLine("OLD: " + oldTVI + ", NEW: " + newTVI);
            if (newTVI == null || newTVI.Tag == null)
            {
                return;
            }

            Cursor = Cursors.Wait;
            Content oldContent = CurrentContent;
            Content newContent = (newTVI.Tag is ImageBlock ? (newTVI.Tag as ImageBlock).Content : newTVI.Tag as Content);

            if (oldContent != newContent)
            {
                Paragraphs.Clear();
                if (CurrentContent != null)
                {
                    foreach (Block block in CurrentContent.Blocks)
                    {
                        foreach (Sentence sentence in block.Sentences)
                        {
                            sentence.ClearCachedSound();
                        }
                    }
                }
                if (SelectedTVI != null)
                {
                    SelectedTVI.Background = ProjectProperties.Transparent;
                }
                foreach (TreeViewItem tvi in _AllContentsTVI.Items)
                {
                    if (tvi.Tag == oldContent)
                    {
                        tvi.Background = ProjectProperties.Transparent;
                    }
                }

                CurrentState   = State.Stop;
                SelectedTVI    = newTVI;
                CurrentContent = newContent;
                //Console.WriteLine("Sentences Count = " + CurrentContent.TotalSentences);

                foreach (Block block in CurrentContent.Blocks)
                {
                    Paragraph paragraph = new Paragraph();
                    Paragraphs.Add(paragraph);

                    if (block is ImageBlock)
                    {
                        RunImage image = new RunImage(block as ImageBlock);
                        InitiateRun(image);
                        paragraph.Inlines.Add(image);
                        continue;
                    }

                    foreach (Sentence sentence in block.Sentences)
                    {
                        //Console.WriteLine("S: " + sentence.ID);
                        sentence.GetCachedSound();
                        foreach (Word word in sentence.Words)
                        {
                            RunWord run = new RunWord(word);
                            paragraph.Inlines.Add(run);
                            InitiateRun(run);
                        }
                    }
                }
                SelectedTVI.Background = ProjectProperties.SelectedContent;
                foreach (TreeViewItem tvi in _AllContentsTVI.Items)
                {
                    if (tvi.Tag == newContent)
                    {
                        tvi.Background = ProjectProperties.SelectedContent;
                    }
                }

                PageTeller.Text = (1 + ProjectInfo.Contents.IndexOf(CurrentContent)) + " / " + ProjectInfo.Contents.Count;
            }

            if (newTVI.Tag is ImageBlock)
            {
                RunImage runImg = (newTVI.Tag as ImageBlock).Run;
                runImg.Select();
                runImg.BringIntoView();
            }
            else if (CurrentARun == null)
            {
                SelectFirstRunWord();
            }
            else
            {
                CurrentARun.Select();
            }
            Cursor = Cursors.Arrow;
        }