Refactor (minor cleanup)

This commit is contained in:
Nikolaj Olsson 2018-01-27 13:50:44 +01:00
parent d29c23c831
commit 8977442960
20 changed files with 129 additions and 227 deletions

View File

@ -113,14 +113,13 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
/// <returns>RLE buffer</returns>
private static byte[] EncodeImage(NikseBitmap bm, Dictionary<Color, int> palette)
{
var bytes = new List<Byte>();
var bytes = new List<byte>();
for (int y = 0; y < bm.Height; y++)
{
var ofs = y * bm.Width;
//eol = false;
int x;
int len;
for (x = 0; x < bm.Width; x += len, ofs += len)
for (x = 0; x < bm.Width; x += len)
{
Color c = bm.GetPixel(x, y);
byte color;
@ -239,7 +238,7 @@ namespace Nikse.SubtitleEdit.Core.BluRaySup
pal.Add(c, pal.Count);
}
else if (pal.Count < 254 && !HasCloseColor(c, pal, 25))
{
{
pal.Add(c, pal.Count);
}
}

View File

@ -6,13 +6,13 @@
/// Checks if character matches [0-9]
/// </summary>
/// <param name="ch"></param>
public static bool IsDigit(char ch) => (ch >= '0') && (ch <= '9');
public static bool IsDigit(char ch) => ch >= '0' && ch <= '9';
/// <summary>
/// Checks if given character is hexadecimal
/// </summary>
/// <param name="ch"></param>
public static bool IsHexadecimal(char ch) => (ch >= '0') && (ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F');
public static bool IsHexadecimal(char ch) => ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f' || ch >= 'A' && ch <= 'F';
/// <summary>
/// Checks if character is between A-Z or a-z

View File

@ -6,7 +6,7 @@ using System.Drawing.Imaging;
namespace Nikse.SubtitleEdit.Core
{
unsafe public class FastBitmap
public unsafe class FastBitmap
{
public struct PixelData
{

View File

@ -8,24 +8,16 @@ namespace Nikse.SubtitleEdit.Core.Forms
{
public class CheckForUpdatesHelper
{
private readonly static Regex regex = new Regex(@"\d\.\d", RegexOptions.Compiled); // 3.4.0 (xth June 2014)
private static readonly Regex VersionNumberRegex = new Regex(@"\d\.\d", RegexOptions.Compiled); // 3.4.0 (xth June 2014)
//private const string ReleasesUrl = "https://api.github.com/repos/SubtitleEdit/subtitleedit/releases";
private const string ChangeLogUrl = "https://raw.githubusercontent.com/SubtitleEdit/subtitleedit/master/Changelog.txt";
//private string _jsonReleases;
private string _changeLog;
private int _successCount;
public string Error { get; set; }
public bool Done
{
get
{
return _successCount == 1;
}
}
public bool Done => _successCount == 1;
public string LatestVersionNumber { get; set; }
public string LatestChangeLog { get; set; }
@ -53,21 +45,6 @@ namespace Nikse.SubtitleEdit.Core.Forms
}
}
//void FinishWebRequestReleases(IAsyncResult result)
//{
// try
// {
// _jsonReleases = GetStringFromResponse(result);
// }
// catch (Exception exception)
// {
// if (Error == null)
// {
// Error = exception.Message;
// }
// }
//}
private void FinishWebRequestChangeLog(IAsyncResult result)
{
try
@ -90,7 +67,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
foreach (string line in latestChangeLog.Replace(Environment.NewLine, "\n").Split('\n'))
{
string s = line.Trim();
if (!s.Contains("BETA", StringComparison.OrdinalIgnoreCase) && !s.Contains('x') && !s.Contains('*') && s.Contains('(') && s.Contains(')') && regex.IsMatch(s))
if (!s.Contains("BETA", StringComparison.OrdinalIgnoreCase) && !s.Contains('x') && !s.Contains('*') && s.Contains('(') && s.Contains(')') && VersionNumberRegex.IsMatch(s))
{
int indexOfSpace = s.IndexOf(' ');
if (indexOfSpace > 0)
@ -112,7 +89,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
if (!releaseOn)
{
if (!s.Contains('x') && !s.Contains('*') && s.Contains('(') && s.Contains(')') && regex.IsMatch(s))
if (!s.Contains('x') && !s.Contains('*') && s.Contains('(') && s.Contains(')') && VersionNumberRegex.IsMatch(s))
releaseOn = true;
}
@ -149,9 +126,6 @@ namespace Nikse.SubtitleEdit.Core.Forms
public void CheckForUpdates()
{
// load github release json
//StartDownloadString(ReleasesUrl, "application/json", FinishWebRequestReleases);
// load change log
StartDownloadString(ChangeLogUrl, null, FinishWebRequestChangeLog);
}
@ -169,7 +143,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
string minorMinorVersion = string.Empty;
if (currentVersionInfo.Length >= 3 && currentVersionInfo[2] != "0")
minorMinorVersion = "." + currentVersionInfo[2];
string currentVersion = String.Format("{0}.{1}{2}", currentVersionInfo[0], currentVersionInfo[1], minorMinorVersion);
string currentVersion = $"{currentVersionInfo[0]}.{currentVersionInfo[1]}{minorMinorVersion}";
if (currentVersion == LatestVersionNumber)
return false;

View File

@ -9,14 +9,14 @@ namespace Nikse.SubtitleEdit.Core
public int Width { get; private set; }
public int Height { get; private set; }
private Color[] _colors;
private readonly Color[] _colors;
public bool LoadedOk { get; private set; }
public ManagedBitmap(string fileName)
{
try
{
byte[] buffer = new byte[1024];
byte[] buffer;
using (var fd = new MemoryStream())
using (Stream csStream = new GZipStream(File.OpenRead(fileName), CompressionMode.Decompress))
{
@ -123,13 +123,6 @@ namespace Nikse.SubtitleEdit.Core
}
}
//private static int ReadInt16(Stream stream)
//{
// byte b0 = (byte)stream.ReadByte();
// byte b1 = (byte)stream.ReadByte();
// return b0 << 8 | b1;
//}
private static void WriteInt16(Stream stream, short val)
{
byte[] buffer = new byte[2];
@ -180,7 +173,7 @@ namespace Nikse.SubtitleEdit.Core
int rectx = 0;
for (int x = section.Left; x < section.Left + section.Width; x++)
{
newRectangle.SetPixel(rectx, recty, this.GetPixel(x, y));
newRectangle.SetPixel(rectx, recty, GetPixel(x, y));
rectx++;
}
recty++;
@ -195,7 +188,7 @@ namespace Nikse.SubtitleEdit.Core
{
for (int x = 0; x < Width; x++)
{
nbmp.SetPixel(x, y, this.GetPixel(x, y));
nbmp.SetPixel(x, y, GetPixel(x, y));
}
}
return nbmp.GetBitmap();

View File

@ -4,7 +4,7 @@
// This code is based on https://gist.github.com/automatonic/3725443
public class MurMurHash3
{
private const uint seed = 144;
private const uint Seed = 144;
/// <summary>
/// Fast hashing of byte array
@ -15,8 +15,8 @@
{
const uint c1 = 0xcc9e2d51;
const uint c2 = 0x1b873593;
uint h1 = seed;
uint k1 = 0;
uint h1 = Seed;
uint k1;
int length = arr.Length / 4;
for (int i = 0; i < length; i++)
@ -26,11 +26,11 @@
// bitmagic hash
k1 *= c1;
k1 = rotl32(k1, 15);
k1 = Rotl32(k1, 15);
k1 *= c2;
h1 ^= k1;
h1 = rotl32(h1, 13);
h1 = Rotl32(h1, 13);
h1 = h1 * 5 + 0xe6546b64;
}
@ -39,21 +39,21 @@
case 3:
k1 = (uint)(arr[arr.Length - 3] | arr[arr.Length - 2] << 8 | arr[arr.Length - 1] << 16);
k1 *= c1;
k1 = rotl32(k1, 15);
k1 = Rotl32(k1, 15);
k1 *= c2;
h1 ^= k1;
break;
case 2:
k1 = (uint)(arr[arr.Length - 2] | arr[arr.Length - 1] << 8);
k1 *= c1;
k1 = rotl32(k1, 15);
k1 = Rotl32(k1, 15);
k1 *= c2;
h1 ^= k1;
break;
case 1:
k1 = arr[arr.Length - 1];
k1 *= c1;
k1 = rotl32(k1, 15);
k1 = Rotl32(k1, 15);
k1 *= c2;
h1 ^= k1;
break;
@ -61,20 +61,17 @@
// finalization, magic chants to wrap it all up
h1 ^= (uint)arr.Length;
h1 = fmix(h1);
h1 = Fmix(h1);
unchecked //ignore overflow
{
return h1;
}
return h1;
}
private static uint rotl32(uint x, byte r)
private static uint Rotl32(uint x, byte r)
{
return (x << r) | (x >> (32 - r));
}
private static uint fmix(uint h)
private static uint Fmix(uint h)
{
h ^= h >> 16;
h *= 0x85ebca6b;

View File

@ -124,7 +124,7 @@ namespace Nikse.SubtitleEdit.Core
while (start >= 0 && start < lower.Length)
{
bool startOk = (start == 0) || (lower[start - 1] == ' ') || (lower[start - 1] == '-') ||
(lower[start - 1] == '"') || (lower[start - 1] == '\'') || (lower[start - 1] == '>') || (lower[start - 1] == '[') || (lower[start - 1] == '“') ||
(lower[start - 1] == '"') || (lower[start - 1] == '\'') || (lower[start - 1] == '>') || (lower[start - 1] == '[') || (lower[start - 1] == '“') ||
Environment.NewLine.EndsWith(lower[start - 1]);
if (startOk && string.CompareOrdinal(name, "Don") == 0 && lower.Substring(start).StartsWith("don't", StringComparison.Ordinal))
@ -308,12 +308,12 @@ namespace Nikse.SubtitleEdit.Core
{
lastWasBreak = true;
}
else if (StrippedText.Length > i + 1 && " \r\n".Contains(StrippedText[i+1]))
else if (StrippedText.Length > i + 1 && " \r\n".Contains(StrippedText[i + 1]))
{
lastWasBreak = true;
}
}
}
}
else if (s == '-' && Pre.Contains("-"))
{
if (sb.ToString().EndsWith(Environment.NewLine + "-"))

View File

@ -15,8 +15,6 @@ namespace Nikse.SubtitleEdit.Core
private List<Paragraph> _paragraphs;
private readonly List<HistoryItem> _history;
private SubtitleFormat _format;
private bool _wasLoadedWithFrameNumbers;
public string Header { get; set; } = string.Empty;
public string Footer { get; set; } = string.Empty;
@ -24,18 +22,9 @@ namespace Nikse.SubtitleEdit.Core
public const int MaximumHistoryItems = 100;
public SubtitleFormat OriginalFormat
{
get
{
return _format;
}
}
public SubtitleFormat OriginalFormat { get; private set; }
public List<HistoryItem> HistoryItems
{
get { return _history; }
}
public List<HistoryItem> HistoryItems => _history;
public Subtitle()
{
@ -72,7 +61,7 @@ namespace Nikse.SubtitleEdit.Core
{
_paragraphs.Add(new Paragraph(p, generateNewId));
}
_wasLoadedWithFrameNumbers = subtitle.WasLoadedWithFrameNumbers;
WasLoadedWithFrameNumbers = subtitle.WasLoadedWithFrameNumbers;
Header = subtitle.Header;
Footer = subtitle.Footer;
FileName = subtitle.FileName;
@ -83,13 +72,7 @@ namespace Nikse.SubtitleEdit.Core
_paragraphs = paragraphs;
}
public List<Paragraph> Paragraphs
{
get
{
return _paragraphs;
}
}
public List<Paragraph> Paragraphs => _paragraphs;
/// <summary>
/// Get the paragraph of index, null if out of bounds
@ -115,7 +98,7 @@ namespace Nikse.SubtitleEdit.Core
if (format != null && format.IsMine(lines, fileName))
{
format.LoadSubtitle(this, lines, fileName);
_format = format;
OriginalFormat = format;
return format;
}
foreach (SubtitleFormat subtitleFormat in SubtitleFormat.AllSubtitleFormats)
@ -123,7 +106,7 @@ namespace Nikse.SubtitleEdit.Core
if (subtitleFormat.IsMine(lines, fileName))
{
subtitleFormat.LoadSubtitle(this, lines, fileName);
_format = subtitleFormat;
OriginalFormat = subtitleFormat;
return subtitleFormat;
}
}
@ -189,9 +172,9 @@ namespace Nikse.SubtitleEdit.Core
subtitleFormat.BatchMode = batchMode;
subtitleFormat.BatchSourceFrameRate = sourceFrameRate;
subtitleFormat.LoadSubtitle(this, lines, fileName);
_format = subtitleFormat;
_wasLoadedWithFrameNumbers = _format.IsFrameBased;
if (_wasLoadedWithFrameNumbers)
OriginalFormat = subtitleFormat;
WasLoadedWithFrameNumbers = OriginalFormat.IsFrameBased;
if (WasLoadedWithFrameNumbers)
CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);
return subtitleFormat;
}
@ -212,13 +195,7 @@ namespace Nikse.SubtitleEdit.Core
_history.Add(new HistoryItem(_history.Count, this, description, FileName, fileModified, subtitleFormat.FriendlyName, original, originalSubtitleFileName, lineNumber, linePosition, linePositionAlternate));
}
public bool CanUndo
{
get
{
return _history.Count > 0;
}
}
public bool CanUndo => _history.Count > 0;
public string UndoHistory(int index, out string subtitleFormatFriendlyName, out DateTime fileModified, out Subtitle originalSubtitle, out string originalSubtitleFileName)
{
@ -263,7 +240,7 @@ namespace Nikse.SubtitleEdit.Core
/// <returns>True if times could be calculated</returns>
public bool CalculateTimeCodesFromFrameNumbers(double frameRate)
{
if (_format == null || _format.IsTimeBased)
if (OriginalFormat == null || OriginalFormat.IsTimeBased)
return false;
foreach (Paragraph p in Paragraphs)
@ -280,7 +257,7 @@ namespace Nikse.SubtitleEdit.Core
/// <returns></returns>
public bool CalculateFrameNumbersFromTimeCodes(double frameRate)
{
if (_format == null || _format.IsFrameBased)
if (OriginalFormat == null || OriginalFormat.IsFrameBased)
return false;
foreach (Paragraph p in Paragraphs)
@ -322,17 +299,7 @@ namespace Nikse.SubtitleEdit.Core
}
}
public bool WasLoadedWithFrameNumbers
{
get
{
return _wasLoadedWithFrameNumbers;
}
set
{
_wasLoadedWithFrameNumbers = value;
}
}
public bool WasLoadedWithFrameNumbers { get; set; }
public void AdjustDisplayTimeUsingPercent(double percent, List<int> selectedIndexes)
{

View File

@ -48,7 +48,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
//00:03:15:22 00:03:23:10 This is line one.
//This is line two.
sb.AppendLine(string.Format("{0} {1} {2}", EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), HtmlUtil.RemoveHtmlTags(p.Text, true)));
sb.AppendLine($"{EncodeTimeCode(p.StartTime)} {EncodeTimeCode(p.EndTime)} {HtmlUtil.RemoveHtmlTags(p.Text, true)}");
}
return sb.ToString();
}

View File

@ -1824,7 +1824,7 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
}
}
if (styleName != null && style.Name != null && (styleName.Equals(style.Name, StringComparison.OrdinalIgnoreCase) ||
(styleName.Equals("*Default", StringComparison.OrdinalIgnoreCase) && style.Name.Equals("Default", StringComparison.OrdinalIgnoreCase))))
styleName.Equals("*Default", StringComparison.OrdinalIgnoreCase) && style.Name.Equals("Default", StringComparison.OrdinalIgnoreCase)))
{
style.LoadedFromHeader = true;
return style;

View File

@ -100,7 +100,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
new JsonType11(),
new JsonType12(),
new KanopyHtml(),
new LambdaCap(),
new LambdaCap(),
new Lrc(),
new MacSub(),
new MediaTransData(),

View File

@ -11,8 +11,8 @@ namespace Nikse.SubtitleEdit.Core
public int Width { get; private set; }
public int Height { get; private set; }
private byte[] colorBuffer;
private byte[] rleBuffer;
private readonly byte[] _colorBuffer;
private readonly byte[] _rleBuffer;
public XSub(string timeCode, int width, int height, byte[] colors, byte[] rle)
{
@ -20,8 +20,8 @@ namespace Nikse.SubtitleEdit.Core
End = DecodeTimeCode(timeCode.Substring(13, 12));
Width = width;
Height = height;
colorBuffer = colors;
rleBuffer = rle;
_colorBuffer = colors;
_rleBuffer = rle;
}
private static TimeCode DecodeTimeCode(string timeCode)
@ -35,12 +35,12 @@ namespace Nikse.SubtitleEdit.Core
int w = bmp.Width;
int h = bmp.Height;
int nibbleOffset = 0;
var nibble_end = buf.Length * 2;
var nibbleEnd = buf.Length * 2;
var x = 0;
var y = 0;
for (;;)
for (; ; )
{
if (nibbleOffset >= nibble_end)
if (nibbleOffset >= nibbleEnd)
return -1;
var v = GetNibble(buf, nibbleOffset++);
if (v < 0x4)
@ -61,13 +61,13 @@ namespace Nikse.SubtitleEdit.Core
}
var len = v >> 2;
if (len > (w - x))
len = (w - x);
if (len > w - x)
len = w - x;
var color = v & 0x03;
if (color > 0)
{
Color c = fourColors[color];
var c = fourColors[color];
bmp.SetPixel(x, y, c, len);
}
@ -84,9 +84,9 @@ namespace Nikse.SubtitleEdit.Core
return 0;
}
private static int GetNibble(byte[] buf, int nibble_offset)
private static int GetNibble(byte[] buf, int nibbleOffset)
{
return (buf[nibble_offset >> 1] >> ((1 - (nibble_offset & 1)) << 2)) & 0xf;
return (buf[nibbleOffset >> 1] >> ((1 - (nibbleOffset & 1)) << 2)) & 0xf;
}
public Bitmap GetImage(Color background, Color pattern, Color emphasis1, Color emphasis2)
@ -102,14 +102,14 @@ namespace Nikse.SubtitleEdit.Core
}
var fastBmp = new FastBitmap(bmp);
fastBmp.LockImage();
GenerateBitmap(fastBmp, rleBuffer, fourColors);
GenerateBitmap(fastBmp, _rleBuffer, fourColors);
fastBmp.UnlockImage();
return bmp;
}
private Color GetColor(int start)
{
return Color.FromArgb(colorBuffer[start], colorBuffer[start + 1], colorBuffer[start + 2]);
return Color.FromArgb(_colorBuffer[start], _colorBuffer[start + 1], _colorBuffer[start + 2]);
}
public Bitmap GetImage()

