mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-29 03:30:43 +12:00
Code refactoring
This commit is contained in:
parent
9b008ac399
commit
5e7dbd23fa
|
@ -345,8 +345,8 @@ public static void SupportSelectAll(this TextBox tb)
|
|||
if (e.KeyData == (Keys.Control | Keys.A))
|
||||
{
|
||||
tb.SelectAll();
|
||||
|
||||
e.SuppressKeyPress = true;
|
||||
e.Handled = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -928,6 +928,14 @@ public static void CloseOnEscape(this Form form)
|
|||
{
|
||||
form.KeyPreview = true;
|
||||
|
||||
form.KeyDown += (sender, e) =>
|
||||
{
|
||||
if (e.KeyCode == Keys.Escape)
|
||||
{
|
||||
e.SuppressKeyPress = true;
|
||||
}
|
||||
};
|
||||
|
||||
form.KeyUp += (sender, e) =>
|
||||
{
|
||||
if (e.KeyCode == Keys.Escape)
|
||||
|
|
|
@ -37,8 +37,7 @@ public partial class ClipboardViewerForm : Form
|
|||
public ClipboardViewerForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
}
|
||||
|
||||
private void ClipboardViewerForm_Load(object sender, EventArgs e)
|
||||
|
|
|
@ -46,8 +46,7 @@ public partial class ColorPickerForm : Form
|
|||
public ColorPickerForm(Color currentColor, bool isScreenColorPickerMode = false, bool checkClipboard = true, ColorPickerOptions options = null)
|
||||
{
|
||||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
clipboardStatusHider = new ControlHider(btnClipboardStatus, 2000);
|
||||
|
||||
IsScreenColorPickerMode = isScreenColorPickerMode;
|
||||
|
|
|
@ -35,8 +35,7 @@ public partial class DNSChangerForm : Form
|
|||
public DNSChangerForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
|
||||
AddDNS(Resources.DNSChangerForm_DNSChangerForm_Manual);
|
||||
AddDNS("Google Public DNS", "8.8.8.8", "8.8.4.4"); // https://developers.google.com/speed/public-dns/
|
||||
|
|
|
@ -40,8 +40,7 @@ public partial class HashCheckForm : Form
|
|||
public HashCheckForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
|
||||
UpdateCompareControls();
|
||||
cbHashType.Items.AddRange(Helpers.GetEnumDescriptions<HashType>());
|
||||
|
|
|
@ -36,8 +36,7 @@ public class InputBox : Form
|
|||
private InputBox(string title, string inputText = null, string okText = null, string cancelText = null)
|
||||
{
|
||||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
|
||||
InputText = inputText;
|
||||
|
||||
|
|
|
@ -35,8 +35,7 @@ public partial class MonitorTestForm : Form
|
|||
public MonitorTestForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
|
||||
Rectangle screenBounds = CaptureHelpers.GetScreenBounds();
|
||||
Location = screenBounds.Location;
|
||||
|
|
|
@ -36,8 +36,7 @@ private OutputBox(string text, string title, bool scrollToEnd = false)
|
|||
{
|
||||
InitializeComponent();
|
||||
rtbText.AddContextMenu();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
|
||||
Text = "ShareX - " + title;
|
||||
rtbText.Text = text;
|
||||
|
|
|
@ -52,7 +52,6 @@ public ScreenTearingTestForm()
|
|||
Bounds = screenRectangle;
|
||||
Cursor = Cursors.Hand;
|
||||
FormBorderStyle = FormBorderStyle.None;
|
||||
Icon = ShareXResources.Icon;
|
||||
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
|
||||
Text = "ShareX - Screen tearing test";
|
||||
ShowInTaskbar = false;
|
||||
|
@ -60,7 +59,7 @@ public ScreenTearingTestForm()
|
|||
|
||||
ResumeLayout(false);
|
||||
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
|
||||
animationTime = Stopwatch.StartNew();
|
||||
}
|
||||
|
|
|
@ -123,8 +123,13 @@ public static Bitmap Logo
|
|||
|
||||
public static ShareXTheme Theme { get; set; } = ShareXTheme.DarkTheme;
|
||||
|
||||
public static void ApplyTheme(Form form, bool setIcon = true)
|
||||
public static void ApplyTheme(Form form, bool closeOnEscape = false, bool setIcon = true)
|
||||
{
|
||||
if (closeOnEscape)
|
||||
{
|
||||
form.CloseOnEscape();
|
||||
}
|
||||
|
||||
if (setIcon)
|
||||
{
|
||||
form.Icon = Icon;
|
||||
|
|
|
@ -89,9 +89,7 @@ public HistoryForm(string historyPath, HistorySettings settings, Action<string>
|
|||
tstbSearch.Text = Settings.SearchText;
|
||||
}
|
||||
|
||||
ShareXResources.ApplyTheme(this);
|
||||
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
|
||||
if (Settings.RememberWindowState)
|
||||
{
|
||||
|
@ -412,11 +410,11 @@ private async void HistoryForm_KeyDown(object sender, KeyEventArgs e)
|
|||
switch (e.KeyData)
|
||||
{
|
||||
case Keys.F5:
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
await RefreshHistoryItems();
|
||||
break;
|
||||
case Keys.Control | Keys.F5 when HelpersOptions.DevMode:
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
await RefreshHistoryItems(true);
|
||||
break;
|
||||
}
|
||||
|
@ -521,7 +519,7 @@ private void lvHistory_MouseDoubleClick(object sender, MouseEventArgs e)
|
|||
|
||||
private void lvHistory_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
e.Handled = e.SuppressKeyPress = him.HandleKeyInput(e);
|
||||
e.SuppressKeyPress = him.HandleKeyInput(e);
|
||||
}
|
||||
|
||||
private void lvHistory_ItemDrag(object sender, ItemDragEventArgs e)
|
||||
|
|
|
@ -74,9 +74,7 @@ public ImageHistoryForm(string historyPath, ImageHistorySettings settings, Actio
|
|||
tstbSearch.Text = Settings.SearchText;
|
||||
}
|
||||
|
||||
ShareXResources.ApplyTheme(this);
|
||||
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
|
||||
if (Settings.RememberWindowState)
|
||||
{
|
||||
|
@ -187,11 +185,11 @@ private void ImageHistoryForm_KeyDown(object sender, KeyEventArgs e)
|
|||
{
|
||||
case Keys.F5:
|
||||
RefreshHistoryItems();
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
break;
|
||||
case Keys.Control | Keys.F5 when HelpersOptions.DevMode:
|
||||
RefreshHistoryItems(true);
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +229,6 @@ private void tstbSearch_KeyDown(object sender, KeyEventArgs e)
|
|||
if (e.KeyCode == Keys.Enter)
|
||||
{
|
||||
RefreshHistoryItems();
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
}
|
||||
}
|
||||
|
@ -254,7 +251,7 @@ private void tsbSettings_Click(object sender, EventArgs e)
|
|||
|
||||
private void ilvImages_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
e.Handled = e.SuppressKeyPress = him.HandleKeyInput(e);
|
||||
e.SuppressKeyPress = him.HandleKeyInput(e);
|
||||
}
|
||||
|
||||
#endregion Form events
|
||||
|
|
|
@ -43,8 +43,7 @@ public partial class DirectoryIndexerForm : Form
|
|||
public DirectoryIndexerForm(IndexerSettings settings)
|
||||
{
|
||||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
|
||||
Settings = settings;
|
||||
pgSettings.SelectedObject = Settings;
|
||||
|
|
|
@ -55,8 +55,7 @@ private ImageBeautifierForm(ImageBeautifierOptions options = null)
|
|||
}
|
||||
|
||||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
title = Text;
|
||||
|
||||
LoadOptions();
|
||||
|
|
|
@ -44,8 +44,7 @@ public ImageCombinerForm(ImageCombinerOptions options)
|
|||
Options = options;
|
||||
|
||||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
|
||||
if (Options.Orientation == Orientation.Horizontal)
|
||||
{
|
||||
|
|
|
@ -42,8 +42,7 @@ public partial class ImageSplitterForm : Form
|
|||
public ImageSplitterForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
UpdateButtonStates();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,8 +37,7 @@ public partial class ImageThumbnailerForm : Form
|
|||
public ImageThumbnailerForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
}
|
||||
|
||||
private void UpdateEnabled()
|
||||
|
|
|
@ -46,8 +46,7 @@ public VideoConverterForm(string ffmpegFilePath, VideoConverterOptions options)
|
|||
Options = options;
|
||||
|
||||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
|
||||
UpdateOptions();
|
||||
|
||||
|
|
|
@ -46,8 +46,7 @@ public VideoThumbnailerForm(string ffmpegPath, VideoThumbnailOptions options)
|
|||
Options = options;
|
||||
|
||||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
|
||||
txtMediaPath.Text = Options.LastVideoPath ?? "";
|
||||
pgOptions.SelectedObject = Options;
|
||||
|
|
|
@ -149,7 +149,6 @@ private void tstbSearch_KeyDown(object sender, KeyEventArgs e)
|
|||
{
|
||||
if (e.KeyCode == Keys.Enter)
|
||||
{
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
}
|
||||
}
|
||||
|
@ -158,7 +157,6 @@ private void tstbSearch_KeyUp(object sender, KeyEventArgs e)
|
|||
{
|
||||
if (e.KeyCode == Keys.Enter)
|
||||
{
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
|
||||
if (ilvStickers.Items.Count > 0)
|
||||
|
|
|
@ -1162,7 +1162,7 @@ internal void CreateToolbar()
|
|||
tsMain.PerformLayout();
|
||||
menuForm.ResumeLayout(false);
|
||||
|
||||
ShareXResources.ApplyTheme(menuForm, false);
|
||||
ShareXResources.ApplyTheme(menuForm, false, false);
|
||||
|
||||
menuForm.Show(Form);
|
||||
|
||||
|
@ -1190,14 +1190,14 @@ private void MenuForm_KeyDown(object sender, KeyEventArgs e)
|
|||
form_KeyDown(sender, e);
|
||||
Form.RegionCaptureForm_KeyDown(sender, e);
|
||||
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
}
|
||||
|
||||
private void MenuForm_KeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
form_KeyUp(sender, e);
|
||||
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
}
|
||||
|
||||
private void MenuForm_LocationChanged(object sender, EventArgs e)
|
||||
|
|
|
@ -36,8 +36,7 @@ public partial class TextUploadForm : Form
|
|||
public TextUploadForm(string content = null)
|
||||
{
|
||||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
|
||||
if (string.IsNullOrEmpty(content) && ClipboardHelpers.ContainsText())
|
||||
{
|
||||
|
|
|
@ -40,8 +40,7 @@ public InspectWindowForm()
|
|||
{
|
||||
InitializeComponent();
|
||||
rtbInfo.AddContextMenu();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
SelectHandle(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -1465,7 +1465,7 @@ private void lvUploads_KeyDown(object sender, KeyEventArgs e)
|
|||
break;
|
||||
}
|
||||
|
||||
e.Handled = e.SuppressKeyPress = true;
|
||||
e.SuppressKeyPress = true;
|
||||
}
|
||||
|
||||
private void pbPreview_MouseDown(object sender, MouseEventArgs e)
|
||||
|
|
|
@ -61,8 +61,7 @@ public QRCodeForm(string text = null)
|
|||
{
|
||||
InitializeComponent();
|
||||
rtbDecodeResult.AddContextMenu();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
{
|
||||
|
|
|
@ -40,8 +40,7 @@ public partial class BorderlessWindowForm : Form
|
|||
public BorderlessWindowForm(BorderlessWindowSettings settings)
|
||||
{
|
||||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
|
||||
Settings = settings;
|
||||
}
|
||||
|
|
|
@ -48,8 +48,7 @@ public OCRForm(Bitmap bmp, OCROptions options)
|
|||
Options = options;
|
||||
|
||||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
this.CloseOnEscape();
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
|
||||
OCRLanguage[] languages = OCRHelper.AvailableLanguages.OrderBy(x => x.DisplayName).ToArray();
|
||||
|
||||
|
|
|
@ -145,10 +145,9 @@ private PinToScreenForm(PinToScreenOptions options)
|
|||
InitializeComponent();
|
||||
// TODO: Add options form
|
||||
tsbOptions.Visible = false;
|
||||
ShareXResources.ApplyTheme(this);
|
||||
ShareXResources.ApplyTheme(this, true);
|
||||
TopMost = Options.TopMost;
|
||||
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true);
|
||||
this.CloseOnEscape();
|
||||
|
||||
tsMain.Cursor = Cursors.Arrow;
|
||||
openHandCursor = Helpers.CreateCursor(Resources.openhand);
|
||||
|
|
Loading…
Reference in a new issue