Misc minor changes

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@611 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2011-09-08 08:52:04 +00:00
parent 290a981212
commit bd4c65db99
10 changed files with 124 additions and 49 deletions

View File

@ -283,6 +283,8 @@ namespace Nikse.SubtitleEdit.Controls
public void SelectNone()
{
if (SelectedItems == null)
return;
foreach (ListViewItem item in SelectedItems)
item.Selected = false;
}

View File

@ -50,7 +50,7 @@ namespace Nikse.SubtitleEdit.Forms
this.comboBoxFrom.FormattingEnabled = true;
this.comboBoxFrom.Location = new System.Drawing.Point(327, 34);
this.comboBoxFrom.Name = "comboBoxFrom";
this.comboBoxFrom.Size = new System.Drawing.Size(121, 25);
this.comboBoxFrom.Size = new System.Drawing.Size(121, 21);
this.comboBoxFrom.TabIndex = 0;
//
// labelFrom
@ -58,7 +58,7 @@ namespace Nikse.SubtitleEdit.Forms
this.labelFrom.AutoSize = true;
this.labelFrom.Location = new System.Drawing.Point(285, 41);
this.labelFrom.Name = "labelFrom";
this.labelFrom.Size = new System.Drawing.Size(45, 17);
this.labelFrom.Size = new System.Drawing.Size(35, 13);
this.labelFrom.TabIndex = 1;
this.labelFrom.Text = "From:";
//
@ -67,7 +67,7 @@ namespace Nikse.SubtitleEdit.Forms
this.labelTo.AutoSize = true;
this.labelTo.Location = new System.Drawing.Point(468, 37);
this.labelTo.Name = "labelTo";
this.labelTo.Size = new System.Drawing.Size(29, 17);
this.labelTo.Size = new System.Drawing.Size(23, 13);
this.labelTo.TabIndex = 4;
this.labelTo.Text = "To:";
//
@ -77,7 +77,7 @@ namespace Nikse.SubtitleEdit.Forms
this.comboBoxTo.FormattingEnabled = true;
this.comboBoxTo.Location = new System.Drawing.Point(497, 34);
this.comboBoxTo.Name = "comboBoxTo";
this.comboBoxTo.Size = new System.Drawing.Size(121, 25);
this.comboBoxTo.Size = new System.Drawing.Size(121, 21);
this.comboBoxTo.TabIndex = 3;
//
// buttonTranslate
@ -118,7 +118,7 @@ namespace Nikse.SubtitleEdit.Forms
this.linkLabelPoweredByGoogleTranslate.AutoSize = true;
this.linkLabelPoweredByGoogleTranslate.Location = new System.Drawing.Point(15, 529);
this.linkLabelPoweredByGoogleTranslate.Name = "linkLabelPoweredByGoogleTranslate";
this.linkLabelPoweredByGoogleTranslate.Size = new System.Drawing.Size(183, 17);
this.linkLabelPoweredByGoogleTranslate.Size = new System.Drawing.Size(146, 13);
this.linkLabelPoweredByGoogleTranslate.TabIndex = 8;
this.linkLabelPoweredByGoogleTranslate.TabStop = true;
this.linkLabelPoweredByGoogleTranslate.Text = "Powered by Google translate";
@ -129,7 +129,7 @@ namespace Nikse.SubtitleEdit.Forms
this.labelPleaseWait.AutoSize = true;
this.labelPleaseWait.Location = new System.Drawing.Point(703, 23);
this.labelPleaseWait.Name = "labelPleaseWait";
this.labelPleaseWait.Size = new System.Drawing.Size(215, 17);
this.labelPleaseWait.Size = new System.Drawing.Size(176, 13);
this.labelPleaseWait.TabIndex = 10;
this.labelPleaseWait.Text = "Please wait... this may take a while";
//
@ -142,33 +142,41 @@ namespace Nikse.SubtitleEdit.Forms
//
// subtitleListViewTo
//
this.subtitleListViewTo.DisplayExtraFromExtra = false;
this.subtitleListViewTo.FirstVisibleIndex = -1;
this.subtitleListViewTo.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.subtitleListViewTo.FullRowSelect = true;
this.subtitleListViewTo.GridLines = true;
this.subtitleListViewTo.HideSelection = false;
this.subtitleListViewTo.Location = new System.Drawing.Point(471, 64);
this.subtitleListViewTo.Name = "subtitleListViewTo";
this.subtitleListViewTo.Size = new System.Drawing.Size(428, 459);
this.subtitleListViewTo.TabIndex = 2;
this.subtitleListViewTo.UseCompatibleStateImageBehavior = false;
this.subtitleListViewTo.View = System.Windows.Forms.View.Details;
this.subtitleListViewTo.Click += new System.EventHandler(this.subtitleListViewTo_DoubleClick);
this.subtitleListViewTo.DoubleClick += new System.EventHandler(this.subtitleListViewTo_DoubleClick);
//
// subtitleListViewFrom
//
this.subtitleListViewFrom.DisplayExtraFromExtra = false;
this.subtitleListViewFrom.FirstVisibleIndex = -1;
this.subtitleListViewFrom.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.subtitleListViewFrom.FullRowSelect = true;
this.subtitleListViewFrom.GridLines = true;
this.subtitleListViewFrom.HideSelection = false;
this.subtitleListViewFrom.Location = new System.Drawing.Point(18, 64);
this.subtitleListViewFrom.Name = "subtitleListViewFrom";
this.subtitleListViewFrom.Size = new System.Drawing.Size(430, 459);
this.subtitleListViewFrom.TabIndex = 0;
this.subtitleListViewFrom.UseCompatibleStateImageBehavior = false;
this.subtitleListViewFrom.View = System.Windows.Forms.View.Details;
this.subtitleListViewFrom.Click += new System.EventHandler(this.subtitleListViewFrom_DoubleClick);
this.subtitleListViewFrom.DoubleClick += new System.EventHandler(this.subtitleListViewFrom_DoubleClick);
//
// GoogleTranslate
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 17F);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(925, 558);
this.Controls.Add(this.comboBoxFrom);

