From ef0f7974ea554b400d499e4c7c6b455f50271d32 Mon Sep 17 00:00:00 2001 From: niksedk Date: Sun, 23 Mar 2014 21:25:03 +0100 Subject: [PATCH] minor cleanup --- src/Forms/About.cs | 14 +++++----- src/Forms/AddToNames.cs | 33 +++++++++++----------- src/Forms/ChangeCasing.cs | 50 ++++++++++++++++------------------ src/Forms/ChangeCasingNames.cs | 47 ++++++++++++++++---------------- 4 files changed, 70 insertions(+), 74 deletions(-) diff --git a/src/Forms/About.cs b/src/Forms/About.cs index a0d30b4f6..1a48f91e1 100644 --- a/src/Forms/About.cs +++ b/src/Forms/About.cs @@ -8,8 +8,8 @@ namespace Nikse.SubtitleEdit.Forms { partial class About : Form { - LanguageStructure.About _language = Configuration.Settings.Language.About; - LanguageStructure.General _languageGeneral = Configuration.Settings.Language.General; + private readonly LanguageStructure.About _language = Configuration.Settings.Language.About; + private readonly LanguageStructure.General _languageGeneral = Configuration.Settings.Language.General; public About() { @@ -33,14 +33,14 @@ namespace Nikse.SubtitleEdit.Forms if (versionInfo.Length >= 4) revisionNumber = versionInfo[3]; linkLabelGitBuildHash.Text = revisionNumber; - System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip(); - ToolTip1.SetToolTip(linkLabelGitBuildHash, GetGitHubHashLink()); + var toolTip1 = new ToolTip(); + toolTip1.SetToolTip(linkLabelGitBuildHash, GetGitHubHashLink()); richTextBoxAbout1.Text = _language.AboutText1.TrimEnd() + Environment.NewLine + Environment.NewLine + _languageGeneral.TranslatedBy.Trim(); - var height = TextDraw.MeasureTextHeight(richTextBoxAbout1.Font, richTextBoxAbout1.Text, false) * 1.4 + 80; - richTextBoxAbout1.Height = (int)height; + double height = TextDraw.MeasureTextHeight(richTextBoxAbout1.Font, richTextBoxAbout1.Text, false)*1.4 + 80; + richTextBoxAbout1.Height = (int) height; Height = richTextBoxAbout1.Top + richTextBoxAbout1.Height + 90; } @@ -95,4 +95,4 @@ namespace Nikse.SubtitleEdit.Forms } } -} +} \ No newline at end of file diff --git a/src/Forms/AddToNames.cs b/src/Forms/AddToNames.cs index 013d56b85..8561d4268 100644 --- a/src/Forms/AddToNames.cs +++ b/src/Forms/AddToNames.cs @@ -1,17 +1,15 @@ -using System; -using System.Windows.Forms; -using Nikse.SubtitleEdit.Logic; +using Nikse.SubtitleEdit.Logic; +using System; using System.Collections.Generic; using System.Drawing; +using System.Windows.Forms; namespace Nikse.SubtitleEdit.Forms { public sealed partial class AddToNamesList : Form { - LanguageStructure.Main _language; - Subtitle _subtitle; - - public string NewName { get; private set; } + private LanguageStructure.Main _language; + private Subtitle _subtitle; public AddToNamesList() { @@ -24,16 +22,18 @@ namespace Nikse.SubtitleEdit.Forms FixLargeFonts(); } + public string NewName { get; private set; } + private void FixLargeFonts() { if (labelDescription.Left + labelDescription.Width + 5 > Width) Width = labelDescription.Left + labelDescription.Width + 5; - Graphics graphics = this.CreateGraphics(); - SizeF textSize = graphics.MeasureString(buttonOK.Text, this.Font); + Graphics graphics = CreateGraphics(); + SizeF textSize = graphics.MeasureString(buttonOK.Text, Font); if (textSize.Height > buttonOK.Height - 4) { - int newButtonHeight = (int)(textSize.Height + 7 + 0.5); + var newButtonHeight = (int) (textSize.Height + 7 + 0.5); Utilities.SetButtonHeight(this, newButtonHeight, 1); } } @@ -61,7 +61,7 @@ namespace Nikse.SubtitleEdit.Forms internal void Initialize(Subtitle subtitle, string hunspellName, string text) { - _subtitle = subtitle; + _subtitle = subtitle; if (!string.IsNullOrEmpty(text)) { @@ -71,7 +71,6 @@ namespace Nikse.SubtitleEdit.Forms } comboBoxDictionaries.Items.Clear(); - string languageName = Utilities.AutoDetectLanguageName(Configuration.Settings.General.SpellCheckLanguage, _subtitle); foreach (string name in Utilities.GetDictionaryLanguages()) { comboBoxDictionaries.Items.Add(name); @@ -99,8 +98,8 @@ namespace Nikse.SubtitleEdit.Forms if (list.Count > 0) { string name = list[0]; - int start = name.LastIndexOf("["); - int end = name.LastIndexOf("]"); + int start = name.LastIndexOf("[", StringComparison.Ordinal); + int end = name.LastIndexOf("]", StringComparison.Ordinal); if (start > 0 && end > start) { start++; @@ -119,8 +118,8 @@ namespace Nikse.SubtitleEdit.Forms if (comboBoxDictionaries.Items.Count > 0) { string name = comboBoxDictionaries.SelectedItem.ToString(); - int start = name.LastIndexOf("["); - int end = name.LastIndexOf("]"); + int start = name.LastIndexOf("[", StringComparison.Ordinal); + int end = name.LastIndexOf("]", StringComparison.Ordinal); if (start >= 0 && end > start) { start++; @@ -139,4 +138,4 @@ namespace Nikse.SubtitleEdit.Forms } } -} +} \ No newline at end of file diff --git a/src/Forms/ChangeCasing.cs b/src/Forms/ChangeCasing.cs index 19407a7de..8f65c0abb 100644 --- a/src/Forms/ChangeCasing.cs +++ b/src/Forms/ChangeCasing.cs @@ -1,17 +1,17 @@ -using System; +using Nikse.SubtitleEdit.Logic; +using System; using System.Collections.Generic; -using System.Globalization; -using System.Windows.Forms; -using Nikse.SubtitleEdit.Logic; -using System.Text.RegularExpressions; using System.Drawing; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Windows.Forms; namespace Nikse.SubtitleEdit.Forms { public sealed partial class ChangeCasing : Form { - private int _noOfLinesChanged; private static readonly Regex AloneI = new Regex(@"\bi\b", RegexOptions.Compiled); + private int _noOfLinesChanged; public ChangeCasing() { @@ -38,26 +38,9 @@ namespace Nikse.SubtitleEdit.Forms radioButtonLowercase.Checked = true; } - private void FixLargeFonts() - { - if (radioButtonNormal.Left + radioButtonNormal.Width + 40 > Width) - Width = radioButtonNormal.Left + radioButtonNormal.Width + 40; - - Graphics graphics = CreateGraphics(); - SizeF textSize = graphics.MeasureString(buttonOK.Text, Font); - if (textSize.Height > buttonOK.Height - 4) - { - int newButtonHeight = (int)(textSize.Height + 7 + 0.5); - Utilities.SetButtonHeight(this, newButtonHeight, 1); - } - } - public int LinesChanged { - get - { - return _noOfLinesChanged; - } + get { return _noOfLinesChanged; } } public bool ChangeNamesToo @@ -69,12 +52,26 @@ namespace Nikse.SubtitleEdit.Forms } } + private void FixLargeFonts() + { + if (radioButtonNormal.Left + radioButtonNormal.Width + 40 > Width) + Width = radioButtonNormal.Left + radioButtonNormal.Width + 40; + + Graphics graphics = CreateGraphics(); + SizeF textSize = graphics.MeasureString(buttonOK.Text, Font); + if (textSize.Height > buttonOK.Height - 4) + { + var newButtonHeight = (int) (textSize.Height + 7 + 0.5); + Utilities.SetButtonHeight(this, newButtonHeight, 1); + } + } + internal void FixCasing(Subtitle subtitle, string language) { var namesEtc = new List(); var tmp = new List(); Utilities.LoadNamesEtcWordLists(tmp, tmp, language); - foreach (var s in tmp) + foreach (string s in tmp) { if (s.Contains(".")) namesEtc.Add(s); @@ -180,5 +177,6 @@ namespace Nikse.SubtitleEdit.Forms Configuration.Settings.Tools.ChangeCasingChoice = "Lowercase"; DialogResult = DialogResult.OK; } + } -} +} \ No newline at end of file diff --git a/src/Forms/ChangeCasingNames.cs b/src/Forms/ChangeCasingNames.cs index e1992b7ee..6db46950c 100644 --- a/src/Forms/ChangeCasingNames.cs +++ b/src/Forms/ChangeCasingNames.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Globalization; using System.Text; using System.Windows.Forms; using Nikse.SubtitleEdit.Logic; @@ -9,9 +10,9 @@ namespace Nikse.SubtitleEdit.Forms { public sealed partial class ChangeCasingNames : Form { - readonly List _usedNames = new List(); - Subtitle _subtitle; - int _noOfLinesChanged; + private readonly List _usedNames = new List(); + private int _noOfLinesChanged; + private Subtitle _subtitle; public ChangeCasingNames() { @@ -35,13 +36,18 @@ namespace Nikse.SubtitleEdit.Forms FixLargeFonts(); } + public int LinesChanged + { + get { return _noOfLinesChanged; } + } + private void FixLargeFonts() { - Graphics graphics = this.CreateGraphics(); - SizeF textSize = graphics.MeasureString(buttonOK.Text, this.Font); + Graphics graphics = CreateGraphics(); + SizeF textSize = graphics.MeasureString(buttonOK.Text, Font); if (textSize.Height > buttonOK.Height - 4) { - int newButtonHeight = (int)(textSize.Height + 7 + 0.5); + var newButtonHeight = (int) (textSize.Height + 7 + 0.5); Utilities.SetButtonHeight(this, newButtonHeight, 1); } } @@ -88,7 +94,7 @@ namespace Nikse.SubtitleEdit.Forms if (item.Checked && text != null && text.ToLower().Contains(name.ToLower()) && name.Length > 1 && name != name.ToLower()) { var st = new StripableText(text); - st.FixCasing(new List { name }, true, false, false, string.Empty); + st.FixCasing(new List {name}, true, false, false, string.Empty); text = st.MergedString; } } @@ -105,7 +111,7 @@ namespace Nikse.SubtitleEdit.Forms { var item = new ListViewItem(string.Empty) {Tag = p, Checked = true}; - var subItem = new ListViewItem.ListViewSubItem(item, p.Number.ToString()); + var subItem = new ListViewItem.ListViewSubItem(item, p.Number.ToString(CultureInfo.InvariantCulture)); item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(item, p.Text.Replace(Environment.NewLine, Configuration.Settings.General.ListViewLineSeparatorString)); item.SubItems.Add(subItem); @@ -147,20 +153,20 @@ namespace Nikse.SubtitleEdit.Forms { if (textToLower.Contains(name.ToLower())) // Optimization - Contains is much faster than IndexOf { - int startIndex = textToLower.IndexOf(name.ToLower()); + int startIndex = textToLower.IndexOf(name.ToLower(), StringComparison.Ordinal); while (startIndex >= 0 && startIndex < text.Length && textToLower.Substring(startIndex).Contains(name.ToLower()) && name.Length > 1 && name != name.ToLower()) { bool startOk = (startIndex == 0) || (text[startIndex - 1] == ' ') || (text[startIndex - 1] == '-') || (text[startIndex - 1] == '"') || (text[startIndex - 1] == '\'') || (text[startIndex - 1] == '>') || - (Environment.NewLine.EndsWith(text[startIndex - 1].ToString())); + (Environment.NewLine.EndsWith(text[startIndex - 1].ToString(CultureInfo.InvariantCulture))); if (startOk) { int end = startIndex + name.Length; bool endOk = end <= text.Length; if (endOk) - endOk = (end == text.Length) || ((" ,.!?:;')-<\"" + Environment.NewLine).Contains(text[end].ToString())); + endOk = (end == text.Length) || ((" ,.!?:;')-<\"" + Environment.NewLine).Contains(text[end].ToString(CultureInfo.InvariantCulture))); if (endOk && text.Substring(startIndex, name.Length) != name) // do not add names where casing already is correct { @@ -173,7 +179,7 @@ namespace Nikse.SubtitleEdit.Forms } } - startIndex = textToLower.IndexOf(name.ToLower(), startIndex + 2); + startIndex = textToLower.IndexOf(name.ToLower(), startIndex + 2, StringComparison.Ordinal); } } } @@ -197,18 +203,18 @@ namespace Nikse.SubtitleEdit.Forms string lower = text.ToLower(); if (lower.Contains(name.ToLower()) && name.Length > 1 && name != name.ToLower()) { - int start = lower.IndexOf(name.ToLower()); + int start = lower.IndexOf(name.ToLower(), StringComparison.Ordinal); if (start >= 0) { bool startOk = (start == 0) || (lower[start - 1] == ' ') || (lower[start - 1] == '-') || (lower[start - 1] == '"') || - (lower[start - 1] == '\'') || (lower[start - 1] == '>') || (Environment.NewLine.EndsWith(lower[start - 1].ToString())); + (lower[start - 1] == '\'') || (lower[start - 1] == '>') || (Environment.NewLine.EndsWith(lower[start - 1].ToString(CultureInfo.InvariantCulture))); if (startOk) { int end = start + name.Length; bool endOk = end <= lower.Length; if (endOk) - endOk = end == lower.Length || (" ,.!?:;')<-\"" + Environment.NewLine).Contains(lower[end].ToString()); + endOk = end == lower.Length || (" ,.!?:;')<-\"" + Environment.NewLine).Contains(lower[end].ToString(CultureInfo.InvariantCulture)); item.Selected = endOk; } @@ -246,14 +252,6 @@ namespace Nikse.SubtitleEdit.Forms } } - public int LinesChanged - { - get - { - return _noOfLinesChanged; - } - } - private void ButtonOkClick(object sender, EventArgs e) { DialogResult = DialogResult.OK; @@ -288,5 +286,6 @@ namespace Nikse.SubtitleEdit.Forms listViewNames.ItemChecked += ListViewNamesItemChecked; GeneratePreview(); } + } -} +} \ No newline at end of file