Added history of previous find texts to the "Find" dialog - thx fox :)

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1728 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2013-03-12 19:52:27 +00:00
parent 18bb62b1a7
commit c4cb0aba7a
5 changed files with 87 additions and 11 deletions

View File

@ -34,6 +34,7 @@
this.radioButtonNormal = new System.Windows.Forms.RadioButton();
this.radioButtonCaseSensitive = new System.Windows.Forms.RadioButton();
this.radioButtonRegEx = new System.Windows.Forms.RadioButton();
this.comboBoxFind = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// textBoxFind
@ -99,11 +100,21 @@
this.radioButtonRegEx.UseVisualStyleBackColor = true;
this.radioButtonRegEx.CheckedChanged += new System.EventHandler(this.RadioButtonCheckedChanged);
//
// comboBoxFind
//
this.comboBoxFind.FormattingEnabled = true;
this.comboBoxFind.Location = new System.Drawing.Point(12, 12);
this.comboBoxFind.Name = "comboBoxFind";
this.comboBoxFind.Size = new System.Drawing.Size(189, 21);
this.comboBoxFind.TabIndex = 0;
this.comboBoxFind.KeyDown += new System.Windows.Forms.KeyEventHandler(this.comboBoxFind_KeyDown);
//
// FindDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(298, 135);
this.Controls.Add(this.comboBoxFind);
this.Controls.Add(this.radioButtonRegEx);
this.Controls.Add(this.radioButtonCaseSensitive);
this.Controls.Add(this.radioButtonNormal);
@ -133,5 +144,6 @@
private System.Windows.Forms.RadioButton radioButtonNormal;
private System.Windows.Forms.RadioButton radioButtonCaseSensitive;
private System.Windows.Forms.RadioButton radioButtonRegEx;
private System.Windows.Forms.ComboBox comboBoxFind;
}
}

View File