View File

@ -20,7 +20,6 @@ namespace Nikse.SubtitleEdit.Forms
bool _googleTranslate = true;
MicrosoftTranslationService.SoapService _microsoftTranslationService = null;
private const string BingApiId = "C2C2E9A508E6748F0494D68DFD92FAA1FF9B0BA4";
bool _googleApiNotWorking = false;
public class ComboBoxItem
{
@ -189,24 +188,10 @@ namespace Nikse.SubtitleEdit.Forms
int index = 0;
foreach (Paragraph p in _subtitle.Paragraphs)
{
string text = string.Format("<p> {0} </p>", p.Text);
if (_googleApiNotWorking)
{
FillTranslatedText(DoTranslate(text), index, index);
sb = new StringBuilder();
progressBar1.Refresh();
Application.DoEvents();
text = string.Empty;
}
else if (HttpUtility.UrlEncode(sb.ToString() + text).Length >= textMaxSize)
string text = string.Format("<p> {0} </p>|", p.Text.Replace("|", "<br />"));
if (HttpUtility.UrlEncode(sb.ToString() + text).Length >= textMaxSize)
{
FillTranslatedText(DoTranslate(sb.ToString()), start, index-1);
if (_googleApiNotWorking)
{
buttonTranslate.Text = Configuration.Settings.Language.GoogleTranslate.Translate;
buttonTranslate_Click(null, null);
return;
}
sb = new StringBuilder();
progressBar1.Refresh();
Application.DoEvents();
@ -236,9 +221,8 @@ namespace Nikse.SubtitleEdit.Forms
private void FillTranslatedText(string translatedText, int start, int end)
{
List<string> lines = new List<string>();
foreach (string s in translatedText.Split(new string[] { "<p>" }, StringSplitOptions.None))
foreach (string s in translatedText.Split(new string[] { "|" }, StringSplitOptions.None))
lines.Add(s);
lines.RemoveAt(0);
int index = start;
foreach (string s in lines)
@ -246,6 +230,9 @@ namespace Nikse.SubtitleEdit.Forms
if (index < _translatedSubtitle.Paragraphs.Count)
{
string cleanText = s.Replace("</p>", string.Empty).Trim();
if (cleanText.IndexOf("<p>") < 4)
cleanText = cleanText.Remove(0, cleanText.IndexOf("<p>"));
cleanText = cleanText.Replace("<p>", string.Empty).Trim();
if (cleanText.Contains("\n") && !cleanText.Contains("\r"))
cleanText = cleanText.Replace("\n", Environment.NewLine);
cleanText = cleanText.Replace(" ...", "...");
@ -269,23 +256,20 @@ namespace Nikse.SubtitleEdit.Forms
input = PreTranslate(input);
string result;
try
{
result = TranslateTextViaApi(input, languagePair);
}
catch
{
_googleApiNotWorking = true;
result = string.Empty;
}
string result = null;
//try
//{
// result = TranslateTextViaApi(input, languagePair);
//}
//catch
//{
// _googleApiNotWorking = true;
// result = string.Empty;
//}
// fallback to screen scraping
if (string.IsNullOrEmpty(result))
{
_googleApiNotWorking = true;
//if (string.IsNullOrEmpty(result))
result = TranslateTextViaScreenScraping(input, languagePair);
}
return PostTranslate(result);
}
@ -824,5 +808,29 @@ namespace Nikse.SubtitleEdit.Forms
}
}
private void subtitleListViewFrom_DoubleClick(object sender, EventArgs e)
{
if (subtitleListViewFrom.SelectedItems.Count > 0)
{
int index = subtitleListViewFrom.SelectedItems[0].Index;
if (index < subtitleListViewTo.Items.Count)
{
subtitleListViewTo.SelectIndexAndEnsureVisible(index);
}
}
}
private void subtitleListViewTo_DoubleClick(object sender, EventArgs e)
{
if (subtitleListViewTo.SelectedItems.Count > 0)
{
int index = subtitleListViewTo.SelectedItems[0].Index;
if (index < subtitleListViewFrom.Items.Count)
{
subtitleListViewFrom.SelectIndexAndEnsureVisible(index);
}
}
}
}
}

