mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
Choose where to replace in translation mode - thx Leon :)
This commit is contained in:
parent
eed3ffff81
commit
5c824f5855
@ -4,5 +4,7 @@
|
||||
{
|
||||
public bool WholeWord { get; set; }
|
||||
public FindType FindType { get; set; }
|
||||
public bool SearchTranslation { get; set; }
|
||||
public bool SearchOriginal { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -6247,6 +6247,8 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
{
|
||||
_findHelper.InProgress = false;
|
||||
}
|
||||
|
||||
Focus();
|
||||
}
|
||||
|
||||
public void FindDialogFindPrevious(string findText)
|
||||
@ -6462,7 +6464,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
_findHelper = _findHelper ?? _replaceDialog.GetFindDialogHelper(_subtitleListViewIndex);
|
||||
}
|
||||
|
||||
_replaceDialog.Initialize(selectedText, _findHelper);
|
||||
_replaceDialog.Initialize(selectedText, _findHelper, IsOriginalEditable && SubtitleListview1.IsOriginalTextColumnVisible);
|
||||
if (!_replaceDialog.Visible)
|
||||
{
|
||||
_replaceDialog.Show(this);
|
||||
@ -6721,6 +6723,8 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
{
|
||||
RestartHistory();
|
||||
}
|
||||
|
||||
Focus();
|
||||
}
|
||||
|
||||
public void ListViewReplaceAll(ReplaceDialog replaceDialog, FindReplaceDialogHelper findHelper)
|
||||
@ -6977,7 +6981,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
}
|
||||
|
||||
_replaceDialog.Initialize(selectedText, _findHelper);
|
||||
_replaceDialog.Initialize(selectedText, _findHelper, IsOriginalEditable && SubtitleListview1.IsOriginalTextColumnVisible);
|
||||
if (!_replaceDialog.Visible)
|
||||
{
|
||||
_replaceDialog.Show(this);
|
||||
|
44
src/ui/Forms/ReplaceDialog.Designer.cs
generated
44
src/ui/Forms/ReplaceDialog.Designer.cs
generated
@ -39,12 +39,15 @@
|
||||
this.labelFindWhat = new System.Windows.Forms.Label();
|
||||
this.buttonFind = new System.Windows.Forms.Button();
|
||||
this.checkBoxWholeWord = new System.Windows.Forms.CheckBox();
|
||||
this.comboBoxFindReplaceIn = new System.Windows.Forms.ComboBox();
|
||||
this.labelFindReplaceIn = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// radioButtonRegEx
|
||||
//
|
||||
this.radioButtonRegEx.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.radioButtonRegEx.AutoSize = true;
|
||||
this.radioButtonRegEx.Location = new System.Drawing.Point(15, 190);
|
||||
this.radioButtonRegEx.Location = new System.Drawing.Point(15, 235);
|
||||
this.radioButtonRegEx.Name = "radioButtonRegEx";
|
||||
this.radioButtonRegEx.Size = new System.Drawing.Size(56, 17);
|
||||
this.radioButtonRegEx.TabIndex = 5;
|
||||
@ -54,8 +57,9 @@
|
||||
//
|
||||
// radioButtonCaseSensitive
|
||||
//
|
||||
this.radioButtonCaseSensitive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.radioButtonCaseSensitive.AutoSize = true;
|
||||
this.radioButtonCaseSensitive.Location = new System.Drawing.Point(15, 167);
|
||||
this.radioButtonCaseSensitive.Location = new System.Drawing.Point(15, 212);
|
||||
this.radioButtonCaseSensitive.Name = "radioButtonCaseSensitive";
|
||||
this.radioButtonCaseSensitive.Size = new System.Drawing.Size(94, 17);
|
||||
this.radioButtonCaseSensitive.TabIndex = 4;
|
||||
@ -65,9 +69,10 @@
|
||||
//
|
||||
// radioButtonNormal
|
||||
//
|
||||
this.radioButtonNormal.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.radioButtonNormal.AutoSize = true;
|
||||
this.radioButtonNormal.Checked = true;
|
||||
this.radioButtonNormal.Location = new System.Drawing.Point(15, 144);
|
||||
this.radioButtonNormal.Location = new System.Drawing.Point(15, 189);
|
||||
this.radioButtonNormal.Name = "radioButtonNormal";
|
||||
this.radioButtonNormal.Size = new System.Drawing.Size(58, 17);
|
||||
this.radioButtonNormal.TabIndex = 3;
|
||||
@ -78,7 +83,7 @@
|
||||
//
|
||||
// buttonReplace
|
||||
//
|
||||
this.buttonReplace.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonReplace.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonReplace.Location = new System.Drawing.Point(266, 54);
|
||||
this.buttonReplace.Name = "buttonReplace";
|
||||
this.buttonReplace.Size = new System.Drawing.Size(119, 23);
|
||||
@ -98,7 +103,7 @@
|
||||
//
|
||||
// buttonReplaceAll
|
||||
//
|
||||
this.buttonReplaceAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonReplaceAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonReplaceAll.Location = new System.Drawing.Point(266, 83);
|
||||
this.buttonReplaceAll.Name = "buttonReplaceAll";
|
||||
this.buttonReplaceAll.Size = new System.Drawing.Size(119, 23);
|
||||
@ -135,7 +140,7 @@
|
||||
//
|
||||
// buttonFind
|
||||
//
|
||||
this.buttonFind.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonFind.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonFind.Location = new System.Drawing.Point(266, 25);
|
||||
this.buttonFind.Name = "buttonFind";
|
||||
this.buttonFind.Size = new System.Drawing.Size(119, 23);
|
||||
@ -146,19 +151,40 @@
|
||||
//
|
||||
// checkBoxWholeWord
|
||||
//
|
||||
this.checkBoxWholeWord.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.checkBoxWholeWord.AutoSize = true;
|
||||
this.checkBoxWholeWord.Location = new System.Drawing.Point(15, 114);
|
||||
this.checkBoxWholeWord.Location = new System.Drawing.Point(15, 159);
|
||||
this.checkBoxWholeWord.Name = "checkBoxWholeWord";
|
||||
this.checkBoxWholeWord.Size = new System.Drawing.Size(83, 17);
|
||||
this.checkBoxWholeWord.TabIndex = 2;
|
||||
this.checkBoxWholeWord.Text = "Whole word";
|
||||
this.checkBoxWholeWord.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// comboBoxFindReplaceIn
|
||||
//
|
||||
this.comboBoxFindReplaceIn.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxFindReplaceIn.FormattingEnabled = true;
|
||||
this.comboBoxFindReplaceIn.Location = new System.Drawing.Point(15, 120);
|
||||
this.comboBoxFindReplaceIn.Name = "comboBoxFindReplaceIn";
|
||||
this.comboBoxFindReplaceIn.Size = new System.Drawing.Size(232, 21);
|
||||
this.comboBoxFindReplaceIn.TabIndex = 15;
|
||||
//
|
||||
// labelFindReplaceIn
|
||||
//
|
||||
this.labelFindReplaceIn.AutoSize = true;
|
||||
this.labelFindReplaceIn.Location = new System.Drawing.Point(12, 104);
|
||||
this.labelFindReplaceIn.Name = "labelFindReplaceIn";
|
||||
this.labelFindReplaceIn.Size = new System.Drawing.Size(96, 13);
|
||||
this.labelFindReplaceIn.TabIndex = 16;
|
||||
this.labelFindReplaceIn.Text = "Replace/search in:";
|
||||
//
|
||||
// ReplaceDialog
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(397, 221);
|
||||
this.ClientSize = new System.Drawing.Size(397, 266);
|
||||
this.Controls.Add(this.labelFindReplaceIn);
|
||||
this.Controls.Add(this.comboBoxFindReplaceIn);
|
||||
this.Controls.Add(this.checkBoxWholeWord);
|
||||
this.Controls.Add(this.buttonFind);
|
||||
this.Controls.Add(this.labelFindWhat);
|
||||
@ -199,5 +225,7 @@
|
||||
private System.Windows.Forms.Label labelFindWhat;
|
||||
private System.Windows.Forms.Button buttonFind;
|
||||
private System.Windows.Forms.CheckBox checkBoxWholeWord;
|
||||
private System.Windows.Forms.ComboBox comboBoxFindReplaceIn;
|
||||
private System.Windows.Forms.Label labelFindReplaceIn;
|
||||
}
|
||||
}
|
@ -43,6 +43,12 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
|
||||
UiUtil.FixLargeFonts(this, buttonReplace);
|
||||
_findNextShortcut = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainEditFindNext);
|
||||
|
||||
comboBoxFindReplaceIn.Items.Clear();
|
||||
comboBoxFindReplaceIn.Items.Add("Translation and original");
|
||||
comboBoxFindReplaceIn.Items.Add("Translation only");
|
||||
comboBoxFindReplaceIn.Items.Add("Original only");
|
||||
comboBoxFindReplaceIn.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
public bool ReplaceAll { get; set; }
|
||||
@ -64,6 +70,14 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
result.FindType = FindType.RegEx;
|
||||
}
|
||||
|
||||
result.SearchOriginal = !comboBoxFindReplaceIn.Visible ||
|
||||
comboBoxFindReplaceIn.SelectedIndex == 0 ||
|
||||
comboBoxFindReplaceIn.SelectedIndex == 2;
|
||||
|
||||
result.SearchTranslation = !comboBoxFindReplaceIn.Visible ||
|
||||
comboBoxFindReplaceIn.SelectedIndex == 0 ||
|
||||
comboBoxFindReplaceIn.SelectedIndex == 1;
|
||||
|
||||
result.WholeWord = checkBoxWholeWord.Checked;
|
||||
return result;
|
||||
}
|
||||
@ -91,7 +105,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
}
|
||||
|
||||
internal void Initialize(string selectedText, FindReplaceDialogHelper findHelper)
|
||||
internal void Initialize(string selectedText, FindReplaceDialogHelper findHelper, bool replaceInOriginal)
|
||||
{
|
||||
_findHelper = findHelper;
|
||||
textBoxFind.Text = selectedText;
|
||||
@ -123,6 +137,9 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
{
|
||||
checkBoxWholeWord.Checked = findHelper.FindReplaceType.WholeWord;
|
||||
}
|
||||
|
||||
labelFindReplaceIn.Visible = replaceInOriginal;
|
||||
comboBoxFindReplaceIn.Visible = replaceInOriginal;
|
||||
}
|
||||
|
||||
private void ButtonReplaceClick(object sender, EventArgs e)
|
||||
@ -133,6 +150,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
Validate(textBoxFind.Text);
|
||||
if (DialogResult == DialogResult.OK)
|
||||
{
|
||||
var findType = GetFindType();
|
||||
_findAndReplaceMethods.ReplaceDialogReplace();
|
||||
}
|
||||
|
||||
@ -147,6 +165,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
Validate(textBoxFind.Text);
|
||||
if (DialogResult == DialogResult.OK)
|
||||
{
|
||||
var findType = GetFindType();
|
||||
_findAndReplaceMethods.ReplaceDialogReplaceAll();
|
||||
}
|
||||
|
||||
@ -203,6 +222,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
Validate(textBoxFind.Text);
|
||||
if (DialogResult == DialogResult.OK)
|
||||
{
|
||||
var findType = GetFindType();
|
||||
_findAndReplaceMethods.ReplaceDialogFind();
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
}
|
||||
|
||||
int pos;
|
||||
if (!MatchInOriginal)
|
||||
if (!MatchInOriginal && FindReplaceType.SearchTranslation)
|
||||
{
|
||||
pos = FindPositionInText(p.Text, position);
|
||||
if (pos >= 0)
|
||||
@ -154,7 +154,7 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
MatchInOriginal = false;
|
||||
}
|
||||
|
||||
if (originalSubtitle != null && allowEditOfOriginalSubtitle)
|
||||
if (originalSubtitle != null && allowEditOfOriginalSubtitle && FindReplaceType.SearchOriginal)
|
||||
{
|
||||
var o = Utilities.GetOriginalParagraph(index, p, originalSubtitle.Paragraphs);
|
||||
if (o != null)
|
||||
@ -193,7 +193,7 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
|
||||
if (originalSubtitle != null && allowEditOfOriginalSubtitle)
|
||||
{
|
||||
if (!first || MatchInOriginal)
|
||||
if ((!first || MatchInOriginal) && FindReplaceType.SearchTranslation)
|
||||
{
|
||||
var o = Utilities.GetOriginalParagraph(index, p, originalSubtitle.Paragraphs);
|
||||
if (o != null)
|
||||
@ -232,32 +232,37 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
position = p.Text.Length - 1;
|
||||
}
|
||||
|
||||
for (var j = 0; j <= position; j++)
|
||||
if (originalSubtitle != null && allowEditOfOriginalSubtitle && FindReplaceType.SearchOriginal)
|
||||
{
|
||||
if (position - j >= 0 && position < p.Text.Length)
|
||||
|
||||
for (var j = 0; j <= position; j++)
|
||||
{
|
||||
var t = p.Text.Substring(position - j, j + 1);
|
||||
var pos = FindPositionInText(t, 0);
|
||||
var startWholeWord = position - j < 1;
|
||||
if (!startWholeWord && position - j - 1 > 0)
|
||||
if (position - j >= 0 && position < p.Text.Length)
|
||||
{
|
||||
startWholeWord = SeparatorChars.Contains(p.Text[position - j - 1]);
|
||||
}
|
||||
var t = p.Text.Substring(position - j, j + 1);
|
||||
var pos = FindPositionInText(t, 0);
|
||||
var startWholeWord = position - j < 1;
|
||||
if (!startWholeWord && position - j - 1 > 0)
|
||||
{
|
||||
startWholeWord = SeparatorChars.Contains(p.Text[position - j - 1]);
|
||||
}
|
||||
|
||||
var startWholeWorkOkay = !FindReplaceType.WholeWord || startWholeWord;
|
||||
var startWholeWorkOkay = !FindReplaceType.WholeWord || startWholeWord;
|
||||
|
||||
if (pos >= 0 && startWholeWorkOkay)
|
||||
{
|
||||
pos += position - j;
|
||||
MatchInOriginal = false;
|
||||
SelectedLineIndex = index;
|
||||
SelectedPosition = pos;
|
||||
ReplaceFromPosition = pos;
|
||||
Success = true;
|
||||
return true;
|
||||
if (pos >= 0 && startWholeWorkOkay)
|
||||
{
|
||||
pos += position - j;
|
||||
MatchInOriginal = false;
|
||||
SelectedLineIndex = index;
|
||||
SelectedPosition = pos;
|
||||
ReplaceFromPosition = pos;
|
||||
Success = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
position = 0;
|
||||
first = false;
|
||||
index--;
|
||||
|
@ -11,8 +11,14 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
{
|
||||
if (findHelper.FindReplaceType.FindType == FindType.RegEx)
|
||||
{
|
||||
var count = ReplaceAllRegEx(findHelper, subtitle, stopAtIndex);
|
||||
if (allowEditOfOriginalSubtitle && subtitleOriginal?.Paragraphs.Count > 0)
|
||||
var count = 0;
|
||||
|
||||
if (findHelper.FindReplaceType.SearchTranslation)
|
||||
{
|
||||
count += ReplaceAllRegEx(findHelper, subtitle, stopAtIndex);
|
||||
}
|
||||
|
||||
if (allowEditOfOriginalSubtitle && findHelper.FindReplaceType.SearchOriginal && subtitleOriginal?.Paragraphs.Count > 0)
|
||||
{
|
||||
count += ReplaceAllRegEx(findHelper, subtitleOriginal, stopAtIndex);
|
||||
}
|
||||
@ -20,8 +26,13 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
return count;
|
||||
}
|
||||
|
||||
var replaceCount = ReplaceAllNonRegEx(findHelper, subtitle, stopAtIndex);
|
||||
if (allowEditOfOriginalSubtitle && subtitleOriginal?.Paragraphs.Count > 0)
|
||||
var replaceCount = 0;
|
||||
if (findHelper.FindReplaceType.SearchTranslation)
|
||||
{
|
||||
replaceCount += ReplaceAllNonRegEx(findHelper, subtitle, stopAtIndex);
|
||||
}
|
||||
|
||||
if (allowEditOfOriginalSubtitle && findHelper.FindReplaceType.SearchOriginal && subtitleOriginal?.Paragraphs.Count > 0)
|
||||
{
|
||||
replaceCount += ReplaceAllNonRegEx(findHelper, subtitleOriginal, stopAtIndex);
|
||||
}
|
||||
@ -55,7 +66,7 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
private static int ReplaceAllRegEx(FindReplaceDialogHelper findHelper, Subtitle subtitle, int stopAtIndex)
|
||||
{
|
||||
var replaceCount = 0;
|
||||
for (int i = Math.Max(0, findHelper.StartLineIndex); i < subtitle.Paragraphs.Count; i++)
|
||||
for (var i = Math.Max(0, findHelper.StartLineIndex); i < subtitle.Paragraphs.Count; i++)
|
||||
{
|
||||
if (i >= stopAtIndex)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user