Esempio n. 1
0
 private void FormFindSubtitleLine_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.F3)
     {
         FindText();
     }
     else if (e.KeyCode == Keys.Escape)
     {
         DialogResult = DialogResult.Cancel;
     }
     else if (_mainGeneralGoToNextSubtitle == e.KeyData || (e.KeyCode == Keys.Down && e.Modifiers == Keys.Alt))
     {
         int selectedIndex = 0;
         if (subtitleListView1.SelectedItems.Count > 0)
         {
             selectedIndex = subtitleListView1.SelectedItems[0].Index;
             selectedIndex++;
         }
         subtitleListView1.SelectIndexAndEnsureVisible(selectedIndex);
     }
     else if (_mainGeneralGoToPrevSubtitle == e.KeyData || (e.KeyCode == Keys.Up && e.Modifiers == Keys.Alt))
     {
         int selectedIndex = 0;
         if (subtitleListView1.SelectedItems.Count > 0)
         {
             selectedIndex = subtitleListView1.SelectedItems[0].Index;
             selectedIndex--;
         }
         subtitleListView1.SelectIndexAndEnsureVisible(selectedIndex);
     }
     else if (e.KeyCode == Keys.Home && e.Alt)
     {
         subtitleListView1.SelectIndexAndEnsureVisible(0);
         e.SuppressKeyPress = true;
     }
     else if (e.KeyCode == Keys.End && e.Alt)
     {
         subtitleListView1.SelectIndexAndEnsureVisible(subtitleListView1.Items.Count - 1);
         e.SuppressKeyPress = true;
     }
     else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.G && subtitleListView1.Items.Count > 1)
     {
         using (var goToLine = new GoToLine())
         {
             goToLine.Initialize(1, subtitleListView1.Items.Count);
             if (goToLine.ShowDialog(this) == DialogResult.OK)
             {
                 subtitleListView1.SelectNone();
                 subtitleListView1.Items[goToLine.LineNumber - 1].Selected = true;
                 subtitleListView1.Items[goToLine.LineNumber - 1].EnsureVisible();
                 subtitleListView1.Items[goToLine.LineNumber - 1].Focused = true;
             }
         }
     }
 }
Esempio n. 2
0
 private void SyncPointsSync_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Escape)
     {
         DialogResult = DialogResult.Cancel;
     }
     else if (e.KeyCode == UiUtil.HelpKeys)
     {
         UiUtil.ShowHelp("#sync");
         e.SuppressKeyPress = true;
     }
     else if (_mainGeneralGoToNextSubtitle == e.KeyData || (e.KeyCode == Keys.Down && e.Modifiers == Keys.Alt))
     {
         int selectedIndex = 0;
         if (SubtitleListview1.SelectedItems.Count > 0)
         {
             selectedIndex = SubtitleListview1.SelectedItems[0].Index;
             selectedIndex++;
         }
         SubtitleListview1.SelectIndexAndEnsureVisible(selectedIndex);
         e.SuppressKeyPress = true;
     }
     else if (_mainGeneralGoToPrevSubtitle == e.KeyData || (e.KeyCode == Keys.Up && e.Modifiers == Keys.Alt))
     {
         int selectedIndex = 0;
         if (SubtitleListview1.SelectedItems.Count > 0)
         {
             selectedIndex = SubtitleListview1.SelectedItems[0].Index;
             selectedIndex--;
         }
         SubtitleListview1.SelectIndexAndEnsureVisible(selectedIndex);
         e.SuppressKeyPress = true;
     }
     else if (e.KeyData == (Keys.Control | Keys.G))
     {
         var subView = SubtitleListview1;
         if (subtitleListView2 != null && subtitleListView2.Visible && !SubtitleListview1.Focused)
         {
             var x = PointToClient(MousePosition).X;
             if (x >= subtitleListView2.Left && x <= subtitleListView2.Left + subtitleListView2.Width)
             {
                 subView = subtitleListView2;
             }
         }
         using (var gotoForm = new GoToLine())
         {
             gotoForm.Initialize(1, subView.Items.Count);
             if (gotoForm.ShowDialog() == DialogResult.OK)
             {
                 subView.SelectIndexAndEnsureVisible(gotoForm.LineNumber - 1, true);
             }
         }
     }
 }