View File

@ -94,6 +94,7 @@ namespace Nikse.SubtitleEdit.Forms
Keys _mainAdjustInsertViaEndAutoStartAndGoToNext = Keys.None;
bool _videoLoadedGoToSubPosAndPause = false;
bool _makeHistory = true;
string _cutText = string.Empty;
private bool AutoRepeatContinueOn
{
@ -114,7 +115,7 @@ namespace Nikse.SubtitleEdit.Forms
if (versionInfo.Length >= 3 && versionInfo[2] != "0")
_title += "." + versionInfo[2];
}
return _title + " RC 1";
return _title + " RC2";
}
}
@ -658,6 +659,7 @@ namespace Nikse.SubtitleEdit.Forms
if (beforeParagraph == null)
beforeParagraph = paragraph;
int selectedIndex = FirstSelectedIndex;
_change = true;
_makeHistory = false;
int index = _subtitle.Paragraphs.IndexOf(paragraph);
@ -705,6 +707,14 @@ namespace Nikse.SubtitleEdit.Forms
SubtitleListview1.SetStartTime(index, paragraph);
SubtitleListview1.SetDuration(index, paragraph);
if (index == selectedIndex)
{
timeUpDownStartTime.TimeCode = paragraph.StartTime;
decimal durationInSeconds = (decimal)(paragraph.Duration.TotalSeconds);
if (durationInSeconds >= numericUpDownDuration.Minimum && durationInSeconds <= numericUpDownDuration.Maximum)
numericUpDownDuration.Value = durationInSeconds;
}
}
}
}
@ -3976,7 +3986,16 @@ namespace Nikse.SubtitleEdit.Forms
}
if (Configuration.Settings.General.PromptDeleteLines && MessageBox.Show(askText, Title, MessageBoxButtons.YesNo) == DialogResult.No)
{
_cutText = string.Empty;
return;
}
if (!string.IsNullOrEmpty(_cutText))
{
Clipboard.SetText(_cutText);
_cutText = string.Empty;
}
MakeHistoryForUndo(historyText);
_subtitleListViewIndex = -1;
@ -6127,9 +6146,6 @@ namespace Nikse.SubtitleEdit.Forms
videoTimer.Stop();
timer1.Stop();
//if (SubtitleListview1.SelectedIndices.Count > 1)
// SubtitleListview1.EnsureVisible(SubtitleListview1.SelectedIndices[0]);
_showEarlierOrLater = new ShowEarlierLater();
if (!_formPositionsAndSizes.SetPositionAndSize(_showEarlierOrLater))
{
@ -6590,7 +6606,7 @@ namespace Nikse.SubtitleEdit.Forms
private void SubtitleListview1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.C && e.Control) //Copy to clipboard
if (e.KeyCode == Keys.C && e.Control) //Ctrl+c = Copy to clipboard
{
Subtitle tmp = new Subtitle();
foreach (int i in SubtitleListview1.SelectedIndices)
@ -6605,7 +6621,7 @@ namespace Nikse.SubtitleEdit.Forms
}
e.SuppressKeyPress = true;
}
else if (e.KeyCode == Keys.V && e.Control) //Paste from clipboard
else if (e.KeyCode == Keys.V && e.Control) //Ctrl+vPaste from clipboard
{
if (Clipboard.ContainsText())
{
@ -6637,6 +6653,19 @@ namespace Nikse.SubtitleEdit.Forms
}
e.SuppressKeyPress = true;
}
else if (e.KeyCode == Keys.X && e.Control) //Ctrl+X = Cut to clipboard
{
Subtitle tmp = new Subtitle();
foreach (int i in SubtitleListview1.SelectedIndices)
{
Paragraph p = _subtitle.GetParagraphOrDefault(i);
if (p != null)
tmp.Paragraphs.Add(new Paragraph(p));
}
e.SuppressKeyPress = true;
_cutText = tmp.ToText(new SubRip());
ToolStripMenuItemDeleteClick(null, null);
}
else if (e.KeyCode == Keys.A && e.Control) //SelectAll
{
foreach (ListViewItem item in SubtitleListview1.Items)

View File

@ -681,7 +681,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAD2
CAAAAk1TRnQBSQFMAgEBAgEAAcgBCgHIAQoBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CAAAAk1TRnQBSQFMAgEBAgEAAdgBCgHYAQoBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA

View File

@ -307,6 +307,9 @@ namespace Nikse.SubtitleEdit.Forms
if ("1234567890".Contains(s.Substring(indexOfColon - 1, 1)) && "1234567890".Contains(s.Substring(indexOfColon + 1, 1)))
remove = false;
}
if (s.StartsWith("Previously on") || s.StartsWith("<i>Previously on"))
remove = false;
if (remove)
{
string content = s.Substring(indexOfColon + 1).Trim();
@ -325,6 +328,8 @@ namespace Nikse.SubtitleEdit.Forms
if (text.StartsWith("(") && newText.EndsWith(")") && !newText.Contains("("))
newText = newText.TrimEnd(')');
else if (newText.EndsWith("</i>") && text.StartsWith("<i>") && !newText.StartsWith("<i>"))
newText = "<i>" + newText;
if (!IsHIDescription(st.StrippedText))
noOfNames++;
@ -333,6 +338,8 @@ namespace Nikse.SubtitleEdit.Forms
{
newText = newText + Environment.NewLine + s;
newText = newText.Trim();
if (newText.EndsWith("</i>") && text.StartsWith("<i>") && !newText.StartsWith("<i>"))
newText = "<i>" + newText;
}
}
else
@ -373,6 +380,10 @@ namespace Nikse.SubtitleEdit.Forms
{
newText = newText + Environment.NewLine + s;
newText = newText.Trim();
if (newText.EndsWith("</i>") && text.StartsWith("<i>") && !newText.StartsWith("<i>"))
newText = "<i>" + newText;
}
}
newText = newText.Trim();

