示例#1
0
        private void AppendTextVisuallyToolStripMenuItemClick(object sender, EventArgs e)
        {
            if (IsSubtitleLoaded)
            {
                ReloadFromSourceView();

                if (MessageBox.Show(_language.SubtitleAppendPrompt, _language.SubtitleAppendPromptTitle, MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                {
                    openFileDialog1.Title = _language.OpenSubtitleToAppend;
                    openFileDialog1.FileName = string.Empty;
                    openFileDialog1.Filter = Utilities.GetOpenDialogFilter();
                    if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
                    {
                        bool success = false;
                        string fileName = openFileDialog1.FileName;
                        if (File.Exists(fileName))
                        {
                            var subtitleToAppend = new Subtitle();
                            Encoding encoding;
                            SubtitleFormat format = null;

                            // do not allow blu-ray/vobsub
                            string extension = Path.GetExtension(fileName).ToLower();
                            if (extension == ".sub" && (IsVobSubFile(fileName, false) || IsSpDvdSupFile(fileName)))
                            {
                                format = null;
                            }
                            else if (extension == ".sup" && IsBluRaySupFile(fileName))
                            {
                                format = null;
                            }
                            else
                            {
                                format = subtitleToAppend.LoadSubtitle(fileName, out encoding, null);
                                if (GetCurrentSubtitleFormat().IsFrameBased)
                                    subtitleToAppend.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
                                else
                                    subtitleToAppend.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
                            }

                            if (format != null)
                            {
                                if (subtitleToAppend != null && subtitleToAppend.Paragraphs.Count > 1)
                                {
                                    var visualSync = new VisualSync();
                                    visualSync.Initialize(toolStripButtonVisualSync.Image as Bitmap, subtitleToAppend, _fileName, _language.AppendViaVisualSyncTitle, CurrentFrameRate);
                                    visualSync.ShowDialog(this);
                                    if (visualSync.OKPressed)
                                    {
                                        if (MessageBox.Show(_language.AppendSynchronizedSubtitlePrompt, _language.SubtitleAppendPromptTitle, MessageBoxButtons.YesNo) == DialogResult.Yes)
                                        {
                                            int start = _subtitle.Paragraphs.Count +1;
                                            var fr = CurrentFrameRate;
                                            MakeHistoryForUndo(_language.BeforeAppend);
                                            foreach (Paragraph p in visualSync.Paragraphs)
                                            {
                                                if (format.IsFrameBased)
                                                    p.CalculateFrameNumbersFromTimeCodes(fr);
                                                _subtitle.Paragraphs.Add(new Paragraph(p));
                                            }
                                            if (format.GetType() == typeof(AdvancedSubStationAlpha) && GetCurrentSubtitleFormat().GetType() == typeof(AdvancedSubStationAlpha))
                                            {
                                                List<string> currentStyles = new List<string>();
                                                if (_subtitle.Header != null)
                                                    currentStyles = AdvancedSubStationAlpha.GetStylesFromHeader(_subtitle.Header);
                                                foreach (string styleName in AdvancedSubStationAlpha.GetStylesFromHeader(subtitleToAppend.Header))
                                                {
                                                    bool alreadyExists = false;
                                                    foreach (string currentStyleName in currentStyles)
                                                    {
                                                        if (currentStyleName.ToLower().Trim() == styleName.ToLower().Trim())
                                                            alreadyExists = true;
                                                    }
                                                    if (!alreadyExists)
                                                    {
                                                        var newStyle = AdvancedSubStationAlpha.GetSsaStyle(styleName, subtitleToAppend.Header);
                                                        _subtitle.Header = AdvancedSubStationAlpha.AddSsaStyle(newStyle, _subtitle.Header);
                                                    }
                                                }
                                            }

                                            _subtitle.Renumber(1);

                                            ShowSource();
                                            SubtitleListview1.Fill(_subtitle, _subtitleAlternate);

                                            // select appended lines
                                            for (int i = start; i < _subtitle.Paragraphs.Count; i++)
                                                SubtitleListview1.Items[i].Selected = true;
                                            SubtitleListview1.EnsureVisible(start);

                                            ShowStatus(string.Format(_language.SubtitleAppendedX, fileName));
                                            success = true;
                                        }
                                    }
                                    visualSync.Dispose();
                                }
                            }
                        }
                        if (!success)
                            ShowStatus(_language.SubtitleNotAppended);
                    }
                }
            }
            else
            {
                MessageBox.Show(_language.NoSubtitleLoaded, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#2
0
        private void ShowVisualSync(bool onlySelectedLines)
        {
            if (IsSubtitleLoaded)
            {
                var visualSync = new VisualSync();
                _formPositionsAndSizes.SetPositionAndSize(visualSync);
                visualSync.VideoFileName = _videoFileName;
                visualSync.AudioTrackNumber = _videoAudioTrackNumber;

                SaveSubtitleListviewIndexes();
                if (onlySelectedLines)
                {
                    var selectedLines = new Subtitle { WasLoadedWithFrameNumbers = _subtitle.WasLoadedWithFrameNumbers };
                    foreach (int index in SubtitleListview1.SelectedIndices)
                        selectedLines.Paragraphs.Add(_subtitle.Paragraphs[index]);
                    visualSync.Initialize(toolStripButtonVisualSync.Image as Bitmap, selectedLines, _fileName, _language.VisualSyncSelectedLines, CurrentFrameRate);
                }
                else
                {
                    visualSync.Initialize(toolStripButtonVisualSync.Image as Bitmap, _subtitle, _fileName, _language.VisualSyncTitle, CurrentFrameRate);
                }

                _endSeconds = -1;
                mediaPlayer.Pause();
                if (visualSync.ShowDialog(this) == DialogResult.OK)
                {
                    MakeHistoryForUndo(_language.BeforeVisualSync);

                    if (onlySelectedLines)
                    { // we only update selected lines
                        int i = 0;
                        foreach (int index in SubtitleListview1.SelectedIndices)
                        {
                            _subtitle.Paragraphs[index] = visualSync.Paragraphs[i];
                            i++;
                        }
                        ShowStatus(_language.VisualSyncPerformedOnSelectedLines);
                    }
                    else
                    {
                        _subtitle.Paragraphs.Clear();
                        foreach (Paragraph p in visualSync.Paragraphs)
                            _subtitle.Paragraphs.Add(new Paragraph(p));
                        ShowStatus(_language.VisualSyncPerformed);
                    }
                    if (visualSync.FrameRateChanged)
                        toolStripComboBoxFrameRate.Text = string.Format("{0:0.###}", visualSync.FrameRate);
                    if (IsFramesRelevant && CurrentFrameRate > 0)
                    {
                        _subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(CurrentFrameRate);
                        if (tabControlSubtitle.SelectedIndex == TabControlSourceView)
                            ShowSource();
                    }
                    ShowSource();
                    SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                    RestoreSubtitleListviewIndexes();
                    if (onlySelectedLines && SubtitleListview1.SelectedItems.Count > 0)
                    {
                        SubtitleListview1.EnsureVisible(SubtitleListview1.SelectedItems[SubtitleListview1.SelectedItems.Count - 1].Index);
                    }
                }
                _videoFileName = visualSync.VideoFileName;
                _formPositionsAndSizes.SavePositionAndSize(visualSync);
                visualSync.Dispose();
            }
            else
            {
                MessageBox.Show(this, _language.NoSubtitleLoaded, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

        }