Esempio n. 3
0
 private void VobSubOcr_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.F1)
     {
         Utilities.ShowHelp("#importvobsub");
         e.SuppressKeyPress = true;
     }
     else if (e.KeyCode == Keys.Down && e.Modifiers == Keys.Alt)
     {
         int selectedIndex = 0;
         if (subtitleListView1.SelectedItems.Count > 0)
         {
             selectedIndex = subtitleListView1.SelectedItems[0].Index;
             selectedIndex++;
         }
         subtitleListView1.SelectIndexAndEnsureVisible(selectedIndex);
     }
     else if (e.KeyCode == Keys.Up && e.Modifiers == Keys.Alt)
     {
         int selectedIndex = 0;
         if (subtitleListView1.SelectedItems.Count > 0)
         {
             selectedIndex = subtitleListView1.SelectedItems[0].Index;
             selectedIndex--;
         }
         subtitleListView1.SelectIndexAndEnsureVisible(selectedIndex);
     }
     else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.G)
     {
         using (var goToLine = new GoToLine())
         {
             goToLine.Initialize(1, subtitleListView1.Items.Count);
             if (goToLine.ShowDialog(this) == DialogResult.OK)
             {
                 subtitleListView1.SelectNone();
                 subtitleListView1.Items[goToLine.LineNumber - 1].Selected = true;
                 subtitleListView1.Items[goToLine.LineNumber - 1].EnsureVisible();
                 subtitleListView1.Items[goToLine.LineNumber - 1].Focused = true;
             }
         }
     }
     else if (_mainGeneralGoToNextSubtitle == e.KeyData)
     {
         int selectedIndex = 0;
         if (subtitleListView1.SelectedItems.Count > 0)
         {
             selectedIndex = subtitleListView1.SelectedItems[0].Index;
             selectedIndex++;
         }
         subtitleListView1.SelectIndexAndEnsureVisible(selectedIndex);
         e.SuppressKeyPress = true;
     }
     else if (_mainGeneralGoToPrevSubtitle == e.KeyData)
     {
         int selectedIndex = 0;
         if (subtitleListView1.SelectedItems.Count > 0)
         {
             selectedIndex = subtitleListView1.SelectedItems[0].Index;
             selectedIndex--;
         }
         subtitleListView1.SelectIndexAndEnsureVisible(selectedIndex);
         e.SuppressKeyPress = true;
     }
 }
Esempio n. 4
0
        private void GotoLineNumberToolStripMenuItemClick(object sender, EventArgs e)
        {
            ReloadFromSourceView();
            if (!IsSubtitleLoaded)
            {
                DisplaySubtitleNotLoadedMessage();
                return;
            }

            using (var goToLine = new GoToLine())
            {
                if (tabControlSubtitle.SelectedIndex == TabControlListView)
                {
                    goToLine.Initialize(1, SubtitleListview1.Items.Count);
                }
                else if (tabControlSubtitle.SelectedIndex == TabControlSourceView)
                {
                    goToLine.Initialize(1, textBoxSource.Lines.Length);
                }
                if (goToLine.ShowDialog(this) == DialogResult.OK)
                {
                    if (tabControlSubtitle.SelectedIndex == TabControlListView)
                    {
                        SubtitleListview1.SelectNone();

                        SubtitleListview1.Items[goToLine.LineNumber - 1].Selected = true;
                        SubtitleListview1.Items[goToLine.LineNumber - 1].EnsureVisible();
                        SubtitleListview1.Items[goToLine.LineNumber - 1].Focused = true;
                        ShowStatus(string.Format(_language.GoToLineNumberX, goToLine.LineNumber));
                    }
                    else if (tabControlSubtitle.SelectedIndex == TabControlSourceView)
                    {
                        // binary search
                        int start = 0;
                        int end = textBoxSource.Text.Length;
                        while (end - start > 10)
                        {
                            int middle = start + (end - start) / 2;
                            if (goToLine.LineNumber - 1 >= textBoxSource.GetLineFromCharIndex(middle))
                                start = middle;
                            else
                                end = middle;
                        }

                        // go before line, so we can find first char on line
                        start -= 100;
                        if (start < 0)
                            start = 0;

                        for (int i = start; i <= end; i++)
                        {
                            if (textBoxSource.GetLineFromCharIndex(i) == goToLine.LineNumber - 1)
                            {
                                // select line, scroll to line, and focus...
                                textBoxSource.SelectionStart = i;
                                textBoxSource.SelectionLength = textBoxSource.Lines[goToLine.LineNumber - 1].Length;
                                textBoxSource.ScrollToCaret();
                                ShowStatus(string.Format(_language.GoToLineNumberX, goToLine.LineNumber));
                                if (textBoxSource.CanFocus)
                                    textBoxSource.Focus();
                                break;
                            }
                        }

                        ShowSourceLineNumber();
                    }
                }
            }
        }
