Minor refact

This commit is contained in:
niksedk 2023-02-05 15:45:21 +01:00
parent 9861e01c32
commit c8b8bda394

View File

@ -163,7 +163,7 @@ namespace Nikse.SubtitleEdit.Controls
var text = base.Text;
var extra = 0;
var target = base.SelectionStart;
for (int i = 0; i < target && i < text.Length; i++)
for (var i = 0; i < target && i < text.Length; i++)
{
if (text[i] == '\n')
{
@ -177,7 +177,7 @@ namespace Nikse.SubtitleEdit.Controls
{
var text = base.Text;
var extra = 0;
for (int i = 0; i < value && i < text.Length; i++)
for (var i = 0; i < value && i < text.Length; i++)
{
if (text[i] == '\n')
{
@ -202,7 +202,7 @@ namespace Nikse.SubtitleEdit.Controls
var text = base.Text;
var extra = 0;
var start = SelectionStart;
for (int i = start; i < target + start && i < text.Length; i++)
for (var i = start; i < target + start && i < text.Length; i++)
{
if (text[i] == '\n')
{
@ -224,7 +224,7 @@ namespace Nikse.SubtitleEdit.Controls
var text = base.Text;
var extra = 0;
var start = SelectionStart;
for (int i = start; i < target + start && i < text.Length; i++)
for (var i = start; i < target + start && i < text.Length; i++)
{
if (text[i] == '\n')
{
@ -246,7 +246,7 @@ namespace Nikse.SubtitleEdit.Controls
{
var text = base.Text;
var extra = 0;
for (int i = 0; i < index && i < text.Length; i++)
for (var i = 0; i < index && i < text.Length; i++)
{
if (text[i] == '\n')
{
@ -329,19 +329,19 @@ namespace Nikse.SubtitleEdit.Controls
SelectionColor = ForeColor;
SelectionBackColor = BackColor;
bool htmlTagOn = false;
bool htmlTagFontOn = false;
int htmlTagStart = -1;
bool assaTagOn = false;
bool assaPrimaryColorTagOn = false;
bool assaSecondaryColorTagOn = false;
bool assaBorderColorTagOn = false;
bool assaShadowColorTagOn = false;
var htmlTagOn = false;
var htmlTagFontOn = false;
var htmlTagStart = -1;
var assaTagOn = false;
var assaPrimaryColorTagOn = false;
var assaSecondaryColorTagOn = false;
var assaBorderColorTagOn = false;
var assaShadowColorTagOn = false;
var assaTagStart = -1;
int tagOn = -1;
var tagOn = -1;
var text = Text;
var textLength = text.Length;
int i = 0;
var i = 0;
while (i < textLength)
{
@ -449,7 +449,7 @@ namespace Nikse.SubtitleEdit.Controls
colorStart++;
}
int colorEnd = text.IndexOf('"', colorStart + 1);
var colorEnd = text.IndexOf('"', colorStart + 1);
if (colorEnd > 0)
{
var color = text.Substring(colorStart, colorEnd - colorStart);
@ -478,7 +478,7 @@ namespace Nikse.SubtitleEdit.Controls
private void SetAssaColor(string text, int assaTagStart, string colorTag)
{
int colorStart = text.IndexOf(colorTag, assaTagStart, StringComparison.OrdinalIgnoreCase);
var colorStart = text.IndexOf(colorTag, assaTagStart, StringComparison.OrdinalIgnoreCase);
if (colorStart > 0)
{
colorStart += colorTag.Length;
@ -491,7 +491,7 @@ namespace Nikse.SubtitleEdit.Controls
colorStart++;
}
int colorEnd = text.IndexOfAny(new[] { '}', '\\', '&' }, colorStart + 1);
var colorEnd = text.IndexOfAny(new[] { '}', '\\', '&' }, colorStart + 1);
if (colorEnd > 0)
{
var color = text.Substring(colorStart, colorEnd - colorStart);
@ -535,15 +535,12 @@ namespace Nikse.SubtitleEdit.Controls
{
base.WndProc(ref m);
if (m.Msg == WM_PAINT)
if (m.Msg == WM_PAINT && !Enabled && Configuration.Settings.General.UseDarkTheme)
{
if (!Enabled && Configuration.Settings.General.UseDarkTheme)
using (var g = Graphics.FromHwnd(Handle))
using (var sb = new SolidBrush(BackColor))
{
using (var g = Graphics.FromHwnd(Handle))
using (var sb = new SolidBrush(BackColor))
{
g.FillRectangle(sb, ClientRectangle);
}
g.FillRectangle(sb, ClientRectangle);
}
}
}
@ -612,7 +609,7 @@ namespace Nikse.SubtitleEdit.Controls
private void LoadDictionaries(string languageName)
{
var dictionaryFolder = Utilities.DictionaryFolder;
string dictionary = Utilities.DictionaryFolder + languageName;
var dictionary = Utilities.DictionaryFolder + languageName;
_spellCheckWordLists = new SpellCheckWordLists(dictionaryFolder, languageName, this);
_skipAllList = new List<string>();
_skipOnceList = new HashSet<string>();
@ -673,17 +670,17 @@ namespace Nikse.SubtitleEdit.Controls
{
_wrongWords = new List<SpellCheckWord>();
for (int i = 0; i < _words.Count; i++)
for (var i = 0; i < _words.Count; i++)
{
var currentWord = _words[i];
var currentWordText = _words[i].Text;
int minLength = 2;
var minLength = 2;
if (Configuration.Settings.Tools.CheckOneLetterWords)
{
minLength = 1;
}
string key = CurrentLineIndex + "-" + currentWord.Text + "-" + currentWord.Index;
var key = CurrentLineIndex + "-" + currentWord.Text + "-" + currentWord.Index;
if (DoSpell(currentWordText) || Utilities.IsNumber(currentWordText) || _skipAllList.Contains(currentWordText)
|| _skipOnceList.Contains(key) || _spellCheckWordLists.HasUserWord(currentWordText) || _spellCheckWordLists.HasName(currentWordText)
|| currentWordText.Length < minLength || currentWordText == "&")
@ -697,12 +694,12 @@ namespace Nikse.SubtitleEdit.Controls
{
if (currentWordText.Length > 0)
{
var trimChars = "'`*#\u200E\u200F\u202A\u202B\u202C\u202D\u202E\u200B\uFEFF";
const string trimChars = "'`*#\u200E\u200F\u202A\u202B\u202C\u202D\u202E\u200B\uFEFF";
var charHit = true;
while (charHit)
{
charHit = false;
foreach (char c in trimChars)
foreach (var c in trimChars)
{
if (currentWordText.StartsWith(c))
{
@ -725,7 +722,8 @@ namespace Nikse.SubtitleEdit.Controls
{
continue;
}
else if (currentWordText.Length > 1)
if (currentWordText.Length > 1)
{
if ("`'".Contains(currentWordText[currentWordText.Length - 1]) && DoSpell(currentWordText.TrimEnd('\'').TrimEnd('`')))
{
@ -733,7 +731,7 @@ namespace Nikse.SubtitleEdit.Controls
}
if (currentWordText.EndsWith("'s", StringComparison.Ordinal) && currentWordText.Length > 4
&& DoSpell(currentWordText.TrimEnd('s').TrimEnd('\'')))
&& DoSpell(currentWordText.TrimEnd('s').TrimEnd('\'')))
{
continue;
}
@ -743,7 +741,7 @@ namespace Nikse.SubtitleEdit.Controls
continue;
}
string removeUnicode = currentWordText.Replace("\u200b", string.Empty); // zero width space
var removeUnicode = currentWordText.Replace("\u200b", string.Empty); // zero width space
removeUnicode = removeUnicode.Replace("\u2060", string.Empty); // word joiner
removeUnicode = removeUnicode.Replace("\ufeff", string.Empty); // zero width no-break space
if (DoSpell(removeUnicode))
@ -768,7 +766,7 @@ namespace Nikse.SubtitleEdit.Controls
if (trimmed != currentWordText)
{
if (_spellCheckWordLists.HasName(trimmed) || _skipAllList.Contains(trimmed.ToUpperInvariant())
|| _spellCheckWordLists.HasUserWord(trimmed) || DoSpell(trimmed))
|| _spellCheckWordLists.HasUserWord(trimmed) || DoSpell(trimmed))
{
continue;
}
@ -786,7 +784,7 @@ namespace Nikse.SubtitleEdit.Controls
wordWithDash = _words[i - 1].Text + "" + currentWordText; // non break hyphen
if (DoSpell(wordWithDash) || _spellCheckWordLists.HasUserWord(wordWithDash)
|| _spellCheckWordLists.HasUserWord(wordWithDash.Replace("", "-")) || _spellCheckWordLists.HasUserWord("-" + currentWordText))
|| _spellCheckWordLists.HasUserWord(wordWithDash.Replace("", "-")) || _spellCheckWordLists.HasUserWord("-" + currentWordText))
{
continue;
}
@ -815,18 +813,20 @@ namespace Nikse.SubtitleEdit.Controls
{
continue;
}
else if (CurrentLanguage == "en " && (currentWordText.Equals("a", StringComparison.OrdinalIgnoreCase) || currentWordText == "I"))
if (CurrentLanguage == "en " && (currentWordText.Equals("a", StringComparison.OrdinalIgnoreCase) || currentWordText == "I"))
{
continue;
}
else if (CurrentLanguage == "da" && currentWordText.Equals("i", StringComparison.OrdinalIgnoreCase))
if (CurrentLanguage == "da" && currentWordText.Equals("i", StringComparison.OrdinalIgnoreCase))
{
continue;
}
}
if (Configuration.Settings.Tools.SpellCheckEnglishAllowInQuoteAsIng && CurrentLanguage == "en"
&& _words[i].Text.EndsWith("in'", StringComparison.OrdinalIgnoreCase) && DoSpell(currentWordText.TrimEnd('\'') + "g"))
&& _words[i].Text.EndsWith("in'", StringComparison.OrdinalIgnoreCase) && DoSpell(currentWordText.TrimEnd('\'') + "g"))
{
continue;
}
@ -878,7 +878,7 @@ namespace Nikse.SubtitleEdit.Controls
{
if (IsLiveSpellCheckEnabled && _wrongWords?.Count > 0 && e.Clicks == 1 && e.Button == MouseButtons.Right)
{
int positionToSearch = GetCharIndexFromPosition(new Point(e.X, e.Y));
var positionToSearch = GetCharIndexFromPosition(new Point(e.X, e.Y));
var wrongWord = _wrongWords.Find(word => positionToSearch > GetIndexWithLineBreak(word.Index) && positionToSearch < GetIndexWithLineBreak(word.Index) + word.Length);
if (wrongWord != null)
{