Refact - add more braces

This commit is contained in:
Nikolaj Olsson 2019-01-13 01:08:28 +01:00
parent 08a6a45777
commit f23f4e742c
2 changed files with 216 additions and 22 deletions

View File

@ -58,23 +58,31 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
foreach (var kp in LoadReplaceList(userDoc, "RemovedWholeWords"))
{
if (WordReplaceList.ContainsKey(kp.Key))
{
WordReplaceList.Remove(kp.Key);
}
}
foreach (var kp in LoadReplaceList(userDoc, "WholeWords"))
{
if (!WordReplaceList.ContainsKey(kp.Key))
{
WordReplaceList.Add(kp.Key, kp.Value);
}
}
foreach (var kp in LoadReplaceList(userDoc, "RemovedPartialLines"))
{
if (PartialLineWordBoundaryReplaceList.ContainsKey(kp.Key))
{
PartialLineWordBoundaryReplaceList.Remove(kp.Key);
}
}
foreach (var kp in LoadReplaceList(userDoc, "PartialLines"))
{
if (!PartialLineWordBoundaryReplaceList.ContainsKey(kp.Key))
{
PartialLineWordBoundaryReplaceList.Add(kp.Key, kp.Value);
}
}
}
@ -87,7 +95,10 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
{
var list = new Dictionary<string, string>();
if (!IsValidXmlDocument(doc, name))
{
return list;
}
var node = doc.DocumentElement?.SelectSingleNode(name);
if (node != null)
{
@ -98,7 +109,9 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
string to = item.Attributes["to"].Value;
string from = item.Attributes["from"].Value;
if (!list.ContainsKey(from))
{
list.Add(from, to);
}
}
}
}
@ -110,7 +123,10 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
{
var list = new Dictionary<string, string>();
if (!IsValidXmlDocument(doc, name))
{
return list;
}
var node = doc.DocumentElement?.SelectSingleNode(name);
if (node != null)
{
@ -121,7 +137,9 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
string to = item.Attributes["replaceWith"].Value;
string from = item.Attributes["find"].Value;
if (!list.ContainsKey(from))
{
list.Add(from, to);
}
}
}
}
@ -131,15 +149,16 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
private static bool IsValidXmlDocument(XmlDocument doc, string elementName)
{
if (doc.DocumentElement?.SelectSingleNode(elementName) == null)
return false;
return true;
return doc.DocumentElement?.SelectSingleNode(elementName) != null;
}
private static bool HasValidAttributes(XmlNode node, bool isRegex)
{
if (node?.Attributes == null)
{
return false;
}
if (isRegex)
{
if (node.Attributes["find"] != null && node.Attributes["replaceWith"] != null)
@ -163,7 +182,9 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
foreach (string from in _wholeLineReplaceList.Keys)
{
if (input == from)
{
return _wholeLineReplaceList[from];
}
}
string newText = input;
@ -196,12 +217,16 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
{
string with = _beginLineReplaceList[from];
if (s.StartsWith(from, StringComparison.Ordinal))
{
s = s.Remove(0, from.Length).Insert(0, with);
}
s = s.Replace(". " + from, ". " + with);
s = s.Replace("! " + from, "! " + with);
s = s.Replace("? " + from, "? " + with);
if (s.StartsWith("\"" + from, StringComparison.Ordinal) && !from.StartsWith('"'))
{
s = s.Replace("\"" + from, "\"" + with);
}
}
}
sb.AppendLine(s);
@ -228,13 +253,17 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
foreach (string from in PartialLineWordBoundaryReplaceList.Keys)
{
if (newText.FastIndexOf(from) >= 0)
{
newText = ReplaceWord(newText, from, PartialLineWordBoundaryReplaceList[from]);
}
}
foreach (string from in _partialLineAlwaysReplaceList.Keys)
{
if (newText.FastIndexOf(from) >= 0)
{
newText = newText.Replace(from, _partialLineAlwaysReplaceList[from]);
}
}
foreach (string findWhat in _regExList.Keys)
@ -248,16 +277,24 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
private static string AddToGuessList(List<string> list, string word, int index, string letter, string replaceLetters)
{
if (string.IsNullOrEmpty(word) || index < 0 || index + letter.Length - 1 >= word.Length)
{
return word;
}
string s = word.Remove(index, letter.Length);
if (index >= s.Length)
{
s += replaceLetters;
}
else
{
s = s.Insert(index, replaceLetters);
}
if (!list.Contains(s))
{
list.Add(s);
}
return s;
}
@ -301,26 +338,34 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
word = word.Replace("ffi", "ffi");
word = word.Replace("ffl", "ffl");
if (!_replaceListXmlFileName.Contains("\\ell" + ReplaceListFileNamePostFix))
{
word = word.Replace('ν', 'v'); // first 'v' is U+03BD GREEK SMALL LETTER NU
}
word = word.Replace('', '\'');
word = word.Replace('`', '\'');
word = word.Replace('´', '\'');
word = word.Replace('', '\'');
word = word.Replace('—', '-');
while (word.Contains("--"))
{
word = word.Replace("--", "-");
}
word = word.Replace('|', 'l');
word = word.Replace("vx/", "w");
if (word.Contains('¤'))
{
if (Regex.IsMatch(word, "[A-ZÆØÅÄÖÉÈÀÙÂÊÎÔÛËÏa-zæøåäöéèàùâêîôûëï]¤"))
{
word = word.Replace('¤', 'o');
}
}
}
//always replace list
foreach (string letter in _partialWordReplaceListAlways.Keys)
{
word = word.Replace(letter, _partialWordReplaceListAlways[letter]);
}
string pre = string.Empty;
string post = string.Empty;
@ -403,13 +448,17 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
}
string preWordPost = pre + word + post;
if (word.Length == 0)
{
return preWordPost;
}
if (word.Contains('?'))
{
var match = RegExQuestion.Match(word);
if (match.Success)
{
word = word.Insert(match.Index + 2, " ");
}
}
if (!string.IsNullOrEmpty(pre) || !string.IsNullOrEmpty(post))
@ -420,12 +469,16 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
if (word.Length == from.Length)
{
if (word == from)
{
return pre + WordReplaceList[from] + post;
}
}
else if (wordPlusPost.Length == from.Length)
{
if (string.CompareOrdinal(wordPlusPost, from) == 0)
{
return pre + WordReplaceList[from];
}
}
if (preWordPost.Length == from.Length && string.CompareOrdinal(preWordPost, from) == 0)
{
@ -438,7 +491,9 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
foreach (string from in WordReplaceList.Keys)
{
if (word.Length == from.Length && word == from)
{
return pre + WordReplaceList[from] + post;
}
}
}
@ -469,12 +524,16 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
if (word.Length == from.Length)
{
if (string.CompareOrdinal(word, from) == 0)
{
return pre + WordReplaceList[from] + post;
}
}
else if (wordPlusPost.Length == from.Length)
{
if (string.CompareOrdinal(wordPlusPost, from) == 0)
{
return pre + WordReplaceList[from];
}
}
if (preWordPost.Length == from.Length && string.CompareOrdinal(preWordPost, from) == 0)
{
@ -487,7 +546,9 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
foreach (string from in WordReplaceList.Keys)
{
if (word.Length == from.Length && string.CompareOrdinal(word, from) == 0)
{
return pre + WordReplaceList[from] + post;
}
}
}
}
@ -510,13 +571,19 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
public static string FixIor1InsideLowerCaseWord(string word)
{
if (StartsAndEndsWithNumber.IsMatch(word))
{
return word;
}
if (word.Contains(new[] { '2', '3', '4', '5', '6', '7', '8', '9' }))
{
return word;
}
if (HexNumber.IsMatch(word))
{
return word;
}
if (word.LastIndexOf('I') > 0 || word.LastIndexOf('1') > 0)
{
@ -527,14 +594,18 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
{
bool doFix = word[match.Index + 1] != 'I' && match.Index >= 1 && word.Substring(match.Index - 1).StartsWith("Mc", StringComparison.Ordinal);
if (word[match.Index + 1] == 'I' && match.Index >= 2 && word.Substring(match.Index - 2).StartsWith("Mac", StringComparison.Ordinal))
{
doFix = false;
}
if (doFix)
{
string oldText = word;
word = word.Substring(0, match.Index + 1) + "l";
if (match.Index + 2 < oldText.Length)
{
word += oldText.Substring(match.Index + 2);
}
}
}
match = RegExIandZero.Match(word, match.Index + 1);
@ -546,17 +617,23 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
public static string Fix0InsideLowerCaseWord(string word)
{
if (StartsAndEndsWithNumber.IsMatch(word))
{
return word;
}
if (word.Contains(new[] { '1', '2', '3', '4', '5', '6', '7', '8', '9' }) ||
word.EndsWith("a.m", StringComparison.Ordinal) ||
word.EndsWith("p.m", StringComparison.Ordinal) ||
word.EndsWith("am", StringComparison.Ordinal) ||
word.EndsWith("pm", StringComparison.Ordinal))
{
return word;
}
if (HexNumber.IsMatch(word))
{
return word;
}
if (word.LastIndexOf('0') > 0)
{
@ -568,7 +645,9 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
string oldText = word;
word = word.Substring(0, match.Index + 1) + "o";
if (match.Index + 2 < oldText.Length)
{
word += oldText.Substring(match.Index + 2);
}
}
match = RegExTime1.Match(word);
}
@ -584,7 +663,9 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
string oldText = word;
word = word.Substring(0, match.Index) + "o";
if (match.Index + 1 < oldText.Length)
{
word += oldText.Substring(match.Index + 1);
}
}
}
match = RegExTime2.Match(word, match.Index + 1);
@ -597,7 +678,9 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
{
//always replace list
foreach (string letter in _partialWordReplaceListAlways.Keys)
{
word = word.Replace(letter, _partialWordReplaceListAlways[letter]);
}
string pre = string.Empty;
string post = string.Empty;
@ -681,7 +764,9 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
string preWordPost = pre + word + post;
if (word.Length == 0)
{
return preWordPost;
}
if (!string.IsNullOrEmpty(pre) || !string.IsNullOrEmpty(post))
{
@ -691,12 +776,16 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
if (word.Length == from.Length)
{
if (string.CompareOrdinal(word, from) == 0)
{
return pre + WordReplaceList[from] + post;
}
}
else if (wordPlusPost.Length == from.Length)
{
if (string.CompareOrdinal(wordPlusPost, from) == 0)
{
return pre + WordReplaceList[from];
}
}
if (pre.Length + word.Length + post.Length == from.Length && string.CompareOrdinal(preWordPost, from) == 0)
{
@ -709,7 +798,9 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
foreach (string from in WordReplaceList.Keys)
{
if (word.Length == from.Length && word == from)
{
return pre + WordReplaceList[from] + post;
}
}
}
return preWordPost;
@ -722,7 +813,10 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
if (DeletePartialLineFromWordList(word))
{
if (PartialLineWordBoundaryReplaceList.ContainsKey(word))
{
PartialLineWordBoundaryReplaceList.Remove(word);
}
return true;
}
return false;
@ -730,7 +824,10 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
if (DeleteWordFromWordList(word))
{
if (WordReplaceList.ContainsKey(word))
{
WordReplaceList.Remove(word);
}
return true;
}
return false;
@ -765,9 +862,13 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
private bool DeleteFromList(string word, XmlDocument userDoc, string replaceListName, string elementName, Dictionary<string, string> dictionary, Dictionary<string, string> userDictionary)
{
if (dictionary == null)
{
throw new ArgumentNullException(nameof(dictionary));
}
if (userDictionary == null)
{
throw new ArgumentNullException(nameof(userDictionary));
}
bool removed = false;
if (userDictionary.ContainsKey((word)))
@ -871,7 +972,9 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
if (SavePartialLineToWordList(fromWord, toWord))
{
if (!PartialLineWordBoundaryReplaceList.ContainsKey(fromWord))
{
PartialLineWordBoundaryReplaceList.Add(fromWord, toWord);
}
return true;
}
return false;
@ -879,7 +982,9 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
if (SaveWordToWordList(fromWord, toWord))
{
if (!WordReplaceList.ContainsKey(fromWord))
{
WordReplaceList.Add(fromWord, toWord);
}
return true;
}
return false;
@ -945,7 +1050,9 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
{
var userDocument = LoadXmlReplaceListUserDocument();
if (!_wholeLineReplaceList.ContainsKey(fromLine))
{
_wholeLineReplaceList.Add(fromLine, toLine);
}
XmlNode wholeWordsNode = userDocument.DocumentElement?.SelectSingleNode("WholeLines");
if (wholeWordsNode != null)
{
@ -967,7 +1074,9 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
public static string ReplaceWord(string text, string word, string newWord)
{
if (string.IsNullOrEmpty(text) || string.IsNullOrEmpty(word))
{
return text;
}
var sb = new StringBuilder(text.Length);
if (text.Contains(word))
@ -980,16 +1089,24 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
{
bool startOk = i == 0;
if (!startOk)
{
startOk = (startChars + Environment.NewLine).Contains(text[i - 1]);
}
if (!startOk && word.StartsWith(' '))
{
startOk = true;
}
if (startOk)
{
bool endOk = (i + word.Length == text.Length);
if (!endOk)
{
endOk = (startChars + Environment.NewLine).Contains(text[i + word.Length]);
}
if (!endOk)
{
endOk = newWord.EndsWith(' ');
}
if (endOk)
{
sb.Append(newWord);
@ -998,7 +1115,9 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
}
}
if (i >= appendFrom)
{
sb.Append(text[i]);
}
}
}
return sb.ToString();

View File

@ -12,24 +12,23 @@ namespace Nikse.SubtitleEdit.Forms
{
public sealed partial class Beamer : Form
{
private Subtitle _subtitle;
private readonly Subtitle _subtitle;
private int _index;
private bool _fullscreen;
private Color _subtitleColor = Color.White;
private string _subtitleFontName = "Verdana";
private float _subtitleFontSize = 75.0f;
private Color _borderColor = Color.Black;
private float _borderWidth = 2.0f;
private bool _isLoading = true;
private Color _subtitleColor;
private string _subtitleFontName;
private float _subtitleFontSize;
private Color _borderColor;
private float _borderWidth;
private readonly bool _isLoading;
private int _marginLeft;
private int _marginBottom = 25;
private int _showIndex = -2;
private double _millisecondsFactor = 1.0;
private Main _main;
private readonly Main _main;
private bool _noTimerAction;
private long _videoStartTick;
//Keys _mainGeneralGoToNextSubtitle = UiUtil.GetKeys(Configuration.Settings.Shortcuts.GeneralGoToNextSubtitle);
private Keys _mainGeneralGoToPrevSubtitle = UiUtil.GetKeys(Configuration.Settings.Shortcuts.GeneralGoToPrevSubtitle);
private readonly Keys _mainGeneralGoToPrevSubtitle = UiUtil.GetKeys(Configuration.Settings.Shortcuts.GeneralGoToPrevSubtitle);
public Beamer(Main main, Subtitle subtitle, int index)
{
@ -39,6 +38,12 @@ namespace Nikse.SubtitleEdit.Forms
_main = main;
_subtitle = subtitle;
_index = index;
_isLoading = true;
_subtitleColor = Color.White;
_subtitleFontName = "Verdana";
_subtitleFontSize = 75.0f;
_borderColor = Color.Black;
_borderWidth = 2.0f;
LanguageStructure.Beamer language = Configuration.Settings.Language.Beamer;
Text = language.Title;
@ -52,7 +57,9 @@ namespace Nikse.SubtitleEdit.Forms
_subtitleFontName = Configuration.Settings.SubtitleBeaming.FontName;
_subtitleFontSize = Configuration.Settings.SubtitleBeaming.FontSize;
if (_subtitleFontSize > 100 || _subtitleFontSize < 10)
{
_subtitleFontSize = 60;
}
_subtitleColor = Configuration.Settings.SubtitleBeaming.FontColor;
_borderColor = Configuration.Settings.SubtitleBeaming.BorderColor;
_borderWidth = Configuration.Settings.SubtitleBeaming.BorderWidth;
@ -61,9 +68,13 @@ namespace Nikse.SubtitleEdit.Forms
panelBorderColor.BackColor = _borderColor;
if (Configuration.Settings.SubtitleBeaming.BorderWidth > 0 && Configuration.Settings.SubtitleBeaming.BorderWidth < 5)
{
comboBoxBorderWidth.SelectedIndex = (int)_borderWidth;
}
else
{
comboBoxBorderWidth.SelectedIndex = 2;
}
comboBoxHAlign.SelectedIndexChanged -= ComboBoxHAlignSelectedIndexChanged;
comboBoxHAlign.SelectedIndex = 1;
@ -74,11 +85,12 @@ namespace Nikse.SubtitleEdit.Forms
{
comboBoxSubtitleFont.Items.Add(x.Name);
if (x.Name.Equals(_subtitleFontName, StringComparison.OrdinalIgnoreCase))
{
comboBoxSubtitleFont.SelectedIndex = comboBoxSubtitleFont.Items.Count - 1;
}
}
comboBoxSubtitleFont.SelectedIndexChanged += ComboBoxSubtitleFontSizeSelectedIndexChanged;
// Index 0 = Value: 10; Index 90 = Value: 100;
comboBoxSubtitleFontSize.SelectedIndex = (_subtitleFontSize >= 10 && _subtitleFontSize <= 100) ? (int)(_subtitleFontSize - 10) : 40;
_isLoading = false;
ShowCurrent();
@ -174,7 +186,9 @@ namespace Nikse.SubtitleEdit.Forms
private void SetupImageParameters()
{
if (_isLoading)
{
return;
}
_subtitleColor = panelColor.BackColor;
_borderColor = panelBorderColor.BackColor;
@ -221,9 +235,13 @@ namespace Nikse.SubtitleEdit.Forms
int sizeX = (int)(textSize.Width * 0.8) + 40;
int sizeY = (int)(textSize.Height * 0.8) + 30;
if (sizeX < 1)
{
sizeX = 1;
}
if (sizeY < 1)
{
sizeY = 1;
}
bmp = new Bitmap(sizeX, sizeY);
g = Graphics.FromImage(bmp);
@ -231,18 +249,25 @@ namespace Nikse.SubtitleEdit.Forms
foreach (var line in HtmlUtil.RemoveOpenCloseTags(text, HtmlUtil.TagItalic, HtmlUtil.TagFont).SplitToLines())
{
if (subtitleAlignLeft)
{
lefts.Add(5);
}
else
{
lefts.Add((float)(bmp.Width - g.MeasureString(line, font).Width * 0.8 + 15) / 2);
}
}
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
g.SmoothingMode = SmoothingMode.AntiAlias;
g.CompositingQuality = CompositingQuality.HighQuality;
var sf = new StringFormat();
sf.Alignment = StringAlignment.Near;
sf.LineAlignment = StringAlignment.Near;// draw the text to a path
var sf = new StringFormat
{
Alignment = StringAlignment.Near,
LineAlignment = StringAlignment.Near
};
// draw the text to a path
var path = new GraphicsPath();
// display italic
@ -251,7 +276,9 @@ namespace Nikse.SubtitleEdit.Forms
bool isItalic = false;
float left = 5;
if (lefts.Count > 0)
{
left = lefts[0];
}
float top = 5;
bool newLine = false;
int lineNumber = 0;
@ -267,7 +294,9 @@ namespace Nikse.SubtitleEdit.Forms
float addLeft = 0;
int oldPathPointIndex = path.PointCount;
if (oldPathPointIndex < 0)
{
oldPathPointIndex = 0;
}
if (sb.Length > 0)
{
@ -279,11 +308,15 @@ namespace Nikse.SubtitleEdit.Forms
for (int k = oldPathPointIndex; k < list.Length; k++)
{
if (list[k].X > addLeft)
{
addLeft = list[k].X;
}
}
}
if (addLeft == 0)
if (Math.Abs(addLeft) < 0.001)
{
addLeft = left + 2;
}
left = addLeft;
if (_borderWidth > 0)
@ -344,7 +377,9 @@ namespace Nikse.SubtitleEdit.Forms
float addLeft = 0;
int oldPathPointIndex = path.PointCount - 1;
if (oldPathPointIndex < 0)
{
oldPathPointIndex = 0;
}
if (sb.Length > 0)
{
TextDraw.DrawText(font, sf, path, sb, isItalic, subtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
@ -355,20 +390,28 @@ namespace Nikse.SubtitleEdit.Forms
for (int k = oldPathPointIndex; k < list.Length; k++)
{
if (list[k].X > addLeft)
{
addLeft = list[k].X;
}
}
}
if (addLeft == 0)
if (Math.Abs(addLeft) < 0.001)
{
addLeft = left + 2;
}
left = addLeft;
if (_borderWidth > 0)
{
g.DrawPath(new Pen(_borderColor, _borderWidth), path);
}
g.FillPath(new SolidBrush(c), path);
path.Reset();
sb.Clear();
if (colorStack.Count > 0)
{
c = colorStack.Pop();
}
}
i += 6;
}
@ -397,7 +440,6 @@ namespace Nikse.SubtitleEdit.Forms
else if (text.Substring(i).StartsWith(Environment.NewLine, StringComparison.Ordinal))
{
TextDraw.DrawText(font, sf, path, sb, isItalic, subtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
top += lineHeight;
newLine = true;
i += Environment.NewLine.Length - 1;
@ -415,11 +457,15 @@ namespace Nikse.SubtitleEdit.Forms
i++;
}
if (sb.Length > 0)
{
TextDraw.DrawText(font, sf, path, sb, isItalic, subtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
}
sf.Dispose();
if (_borderWidth > 0)
{
g.DrawPath(new Pen(_borderColor, _borderWidth), path);
}
g.FillPath(new SolidBrush(c), path);
g.Dispose();
var nbmp = new NikseBitmap(bmp);
@ -430,7 +476,9 @@ namespace Nikse.SubtitleEdit.Forms
private void Timer1Tick(object sender, EventArgs e)
{
if (_noTimerAction)
{
return;
}
double positionInMilliseconds = (DateTime.Now.Ticks - _videoStartTick) / 10000.0D; // 10,000 ticks = 1 millisecond
positionInMilliseconds *= _millisecondsFactor;
@ -445,8 +493,9 @@ namespace Nikse.SubtitleEdit.Forms
index++;
}
if (index == _subtitle.Paragraphs.Count)
{
index = -1;
}
if (index == -1)
{
pictureBox1.Image = null;
@ -508,32 +557,44 @@ namespace Nikse.SubtitleEdit.Forms
else if (e.KeyCode == Keys.Space || (e.KeyCode == Keys.Down && e.Modifiers == Keys.Alt) || _mainGeneralGoToPrevSubtitle == e.KeyData)
{
if (_index < _subtitle.Paragraphs.Count - 1)
{
_index++;
}
ShowCurrent();
e.Handled = true;
}
else if (_mainGeneralGoToPrevSubtitle == e.KeyData || (e.KeyCode == Keys.Up && e.Modifiers == Keys.Alt))
{
if (_index > 0)
{
_index--;
}
ShowCurrent();
e.Handled = true;
}
else if (e.Modifiers == Keys.None && e.KeyCode == Keys.PageDown)
{
if (_index < _subtitle.Paragraphs.Count - 21)
{
_index += 20;
}
else
{
_index = _subtitle.Paragraphs.Count - 1;
}
ShowCurrent();
e.Handled = true;
}
else if (e.Modifiers == Keys.None && e.KeyCode == Keys.PageUp)
{
if (_index > 20)
{
_index -= 20;
}
else
{
_index = 0;
}
ShowCurrent();
e.Handled = true;
}
@ -565,14 +626,17 @@ namespace Nikse.SubtitleEdit.Forms
timer1.Enabled = false;
System.Threading.Thread.Sleep(100);
if (_index < _subtitle.Paragraphs.Count - 1)
{
_index++;
}
_videoStartTick = DateTime.Now.Ticks - ((long)(_subtitle.Paragraphs[_index].StartTime.TotalMilliseconds) * 10000); //10,000 ticks = 1 millisecond
ShowCurrent();
_noTimerAction = false;
if (timer1Enabled || _fullscreen)
{
timer1.Start();
}
e.Handled = true;
}
@ -582,7 +646,9 @@ namespace Nikse.SubtitleEdit.Forms
timer1.Enabled = false;
System.Threading.Thread.Sleep(100);
if (_index > 0)
{
_index--;
}
_videoStartTick = DateTime.Now.Ticks - ((long)(_subtitle.Paragraphs[_index].StartTime.TotalMilliseconds) * 10000); //10,000 ticks = 1 millisecond
ShowCurrent();
if (timer1Enabled)
@ -591,18 +657,26 @@ namespace Nikse.SubtitleEdit.Forms
else if (e.Modifiers == Keys.None && e.KeyCode == Keys.PageDown)
{
if (_index < _subtitle.Paragraphs.Count - 21)
{
_index += 20;
}
else
{
_index = _subtitle.Paragraphs.Count - 1;
}
ShowCurrent();
e.Handled = true;
}
else if (e.Modifiers == Keys.None && e.KeyCode == Keys.PageUp)
{
if (_index > 20)
{
_index -= 20;
}
else
{
_index = 0;
}
ShowCurrent();
e.Handled = true;
}
@ -669,6 +743,7 @@ namespace Nikse.SubtitleEdit.Forms
private void BeamerFormClosing(object sender, FormClosingEventArgs e)
{
Cursor.Show();
// Save user-configurations.
Configuration.Settings.SubtitleBeaming.FontName = _subtitleFontName;
Configuration.Settings.SubtitleBeaming.FontSize = (int)_subtitleFontSize;