예제 #1
0
파일: Main.cs 프로젝트: m1croN/subtitleedit
        private void FixCommonErrors(bool onlySelectedLines)
        {
            if (IsSubtitleLoaded)
            {
                ReloadFromSourceView();
                SaveSubtitleListviewIndices();
                using (var fixErrors = new FixCommonErrors())
                {
                    if (onlySelectedLines)
                    {
                        var selectedLines = new Subtitle { WasLoadedWithFrameNumbers = _subtitle.WasLoadedWithFrameNumbers };
                        foreach (int index in SubtitleListview1.SelectedIndices)
                            selectedLines.Paragraphs.Add(_subtitle.Paragraphs[index]);
                        fixErrors.Initialize(selectedLines, GetCurrentSubtitleFormat(), GetCurrentEncoding());
                    }
                    else
                    {
                        fixErrors.Initialize(_subtitle, GetCurrentSubtitleFormat(), GetCurrentEncoding());
                    }

                    if (fixErrors.ShowDialog(this) == DialogResult.OK)
                    {
                        MakeHistoryForUndo(_language.BeforeCommonErrorFixes);
                        _subtitle.Renumber();
                        if (onlySelectedLines)
                        {
                            // we only update selected lines
                            int i = 0;
                            if (_networkSession != null)
                            {
                                var deletes = new List<int>();
                                _networkSession.TimerStop();
                                foreach (int index in SubtitleListview1.SelectedIndices)
                                {
                                    var pOld = _subtitle.Paragraphs[index];
                                    var p = fixErrors.FixedSubtitle.GetParagraphOrDefaultById(pOld.ID);
                                    if (p == null)
                                    {
                                        deletes.Add(index);
                                    }
                                    else
                                    {
                                        _subtitle.Paragraphs[index] = p;
                                        SubtitleListview1.SetTimeAndText(index, p);
                                    }
                                    i++;
                                }
                                NetworkGetSendUpdates(deletes, 0, null);
                            }
                            else
                            {
                                for (int index = SubtitleListview1.SelectedIndices.Count - 1; index >= 0; index--)
                                {
                                    var idx = SubtitleListview1.SelectedIndices[index];
                                    var pOld = _subtitle.Paragraphs[idx];
                                    var p = fixErrors.FixedSubtitle.GetParagraphOrDefaultById(pOld.ID);
                                    if (p == null)
                                    {
                                        _subtitle.Paragraphs.RemoveAt(idx);
                                    }
                                    else
                                    {
                                        _subtitle.Paragraphs[idx] = p;
                                    }
                                    i++;
                                }
                            }
                            ShowStatus(_language.CommonErrorsFixedInSelectedLines);
                        }
                        else
                        {
                            _subtitle.Paragraphs.Clear();
                            foreach (var p in fixErrors.FixedSubtitle.Paragraphs)
                                _subtitle.Paragraphs.Add(p);
                            ShowStatus(_language.CommonErrorsFixed);
                        }
                        _subtitle.Renumber();
                        ShowSource();
                        SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                        RestoreSubtitleListviewIndices();
                    }
                    Configuration.Settings.CommonErrors.StartSize = fixErrors.Width + ";" + fixErrors.Height;
                    Configuration.Settings.CommonErrors.StartPosition = fixErrors.Left + ";" + fixErrors.Top;
                }
            }
            else
            {
                DisplaySubtitleNotLoadedMessage();
            }
            ShowInTaskbar = true;
        }
예제 #2
0
 private void buttonFixCommonErrorSettings_Click(object sender, EventArgs e)
 {
     var form = new FixCommonErrors();
     form.RunBatchSettings(new Subtitle(), GetCurrentSubtitleFormat(), GetCurrentEncoding(), Configuration.Settings.Tools.BatchConvertLanguage);
     form.ShowDialog(this);
     Configuration.Settings.Tools.BatchConvertLanguage = form.Language;
 }