@ -1,15 +1,17 @@
using System;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Logic.Enums;
using System.Drawing;
using System.Collections.Generic;
namespace Nikse.SubtitleEdit.Forms
{
public sealed partial class FindDialog : Form
{
private Regex _regEx;
private List<string> _history = new List<string>();
public FindDialog()
{
@ -38,7 +40,6 @@ namespace Nikse.SubtitleEdit.Forms
}
}
private FindType GetFindType()
{
if (radioButtonNormal.Checked)
@ -48,9 +49,19 @@ namespace Nikse.SubtitleEdit.Forms
return FindType.RegEx;
}
private string FindText
{
get
{
if (textBoxFind.Visible)
return textBoxFind.Text;
return comboBoxFind.Text;
}
}
public FindReplaceDialogHelper GetFindDialogHelper(int startLineIndex)
{
return new FindReplaceDialogHelper(GetFindType(), textBoxFind.Text, _regEx, string.Empty, 200, 300, startLineIndex);
return new FindReplaceDialogHelper(GetFindType(), FindText, _history, _regEx, string.Empty, 200, 300, startLineIndex);
}
private void FormFindDialog_KeyDown(object sender, KeyEventArgs e)
@ -63,7 +74,10 @@ namespace Nikse.SubtitleEdit.Forms
private void ButtonFindClick(object sender, EventArgs e)
{
string searchText = textBoxFind.Text.Trim();
string searchText = FindText;
textBoxFind.Text = searchText;
comboBoxFind.Text = searchText;
_history.Add(searchText);
if (searchText.Length == 0)
{
@ -81,7 +95,7 @@ namespace Nikse.SubtitleEdit.Forms
{
try
{
_regEx = new Regex(textBoxFind.Text, RegexOptions.Compiled);
_regEx = new Regex(FindText, RegexOptions.Compiled);
DialogResult = DialogResult.OK;
}
catch (Exception exception)
@ -95,21 +109,59 @@ namespace Nikse.SubtitleEdit.Forms
{
if (e.KeyCode == Keys.Enter)
ButtonFindClick(null, null);
}
private void comboBoxFind_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
ButtonFindClick(null, null);
}
private void RadioButtonCheckedChanged(object sender, EventArgs e)
{
if (sender == radioButtonRegEx)
textBoxFind.ContextMenu = FindReplaceDialogHelper.GetRegExContextMenu(textBoxFind);
{
if (textBoxFind.Visible)
{
comboBoxFind.ContextMenuStrip = null;
textBoxFind.ContextMenu = FindReplaceDialogHelper.GetRegExContextMenu(textBoxFind);
}
else
{
textBoxFind.ContextMenu = null;
comboBoxFind.ContextMenu = FindReplaceDialogHelper.GetRegExContextMenu(textBoxFind);
}
}
else
{
textBoxFind.ContextMenuStrip = null;
comboBoxFind.ContextMenuStrip = null;
}
}
internal void Initialize(string selectedText, FindReplaceDialogHelper findHelper)
{
textBoxFind.Text = selectedText;
textBoxFind.SelectAll();
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)
{

View File

@ -3491,6 +3491,7 @@ namespace Nikse.SubtitleEdit.Forms
if (findDialog.ShowDialog(this) == DialogResult.OK)
{
_findHelper = findDialog.GetFindDialogHelper(_subtitleListViewIndex);
_findHelper.AddHistory(_findHelper.FindText);
ShowStatus(string.Format(_language.SearchingForXFromLineY, _findHelper.FindText, _subtitleListViewIndex +1));
if (tabControlSubtitle.SelectedIndex == TabControlListView)
{
@ -10142,7 +10143,7 @@ namespace Nikse.SubtitleEdit.Forms
private void FindDoubleWordsToolStripMenuItemClick(object sender, EventArgs e)
{
var regex = new Regex(@"\b([\w]+)[ \r\n]+\1[ ,.!?]");
_findHelper = new FindReplaceDialogHelper(FindType.RegEx, string.Format(_language.DoubleWordsViaRegEx, regex), regex, string.Empty, 0, 0, _subtitleListViewIndex);
_findHelper = new FindReplaceDialogHelper(FindType.RegEx, string.Format(_language.DoubleWordsViaRegEx, regex), new List<string>(), regex, string.Empty, 0, 0, _subtitleListViewIndex);
ReloadFromSourceView();
FindNext();

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
@ -59,7 +60,7 @@ namespace Nikse.SubtitleEdit.Forms
public FindReplaceDialogHelper GetFindDialogHelper(int startLineIndex)
{
return new FindReplaceDialogHelper(GetFindType(), textBoxFind.Text, _regEx, textBoxReplace.Text, _left, _top, startLineIndex);
return new FindReplaceDialogHelper(GetFindType(), textBoxFind.Text, new List<string>(), _regEx, textBoxReplace.Text, _left, _top, startLineIndex);
}
private void FormReplaceDialog_KeyDown(object sender, KeyEventArgs e)

View File

@ -1,6 +1,7 @@
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Logic.Enums;
using System.Collections.Generic;
namespace Nikse.SubtitleEdit.Logic
{
@ -19,6 +20,7 @@ namespace Nikse.SubtitleEdit.Logic
public int WindowPositionTop { get; set; }
public int StartLineIndex { get; set; }
public bool MatchInOriginal { get; set; }
public List<string> FindTextHistory { get; private set; }
public int FindTextLength
{
@ -44,7 +46,7 @@ namespace Nikse.SubtitleEdit.Logic
}
}
public FindReplaceDialogHelper(FindType findType, string findText, Regex regEx, string replaceText, int left, int top, int startLineIndex)
public FindReplaceDialogHelper(FindType findType, string findText, List<string> history, Regex regEx, string replaceText, int left, int top, int startLineIndex)
{
FindType = findType;
_findText = findText;
@ -54,6 +56,7 @@ namespace Nikse.SubtitleEdit.Logic
WindowPositionLeft = left;
WindowPositionTop = top;
StartLineIndex = startLineIndex;
FindTextHistory = history;
}
public bool Find(Subtitle subtitle, Subtitle originalSubtitle, int startIndex)
@ -204,5 +207,12 @@ namespace Nikse.SubtitleEdit.Logic
}
return false;
}
internal void AddHistory(string findText)
{
if (FindTextHistory.Contains(findText))
FindTextHistory.Remove(findText);
FindTextHistory.Add(findText);
}
}
}