Esempio n. 1
0
 private void comboBoxRule_SelectedIndexChanged(object sender, EventArgs e)
 {
     listViewStyles.Visible = false;
     if (comboBoxRule.SelectedIndex == FunctionRegEx) // regex
     {
         textBox1.ContextMenu          = FindReplaceDialogHelper.GetRegExContextMenu(textBox1);
         checkBoxCaseSensitive.Enabled = false;
     }
     else if (comboBoxRule.SelectedIndex == FunctionUnequal || comboBoxRule.SelectedIndex == FunctionEqual)
     {
         textBox1.ContextMenuStrip     = null;
         checkBoxCaseSensitive.Enabled = false;
     }
     else if (comboBoxRule.SelectedIndex == FunctionStyle)
     {
         checkBoxCaseSensitive.Enabled = false;
         listViewStyles.Visible        = true;
         listViewStyles.BringToFront();
         if (listViewStyles.Items.Count == 0)
         {
             FillStyles();
         }
     }
     else
     {
         textBox1.ContextMenuStrip     = null;
         checkBoxCaseSensitive.Enabled = true;
     }
     Preview();
 }
Esempio n. 2
0
        internal void Initialize(string selectedText, FindReplaceDialogHelper findHelper)
        {
            textBoxFind.Text = selectedText;
            //if we are searching for the same thing, then keep the replace text the same.
            if (selectedText == findHelper.FindText)
            {
                textBoxReplace.Text = findHelper.ReplaceText;
            }
            textBoxFind.SelectAll();
            _left = findHelper.WindowPositionLeft;
            _top  = findHelper.WindowPositionTop;

            if (findHelper.FindType == FindType.RegEx)
            {
                radioButtonRegEx.Checked = true;
            }
            else if (findHelper.FindType == FindType.CaseSensitive)
            {
                radioButtonCaseSensitive.Checked = true;
            }
            else
            {
                radioButtonNormal.Checked = true;
            }
        }
Esempio n. 3
0
        internal void Initialize(string selectedText, FindReplaceDialogHelper findHelper)
        {
            if (Configuration.Settings.Tools.FindHistory.Count > 0)
            {
                textBoxFind.Visible  = false;
                comboBoxFind.Visible = true;
                comboBoxFind.Text    = selectedText;
                comboBoxFind.SelectAll();
                comboBoxFind.Items.Clear();
                for (int index = 0; index < Configuration.Settings.Tools.FindHistory.Count; index++)
                {
                    string s = Configuration.Settings.Tools.FindHistory[index];
                    comboBoxFind.Items.Add(s);
                }
            }
            else
            {
                comboBoxFind.Visible = false;
                textBoxFind.Visible  = true;
                textBoxFind.Text     = selectedText;
                textBoxFind.SelectAll();
            }

            if (findHelper != null)
            {
                FindType = findHelper.FindType;
            }
        }
Esempio n. 4
0
        internal void Initialize(string selectedText, FindReplaceDialogHelper findHelper)
        {
            _findHelper      = findHelper;
            textBoxFind.Text = selectedText;
            if (FindOnly && !string.IsNullOrEmpty(selectedText))
            {
                _findNext = true;
            }

            //if we are searching for the same thing, then keep the replace text the same.
            if (selectedText == findHelper.FindText)
            {
                textBoxReplace.Text = findHelper.ReplaceText.Replace(Environment.NewLine, "\\n");
            }
            textBoxFind.SelectAll();
            if (findHelper.FindReplaceType.FindType == FindType.RegEx)
            {
                radioButtonRegEx.Checked = true;
            }
            else if (findHelper.FindReplaceType.FindType == FindType.CaseSensitive)
            {
                radioButtonCaseSensitive.Checked = true;
            }
            else
            {
                radioButtonNormal.Checked = true;
            }

            if (findHelper.FindReplaceType.FindType != FindType.RegEx)
            {
                checkBoxWholeWord.Checked = findHelper.FindReplaceType.WholeWord;
            }
        }
Esempio n. 5
0
        public MultipleReplace()
        {
            UiUtil.PreInitialize(this);
            InitializeComponent();
            UiUtil.FixFonts(this);

            openFileDialog1.FileName = string.Empty;
            saveFileDialog1.FileName = string.Empty;

            textBoxReplace.ContextMenu = FindReplaceDialogHelper.GetReplaceTextContextMenu(textBoxReplace);
            buttonUpdate.Enabled       = false;

            Text = Configuration.Settings.Language.MultipleReplace.Title;
            labelFindWhat.Text            = Configuration.Settings.Language.MultipleReplace.FindWhat;
            labelReplaceWith.Text         = Configuration.Settings.Language.MultipleReplace.ReplaceWith;
            radioButtonNormal.Text        = Configuration.Settings.Language.MultipleReplace.Normal;
            radioButtonRegEx.Text         = Configuration.Settings.Language.MultipleReplace.RegularExpression;
            radioButtonCaseSensitive.Text = Configuration.Settings.Language.MultipleReplace.CaseSensitive;
            buttonAdd.Text                  = Configuration.Settings.Language.MultipleReplace.Add;
            buttonUpdate.Text               = Configuration.Settings.Language.MultipleReplace.Update;
            listViewRules.Columns[0].Text   = Configuration.Settings.Language.MultipleReplace.Enabled;
            listViewRules.Columns[1].Text   = Configuration.Settings.Language.MultipleReplace.FindWhat;
            listViewRules.Columns[2].Text   = Configuration.Settings.Language.MultipleReplace.ReplaceWith;
            listViewRules.Columns[3].Text   = Configuration.Settings.Language.MultipleReplace.SearchType;
            groupBoxGroups.Text             = Configuration.Settings.Language.MultipleReplace.Groups;
            groupBoxLinesFound.Text         = string.Empty;
            listViewFixes.Columns[0].Text   = Configuration.Settings.Language.General.Apply;
            listViewFixes.Columns[1].Text   = Configuration.Settings.Language.General.LineNumber;
            listViewFixes.Columns[2].Text   = Configuration.Settings.Language.General.Before;
            listViewFixes.Columns[3].Text   = Configuration.Settings.Language.General.After;
            deleteToolStripMenuItem.Text    = Configuration.Settings.Language.MultipleReplace.Remove;
            toolStripMenuItemRemoveAll.Text = Configuration.Settings.Language.MultipleReplace.RemoveAll;
            toolStripMenuItemImport.Text    = Configuration.Settings.Language.MultipleReplace.Import;
            toolStripMenuItemExport.Text    = Configuration.Settings.Language.MultipleReplace.Export;
            buttonNewGroup.Text             = Configuration.Settings.Language.MultipleReplace.NewGroup;
            buttonOK.Text                       = Configuration.Settings.Language.General.Ok;
            buttonCancel.Text                   = Configuration.Settings.Language.General.Cancel;
            buttonReplacesSelectAll.Text        = Configuration.Settings.Language.FixCommonErrors.SelectAll;
            buttonReplacesInverseSelection.Text = Configuration.Settings.Language.FixCommonErrors.InverseSelection;
            UiUtil.FixLargeFonts(this, buttonOK);
            splitContainer1.Panel1MinSize = 200;
            splitContainer1.Panel2MinSize = 200;

            moveUpToolStripMenuItem.Text     = Configuration.Settings.Language.DvdSubRip.MoveUp;
            moveDownToolStripMenuItem.Text   = Configuration.Settings.Language.DvdSubRip.MoveDown;
            moveTopToolStripMenuItem.Text    = Configuration.Settings.Language.MultipleReplace.MoveToTop;
            moveBottomToolStripMenuItem.Text = Configuration.Settings.Language.MultipleReplace.MoveToBottom;
            newToolStripMenuItem.Text        = Configuration.Settings.Language.MultipleReplace.NewGroup;

            toolStripMenuItemMoveRulesToGroup.Text = Configuration.Settings.Language.MultipleReplace.MoveSelectedRulesToGroup;
            moveUpToolStripMenuItem1.Text          = Configuration.Settings.Language.DvdSubRip.MoveUp;
            moveDownToolStripMenuItem1.Text        = Configuration.Settings.Language.DvdSubRip.MoveDown;
            moveToTopToolStripMenuItem.Text        = Configuration.Settings.Language.MultipleReplace.MoveToTop;
            moveToBottomToolStripMenuItem.Text     = Configuration.Settings.Language.MultipleReplace.MoveToBottom;
            toolStripMenuItemRename.Text           = Configuration.Settings.Language.MultipleReplace.RenameGroup;
            deleteToolStripMenuItem1.Text          = Configuration.Settings.Language.MultipleReplace.Remove;

            radioButtonCaseSensitive.Left = radioButtonNormal.Left + radioButtonNormal.Width + 40;
            radioButtonRegEx.Left         = radioButtonCaseSensitive.Left + radioButtonCaseSensitive.Width + 40;
        }