Esempio n. 5
0
 private void GoToLineNumber()
 {
     var goToLine = new GoToLine();
     goToLine.Initialize(1, subtitleListView1.Items.Count);
     if (goToLine.ShowDialog(this) == DialogResult.OK)
     {
         subtitleListView1.SelectNone();
         subtitleListView1.Items[goToLine.LineNumber - 1].Selected = true;
         subtitleListView1.Items[goToLine.LineNumber - 1].EnsureVisible();
         subtitleListView1.Items[goToLine.LineNumber - 1].Focused = true;
     }
 }
 private void FormFindSubtitleLine_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.F3)
         FindText();
     else if (e.KeyCode == Keys.Escape)
     {
         DialogResult = DialogResult.Cancel;
     }
     else if (_mainGeneralGoToNextSubtitle == e.KeyData || (e.KeyCode == Keys.Down && e.Modifiers == Keys.Alt))
     {
         int selectedIndex = 0;
         if (subtitleListView1.SelectedItems.Count > 0)
         {
             selectedIndex = subtitleListView1.SelectedItems[0].Index;
             selectedIndex++;
         }
         subtitleListView1.SelectIndexAndEnsureVisible(selectedIndex);
     }
     else if (_mainGeneralGoToPrevSubtitle == e.KeyData || (e.KeyCode == Keys.Up && e.Modifiers == Keys.Alt))
     {
         int selectedIndex = 0;
         if (subtitleListView1.SelectedItems.Count > 0)
         {
             selectedIndex = subtitleListView1.SelectedItems[0].Index;
             selectedIndex--;
         }
         subtitleListView1.SelectIndexAndEnsureVisible(selectedIndex);
     }
     else if (e.KeyCode == Keys.Home && e.Alt)
     {
         subtitleListView1.SelectIndexAndEnsureVisible(0);
         e.SuppressKeyPress = true;
     }
     else if (e.KeyCode == Keys.End && e.Alt)
     {
         subtitleListView1.SelectIndexAndEnsureVisible(subtitleListView1.Items.Count - 1);
         e.SuppressKeyPress = true;
     }
     else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.G && subtitleListView1.Items.Count > 1)
     {
         using (var goToLine = new GoToLine())
         {
             goToLine.Initialize(1, subtitleListView1.Items.Count);
             if (goToLine.ShowDialog(this) == DialogResult.OK)
             {
                 subtitleListView1.SelectNone();
                 subtitleListView1.Items[goToLine.LineNumber - 1].Selected = true;
                 subtitleListView1.Items[goToLine.LineNumber - 1].EnsureVisible();
                 subtitleListView1.Items[goToLine.LineNumber - 1].Focused = true;
             }
         }
     }
 }
 /// <summary>
 /// The export png xml_ key down.
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The e.
 /// </param>
 private void ExportPngXml_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Escape)
     {
         this.DialogResult = DialogResult.Cancel;
     }
     else if (e.KeyCode == Keys.F1)
     {
         Utilities.ShowHelp("#export");
         e.SuppressKeyPress = true;
     }
     else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.G && this.subtitleListView1.Items.Count > 1)
     {
         using (var goToLine = new GoToLine())
         {
             goToLine.Initialize(1, this.subtitleListView1.Items.Count);
             if (goToLine.ShowDialog(this) == DialogResult.OK)
             {
                 this.subtitleListView1.Items[goToLine.LineNumber - 1].Selected = true;
                 this.subtitleListView1.Items[goToLine.LineNumber - 1].EnsureVisible();
                 this.subtitleListView1.Items[goToLine.LineNumber - 1].Focused = true;
             }
         }
     }
 }
 public void FixOcrErrorsViaHardcodedRules1()
 {
     using (var form = new GoToLine())
     {
         Configuration.Settings.Tools.OcrFixUseHardcodedRules = true;
         const string input = "l-l'll see you.";
         var ofe = new Nikse.SubtitleEdit.Logic.Ocr.OcrFixEngine("eng", "us_en", form);
         var res = ofe.FixOcrErrorsViaHardcodedRules(input, "Previous line.", new HashSet<string>());
         Assert.AreEqual(res, "I-I'll see you.");
     }
 }
