mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 17:56:51 +13:00
Enum changes
This commit is contained in:
parent
a2b8fb61ec
commit
02fc81dec2
9 changed files with 31 additions and 29 deletions
|
@ -54,7 +54,7 @@ public static int GetIndex(this Enum value)
|
|||
|
||||
public static IEnumerable<T> GetFlags<T>(this Enum value)
|
||||
{
|
||||
return Enum.GetValues(value.GetType()).OfType<T>().Where(x => Convert.ToUInt64(x) != 0 && value.HasFlag(x));
|
||||
return Helpers.GetEnums<T>().Where(x => Convert.ToUInt64(x) != 0 && value.HasFlag(x));
|
||||
}
|
||||
|
||||
public static bool HasFlag<T>(this Enum value, params T[] flags)
|
||||
|
|
|
@ -246,7 +246,7 @@ public static string GetMimeType(string fileName)
|
|||
|
||||
public static T[] GetEnums<T>()
|
||||
{
|
||||
return Enum.GetValues(typeof(T)).Cast<T>().ToArray();
|
||||
return (T[])Enum.GetValues(typeof(T));
|
||||
}
|
||||
|
||||
public static string[] GetEnumDescriptions<T>()
|
||||
|
@ -261,8 +261,7 @@ public static int GetEnumLength<T>()
|
|||
|
||||
public static T GetEnumFromIndex<T>(int i)
|
||||
{
|
||||
Array values = Enum.GetValues(typeof(T));
|
||||
return (T)values.GetValue(i);
|
||||
return GetEnums<T>()[i];
|
||||
}
|
||||
|
||||
public static string[] GetEnumNamesProper<T>()
|
||||
|
@ -301,6 +300,7 @@ public static string GetProperName(string name)
|
|||
return sb.ToString();
|
||||
}
|
||||
|
||||
// Extension without dot
|
||||
public static string GetProperExtension(string filePath)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(filePath))
|
||||
|
|
|
@ -247,7 +247,7 @@ public static ContextMenuStrip CreateCodesMenu(TextBox tb, params ReplacementVar
|
|||
ShowImageMargin = false
|
||||
};
|
||||
|
||||
var variables = Enum.GetValues(typeof(ReplacementVariables)).Cast<ReplacementVariables>().Where(x => !ignoreList.Contains(x)).
|
||||
var variables = Helpers.GetEnums<ReplacementVariables>().Where(x => !ignoreList.Contains(x)).
|
||||
Select(x => new
|
||||
{
|
||||
Name = ReplacementExtension.Prefix + Enum.GetName(typeof(ReplacementVariables), x),
|
||||
|
|
|
@ -49,7 +49,7 @@ public void Init(TaskInfo info)
|
|||
InitCapture(info.TaskSettings);
|
||||
break;
|
||||
case EDataType.Text:
|
||||
Enum.GetValues(typeof(TextDestination)).Cast<TextDestination>().ForEach(x =>
|
||||
Helpers.GetEnums<TextDestination>().ForEach(x =>
|
||||
{
|
||||
if (x != TextDestination.FileUploader)
|
||||
{
|
||||
|
@ -57,19 +57,19 @@ public void Init(TaskInfo info)
|
|||
}
|
||||
});
|
||||
|
||||
Enum.GetValues(typeof(FileDestination)).Cast<FileDestination>().ForEach(x =>
|
||||
Helpers.GetEnums<FileDestination>().ForEach(x =>
|
||||
{
|
||||
AddDestination<FileDestination>((int)x, EDataType.Text, info.TaskSettings);
|
||||
});
|
||||
|
||||
flp.Controls.OfType<RadioButton>().ForEach(x =>
|
||||
{
|
||||
x.Checked = (x.Tag is TextDestination && (TextDestination)x.Tag == (TextDestination)info.TaskSettings.ImageDestination) ||
|
||||
x.Checked = (x.Tag is TextDestination && (TextDestination)x.Tag == (TextDestination)info.TaskSettings.TextDestination) ||
|
||||
(x.Tag is FileDestination && (FileDestination)x.Tag == (FileDestination)info.TaskSettings.TextFileDestination);
|
||||
});
|
||||
break;
|
||||
case EDataType.File:
|
||||
Enum.GetValues(typeof(FileDestination)).Cast<FileDestination>().ForEach(x =>
|
||||
Helpers.GetEnums<FileDestination>().ForEach(x =>
|
||||
{
|
||||
AddDestination<FileDestination>((int)x, EDataType.File, info.TaskSettings);
|
||||
});
|
||||
|
@ -80,7 +80,7 @@ public void Init(TaskInfo info)
|
|||
});
|
||||
break;
|
||||
case EDataType.URL:
|
||||
Enum.GetValues(typeof(UrlShortenerType)).Cast<UrlShortenerType>().ForEach(x =>
|
||||
Helpers.GetEnums<UrlShortenerType>().ForEach(x =>
|
||||
{
|
||||
AddDestination<UrlShortenerType>((int)x, EDataType.URL, info.TaskSettings);
|
||||
});
|
||||
|
@ -98,7 +98,7 @@ public void Init(TaskInfo info)
|
|||
|
||||
public void InitCapture(TaskSettings taskSettings)
|
||||
{
|
||||
Enum.GetValues(typeof(ImageDestination)).Cast<ImageDestination>().ForEach(x =>
|
||||
Helpers.GetEnums<ImageDestination>().ForEach(x =>
|
||||
{
|
||||
if (x != ImageDestination.FileUploader)
|
||||
{
|
||||
|
@ -106,7 +106,7 @@ public void InitCapture(TaskSettings taskSettings)
|
|||
}
|
||||
});
|
||||
|
||||
Enum.GetValues(typeof(FileDestination)).Cast<FileDestination>().ForEach(x =>
|
||||
Helpers.GetEnums<FileDestination>().ForEach(x =>
|
||||
{
|
||||
AddDestination<FileDestination>((int)x, EDataType.File, taskSettings);
|
||||
});
|
||||
|
@ -114,7 +114,7 @@ public void InitCapture(TaskSettings taskSettings)
|
|||
flp.Controls.OfType<RadioButton>().ForEach(x =>
|
||||
{
|
||||
x.Checked = (x.Tag is ImageDestination && (ImageDestination)x.Tag == (ImageDestination)taskSettings.ImageDestination) ||
|
||||
(x.Tag is FileDestination && (FileDestination)x.Tag == (FileDestination)taskSettings.ImageFileDestination);
|
||||
(x.Tag is FileDestination && (FileDestination)x.Tag == (FileDestination)taskSettings.ImageFileDestination);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,8 @@ private void OnInitCompleted()
|
|||
{
|
||||
if (InitCompleted != null)
|
||||
{
|
||||
string currentDestination = flp.Controls.OfType<RadioButton>().First<RadioButton>(x => x.Checked).Text;
|
||||
string currentDestination = flp.Controls.OfType<RadioButton>().First(x => x.Checked).Text;
|
||||
|
||||
if (!string.IsNullOrEmpty(currentDestination))
|
||||
{
|
||||
InitCompleted(currentDestination);
|
||||
|
|
|
@ -55,7 +55,7 @@ public AfterCaptureForm(Image img, TaskSettings taskSettings)
|
|||
|
||||
private void AddAfterCaptureItems(AfterCaptureTasks afterCaptureTasks)
|
||||
{
|
||||
AfterCaptureTasks[] enums = (AfterCaptureTasks[])Enum.GetValues(typeof(AfterCaptureTasks));
|
||||
AfterCaptureTasks[] enums = Helpers.GetEnums<AfterCaptureTasks>();
|
||||
|
||||
for (int i = 1; i < enums.Length; i++)
|
||||
{
|
||||
|
|
|
@ -72,12 +72,12 @@ public AfterUploadForm(TaskInfo info)
|
|||
lvClipboardFormats.Groups.Add(lvgLocal);
|
||||
lvClipboardFormats.Groups.Add(lvgCustom);
|
||||
|
||||
foreach (LinkFormatEnum type in Enum.GetValues(typeof(LinkFormatEnum)))
|
||||
foreach (LinkFormatEnum type in Helpers.GetEnums<LinkFormatEnum>())
|
||||
{
|
||||
if (!Helpers.IsImageFile(Info.Result.URL) &&
|
||||
(type == LinkFormatEnum.HTMLImage || type == LinkFormatEnum.HTMLLinkedImage ||
|
||||
type == LinkFormatEnum.ForumImage || type == LinkFormatEnum.ForumLinkedImage ||
|
||||
type == LinkFormatEnum.WikiImage || type == LinkFormatEnum.WikiLinkedImage))
|
||||
type == LinkFormatEnum.ForumImage || type == LinkFormatEnum.ForumLinkedImage ||
|
||||
type == LinkFormatEnum.WikiImage || type == LinkFormatEnum.WikiLinkedImage))
|
||||
continue;
|
||||
|
||||
AddFormat(type.GetDescription(), GetUrlByType(type));
|
||||
|
|
|
@ -99,13 +99,13 @@ private void LoadSettings()
|
|||
chkUseSecondaryUploaders.Checked = Program.Settings.UseSecondaryUploaders;
|
||||
tlpBackupDestinations.Enabled = Program.Settings.UseSecondaryUploaders;
|
||||
|
||||
Program.Settings.SecondaryImageUploaders.AddRange(((ImageDestination[])Enum.GetValues(typeof(ImageDestination))).Where(n => (Program.Settings.SecondaryImageUploaders.All(e => e != n))));
|
||||
Program.Settings.SecondaryTextUploaders.AddRange(((TextDestination[])Enum.GetValues(typeof(TextDestination))).Where(n => (Program.Settings.SecondaryTextUploaders.All(e => e != n))));
|
||||
Program.Settings.SecondaryFileUploaders.AddRange(((FileDestination[])Enum.GetValues(typeof(FileDestination))).Where(n => (Program.Settings.SecondaryFileUploaders.All(e => e != n))));
|
||||
Program.Settings.SecondaryImageUploaders.AddRange(Helpers.GetEnums<ImageDestination>().Where(n => Program.Settings.SecondaryImageUploaders.All(e => e != n)));
|
||||
Program.Settings.SecondaryTextUploaders.AddRange(Helpers.GetEnums<TextDestination>().Where(n => Program.Settings.SecondaryTextUploaders.All(e => e != n)));
|
||||
Program.Settings.SecondaryFileUploaders.AddRange(Helpers.GetEnums<FileDestination>().Where(n => Program.Settings.SecondaryFileUploaders.All(e => e != n)));
|
||||
|
||||
Program.Settings.SecondaryImageUploaders.Where(n => (((ImageDestination[])Enum.GetValues(typeof(ImageDestination))).All(e => e != n))).ForEach(x => Program.Settings.SecondaryImageUploaders.Remove(x));
|
||||
Program.Settings.SecondaryTextUploaders.Where(n => (((TextDestination[])Enum.GetValues(typeof(TextDestination))).All(e => e != n))).ForEach(x => Program.Settings.SecondaryTextUploaders.Remove(x));
|
||||
Program.Settings.SecondaryFileUploaders.Where(n => (((FileDestination[])Enum.GetValues(typeof(FileDestination))).All(e => e != n))).ForEach(x => Program.Settings.SecondaryFileUploaders.Remove(x));
|
||||
Program.Settings.SecondaryImageUploaders.Where(n => Helpers.GetEnums<ImageDestination>().All(e => e != n)).ForEach(x => Program.Settings.SecondaryImageUploaders.Remove(x));
|
||||
Program.Settings.SecondaryTextUploaders.Where(n => Helpers.GetEnums<TextDestination>().All(e => e != n)).ForEach(x => Program.Settings.SecondaryTextUploaders.Remove(x));
|
||||
Program.Settings.SecondaryFileUploaders.Where(n => Helpers.GetEnums<FileDestination>().All(e => e != n)).ForEach(x => Program.Settings.SecondaryFileUploaders.Remove(x));
|
||||
|
||||
Program.Settings.SecondaryImageUploaders.ForEach<ImageDestination>(x => lvSecondaryImageUploaders.Items.Add(new ListViewItem(x.GetDescription()) { Tag = x }));
|
||||
Program.Settings.SecondaryTextUploaders.ForEach<TextDestination>(x => lvSecondaryTextUploaders.Items.Add(new ListViewItem(x.GetDescription()) { Tag = x }));
|
||||
|
@ -123,6 +123,7 @@ private void LoadSettings()
|
|||
Program.Settings.VideoEncoders.Add(new VideoEncoder() { Name = "Change container to MP4 using ffmpeg.exe", Path = "ffmpeg.exe", Args = "-i %input -c:v copy %output", OutputExtension = "mp4" });
|
||||
Program.Settings.VideoEncoders.Add(new VideoEncoder() { Name = "Optimize GIF using gifsicle.exe", Path = "gifsicle.exe", Args = "-O2 %input -o %output", OutputExtension = "gif" });
|
||||
}
|
||||
|
||||
Program.Settings.VideoEncoders.ForEach(x => AddVideoEncoder(x));
|
||||
|
||||
// Advanced
|
||||
|
|
|
@ -296,7 +296,7 @@ private void UpdateControls()
|
|||
cmsUploadInfo.SuspendLayout();
|
||||
|
||||
tsmiStopUpload.Visible = tsmiOpen.Visible = tsmiCopy.Visible = tsmiShowErrors.Visible = tsmiShowResponse.Visible = tsmiShowQRCode.Visible =
|
||||
tsmiUploadSelectedFile.Visible = tsmiShareSelectedURL.Visible = tsmiClearList.Visible = tssUploadInfo1.Visible = false;
|
||||
tsmiUploadSelectedFile.Visible = tsmiShortenSelectedURL.Visible = tsmiShareSelectedURL.Visible = tsmiClearList.Visible = tssUploadInfo1.Visible = false;
|
||||
pbPreview.Reset();
|
||||
uim.RefreshSelectedItems();
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ public UploadTestForm()
|
|||
ListViewGroup urlShortenersGroup = new ListViewGroup("URL Shorteners", HorizontalAlignment.Left);
|
||||
lvUploaders.Groups.AddRange(new[] { imageUploadersGroup, textUploadersGroup, fileUploadersGroup, urlShortenersGroup });
|
||||
|
||||
foreach (ImageDestination uploader in Enum.GetValues(typeof(ImageDestination)))
|
||||
foreach (ImageDestination uploader in Helpers.GetEnums<ImageDestination>())
|
||||
{
|
||||
switch (uploader)
|
||||
{
|
||||
|
@ -112,7 +112,7 @@ public UploadTestForm()
|
|||
lvUploaders.Items.Add(lvi);
|
||||
}
|
||||
|
||||
foreach (TextDestination uploader in Enum.GetValues(typeof(TextDestination)))
|
||||
foreach (TextDestination uploader in Helpers.GetEnums<TextDestination>())
|
||||
{
|
||||
switch (uploader)
|
||||
{
|
||||
|
@ -131,7 +131,7 @@ public UploadTestForm()
|
|||
lvUploaders.Items.Add(lvi);
|
||||
}
|
||||
|
||||
foreach (FileDestination uploader in Enum.GetValues(typeof(FileDestination)))
|
||||
foreach (FileDestination uploader in Helpers.GetEnums<FileDestination>())
|
||||
{
|
||||
switch (uploader)
|
||||
{
|
||||
|
@ -153,7 +153,7 @@ public UploadTestForm()
|
|||
lvUploaders.Items.Add(lvi);
|
||||
}
|
||||
|
||||
foreach (UrlShortenerType uploader in Enum.GetValues(typeof(UrlShortenerType)))
|
||||
foreach (UrlShortenerType uploader in Helpers.GetEnums<UrlShortenerType>())
|
||||
{
|
||||
lvi = new ListViewItem(uploader.GetDescription());
|
||||
|
||||
|
|
Loading…
Reference in a new issue