Code quality changes

This commit is contained in:
Robin 2016-09-22 20:40:13 +02:00
commit 610f45d082
189 changed files with 4609 additions and 5203 deletions

View file

@ -34,8 +34,8 @@ namespace Greenshot {
/// Description of ColorDialog.
/// </summary>
public partial class ColorDialog : BaseForm {
private static ColorDialog uniqueInstance;
private static readonly EditorConfiguration editorConfiguration = IniConfig.GetIniSection<EditorConfiguration>();
private static ColorDialog _uniqueInstance;
private static readonly EditorConfiguration EditorConfig = IniConfig.GetIniSection<EditorConfiguration>();
private ColorDialog() {
SuspendLayout();
@ -47,11 +47,9 @@ namespace Greenshot {
UpdateRecentColorsButtonRow();
}
public static ColorDialog GetInstance() {
if (uniqueInstance == null) {
uniqueInstance = new ColorDialog();
}
return uniqueInstance;
public static ColorDialog GetInstance()
{
return _uniqueInstance ?? (_uniqueInstance = new ColorDialog());
}
private readonly List<Button> _colorButtons = new List<Button>();
@ -108,13 +106,15 @@ namespace Greenshot {
}
private Button CreateColorButton(Color color, int x, int y, int w, int h) {
Button b = new Button();
b.BackColor = color;
Button b = new Button
{
BackColor = color,
FlatStyle = FlatStyle.Flat,
Location = new Point(x, y),
Size = new Size(w, h),
TabStop = false
};
b.FlatAppearance.BorderSize = 0;
b.FlatStyle = FlatStyle.Flat;
b.Location = new Point(x, y);
b.Size = new Size(w, h);
b.TabStop = false;
b.Click += ColorButtonClick;
_toolTip.SetToolTip(b, ColorTranslator.ToHtml(color) + " | R:" + color.R + ", G:" + color.G + ", B:" + color.B);
return b;
@ -133,8 +133,8 @@ namespace Greenshot {
#region update user interface
private void UpdateRecentColorsButtonRow() {
for (int i = 0; i < editorConfiguration.RecentColors.Count && i < 12; i++) {
_recentColorButtons[i].BackColor = editorConfiguration.RecentColors[i];
for (int i = 0; i < EditorConfig.RecentColors.Count && i < 12; i++) {
_recentColorButtons[i].BackColor = EditorConfig.RecentColors[i];
_recentColorButtons[i].Enabled = true;
}
}
@ -155,10 +155,10 @@ namespace Greenshot {
}
private void AddToRecentColors(Color c) {
editorConfiguration.RecentColors.Remove(c);
editorConfiguration.RecentColors.Insert(0, c);
if (editorConfiguration.RecentColors.Count > 12) {
editorConfiguration.RecentColors.RemoveRange(12, editorConfiguration.RecentColors.Count - 12);
EditorConfig.RecentColors.Remove(c);
EditorConfig.RecentColors.Insert(0, c);
if (EditorConfig.RecentColors.Count > 12) {
EditorConfig.RecentColors.RemoveRange(12, EditorConfig.RecentColors.Count - 12);
}
UpdateRecentColorsButtonRow();
}
@ -172,14 +172,14 @@ namespace Greenshot {
}
TextBox textBox = (TextBox)sender;
string text = textBox.Text.Replace("#", "");
int i = 0;
int i;
Color c;
if (Int32.TryParse(text, NumberStyles.AllowHexSpecifier, Thread.CurrentThread.CurrentCulture, out i)) {
if (int.TryParse(text, NumberStyles.AllowHexSpecifier, Thread.CurrentThread.CurrentCulture, out i)) {
c = Color.FromArgb(i);
} else {
KnownColor knownColor;
try {
knownColor = (KnownColor)Enum.Parse(typeof(KnownColor), text, true);
try
{
var knownColor = (KnownColor)Enum.Parse(typeof(KnownColor), text, true);
c = Color.FromKnownColor(knownColor);
} catch (Exception) {
return;
@ -189,7 +189,7 @@ namespace Greenshot {
PreviewColor(opaqueColor, textBox);
}
private void TextBoxRGBTextChanged(object sender, EventArgs e) {
private void TextBoxRgbTextChanged(object sender, EventArgs e) {
if (_updateInProgress) {
return;
}
@ -228,10 +228,16 @@ namespace Greenshot {
#region helper functions
private int GetColorPartIntFromString(string s) {
int ret = 0;
Int32.TryParse(s, out ret);
if (ret < 0) ret = 0;
else if (ret > 255) ret = 255;
int ret;
int.TryParse(s, out ret);
if (ret < 0)
{
ret = 0;
}
else if (ret > 255)
{
ret = 255;
}
return ret;
}