Esempio n. 6
0
        private void comboBoxRule_SelectedIndexChanged(object sender, EventArgs e)
        {
            textBoxText.Visible           = true;
            listViewStyles.Visible        = false;
            numericUpDownDuration.Visible = comboBoxRule.SelectedIndex == FunctionDurationLessThan || comboBoxRule.SelectedIndex == FunctionDurationGreaterThan;
            if (comboBoxRule.SelectedIndex == FunctionRegEx) // regex
            {
                textBoxText.ContextMenu       = FindReplaceDialogHelper.GetRegExContextMenu(textBoxText);
                checkBoxCaseSensitive.Enabled = false;
            }
            else if (comboBoxRule.SelectedIndex == FunctionUnequal || comboBoxRule.SelectedIndex == FunctionEqual)
            {
                textBoxText.ContextMenuStrip  = null;
                checkBoxCaseSensitive.Enabled = false;
            }
            else if (comboBoxRule.SelectedIndex == FunctionStyle)
            {
                checkBoxCaseSensitive.Enabled = false;
                listViewStyles.Visible        = true;
                listViewStyles.BringToFront();
                if (listViewStyles.Items.Count == 0)
                {
                    FillStyles();
                }
            }
            else if (comboBoxRule.SelectedIndex == FunctionDurationLessThan || comboBoxRule.SelectedIndex == FunctionDurationGreaterThan || comboBoxRule.SelectedIndex == FunctionAlUppercase)
            {
                checkBoxCaseSensitive.Enabled = false;
                listViewStyles.Visible        = false;
                textBoxText.Visible           = false;
                if (comboBoxRule.SelectedIndex == FunctionDurationLessThan)
                {
                    if (numericUpDownDuration.Value == 0 &&
                        Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds >= numericUpDownDuration.Minimum &&
                        Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds <= numericUpDownDuration.Maximum)
                    {
                        numericUpDownDuration.Value = Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds;
                    }
                }
                else
                {
                    if (numericUpDownDuration.Value == 0 &&
                        Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds >= numericUpDownDuration.Minimum &&
                        Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds <= numericUpDownDuration.Maximum)
                    {
                        numericUpDownDuration.Value = Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds;
                    }
                }
            }
            else
            {
                textBoxText.ContextMenuStrip  = null;
                checkBoxCaseSensitive.Enabled = true;
            }

            Preview();
        }
 private void RadioButtonCheckedChanged(object sender, EventArgs e)
 {
     if (sender == radioButtonRegEx)
     {
         textBoxFind.ContextMenu = FindReplaceDialogHelper.GetRegExContextMenu(textBoxFind);
     }
     else
     {
         textBoxFind.ContextMenuStrip = null;
     }
 }
Esempio n. 8
0
 private void RadioButtonCheckedChanged(object sender, EventArgs e)
 {
     if (sender == radioButtonRegEx)
     {
         textBoxFind.ContextMenu = FindReplaceDialogHelper.GetRegExContextMenu(textBoxFind);
     }
     else
     {
         textBoxFind.ContextMenu = null;
     }
     checkBoxWholeWord.Enabled = !radioButtonRegEx.Checked;
 }
Esempio n. 9
0
 private void comboBoxRule_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (comboBoxRule.SelectedIndex == 4) // regex
     {
         textBox1.ContextMenu          = FindReplaceDialogHelper.GetRegExContextMenu(textBox1);
         checkBoxCaseSensitive.Enabled = false;
     }
     else
     {
         textBox1.ContextMenuStrip     = null;
         checkBoxCaseSensitive.Enabled = true;
     }
     Preview();
 }
Esempio n. 10
0
 internal void Initialize(string selectedText, FindReplaceDialogHelper findHelper)
 {
     textBoxFind.Text = selectedText;
     //if we are searching for the same thing, then keep the replace text the same.
     if (selectedText == findHelper.FindText)
         textBoxReplace.Text = findHelper.ReplaceText;
     textBoxFind.SelectAll();
     if (findHelper.FindType == FindType.RegEx)
         radioButtonRegEx.Checked = true;
     else if (findHelper.FindType == FindType.CaseSensitive)
         radioButtonCaseSensitive.Checked = true;
     else
         radioButtonNormal.Checked = true;
 }
Esempio n. 11
0
 private void RadioButton_CheckedChanged(object sender, EventArgs e)
 {
     if (sender == radioButtonRegEx)
     {
         if (textBoxFind.Visible)
         {
             comboBoxFind.ContextMenu = null;
             textBoxFind.ContextMenu  = FindReplaceDialogHelper.GetRegExContextMenu(textBoxFind);
         }
         else
         {
             textBoxFind.ContextMenu  = null;
             comboBoxFind.ContextMenu = FindReplaceDialogHelper.GetRegExContextMenu(comboBoxFind);
         }
     }
     else
     {
         textBoxFind.ContextMenu  = null;
         comboBoxFind.ContextMenu = null;
     }
 }
Esempio n. 12
0
        internal void Initialize(string selectedText, FindReplaceDialogHelper findHelper)
        {
            if (findHelper != null && findHelper.FindTextHistory.Count > 0)
            {
                textBoxFind.Visible  = false;
                comboBoxFind.Visible = true;
                comboBoxFind.Text    = selectedText;
                comboBoxFind.SelectAll();
                comboBoxFind.Items.Clear();
                _history = new List <string>();
                foreach (string s in findHelper.FindTextHistory)
                {
                    comboBoxFind.Items.Add(s);
                    _history.Add(s);
                }
            }
            else
            {
                comboBoxFind.Visible = false;
                textBoxFind.Visible  = true;
                textBoxFind.Text     = selectedText;
                textBoxFind.SelectAll();
            }

            if (findHelper != null)
            {
                if (findHelper.FindType == FindType.RegEx)
                {
                    radioButtonRegEx.Checked = true;
                }
                else if (findHelper.FindType == FindType.CaseSensitive)
                {
                    radioButtonCaseSensitive.Checked = true;
                }
                else
                {
                    radioButtonNormal.Checked = true;
                }
            }
        }
Esempio n. 13
0
        internal void Initialize(string selectedText, FindReplaceDialogHelper findHelper)
        {
            if (Configuration.Settings.Tools.FindHistory.Count > 0)
            {
                textBoxFind.Visible  = false;
                comboBoxFind.Visible = true;
                comboBoxFind.Text    = selectedText;
                comboBoxFind.SelectAll();
                comboBoxFind.Items.Clear();
                for (int index = 0; index < Configuration.Settings.Tools.FindHistory.Count; index++)
                {
                    string s = Configuration.Settings.Tools.FindHistory[index];
                    comboBoxFind.Items.Add(s);
                }
            }
            else
            {
                comboBoxFind.Visible = false;
                textBoxFind.Visible  = true;
                textBoxFind.Text     = selectedText;
                textBoxFind.SelectAll();
            }

            if (findHelper != null)
            {
                if (findHelper.FindType == FindType.RegEx)
                {
                    radioButtonRegEx.Checked = true;
                }
                else if (findHelper.FindType == FindType.CaseSensitive)
                {
                    radioButtonCaseSensitive.Checked = true;
                }
                else
                {
                    radioButtonNormal.Checked = true;
                }
            }
        }
Esempio n. 14
0
 private void RadioButton_CheckedChanged(object sender, EventArgs e)
 {
     if (sender == radioButtonRegEx)
     {
         if (textBoxFind.Visible)
         {
             comboBoxFind.ContextMenuStrip = null;
             textBoxFind.ContextMenuStrip  = FindReplaceDialogHelper.GetRegExContextMenu(textBoxFind);
         }
         else
         {
             textBoxFind.ContextMenuStrip  = null;
             comboBoxFind.ContextMenuStrip = FindReplaceDialogHelper.GetRegExContextMenu(comboBoxFind);
         }
     }
     else
     {
         textBoxFind.ContextMenuStrip  = null;
         comboBoxFind.ContextMenuStrip = null;
     }
     checkBoxWholeWord.Enabled = !radioButtonRegEx.Checked;
     labelCount.Text           = string.Empty;
 }
