public void OcrFixReplaceListRemovePartialLineReload()
        {
            // Arrange
            string fileName = Path.Combine(Directory.GetCurrentDirectory(), Guid.NewGuid() + ".xml");
            var    fixList  = new OcrFixReplaceList(fileName);

            fixList.PartialLineWordBoundaryReplaceList.Clear();
            fixList.AddWordOrPartial("from me", "to you");
            fixList = new OcrFixReplaceList(fileName);
            fixList.RemoveWordOrPartial("from me");

            // Act
            fixList = new OcrFixReplaceList(fileName);

            // Assert
            Assert.IsTrue(!fixList.WordReplaceList.ContainsKey("from me"));

            // Clean up
            try
            {
                File.Delete(fileName);
            }
            catch
            {
            }
        }
Exemple #2
0
        private void ListBoxKeyDownSearch(object sender, KeyEventArgs e)
        {
            var languageIndex = comboBoxWordListLanguage.SelectedIndex;
            if (languageIndex < 0)
            {
                return;
            }

            if (!(comboBoxWordListLanguage.Items[languageIndex] is Settings.ComboBoxLanguage))
            {
                return;
            }

            if (listBoxOcrFixList.SelectedIndices.Count == 0)
            {
                return;
            }

            var itemsToRemoveCount = listBoxOcrFixList.SelectedIndices.Count;

            var index = listBoxOcrFixList.SelectedIndex;
            var text = listBoxOcrFixList.Items[index].ToString();
            var key = text.Substring(0, text.IndexOf(" --> ", StringComparison.Ordinal));

            if (_ocrFixReplaceList.WordReplaceList.ContainsKey(key) || _ocrFixReplaceList.PartialLineWordBoundaryReplaceList.ContainsKey(key))
            {
                DialogResult result;
                if (itemsToRemoveCount == 1)
                {
                    result = MessageBox.Show(string.Format(LanguageSettings.Current.Settings.RemoveX, text), "Subtitle Edit", MessageBoxButtons.YesNo);
                }
                else
                {
                    result = MessageBox.Show(string.Format(LanguageSettings.Current.Main.DeleteXLinesPrompt, itemsToRemoveCount), "Subtitle Edit", MessageBoxButtons.YesNo);
                }

                if (result == DialogResult.Yes)
                {
                    listBoxOcrFixList.BeginUpdate();
                    for (var idx = listBoxOcrFixList.SelectedIndices.Count - 1; idx >= 0; idx--)
                    {
                        index = listBoxOcrFixList.SelectedIndices[idx];
                        text = listBoxOcrFixList.Items[index].ToString();
                        key = text.Substring(0, text.IndexOf(" --> ", StringComparison.Ordinal));

                        if (_ocrFixReplaceList.WordReplaceList.ContainsKey(key) || _ocrFixReplaceList.PartialLineWordBoundaryReplaceList.ContainsKey(key))
                        {
                            _ocrFixReplaceList.RemoveWordOrPartial(key);
                        }
                        listBoxOcrFixList.Items.RemoveAt(index);
                    }
                    listBoxOcrFixList.EndUpdate();

                    LoadOcrFixList(false);
                    buttonRemoveOcrFix.Enabled = false;

                    if (index < listBoxOcrFixList.Items.Count)
                    {
                        listBoxOcrFixList.SelectedIndex = index;
                    }
                    else if (listBoxOcrFixList.Items.Count > 0)
                    {
                        listBoxOcrFixList.SelectedIndex = index - 1;
                    }

                    listBoxOcrFixList.Focus();
                }
            }
        }