View File

@ -1,6 +1,6 @@
namespace Nikse.SubtitleEdit.Controls
{
partial class AudioVisualizer
sealed partial class AudioVisualizer
{
/// <summary>
/// Required designer variable.

View File

@ -10,7 +10,7 @@ using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Controls
{
public partial class AudioVisualizer : UserControl
public sealed partial class AudioVisualizer : UserControl
{
public enum MouseDownParagraphType
{
@ -1935,7 +1935,9 @@ namespace Nikse.SubtitleEdit.Controls
}
catch
{
// ignored
}
return -1;
}

View File

@ -1,6 +1,6 @@
namespace Nikse.SubtitleEdit.Controls
{
partial class TimeUpDown
sealed partial class TimeUpDown
{
/// <summary>
/// Required designer variable.

View File

@ -9,7 +9,7 @@ using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Controls
{
public partial class TimeUpDown : UserControl
public sealed partial class TimeUpDown : UserControl
{
public enum TimeMode
{
@ -17,7 +17,7 @@ namespace Nikse.SubtitleEdit.Controls
HHMMSSFF
}
private bool _designMode = LicenseManager.UsageMode == LicenseUsageMode.Designtime;
private readonly bool _designMode = LicenseManager.UsageMode == LicenseUsageMode.Designtime;
private const int NumericUpDownValue = 50;
@ -29,7 +29,7 @@ namespace Nikse.SubtitleEdit.Controls
private static char[] _splitChars;
public bool _dirty = false;
private bool _dirty = false;
double _initialTotalMilliseconds;
internal void ForceHHMMSSFF()
@ -135,7 +135,7 @@ namespace Nikse.SubtitleEdit.Controls
{
var tc = new TimeCode(milliseconds);
maskedTextBox1.Mask = GetMaskFrames(milliseconds);
maskedTextBox1.Text = tc.ToString().Substring(0, 9) + string.Format("{0:00}", Core.SubtitleFormats.SubtitleFormat.MillisecondsToFrames(tc.Milliseconds));
maskedTextBox1.Text = tc.ToString().Substring(0, 9) + $"{Core.SubtitleFormats.SubtitleFormat.MillisecondsToFrames(tc.Milliseconds):00}";
}
_dirty = false;
}
@ -145,10 +145,7 @@ namespace Nikse.SubtitleEdit.Controls
if (!_dirty)
return _initialTotalMilliseconds;
TimeCode tc = TimeCode;
if (tc != null)
return tc.TotalMilliseconds;
return null;
return TimeCode?.TotalMilliseconds;
}
public TimeCode TimeCode

View File

@ -1367,12 +1367,12 @@ namespace Nikse.SubtitleEdit.Controls
if (SmpteMode)
{
var span = TimeCode.FromSeconds(pos + 0.017 + Configuration.Settings.General.CurrentVideoOffsetInMs / TimeCode.BaseUnit);
_labelTimeCode.Text = string.Format("{0} / {1} SMPTE", span.ToDisplayString(), dur.ToDisplayString());
_labelTimeCode.Text = $"{span.ToDisplayString()} / {dur.ToDisplayString()} SMPTE";
}
else
{
var span = TimeCode.FromSeconds(pos + Configuration.Settings.General.CurrentVideoOffsetInMs / TimeCode.BaseUnit);
_labelTimeCode.Text = string.Format("{0} / {1}", span.ToDisplayString(), dur.ToDisplayString());
_labelTimeCode.Text = $"{span.ToDisplayString()} / {dur.ToDisplayString()}";
}
RefreshPlayPauseButtons();

View File

@ -7,7 +7,6 @@ using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Globalization;
using System.IO;
using System.Text;
using System.Windows.Forms;
@ -129,13 +128,7 @@ namespace Nikse.SubtitleEdit.Forms.Styles
checkBoxFontUnderline.Left = checkBoxFontItalic.Left + checkBoxFontItalic.Width + 12;
}
public override string Header
{
get
{
return _header;
}
}
public override string Header => _header;
protected override void GeneratePreviewReal()
{
@ -266,9 +259,11 @@ namespace Nikse.SubtitleEdit.Forms.Styles
public static void AddStyle(ListView lv, SsaStyle ssaStyle, Subtitle subtitle, bool isSubstationAlpha)
{
var item = new ListViewItem(ssaStyle.Name.Trim());
item.Checked = true;
item.UseItemStyleForSubItems = false;
var item = new ListViewItem(ssaStyle.Name.Trim())
{
Checked = true,
UseItemStyleForSubItems = false
};
var subItem = new ListViewItem.ListViewSubItem(item, ssaStyle.FontName);
item.SubItems.Add(subItem);
@ -287,17 +282,15 @@ namespace Nikse.SubtitleEdit.Forms.Styles
subItem = new ListViewItem.ListViewSubItem(item, count.ToString());
item.SubItems.Add(subItem);
subItem = new ListViewItem.ListViewSubItem(item, string.Empty);
subItem.BackColor = ssaStyle.Primary;
subItem = new ListViewItem.ListViewSubItem(item, string.Empty) { BackColor = ssaStyle.Primary };
item.SubItems.Add(subItem);
subItem = new ListViewItem.ListViewSubItem(item, string.Empty);
if (isSubstationAlpha)
subItem.BackColor = ssaStyle.Background;
else
subItem.BackColor = ssaStyle.Outline;
subItem.Text = Configuration.Settings.Language.General.Text;
subItem.ForeColor = ssaStyle.Primary;
subItem = new ListViewItem.ListViewSubItem(item, string.Empty)
{
BackColor = isSubstationAlpha ? ssaStyle.Background : ssaStyle.Outline,
Text = Configuration.Settings.Language.General.Text,
ForeColor = ssaStyle.Primary
};
try
{
if (ssaStyle.Bold || ssaStyle.Italic)
@ -311,7 +304,9 @@ namespace Nikse.SubtitleEdit.Forms.Styles
}
catch
{
// ignored
}
item.SubItems.Add(subItem);
lv.Items.Add(item);
@ -695,8 +690,7 @@ namespace Nikse.SubtitleEdit.Forms.Styles
{
string styleName = listViewStyles.SelectedItems[0].Text;
SsaStyle oldStyle = GetSsaStyle(styleName);
var style = new SsaStyle(oldStyle); // Copy contructor
style.Name = string.Format(Configuration.Settings.Language.SubStationAlphaStyles.CopyOfY, styleName);
var style = new SsaStyle(oldStyle) { Name = string.Format(Configuration.Settings.Language.SubStationAlphaStyles.CopyOfY, styleName) }; // Copy contructor
if (GetSsaStyle(style.Name).LoadedFromHeader)
{
@ -901,10 +895,7 @@ namespace Nikse.SubtitleEdit.Forms.Styles
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate)
{
string name = listViewStyles.SelectedItems[0].Text;
if (checkBoxFontBold.Checked)
SetSsaStyle(name, "bold", "-1");
else
SetSsaStyle(name, "bold", "0");
SetSsaStyle(name, "bold", checkBoxFontBold.Checked ? "-1" : "0");
GeneratePreview();
}
}
@ -914,10 +905,7 @@ namespace Nikse.SubtitleEdit.Forms.Styles
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate)
{
string name = listViewStyles.SelectedItems[0].Text;
if (checkBoxFontItalic.Checked)
SetSsaStyle(name, "italic", "-1");
else
SetSsaStyle(name, "italic", "0");
SetSsaStyle(name, "italic", checkBoxFontItalic.Checked ? "-1" : "0");
GeneratePreview();
}
}
@ -927,17 +915,14 @@ namespace Nikse.SubtitleEdit.Forms.Styles
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate)
{
string name = listViewStyles.SelectedItems[0].Text;
if (checkBoxFontUnderline.Checked)
SetSsaStyle(name, "underline", "-1");
else
SetSsaStyle(name, "underline", "0");
SetSsaStyle(name, "underline", checkBoxFontUnderline.Checked ? "-1" : "0");
GeneratePreview();
}
}
private void radioButtonBottomLeft_CheckedChanged(object sender, EventArgs e)
{
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && (sender as RadioButton).Checked)
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && ((RadioButton)sender).Checked)
{
string name = listViewStyles.SelectedItems[0].Text;
SetSsaStyle(name, "alignment", "1");
@ -947,7 +932,7 @@ namespace Nikse.SubtitleEdit.Forms.Styles
private void radioButtonBottomCenter_CheckedChanged(object sender, EventArgs e)
{
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && (sender as RadioButton).Checked)
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && ((RadioButton)sender).Checked)
{
string name = listViewStyles.SelectedItems[0].Text;
SetSsaStyle(name, "alignment", "2");
@ -957,7 +942,7 @@ namespace Nikse.SubtitleEdit.Forms.Styles
private void radioButtonBottomRight_CheckedChanged(object sender, EventArgs e)
{
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && (sender as RadioButton).Checked)
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && ((RadioButton)sender).Checked)
{
string name = listViewStyles.SelectedItems[0].Text;
SetSsaStyle(name, "alignment", "3");
@ -967,78 +952,60 @@ namespace Nikse.SubtitleEdit.Forms.Styles
private void radioButtonMiddleLeft_CheckedChanged(object sender, EventArgs e)
{
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && (sender as RadioButton).Checked)
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && ((RadioButton)sender).Checked)
{
string name = listViewStyles.SelectedItems[0].Text;
if (_isSubStationAlpha)
SetSsaStyle(name, "alignment", "9");
else
SetSsaStyle(name, "alignment", "4");
SetSsaStyle(name, "alignment", _isSubStationAlpha ? "9" : "4");
GeneratePreview();
}
}
private void radioButtonMiddleCenter_CheckedChanged(object sender, EventArgs e)
{
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && (sender as RadioButton).Checked)
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && ((RadioButton)sender).Checked)
{
string name = listViewStyles.SelectedItems[0].Text;
if (_isSubStationAlpha)
SetSsaStyle(name, "alignment", "10");
else
SetSsaStyle(name, "alignment", "5");
SetSsaStyle(name, "alignment", _isSubStationAlpha ? "10" : "5");
GeneratePreview();
}
}
private void radioButtonMiddleRight_CheckedChanged(object sender, EventArgs e)
{
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && (sender as RadioButton).Checked)
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && ((RadioButton)sender).Checked)
{
string name = listViewStyles.SelectedItems[0].Text;
if (_isSubStationAlpha)
SetSsaStyle(name, "alignment", "11");
else
SetSsaStyle(name, "alignment", "6");
SetSsaStyle(name, "alignment", _isSubStationAlpha ? "11" : "6");
GeneratePreview();
}
}
private void radioButtonTopLeft_CheckedChanged(object sender, EventArgs e)
{
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && (sender as RadioButton).Checked)
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && ((RadioButton)sender).Checked)
{
string name = listViewStyles.SelectedItems[0].Text;
if (_isSubStationAlpha)
SetSsaStyle(name, "alignment", "5");
else
SetSsaStyle(name, "alignment", "7");
SetSsaStyle(name, "alignment", _isSubStationAlpha ? "5" : "7");
GeneratePreview();
}
}
private void radioButtonTopCenter_CheckedChanged(object sender, EventArgs e)
{
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && (sender as RadioButton).Checked)
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && ((RadioButton)sender).Checked)
{
string name = listViewStyles.SelectedItems[0].Text;
if (_isSubStationAlpha)
SetSsaStyle(name, "alignment", "6");
else
SetSsaStyle(name, "alignment", "8");
SetSsaStyle(name, "alignment", _isSubStationAlpha ? "6" : "8");
GeneratePreview();
}
}
private void radioButtonTopRight_CheckedChanged(object sender, EventArgs e)
{
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && (sender as RadioButton).Checked)
if (listViewStyles.SelectedItems.Count == 1 && _doUpdate && ((RadioButton)sender).Checked)
{
string name = listViewStyles.SelectedItems[0].Text;
if (_isSubStationAlpha)
SetSsaStyle(name, "alignment", "7");
else
SetSsaStyle(name, "alignment", "9");
SetSsaStyle(name, "alignment", _isSubStationAlpha ? "7" : "9");
GeneratePreview();
}
}
@ -1101,7 +1068,7 @@ namespace Nikse.SubtitleEdit.Forms.Styles
private void radioButtonOutline_CheckedChanged(object sender, EventArgs e)
{
var rb = (sender as RadioButton);
var rb = sender as RadioButton;
if (rb != null && listViewStyles.SelectedItems.Count == 1 && _doUpdate && rb.Checked)
{
numericUpDownShadowWidth.Value = 2;
@ -1118,7 +1085,7 @@ namespace Nikse.SubtitleEdit.Forms.Styles
private void radioButtonOpaqueBox_CheckedChanged(object sender, EventArgs e)
{
var rb = (sender as RadioButton);
var rb = sender as RadioButton;
if (rb != null && listViewStyles.SelectedItems.Count == 1 && _doUpdate && rb.Checked)
{
numericUpDownShadowWidth.Value = 0;

View File

@ -67,7 +67,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
private IntPtr _libMpvDll;
private IntPtr _mpvHandle;
private Timer _videoLoadedTimer;
private double? _pausePosition = null; // Hack to hold precise seeking when paused
private double? _pausePosition; // Hack to hold precise seeking when paused
// private Timer _videoEndedTimer;
public override event EventHandler OnVideoLoaded;

View File

@ -1,15 +1,21 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=511A5B59_002D1C35_002D4719_002D8536_002D23B19AF9B21A_002Fd_003ADLLs/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=511A5B59_002D1C35_002D4719_002D8536_002D23B19AF9B21A_002Fd_003AIcons/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=511A5B59_002D1C35_002D4719_002D8536_002D23B19AF9B21A_002Fd_003ALanguages/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=511A5B59_002D1C35_002D4719_002D8536_002D23B19AF9B21A_002Fd_003AResources/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7BE5B8E8_002D9469_002D4C7C_002D89D7_002DE8C884DEFC0E_002Fd_003ADictionaries/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7BE5B8E8_002D9469_002D4C7C_002D89D7_002DE8C884DEFC0E_002Fd_003AFiles/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALLOW_COMMENT_AFTER_LBRACE/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_BEFORE_TYPEOF_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LINES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=511A5B59_002D1C35_002D4719_002D8536_002D23B19AF9B21A_002Fd_003ADLLs/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=511A5B59_002D1C35_002D4719_002D8536_002D23B19AF9B21A_002Fd_003AIcons/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=511A5B59_002D1C35_002D4719_002D8536_002D23B19AF9B21A_002Fd_003ALanguages/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=511A5B59_002D1C35_002D4719_002D8536_002D23B19AF9B21A_002Fd_003AResources/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7BE5B8E8_002D9469_002D4C7C_002D89D7_002DE8C884DEFC0E_002Fd_003ADictionaries/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7BE5B8E8_002D9469_002D4C7C_002D89D7_002DE8C884DEFC0E_002Fd_003AFiles/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALLOW_COMMENT_AFTER_LBRACE/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSORHOLDER_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_BEFORE_TYPEOF_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LINES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>