Esempio n. 9
0
 private void SyncPointsSync_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Escape)
         DialogResult = DialogResult.Cancel;
     else if (e.KeyCode == Keys.F1)
     {
         Utilities.ShowHelp("#sync");
         e.SuppressKeyPress = true;
     }
     else if (_mainGeneralGoToNextSubtitle == e.KeyData || (e.KeyCode == Keys.Down && e.Modifiers == Keys.Alt))
     {
         int selectedIndex = 0;
         if (SubtitleListview1.SelectedItems.Count > 0)
         {
             selectedIndex = SubtitleListview1.SelectedItems[0].Index;
             selectedIndex++;
         }
         SubtitleListview1.SelectIndexAndEnsureVisible(selectedIndex);
         e.SuppressKeyPress = true;
     }
     else if (_mainGeneralGoToPrevSubtitle == e.KeyData || (e.KeyCode == Keys.Up && e.Modifiers == Keys.Alt))
     {
         int selectedIndex = 0;
         if (SubtitleListview1.SelectedItems.Count > 0)
         {
             selectedIndex = SubtitleListview1.SelectedItems[0].Index;
             selectedIndex--;
         }
         SubtitleListview1.SelectIndexAndEnsureVisible(selectedIndex);
         e.SuppressKeyPress = true;
     }
     else if (e.KeyData == (Keys.Control | Keys.G))
     {
         var subView = SubtitleListview1;
         if (subtitleListView2 != null && subtitleListView2.Visible && !SubtitleListview1.Focused)
         {
             var x = PointToClient(MousePosition).X;
             if (x >= subtitleListView2.Left && x <= subtitleListView2.Left + subtitleListView2.Width)
             {
                 subView = subtitleListView2;
             }
         }
         using (var gotoForm = new GoToLine())
         {
             gotoForm.Initialize(1, subView.Items.Count);
             if (gotoForm.ShowDialog() == DialogResult.OK)
             {
                 subView.SelectIndexAndEnsureVisible(gotoForm.LineNumber - 1, true);
             }
         }
     }
 }
Esempio n. 10
0
        private void GotoLineNumberToolStripMenuItemClick(object sender, EventArgs e)
        {
            ReloadFromSourceView();
            if (!IsSubtitleLoaded)
            {
                DisplaySubtitleNotLoadedMessage();
                return;
            }

            using (var goToLine = new GoToLine())
            {
                if (tabControlSubtitle.SelectedIndex == TabControlListView)
                {
                    goToLine.Initialize(1, SubtitleListview1.Items.Count);
                }
                else if (tabControlSubtitle.SelectedIndex == TabControlSourceView)
                {
                    goToLine.Initialize(1, textBoxSource.Lines.Length);
                }
                if (goToLine.ShowDialog(this) == DialogResult.OK)
                {
                    if (tabControlSubtitle.SelectedIndex == TabControlListView)
                    {
                        SubtitleListview1.SelectNone();

                        SubtitleListview1.Items[goToLine.LineNumber - 1].Selected = true;
                        SubtitleListview1.Items[goToLine.LineNumber - 1].EnsureVisible();
                        SubtitleListview1.Items[goToLine.LineNumber - 1].Focused = true;
                        ShowStatus(string.Format(_language.GoToLineNumberX, goToLine.LineNumber));
                    }
                    else if (tabControlSubtitle.SelectedIndex == TabControlSourceView)
                    {
                        textBoxSource.SelectionStart = textBoxSource.GetFirstCharIndexFromLine(goToLine.LineNumber - 1);
                        textBoxSource.SelectionLength = textBoxSource.Lines[goToLine.LineNumber - 1].Length;
                        textBoxSource.ScrollToCaret();
                        ShowSourceLineNumber();
                    }
                }
            }
        }