Esempio n. 15
0
        private void ReplaceListView(ReplaceDialog replaceDialog)
        {
            SaveSubtitleListviewIndices();
            int firstIndex = FirstSelectedIndex;
            bool isFirst = true;
            string selectedText = textBoxListViewText.SelectedText;
            if (selectedText.Length == 0 && _findHelper != null)
                selectedText = _findHelper.FindText;

            if (replaceDialog == null)
            {
                replaceDialog = new ReplaceDialog();
                replaceDialog.SetIcon(toolStripButtonReplace.Image as Bitmap);
                if (_findHelper == null)
                {
                    _findHelper = replaceDialog.GetFindDialogHelper(_subtitleListViewIndex);
                    _findHelper.WindowPositionLeft = Left + (Width / 2) - (replaceDialog.Width / 2);
                    _findHelper.WindowPositionTop = Top + (Height / 2) - (replaceDialog.Height / 2);
                }
                int index = 0;

                if (SubtitleListview1.SelectedItems.Count > 0)
                    index = SubtitleListview1.SelectedItems[0].Index;

                _findHelper.SelectedIndex = index;
                _findHelper.SelectedPosition = index;
                _replaceStartLineIndex = index;
            }
            else
            {
                isFirst = false;
                if (_findHelper != null)
                    selectedText = _findHelper.FindText;
            }
            replaceDialog.Initialize(selectedText, _findHelper);
            if (replaceDialog.ShowDialog(this) == DialogResult.OK)
            {
                if (_findHelper == null)
                {
                    _findHelper = replaceDialog.GetFindDialogHelper(_subtitleListViewIndex);
                }
                else
                {
                    int line = _findHelper.SelectedIndex;
                    int pos = _findHelper.SelectedPosition;
                    bool success = _findHelper.Success;
                    _findHelper = replaceDialog.GetFindDialogHelper(_subtitleListViewIndex);
                    _findHelper.SelectedIndex = line;
                    _findHelper.SelectedPosition = pos;
                    _findHelper.Success = success;
                }
                ShowStatus(string.Format(_language.SearchingForXFromLineY, _findHelper.FindText, _subtitleListViewIndex + 1));
                int replaceCount = 0;
                bool searchStringFound = true;
                while (searchStringFound)
                {
                    searchStringFound = false;
                    if (isFirst)
                    {
                        MakeHistoryForUndo(string.Format(_language.BeforeReplace, _findHelper.FindText));
                        isFirst = false;
                        _makeHistoryPaused = true;
                    }

                    if (replaceDialog.ReplaceAll)
                    {
                        if (_findHelper.FindNext(_subtitle, _subtitleAlternate, _findHelper.SelectedIndex, _findHelper.SelectedPosition, Configuration.Settings.General.AllowEditOfOriginalSubtitle))
                        {
                            textBoxListViewText.Visible = false;
                            SetTextForFindAndReplace(true);
                            _findHelper.SelectedPosition += _findHelper.ReplaceText.Length;
                            searchStringFound = true;
                            replaceCount++;
                        }
                        else
                        {
                            textBoxListViewText.Visible = true;
                            _subtitleListViewIndex = -1;
                            if (firstIndex >= 0 && firstIndex < SubtitleListview1.Items.Count)
                            {
                                SubtitleListview1.Items[firstIndex].Selected = true;
                                SubtitleListview1.Items[firstIndex].Focused = true;
                                SubtitleListview1.Focus();
                                textBoxListViewText.Text = _subtitle.Paragraphs[firstIndex].Text;
                                if (_subtitleAlternate != null && textBoxListViewTextAlternate.Visible)
                                {
                                    var orginial = Utilities.GetOriginalParagraph(_findHelper.SelectedIndex, _subtitle.Paragraphs[_findHelper.SelectedIndex], _subtitleAlternate.Paragraphs);
                                    if (orginial != null)
                                        textBoxListViewTextAlternate.Text = orginial.Text;
                                }
                            }
                            else
                            {
                                SubtitleListview1.SelectIndexAndEnsureVisible(0, true);
                            }
                            ShowStatus(string.Format(_language.NoMatchFoundX, _findHelper.FindText));

                            if (_replaceStartLineIndex >= 1) // Prompt for start over
                            {
                                _replaceStartLineIndex = 0;
                                string msgText = _language.ReplaceContinueNotFound;
                                if (replaceCount > 0)
                                    msgText = string.Format(_language.ReplaceXContinue, replaceCount);
                                if (MessageBox.Show(msgText, _language.ReplaceContinueTitle, MessageBoxButtons.YesNo) == DialogResult.Yes)
                                {
                                    _findHelper.StartLineIndex = 0;
                                    _findHelper.SelectedIndex = 0;
                                    _findHelper.SelectedPosition = 0;
                                    SetTextForFindAndReplace(false);

                                    if (_findHelper.FindNext(_subtitle, _subtitleAlternate, _findHelper.SelectedIndex, _findHelper.SelectedPosition, Configuration.Settings.General.AllowEditOfOriginalSubtitle))
                                    {
                                        SetTextForFindAndReplace(true);
                                        _findHelper.SelectedPosition += _findHelper.ReplaceText.Length;
                                        searchStringFound = true;
                                        replaceCount++;
                                    }
                                }
                            }
                        }
                    }
                    else if (replaceDialog.FindOnly)
                    {
                        if (_findHelper.FindNext(_subtitle, _subtitleAlternate, _findHelper.SelectedIndex, _findHelper.SelectedPosition, Configuration.Settings.General.AllowEditOfOriginalSubtitle))
                        {
                            SubtitleListview1.SelectIndexAndEnsureVisible(_findHelper.SelectedIndex, true);
                            textBoxListViewText.Focus();
                            textBoxListViewText.SelectionStart = _findHelper.SelectedPosition;
                            textBoxListViewText.SelectionLength = _findHelper.FindTextLength;
                            _findHelper.SelectedPosition += _findHelper.FindTextLength;
                            ShowStatus(string.Format(_language.NoXFoundAtLineY, _findHelper.SelectedIndex + 1, _findHelper.FindText));
                            Replace(replaceDialog);
                            if (replaceDialog != null && !replaceDialog.IsDisposed)
                            {
                                replaceDialog.Dispose();
                                replaceDialog = null;
                            }
                            return;
                        }
                        if (_replaceStartLineIndex >= 1) // Prompt for start over
                        {
                            _replaceStartLineIndex = 0;
                            if (MessageBox.Show(_language.FindContinue, _language.FindContinueTitle, MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                SubtitleListview1.SelectIndexAndEnsureVisible(0);
                                _findHelper.StartLineIndex = 0;
                                _findHelper.SelectedIndex = 0;
                                _findHelper.SelectedPosition = 0;
                                if (_findHelper.FindNext(_subtitle, _subtitleAlternate, _findHelper.SelectedIndex, _findHelper.SelectedPosition, Configuration.Settings.General.AllowEditOfOriginalSubtitle))
                                {
                                    SubtitleListview1.SelectIndexAndEnsureVisible(_findHelper.SelectedIndex);
                                    textBoxListViewText.Focus();
                                    textBoxListViewText.SelectionStart = _findHelper.SelectedPosition;
                                    textBoxListViewText.SelectionLength = _findHelper.FindTextLength;
                                    _findHelper.SelectedPosition += _findHelper.FindTextLength;
                                    ShowStatus(string.Format(_language.NoXFoundAtLineY, _findHelper.SelectedIndex + 1, _findHelper.FindText));
                                    Replace(replaceDialog);
                                    if (replaceDialog != null)
                                    {
                                        replaceDialog.Dispose();
                                        replaceDialog = null;
                                    }
                                    return;
                                }
                            }
                            else
                            {
                                if (replaceDialog != null && !replaceDialog.IsDisposed)
                                {
                                    replaceDialog.Dispose();
                                    replaceDialog = null;
                                }
                                return;
                            }
                        }
                        ShowStatus(string.Format(_language.NoMatchFoundX, _findHelper.FindText));
                    }
                    else if (!replaceDialog.FindOnly) // replace once only
                    {
                        string msg = string.Empty;
                        if (_findHelper.FindType == FindType.RegEx && _findHelper.Success)
                        {
                            if (_findHelper.FindType == FindType.RegEx)
                            {
                                ReplaceViaRegularExpression();
                            }
                            else
                            {
                                textBoxListViewText.SelectedText = _findHelper.ReplaceText;
                            }
                            msg = _language.OneReplacementMade + " ";
                        }
                        else if (textBoxListViewText.SelectionLength == _findHelper.FindTextLength)
                        {
                            textBoxListViewText.SelectedText = _findHelper.ReplaceText;
                            msg = _language.OneReplacementMade + " ";
                        }

                        if (_findHelper.FindNext(_subtitle, _subtitleAlternate, _findHelper.SelectedIndex, _findHelper.SelectedPosition, Configuration.Settings.General.AllowEditOfOriginalSubtitle))
                        {
                            SubtitleListview1.SelectIndexAndEnsureVisible(_findHelper.SelectedIndex);
                            if (_findHelper.MatchInOriginal)
                            {
                                textBoxListViewTextAlternate.Focus();
                                textBoxListViewTextAlternate.SelectionStart = _findHelper.SelectedPosition;
                                textBoxListViewTextAlternate.SelectionLength = _findHelper.FindTextLength;
                            }
                            else
                            {
                                textBoxListViewText.Focus();
                                textBoxListViewText.SelectionStart = _findHelper.SelectedPosition;
                                textBoxListViewText.SelectionLength = _findHelper.FindTextLength;
                            }
                            _findHelper.SelectedPosition += _findHelper.ReplaceText.Length;
                            ShowStatus(string.Format(msg + _language.XFoundAtLineNumberY, _findHelper.FindText, _findHelper.SelectedIndex + 1));
                        }
                        else
                        {
                            ShowStatus(msg + string.Format(_language.XNotFound, _findHelper.FindText));

                            // Prompt for start over
                            if (_replaceStartLineIndex >= 1)
                            {
                                _replaceStartLineIndex = 0;
                                if (MessageBox.Show(_language.FindContinue, _language.FindContinueTitle, MessageBoxButtons.YesNo) == DialogResult.Yes)
                                {
                                    SubtitleListview1.SelectIndexAndEnsureVisible(0);
                                    _findHelper.StartLineIndex = 0;
                                    _findHelper.SelectedIndex = 0;
                                    _findHelper.SelectedPosition = 0;

                                    if (_findHelper.FindNext(_subtitle, _subtitleAlternate, _findHelper.SelectedIndex, _findHelper.SelectedPosition, Configuration.Settings.General.AllowEditOfOriginalSubtitle))
                                    {
                                        SubtitleListview1.SelectIndexAndEnsureVisible(_findHelper.SelectedIndex, true);
                                        textBoxListViewText.Focus();
                                        textBoxListViewText.SelectionStart = _findHelper.SelectedPosition;
                                        textBoxListViewText.SelectionLength = _findHelper.FindTextLength;
                                        _findHelper.SelectedPosition += _findHelper.ReplaceText.Length;
                                        ShowStatus(string.Format(msg + _language.XFoundAtLineNumberY, _findHelper.FindText, _findHelper.SelectedIndex + 1));
                                    }
                                }
                                else
                                {
                                    if (replaceDialog != null && !replaceDialog.IsDisposed)
                                    {
                                        replaceDialog.Dispose();
                                        replaceDialog = null;
                                    }
                                    return;
                                }
                            }
                        }
                        Replace(replaceDialog);
                        if (replaceDialog != null && !replaceDialog.IsDisposed)
                        {
                            replaceDialog.Dispose();
                            replaceDialog = null;
                        }
                        return;
                    }
                }

                ShowSource();
                if (replaceCount == 0)
                    ShowStatus(_language.FoundNothingToReplace);
                else
                    ShowStatus(string.Format(_language.ReplaceCountX, replaceCount));
            }
            RestoreSubtitleListviewIndices();
            if (_makeHistoryPaused)
                RestartHistory();
            replaceDialog.Dispose();
        }
Esempio n. 16
0
        private void SourceListReplaceAll(ReplaceDialog replaceDialog, FindReplaceDialogHelper findHelper)
        {
            int replaceCount = 0;
            bool searchStringFound = true;
            int start = textBoxSource.SelectionStart;
            bool isFirst = true;
            string text = textBoxSource.Text;
            while (searchStringFound)
            {
                searchStringFound = false;
                if (isFirst)
                {
                    MakeHistoryForUndo(string.Format(_language.BeforeReplace, _findHelper.FindText));
                    isFirst = false;
                    _makeHistoryPaused = true;
                    if (start >= 0)
                        start--;
                }
                else
                {
                    start--;
                }

                if (_findHelper.FindNext(text, start))
                {
                    text = text.Remove(findHelper.SelectedIndex, findHelper.FindTextLength).Insert(findHelper.SelectedIndex, findHelper.ReplaceText);
                    start = findHelper.SelectedIndex + findHelper.FindTextLength;
                    replaceCount++;
                    searchStringFound = true;
                }
            }
            textBoxSource.Text = text;
            ReloadFromSourceView();
            if (replaceCount == 0)
                ShowStatus(_language.FoundNothingToReplace);
            else
                ShowStatus(string.Format(_language.ReplaceCountX, replaceCount));

            if (_makeHistoryPaused)
                RestartHistory();
            replaceDialog.Dispose();
        }
Esempio n. 17
0
        private void ReplaceSourceView(ReplaceDialog replaceDialog)
        {
            bool isFirst = true;
            string selectedText = textBoxSource.SelectedText;
            if (selectedText.Length == 0 && _findHelper != null)
                selectedText = _findHelper.FindText;

            if (replaceDialog == null)
            {
                replaceDialog = new ReplaceDialog();
                replaceDialog.SetIcon(toolStripButtonReplace.Image as Bitmap);
                if (_findHelper == null)
                {
                    _findHelper = replaceDialog.GetFindDialogHelper(_subtitleListViewIndex);
                    _findHelper.WindowPositionLeft = Left + (Width / 2) - (replaceDialog.Width / 2);
                    _findHelper.WindowPositionTop = Top + (Height / 2) - (replaceDialog.Height / 2);
                }
            }
            else
                isFirst = false;

            replaceDialog.Initialize(selectedText, _findHelper);
            if (replaceDialog.ShowDialog(this) == DialogResult.OK)
            {
                _findHelper = replaceDialog.GetFindDialogHelper(_subtitleListViewIndex);
                ShowStatus(string.Format(_language.SearchingForXFromLineY, _findHelper.FindText, _subtitleListViewIndex + 1));
                if (replaceDialog.ReplaceAll)
                {
                    SourceListReplaceAll(replaceDialog, _findHelper);
                    return;
                }
                int replaceCount = 0;
                bool searchStringFound = true;
                if (searchStringFound)
                {
                    searchStringFound = false;
                    int start = textBoxSource.SelectionStart;
                    if (isFirst)
                    {
                        MakeHistoryForUndo(string.Format(_language.BeforeReplace, _findHelper.FindText));
                        isFirst = false;
                        _makeHistoryPaused = true;
                        if (start >= 0)
                            start--;
                    }
                    else
                    {
                        if (textBoxSource.SelectionLength > 0 && start > 0 && !replaceDialog.FindOnly)
                            start--;
                    }

                    if (_findHelper.FindNext(textBoxSource.Text, start))
                    {
                        textBoxSource.SelectionStart = _findHelper.SelectedIndex;
                        textBoxSource.SelectionLength = _findHelper.FindTextLength;
                        if (!replaceDialog.FindOnly)
                            textBoxSource.SelectedText = _findHelper.ReplaceText;
                        textBoxSource.ScrollToCaret();

                        replaceCount++;
                        searchStringFound = true;

                        if (!replaceDialog.FindOnly)
                        {
                            if (_findHelper.FindNext(textBoxSource.Text, start))
                            {
                                textBoxSource.SelectionStart = _findHelper.SelectedIndex;
                                textBoxSource.SelectionLength = _findHelper.FindTextLength;
                                textBoxSource.ScrollToCaret();
                            }
                            Replace(replaceDialog);
                            return;
                        }
                    }
                    if (replaceDialog.FindOnly)
                    {
                        if (searchStringFound)
                            ShowStatus(string.Format(_language.MatchFoundX, _findHelper.FindText));
                        else
                            ShowStatus(string.Format(_language.NoMatchFoundX, _findHelper.FindText));

                        Replace(replaceDialog);
                        return;
                    }
                }
                ReloadFromSourceView();
                if (replaceCount == 0)
                    ShowStatus(_language.FoundNothingToReplace);
                else
                    ShowStatus(string.Format(_language.ReplaceCountX, replaceCount));
            }
            if (_makeHistoryPaused)
                RestartHistory();
            replaceDialog.Dispose();
        }
Esempio n. 18
0
        private void Find()
        {
            string selectedText;
            if (tabControlSubtitle.SelectedIndex == TabControlSourceView)
                selectedText = textBoxSource.SelectedText;
            else
                selectedText = textBoxListViewText.SelectedText;

            if (selectedText.Length == 0 && _findHelper != null)
            {
                if (_clearLastFind)
                {
                    _clearLastFind = false;
                    _findHelper.FindType = _clearLastFindType;
                    selectedText = _clearLastFindText;
                }
                else
                {
                    selectedText = _findHelper.FindText;
                }
            }

            using (var findDialog = new FindDialog(_subtitle))
            {
                findDialog.SetIcon(toolStripButtonFind.Image as Bitmap);
                findDialog.Initialize(selectedText, _findHelper);
                if (findDialog.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                _findHelper = findDialog.GetFindDialogHelper(_subtitleListViewIndex);
                if (!string.IsNullOrWhiteSpace(_findHelper.FindText))
                {
                    if (Configuration.Settings.Tools.FindHistory.Count == 0 || Configuration.Settings.Tools.FindHistory[0] != _findHelper.FindText)
                        Configuration.Settings.Tools.FindHistory.Insert(0, _findHelper.FindText);
                }
                ShowStatus(string.Format(_language.SearchingForXFromLineY, _findHelper.FindText, _subtitleListViewIndex + 1));
                if (tabControlSubtitle.SelectedIndex == TabControlListView)
                {
                    int selectedIndex = -1;
                    //set the starting selectedIndex if a row is highlighted
                    if (SubtitleListview1.SelectedItems.Count > 0)
                        selectedIndex = SubtitleListview1.SelectedItems[0].Index;

                    //if we fail to find the text, we might want to start searching from the top of the file.
                    bool foundIt = false;
                    if (_findHelper.Find(_subtitle, _subtitleAlternate, selectedIndex))
                    {
                        foundIt = true;
                    }
                    else if (_findHelper.StartLineIndex >= 1)
                    {
                        if (MessageBox.Show(_language.FindContinue, _language.FindContinueTitle, MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            selectedIndex = -1;
                            if (_findHelper.Find(_subtitle, _subtitleAlternate, selectedIndex))
                                foundIt = true;
                        }
                    }

                    if (foundIt)
                    {
                        SubtitleListview1.SelectIndexAndEnsureVisible(_findHelper.SelectedIndex);
                        TextBox tb;
                        if (_findHelper.MatchInOriginal)
                            tb = textBoxListViewTextAlternate;
                        else
                            tb = textBoxListViewText;
                        tb.Focus();
                        tb.SelectionStart = _findHelper.SelectedPosition;
                        tb.SelectionLength = _findHelper.FindTextLength;
                        ShowStatus(string.Format(_language.XFoundAtLineNumberY, _findHelper.FindText, _findHelper.SelectedIndex + 1));
                        _findHelper.SelectedPosition++;
                    }
                    else
                    {
                        ShowStatus(string.Format(_language.XNotFound, _findHelper.FindText));
                    }
                }
                else if (tabControlSubtitle.SelectedIndex == TabControlSourceView)
                {
                    if (_findHelper.Find(textBoxSource, textBoxSource.SelectionStart))
                    {
                        textBoxSource.SelectionStart = _findHelper.SelectedIndex;
                        textBoxSource.SelectionLength = _findHelper.FindTextLength;
                        textBoxSource.ScrollToCaret();
                        ShowStatus(string.Format(_language.XFoundAtLineNumberY, _findHelper.FindText, textBoxSource.GetLineFromCharIndex(textBoxSource.SelectionStart)));
                    }
                    else
                    {
                        ShowStatus(string.Format(_language.XNotFound, _findHelper.FindText));
                    }
                }
            }
        }
Esempio n. 19
0
        private void ResetSubtitle()
        {
            SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);

            labelStartTimeWarning.Text = string.Empty;
            labelDurationWarning.Text = string.Empty;

            _subtitle = new Subtitle(_subtitle.HistoryItems);
            _changeAlternateSubtitleToString = string.Empty;
            _changeSubtitleToString = string.Empty;
            _subtitleAlternateFileName = null;
            textBoxSource.Text = string.Empty;
            SubtitleListview1.Items.Clear();
            _fileName = string.Empty;
            _fileDateTime = new DateTime();
            Text = Title;
            _oldSubtitleFormat = null;
            labelSingleLine.Text = string.Empty;
            RemoveAlternate(true);
            _splitDualSami = false;

            SubtitleListview1.HideExtraColumn();
            SubtitleListview1.DisplayExtraFromExtra = false;

            ComboBoxSubtitleFormatsSelectedIndexChanged(null, null);

            toolStripComboBoxFrameRate.Text = Configuration.Settings.General.DefaultFrameRate.ToString();

            SetEncoding(Configuration.Settings.General.DefaultEncoding);

            toolStripComboBoxFrameRate.Text = Configuration.Settings.General.DefaultFrameRate.ToString();
            _findHelper = null;
            _spellCheckForm = null;
            _videoFileName = null;
            _videoInfo = null;
            _videoAudioTrackNumber = -1;
            labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
            audioVisualizer.WavePeaks = null;
            audioVisualizer.Spectrogram = null;

            _sourceViewChange = false;

            _subtitleListViewIndex = -1;
            textBoxListViewText.Text = string.Empty;
            textBoxListViewTextAlternate.Text = string.Empty;
            textBoxListViewText.Enabled = false;
            labelTextLineLengths.Text = string.Empty;
            labelCharactersPerSecond.Text = string.Empty;
            labelTextLineTotal.Text = string.Empty;

            _listViewTextUndoLast = null;
            _listViewAlternateTextUndoLast = null;
            _listViewTextUndoIndex = -1;

            if (mediaPlayer.VideoPlayer != null)
            {
                mediaPlayer.VideoPlayer.DisposeVideoPlayer();
                mediaPlayer.VideoPlayer = null;
            }

            _changeSubtitleToString = _subtitle.GetFastHashCode();
            _converted = false;

            SetUndockedWindowsTitle();
            mediaPlayer.SubtitleText = string.Empty;
            ShowStatus(_language.New);

            ResetShowEarlierOrLater();
        }
Esempio n. 20
0
        private void OpenSubtitle(string fileName, Encoding encoding, string videoFileName, string originalFileName)
        {
            if (File.Exists(fileName))
            {
                bool videoFileLoaded = false;
                var file = new FileInfo(fileName);
                var ext = file.Extension.ToLowerInvariant();

                // save last first visible index + first selected index from listview
                if (!string.IsNullOrEmpty(_fileName))
                    Configuration.Settings.RecentFiles.Add(_fileName, FirstVisibleIndex, FirstSelectedIndex, _videoFileName, originalFileName);

                openFileDialog1.InitialDirectory = file.DirectoryName;

                if (ext == ".sub" && IsVobSubFile(fileName, false))
                {
                    if (MessageBox.Show(this, _language.ImportThisVobSubSubtitle, _title, MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        ImportAndOcrVobSubSubtitleNew(fileName, _loading);
                    }
                    return;
                }

                if (ext == ".sup")
                {
                    if (FileUtil.IsBluRaySup(fileName))
                    {
                        ImportAndOcrBluRaySup(fileName, _loading);
                        return;
                    }
                    else if (FileUtil.IsSpDvdSup(fileName))
                    {
                        ImportAndOcrSpDvdSup(fileName, _loading);
                        return;
                    }
                }

                if (ext == ".mkv" || ext == ".mks")
                {
                    ImportSubtitleFromMatroskaFile(fileName);
                    return;
                }

                if (ext == ".divx" || ext == ".avi")
                {
                    if (ImportSubtitleFromDivX(fileName))
                        return;
                }

                if ((ext == ".ts" || ext == ".rec" || ext == ".mpeg" || ext == ".mpg") && file.Length > 10000 && FileUtil.IsTransportStream(fileName))
                {
                    ImportSubtitleFromTransportStream(fileName);
                    return;
                }

                if (((ext == ".m2ts" || ext == ".ts") && file.Length > 10000 && FileUtil.IsM2TransportStream(fileName)) ||
                    (ext == ".textst" && FileUtil.IsMpeg2PrivateStream2(fileName)))
                {
                    bool isTextSt = false;
                    if (file.Length < 2000000)
                    {
                        var textSt = new TextST();
                        isTextSt = textSt.IsMine(null, fileName);
                    }

                    if (!isTextSt)
                    {
                        ImportSubtitleFromTransportStream(fileName);
                        return;
                    }
                }

                if ((ext == ".mp4" || ext == ".m4v" || ext == ".3gp") && file.Length > 10000)
                {
                    if (ImportSubtitleFromMp4(fileName))
                        OpenVideo(fileName);
                    return;
                }

                if (ext == ".mxf")
                {
                    if (FileUtil.IsMaterialExchangeFormat(fileName))
                    {
                        var parser = new MxfParser(fileName);
                        if (parser.IsValid)
                        {
                            var subtitles = parser.GetSubtitles();
                            if (subtitles.Count > 0)
                            {
                                SetEncoding(Configuration.Settings.General.DefaultEncoding);
                                encoding = GetCurrentEncoding();
                                var list = new List<string>(subtitles[0].SplitToLines());
                                _subtitle = new Subtitle();
                                var mxfFormat = _subtitle.ReloadLoadSubtitle(list, null, null);
                                SetCurrentFormat(mxfFormat);
                                _fileName = Path.GetFileNameWithoutExtension(fileName);
                                SetTitle();
                                ShowStatus(string.Format(_language.LoadedSubtitleX, _fileName));
                                _sourceViewChange = false;
                                _changeSubtitleToString = _subtitle.GetFastHashCode();
                                ResetHistory();
                                SetUndockedWindowsTitle();
                                _converted = true;
                                ShowStatus(string.Format(_language.LoadedSubtitleX, _fileName) + " - " + string.Format(_language.ConvertedToX, mxfFormat.FriendlyName));

                                ShowSource();
                                SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                                _subtitleListViewIndex = -1;
                                SubtitleListview1.FirstVisibleIndex = -1;
                                SubtitleListview1.SelectIndexAndEnsureVisible(0);

                                return;
                            }
                            MessageBox.Show("No subtitles found!");
                            return;
                        }
                    }
                }

                if (file.Length > 1024 * 1024 * 10) // max 10 mb
                {
                    // retry Blu-ray sup (file with wrong extension)
                    if (FileUtil.IsBluRaySup(fileName))
                    {
                        ImportAndOcrBluRaySup(fileName, _loading);
                        return;
                    }

                    // retry vobsub (file with wrong extension)
                    if (IsVobSubFile(fileName, false))
                    {
                        if (MessageBox.Show(this, _language.ImportThisVobSubSubtitle, _title, MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            ImportAndOcrVobSubSubtitleNew(fileName, _loading);
                        }
                        return;
                    }

                    var text = string.Format(_language.FileXIsLargerThan10MB + Environment.NewLine + Environment.NewLine + _language.ContinueAnyway, fileName);
                    if (MessageBox.Show(this, text, Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                        return;
                }

                if (_subtitle.HistoryItems.Count > 0 || _subtitle.Paragraphs.Count > 0)
                    MakeHistoryForUndo(string.Format(_language.BeforeLoadOf, Path.GetFileName(fileName)));

                bool change = _changeSubtitleToString != _subtitle.GetFastHashCode();
                if (change)
                    change = _lastDoNotPrompt != _subtitle.GetFastHashCode();

                SubtitleFormat format = _subtitle.LoadSubtitle(fileName, out encoding, encoding);
                if (!change)
                    _changeSubtitleToString = _subtitle.GetFastHashCode();

                ShowHideTextBasedFeatures(format);

                bool justConverted = false;
                if (format == null)
                {
                    var ebu = new Ebu();
                    if (ebu.IsMine(null, fileName))
                    {
                        ebu.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = ebu;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var pac = new Pac();
                    if (pac.IsMine(null, fileName))
                    {
                        pac.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = pac;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (ext == ".m2ts" || ext == ".textst")
                {
                    var textST = new TextST();
                    if (textST.IsMine(null, fileName))
                    {
                        textST.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = textST;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var pns = new Pns();
                    if (pns.IsMine(null, fileName))
                    {
                        pns.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = pns;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }


                if (format == null)
                {
                    var cavena890 = new Cavena890();
                    if (cavena890.IsMine(null, fileName))
                    {
                        cavena890.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = cavena890;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var spt = new Spt();
                    if (spt.IsMine(null, fileName))
                    {
                        spt.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = spt;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null && ext == ".wsb")
                {
                    var wsb = new Wsb();
                    var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                    if (wsb.IsMine(list, fileName))
                    {
                        wsb.LoadSubtitle(_subtitle, list, fileName);
                        _oldSubtitleFormat = wsb;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var cheetahCaption = new CheetahCaption();
                    if (cheetahCaption.IsMine(null, fileName))
                    {
                        cheetahCaption.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = cheetahCaption;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var capMakerPlus = new CapMakerPlus();
                    if (capMakerPlus.IsMine(null, fileName))
                    {
                        capMakerPlus.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = capMakerPlus;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var captionsInc = new CaptionsInc();
                    if (captionsInc.IsMine(null, fileName))
                    {
                        captionsInc.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = captionsInc;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var ultech130 = new Ultech130();
                    if (ultech130.IsMine(null, fileName))
                    {
                        ultech130.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = ultech130;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var nciCaption = new NciCaption();
                    if (nciCaption.IsMine(null, fileName))
                    {
                        nciCaption.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = nciCaption;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var tsb4 = new TSB4();
                    if (tsb4.IsMine(null, fileName))
                    {
                        tsb4.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = tsb4;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var avidStl = new AvidStl();
                    if (avidStl.IsMine(null, fileName))
                    {
                        avidStl.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = avidStl;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var chk = new Chk();
                    if (chk.IsMine(null, fileName))
                    {
                        chk.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = chk;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var ayato = new Ayato();
                    if (ayato.IsMine(null, fileName))
                    {
                        ayato.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = ayato;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var pacUnicode = new PacUnicode();
                    if (pacUnicode.IsMine(null, fileName))
                    {
                        pacUnicode.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = pacUnicode;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var iai = new IaiSub();
                    if (iai.IsMine(null, fileName))
                    {
                        iai.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = iai;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    try
                    {
                        var bdnXml = new BdnXml();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (bdnXml.IsMine(list, fileName))
                        {
                            if (ContinueNewOrExit())
                            {
                                ImportAndOcrBdnXml(fileName, bdnXml, list);
                            }
                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null)
                {
                    try
                    {
                        var fcpImage = new FinalCutProImage();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (fcpImage.IsMine(list, fileName))
                        {
                            if (ContinueNewOrExit())
                            {
                                ImportAndOcrDost(fileName, fcpImage, list);
                            }
                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null)
                {
                    var elr = new ELRStudioClosedCaption();
                    if (elr.IsMine(null, fileName))
                    {
                        elr.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = elr;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var asc = new TimeLineAscii();
                    if (asc.IsMine(null, fileName))
                    {
                        asc.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = asc;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var asc = new TimeLineFootageAscii();
                    if (asc.IsMine(null, fileName))
                    {
                        asc.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = asc;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var mtv = new TimeLineMvt();
                    if (mtv.IsMine(null, fileName))
                    {
                        mtv.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = mtv;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (ext == ".dost")
                {
                    try
                    {
                        var dost = new Dost();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (dost.IsMine(list, fileName))
                        {
                            if (ContinueNewOrExit())
                                ImportAndOcrDost(fileName, dost, list);
                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null)
                {
                    try
                    {
                        var timedtextImage = new TimedTextImage();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (timedtextImage.IsMine(list, fileName))
                        {
                            if (ContinueNewOrExit())
                                ImportAndOcrDost(fileName, timedtextImage, list);
                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null)
                {
                    try
                    {
                        var seImageHtmlIndex = new SeImageHtmlIndex();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (seImageHtmlIndex.IsMine(list, fileName))
                        {
                            if (ContinueNewOrExit())
                                ImportAndOcrDost(fileName, seImageHtmlIndex, list);
                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null || format.Name == Scenarist.NameOfFormat)
                {
                    try
                    {
                        var son = new Son();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (son.IsMine(list, fileName))
                        {
                            if (ContinueNewOrExit())
                                ImportAndOcrSon(fileName, son, list);
                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null || format.Name == SubRip.NameOfFormat)
                {
                    if (_subtitle.Paragraphs.Count > 1)
                    {
                        int imageCount = 0;
                        foreach (var p in _subtitle.Paragraphs)
                        {
                            string s = p.Text.ToLowerInvariant();
                            if (s.EndsWith(".bmp", StringComparison.Ordinal) || s.EndsWith(".png", StringComparison.Ordinal) || s.EndsWith(".jpg", StringComparison.Ordinal) || s.EndsWith(".tif", StringComparison.Ordinal))
                            {
                                imageCount++;
                            }
                        }
                        if (imageCount > 2 && imageCount >= _subtitle.Paragraphs.Count - 2)
                        {
                            if (ContinueNewOrExit())
                                ImportAndOcrSrt(_subtitle);
                            return;
                        }
                    }
                }

                if (format == null)
                {
                    try
                    {
                        var satBoxPng = new SatBoxPng();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (satBoxPng.IsMine(list, fileName))
                        {
                            var subtitle = new Subtitle();
                            satBoxPng.LoadSubtitle(subtitle, list, fileName);
                            if (ContinueNewOrExit())
                                ImportAndOcrSrt(subtitle);
                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null || format.Name == Scenarist.NameOfFormat)
                {
                    try
                    {
                        var sst = new SonicScenaristBitmaps();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (sst.IsMine(list, fileName))
                        {
                            if (ContinueNewOrExit())
                                ImportAndOcrSst(fileName, sst, list);
                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null)
                {
                    try
                    {
                        var htmlSamiArray = new HtmlSamiArray();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (htmlSamiArray.IsMine(list, fileName))
                        {
                            htmlSamiArray.LoadSubtitle(_subtitle, list, fileName);
                            _oldSubtitleFormat = htmlSamiArray;
                            SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                            SetEncoding(Configuration.Settings.General.DefaultEncoding);
                            encoding = GetCurrentEncoding();
                            justConverted = true;
                            format = GetCurrentSubtitleFormat();
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                // retry vobsub (file with wrong extension)
                if (format == null && file.Length > 500 && IsVobSubFile(fileName, false))
                {
                    if (MessageBox.Show(this, _language.ImportThisVobSubSubtitle, _title, MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        ImportAndOcrVobSubSubtitleNew(fileName, _loading);
                    }
                    return;
                }

                // retry Blu-ray (file with wrong extension)
                if (format == null && file.Length > 500 && FileUtil.IsBluRaySup(fileName))
                {
                    ImportAndOcrBluRaySup(fileName, _loading);
                    return;
                }

                // retry SP DVD (file with wrong extension)
                if (format == null && file.Length > 500 && FileUtil.IsSpDvdSup(fileName))
                {
                    ImportAndOcrSpDvdSup(fileName, _loading);
                    return;
                }

                // retry Matroska (file with wrong extension)
                if (format == null && !string.IsNullOrWhiteSpace(fileName))
                {
                    var matroska = new MatroskaFile(fileName);
                    if (matroska.IsValid)
                    {
                        var subtitleList = matroska.GetTracks(true);
                        if (subtitleList.Count > 0)
                        {
                            ImportSubtitleFromMatroskaFile(fileName);
                            return;
                        }
                    }
                }

                // check for idx file
                if (format == null && file.Length > 100 && ext == ".idx")
                {
                    MessageBox.Show(_language.ErrorLoadIdx);
                    return;
                }

                // check for .rar file
                if (format == null && file.Length > 100 && FileUtil.IsRar(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadRar);
                    return;
                }

                // check for .zip file
                if (format == null && file.Length > 100 && FileUtil.IsZip(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadZip);
                    return;
                }

                // check for .png file
                if (format == null && file.Length > 100 && FileUtil.IsPng(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadPng);
                    return;
                }

                // check for .jpg file
                if (format == null && file.Length > 100 && FileUtil.IsJpg(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadJpg);
                    return;
                }

                // check for .srr file
                if (format == null && file.Length > 100 && ext == ".srr" && FileUtil.IsSrr(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadSrr);
                    return;
                }

                // check for Torrent file
                if (format == null && file.Length > 50 && FileUtil.IsTorrentFile(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadTorrent);
                    return;
                }

                // check for all binary zeroes (I've heard about this a few times... perhaps related to crashes?)
                if (format == null && file.Length > 50 && FileUtil.IsSubtitleFileAllBinaryZeroes(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadBinaryZeroes);
                    return;
                }

                if (format == null && file.Length < 100 * 1000000 && TransportStreamParser.IsDvbSup(fileName))
                {
                    ImportSubtitleFromDvbSupFile(fileName);
                    return;
                }

                if (format == null && file.Length < 500000)
                {
                    // check for valid timed text
                    if (ext == ".xml" || ext == ".dfxp")
                    {
                        var sb = new StringBuilder();
                        foreach (var line in File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)))
                            sb.AppendLine(line);
                        var xmlAsString = sb.ToString().Trim();

                        if (xmlAsString.Contains("http://www.w3.org/ns/ttml") && xmlAsString.Contains("<?xml version=") ||
                            xmlAsString.Contains("http://www.w3.org/") && xmlAsString.Contains("/ttaf1"))
                        {
                            var xml = new System.Xml.XmlDocument();
                            try
                            {
                                xml.LoadXml(xmlAsString);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Timed text is not valid (xml is not well-formed): " + ex.Message);
                                return;
                            }
                        }
                    }


                    // Try to use a generic subtitle format parser (guessing subtitle format)
                    try
                    {
                        var enc = LanguageAutoDetect.GetEncodingFromFile(fileName);
                        var s = File.ReadAllText(fileName, enc);

                        // check for RTF file
                        if (ext == ".rtf" && s.TrimStart().StartsWith("{\\rtf", StringComparison.Ordinal))
                        {
                            using (var rtb = new RichTextBox { Rtf = s })
                            {
                                s = rtb.Text;
                            }
                        }
                        var uknownFormatImporter = new UknownFormatImporter { UseFrames = true };
                        var genericParseSubtitle = uknownFormatImporter.AutoGuessImport(s.SplitToLines());
                        if (genericParseSubtitle.Paragraphs.Count > 1)
                        {
                            _subtitle = genericParseSubtitle;
                            SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                            SetEncoding(Configuration.Settings.General.DefaultEncoding);
                            encoding = GetCurrentEncoding();
                            justConverted = true;
                            format = GetCurrentSubtitleFormat();
                            ShowStatus("Guessed subtitle format via generic subtitle parser!");
                        }
                    }
                    catch
                    {
                    }
                }

                _fileDateTime = File.GetLastWriteTime(fileName);

                if (format != null && format.IsFrameBased)
                    _subtitle.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
                else
                    _subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);

                if (format != null)
                {
                    if (Configuration.Settings.General.RemoveBlankLinesWhenOpening)
                    {
                        _subtitle.RemoveEmptyLines();
                    }

                    foreach (var p in _subtitle.Paragraphs)
                    {
                        // Replace U+0456 (CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I) by U+0069 (LATIN SMALL LETTER I)
                        p.Text = p.Text.Replace("<і>", "<i>").Replace("</і>", "</i>");
                    }

                    _subtitleListViewIndex = -1;
                    SetCurrentFormat(format);
                    _subtitleAlternateFileName = null;
                    if (LoadAlternateSubtitleFile(originalFileName))
                        _subtitleAlternateFileName = originalFileName;

                    // Seungki begin
                    _splitDualSami = false;
                    if (Configuration.Settings.SubtitleSettings.SamiDisplayTwoClassesAsTwoSubtitles && format.GetType() == typeof(Sami) && Sami.GetStylesFromHeader(_subtitle.Header).Count == 2)
                    {
                        var classes = Sami.GetStylesFromHeader(_subtitle.Header);
                        var s1 = new Subtitle(_subtitle);
                        var s2 = new Subtitle(_subtitle);
                        s1.Paragraphs.Clear();
                        s2.Paragraphs.Clear();
                        foreach (var p in _subtitle.Paragraphs)
                        {
                            if (p.Extra != null && p.Extra.Equals(classes[0], StringComparison.OrdinalIgnoreCase))
                                s1.Paragraphs.Add(p);
                            else
                                s2.Paragraphs.Add(p);
                        }
                        if (s1.Paragraphs.Count == 0 || s2.Paragraphs.Count == 0)
                            return;

                        _subtitle = s1;
                        _subtitleAlternate = s2;
                        _subtitleAlternateFileName = _fileName;
                        SubtitleListview1.HideExtraColumn();
                        SubtitleListview1.ShowAlternateTextColumn(classes[1]);
                        _splitDualSami = true;
                    }
                    // Seungki end

                    textBoxSource.Text = _subtitle.ToText(format);
                    SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                    if (SubtitleListview1.Items.Count > 0)
                        SubtitleListview1.Items[0].Selected = true;
                    _findHelper = null;
                    _spellCheckForm = null;

                    if (_resetVideo)
                    {
                        _videoFileName = null;
                        _videoInfo = null;
                        _videoAudioTrackNumber = -1;
                        labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
                        audioVisualizer.WavePeaks = null;
                        audioVisualizer.Spectrogram = null;
                    }

                    if (Configuration.Settings.General.ShowVideoPlayer || Configuration.Settings.General.ShowAudioVisualizer)
                    {
                        if (!Configuration.Settings.General.DisableVideoAutoLoading)
                        {
                            if (!string.IsNullOrEmpty(videoFileName) && File.Exists(videoFileName))
                            {
                                OpenVideo(videoFileName);
                            }
                            else if (!string.IsNullOrEmpty(fileName) && (toolStripButtonToggleVideo.Checked || toolStripButtonToggleWaveform.Checked))
                            {
                                TryToFindAndOpenVideoFile(Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName)));
                            }
                        }
                    }
                    videoFileLoaded = _videoFileName != null;

                    if (Configuration.Settings.RecentFiles.Files.Count > 0 &&
                        Configuration.Settings.RecentFiles.Files[0].FileName == fileName)
                    {
                    }
                    else
                    {
                        Configuration.Settings.RecentFiles.Add(fileName, _videoFileName, _subtitleAlternateFileName);
                        Configuration.Settings.Save();
                        UpdateRecentFilesUI();
                    }
                    _fileName = fileName;
                    SetTitle();
                    ShowStatus(string.Format(_language.LoadedSubtitleX, _fileName));
                    _sourceViewChange = false;
                    _changeSubtitleToString = _subtitle.GetFastHashCode();
                    _converted = false;
                    ResetHistory();

                    SetUndockedWindowsTitle();

                    if (justConverted)
                    {
                        _converted = true;
                        ShowStatus(string.Format(_language.LoadedSubtitleX, _fileName) + " - " + string.Format(_language.ConvertedToX, format.FriendlyName));
                    }
                    if (Configuration.Settings.General.AutoConvertToUtf8)
                        encoding = Encoding.UTF8;
                    SetEncoding(encoding);

                    var formatType = format.GetType();
                    if (formatType == typeof(SubStationAlpha))
                    {
                        string errors = AdvancedSubStationAlpha.CheckForErrors(_subtitle.Header);
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(this, errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        errors = (format as SubStationAlpha).Errors;
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(this, errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (formatType == typeof(AdvancedSubStationAlpha))
                    {
                        string errors = AdvancedSubStationAlpha.CheckForErrors(_subtitle.Header);
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(this, errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        errors = (format as AdvancedSubStationAlpha).Errors;
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(this, errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (formatType == typeof(SubRip))
                    {
                        string errors = (format as SubRip).Errors;
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(this, errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (formatType == typeof(MicroDvd))
                    {
                        string errors = (format as MicroDvd).Errors;
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(this, errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (formatType == typeof(DCinemaSmpte2007))
                    {
                        format.ToText(_subtitle, string.Empty);
                        string errors = (format as DCinemaSmpte2007).Errors;
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (formatType == typeof(DCinemaSmpte2010))
                    {
                        format.ToText(_subtitle, string.Empty);
                        string errors = (format as DCinemaSmpte2010).Errors;
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    if (file.Length < 50)
                    {
                        _findHelper = null;
                        _spellCheckForm = null;
                        _videoFileName = null;
                        _videoInfo = null;
                        _videoAudioTrackNumber = -1;
                        labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
                        audioVisualizer.WavePeaks = null;
                        audioVisualizer.Spectrogram = null;

                        Configuration.Settings.RecentFiles.Add(fileName, FirstVisibleIndex, FirstSelectedIndex, _videoFileName, _subtitleAlternateFileName);
                        Configuration.Settings.Save();
                        UpdateRecentFilesUI();
                        _fileName = fileName;
                        SetTitle();
                        ShowStatus(string.Format(_language.LoadedEmptyOrShort, _fileName));
                        _sourceViewChange = false;
                        _converted = false;

                        MessageBox.Show(_language.FileIsEmptyOrShort);
                    }
                    else
                    {
                        ShowUnknownSubtitle();
                        return;
                    }
                }

                if (!videoFileLoaded && mediaPlayer.VideoPlayer != null)
                {
                    mediaPlayer.VideoPlayer.DisposeVideoPlayer();
                    mediaPlayer.VideoPlayer = null;
                    timer1.Stop();
                }
                ResetShowEarlierOrLater();
            }
            else
            {
                MessageBox.Show(string.Format(_language.FileNotFound, fileName));
            }
        }
Esempio n. 21
0
        private void FindDoubleWordsToolStripMenuItemClick(object sender, EventArgs e)
        {
            var regex = new Regex(@"\b(\w+)\s+\1\b");
            _clearLastFind = true;
            if (_findHelper != null)
            {
                _clearLastFindType = _findHelper.FindType;
                _clearLastFindText = _findHelper.FindText;
            }
            _findHelper = new FindReplaceDialogHelper(FindType.RegEx, false, string.Format(_language.DoubleWordsViaRegEx, regex), regex, string.Empty, 0, 0, _subtitleListViewIndex);

            ReloadFromSourceView();
            FindNext();
        }
Esempio n. 22
0
        private void comboBoxRule_SelectedIndexChanged(object sender, EventArgs e)
        {
            textBoxText.Visible           = true;
            listViewStyles.Visible        = false;
            numericUpDownDuration.Visible = comboBoxRule.SelectedIndex == FunctionDurationLessThan || comboBoxRule.SelectedIndex == FunctionDurationGreaterThan;
            if (comboBoxRule.SelectedIndex == FunctionRegEx) // RegEx
            {
                textBoxText.ContextMenuStrip  = FindReplaceDialogHelper.GetRegExContextMenu(textBoxText);
                checkBoxCaseSensitive.Enabled = false;
            }
            else if (comboBoxRule.SelectedIndex == FunctionOdd ||
                     comboBoxRule.SelectedIndex == FunctionEven ||
                     comboBoxRule.SelectedIndex == FunctionExactlyOneLine ||
                     comboBoxRule.SelectedIndex == FunctionExactlyTwoLines ||
                     comboBoxRule.SelectedIndex == FunctionMoreThanTwoLines ||
                     comboBoxRule.SelectedIndex == FunctionBookmarked ||
                     comboBoxRule.SelectedIndex == FunctionBlankLines)
            {
                checkBoxCaseSensitive.Enabled = false;
                textBoxText.ContextMenuStrip  = null;
                textBoxText.Visible           = false;
            }
            else if (comboBoxRule.SelectedIndex == FunctionDurationLessThan || comboBoxRule.SelectedIndex == FunctionDurationGreaterThan || comboBoxRule.SelectedIndex == FunctionAllUppercase)
            {
                checkBoxCaseSensitive.Enabled = false;
                listViewStyles.Visible        = false;
                textBoxText.Visible           = false;
                if (comboBoxRule.SelectedIndex == FunctionDurationLessThan)
                {
                    if (numericUpDownDuration.Value == 0 &&
                        Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds >= numericUpDownDuration.Minimum &&
                        Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds <= numericUpDownDuration.Maximum)
                    {
                        numericUpDownDuration.Value = Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds;
                    }
                }
                else
                {
                    if (numericUpDownDuration.Value == 0 &&
                        Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds >= numericUpDownDuration.Minimum &&
                        Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds <= numericUpDownDuration.Maximum)
                    {
                        numericUpDownDuration.Value = Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds;
                    }
                }
            }
            else if (comboBoxRule.SelectedIndex == FunctionStyle)
            {
                checkBoxCaseSensitive.Enabled = false;
                listViewStyles.Visible        = true;
                listViewStyles.BringToFront();
                FillStyles();
            }
            else if (comboBoxRule.SelectedIndex == FunctionActor)
            {
                checkBoxCaseSensitive.Enabled = false;
                listViewStyles.Visible        = true;
                listViewStyles.BringToFront();
                FillActors();
            }
            else
            {
                textBoxText.ContextMenuStrip  = null;
                checkBoxCaseSensitive.Enabled = true;
            }

            Preview();
        }
Esempio n. 23
0
        private void ReplaceSourceView(ReplaceDialog replaceDialog)
        {
            bool isFirst = true;
            string selectedText = this.textBoxSource.SelectedText;
            if (selectedText.Length == 0 && this._findHelper != null)
            {
                selectedText = this._findHelper.FindText;
            }

            if (replaceDialog == null)
            {
                replaceDialog = new ReplaceDialog();
                replaceDialog.SetIcon(this.toolStripButtonReplace.Image as Bitmap);
                if (this._findHelper == null)
                {
                    this._findHelper = replaceDialog.GetFindDialogHelper(this._subtitleListViewIndex);
                    this._findHelper.WindowPositionLeft = this.Left + (this.Width / 2) - (replaceDialog.Width / 2);
                    this._findHelper.WindowPositionTop = this.Top + (this.Height / 2) - (replaceDialog.Height / 2);
                }
            }
            else
            {
                isFirst = false;
            }

            replaceDialog.Initialize(selectedText, this._findHelper);
            if (replaceDialog.ShowDialog(this) == DialogResult.OK)
            {
                this._findHelper = replaceDialog.GetFindDialogHelper(this._subtitleListViewIndex);
                this.ShowStatus(string.Format(this._language.SearchingForXFromLineY, this._findHelper.FindText, this._subtitleListViewIndex + 1));
                int replaceCount = 0;
                bool searchStringFound = true;
                while (searchStringFound)
                {
                    searchStringFound = false;
                    int start = this.textBoxSource.SelectionStart;
                    if (isFirst)
                    {
                        this.MakeHistoryForUndo(string.Format(this._language.BeforeReplace, this._findHelper.FindText));
                        isFirst = false;
                        this._makeHistoryPaused = true;
                        if (start >= 0)
                        {
                            start--;
                        }
                    }
                    else
                    {
                        if (this.textBoxSource.SelectionLength > 0 && start > 0 && !replaceDialog.FindOnly)
                        {
                            start--;
                        }
                    }

                    if (this._findHelper.FindNext(this.textBoxSource, start))
                    {
                        this.textBoxSource.SelectionStart = this._findHelper.SelectedIndex;
                        this.textBoxSource.SelectionLength = this._findHelper.FindTextLength;
                        if (!replaceDialog.FindOnly)
                        {
                            this.textBoxSource.SelectedText = this._findHelper.ReplaceText;
                        }

                        this.textBoxSource.ScrollToCaret();

                        replaceCount++;
                        searchStringFound = true;

                        if (!replaceDialog.ReplaceAll && !replaceDialog.FindOnly)
                        {
                            if (this._findHelper.FindNext(this.textBoxSource, start))
                            {
                                this.textBoxSource.SelectionStart = this._findHelper.SelectedIndex;
                                this.textBoxSource.SelectionLength = this._findHelper.FindTextLength;
                                this.textBoxSource.ScrollToCaret();
                            }

                            this.Replace(replaceDialog);
                            return;
                        }
                    }

                    if (replaceDialog.FindOnly)
                    {
                        if (searchStringFound)
                        {
                            this.ShowStatus(string.Format(this._language.MatchFoundX, this._findHelper.FindText));
                        }
                        else
                        {
                            this.ShowStatus(string.Format(this._language.NoMatchFoundX, this._findHelper.FindText));
                        }

                        this.Replace(replaceDialog);
                        return;
                    }

                    if (!replaceDialog.ReplaceAll)
                    {
                        break; // out of while loop
                    }
                }

                this.ReloadFromSourceView();
                if (replaceCount == 0)
                {
                    this.ShowStatus(this._language.FoundNothingToReplace);
                }
                else
                {
                    this.ShowStatus(string.Format(this._language.ReplaceCountX, replaceCount));
                }
            }

            if (this._makeHistoryPaused)
            {
                this.RestartHistory();
            }

            replaceDialog.Dispose();
        }
Esempio n. 24
0
        internal void Initialize(string selectedText, FindReplaceDialogHelper findHelper)
        {
            if (Configuration.Settings.Tools.FindHistory.Count > 0)
            {
                textBoxFind.Visible = false;
                comboBoxFind.Visible = true;
                comboBoxFind.Text = selectedText;
                comboBoxFind.SelectAll();
                comboBoxFind.Items.Clear();
                for (int index = 0; index < Configuration.Settings.Tools.FindHistory.Count; index++)
                {
                    string s = Configuration.Settings.Tools.FindHistory[index];
                    comboBoxFind.Items.Add(s);
                }
            }
            else
            {
                comboBoxFind.Visible = false;
                textBoxFind.Visible = true;
                textBoxFind.Text = selectedText;
                textBoxFind.SelectAll();
            }

            if (findHelper != null)
            {
                FindType = findHelper.FindType;
                checkBoxWholeWord.Checked = findHelper.MatchWholeWord;
                checkBoxWholeWord.Enabled = FindType != FindType.RegEx;
            }
        }