View File

@ -75,7 +75,7 @@ namespace Nikse.SubtitleEdit.Logic
{
Title = "Subtitle Edit",
Version = "3.2",
TranslatedBy = "",
TranslatedBy = "Translated by Nikse",
CultureName = "en-US",
OK = "&OK",
Cancel = "C&ancel",

View File

@ -107,7 +107,7 @@ namespace Nikse.SubtitleEdit.Logic
public static IEnumerable<string> GetMovieFileExtensions()
{
return new List<string> { ".avi", ".mkv", ".wmv", ".mpg", ".mpeg", ".divx", ".mp4", ".asf", ".flv", ".mov" };
return new List<string> { ".avi", ".mkv", ".wmv", ".mpg", ".mpeg", ".divx", ".mp4", ".asf", ".flv", ".mov", ".m4v", ".vob" };
}
public static string GetVideoFileFilter()

View File

@ -936,6 +936,7 @@
<ItemGroup>
<Content Include="Languages\bg-BG.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType>
</Content>
<Content Include="Languages\cs-CZ.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

View File

@ -1,5 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nikse.SubtitleEdit.Forms;
using System;
namespace Test
{
@ -133,5 +134,20 @@ namespace Test
Assert.AreEqual(expected, actual);
}
/// <summary>
///A test for RemoveHI
///</summary>
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHIMultilineItalic()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
string text = "<i>NARRATOR:" + Environment.NewLine +
"Previously on NCIS</i>";
string expected = "<i>Previously on NCIS</i>";
string actual = target.RemoveTextFromHearImpaired(text);
Assert.AreEqual(expected, actual);
}
}
}