diff --git a/HelpersLib/CodeMenu.cs b/HelpersLib/CodeMenu.cs new file mode 100644 index 000000000..16b9f9650 --- /dev/null +++ b/HelpersLib/CodeMenu.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace HelpersLib +{ + public static class CodeMenu + { + public static ContextMenuStrip Create(TextBox tb, params TEntry[] ignoreList) + where TEntry : CodeMenuEntry + { + ContextMenuStrip cms = new ContextMenuStrip { + Font = new Font("Lucida Console", 8), + AutoClose = false, + Opacity = 0.9, + ShowImageMargin = false + }; + + var variables = Helpers.GetValueFields().Where(x => !ignoreList.Contains(x)). + Select(x => new { + Name = x.ToPrefixString(), + Description = x.Description, + }); + + foreach (var variable in variables) { + ToolStripMenuItem tsmi = new ToolStripMenuItem { Text = string.Format("{0} - {1}", variable.Name, variable.Description), Tag = variable.Name }; + tsmi.Click += (sender, e) => + { + string text = ((ToolStripMenuItem)sender).Tag.ToString(); + tb.AppendTextToSelection(text); + }; + cms.Items.Add(tsmi); + } + + cms.Items.Add(new ToolStripSeparator()); + + ToolStripMenuItem tsmiClose = new ToolStripMenuItem("Close"); + tsmiClose.Click += (sender, e) => cms.Close(); + cms.Items.Add(tsmiClose); + + tb.MouseDown += (sender, e) => + { + if (cms.Items.Count > 0) cms.Show(tb, new Point(tb.Width + 1, 0)); + }; + + tb.Leave += (sender, e) => + { + if (cms.Visible) cms.Close(); + }; + + tb.KeyDown += (sender, e) => + { + if ((e.KeyCode == Keys.Enter || e.KeyCode == Keys.Escape) && cms.Visible) { + cms.Close(); + e.SuppressKeyPress = true; + } + }; + + tb.Disposed += (sender, e) => cms.Dispose(); + + return cms; + } + } +} diff --git a/HelpersLib/CodeMenuEntry.cs b/HelpersLib/CodeMenuEntry.cs new file mode 100644 index 000000000..63fa25afc --- /dev/null +++ b/HelpersLib/CodeMenuEntry.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace HelpersLib +{ + public abstract class CodeMenuEntry + { + protected readonly String _value, _description; + + public CodeMenuEntry(string value, string description) + { + _value = value; + _description = description; + } + + public String Value { get { return _value; } } + public String Description { get { return _description; } } + + public abstract string ToPrefixString(); + } +} diff --git a/HelpersLib/ExtCodeMenuEntry.cs b/HelpersLib/ExtCodeMenuEntry.cs new file mode 100644 index 000000000..6464ebd5c --- /dev/null +++ b/HelpersLib/ExtCodeMenuEntry.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace HelpersLib +{ + public class ExtCodeMenuEntry : CodeMenuEntry + { + public ExtCodeMenuEntry(string value, string description) : base(value, description) { } + + public override String ToPrefixString() { return '.' + _value; } + + public static readonly ExtCodeMenuEntry bmp = new ExtCodeMenuEntry("bmp", "Bitmap Image File"); + public static readonly ExtCodeMenuEntry gif = new ExtCodeMenuEntry("gif", "Graphical Interchange Format File"); + public static readonly ExtCodeMenuEntry jpg = new ExtCodeMenuEntry("jpg", "JPEG Image"); + public static readonly ExtCodeMenuEntry png = new ExtCodeMenuEntry("png", "Portable Network Graphic"); + public static readonly ExtCodeMenuEntry tif = new ExtCodeMenuEntry("tif", "Tagged Image File"); + } +} diff --git a/HelpersLib/ExternalProgram.cs b/HelpersLib/ExternalProgram.cs index cc1fa5012..134e9d3fe 100644 --- a/HelpersLib/ExternalProgram.cs +++ b/HelpersLib/ExternalProgram.cs @@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License #endregion License Information (GPL v3) using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -35,6 +36,7 @@ public class ExternalProgram public string Name { get; set; } public string Path { get; set; } public string Args { get; set; } + public string Extensions { get; set; } public ExternalProgram() { @@ -60,6 +62,7 @@ public ExternalProgram(string name, string path, string args) public void Run(string filePath) { + if (!CheckExtensions(filePath)) return; if (!string.IsNullOrEmpty(Path) && File.Exists(Path)) { filePath = '"' + filePath.Trim('"') + '"'; @@ -93,5 +96,18 @@ public void Run(string filePath) } } } + + private bool CheckExtensions(string path) + { + if (string.IsNullOrEmpty(Extensions) || string.IsNullOrEmpty(path)) return true; + int idx = 0; + for (int i = 0; i <= Extensions.Length; ++i) { + if (i == Extensions.Length || !char.IsLetterOrDigit(Extensions[i])) { + if (idx < i && path.EndsWith(Extensions.Substring(idx, i - idx))) return true; + idx = i + 1; + } + } + return false; + } } } \ No newline at end of file diff --git a/HelpersLib/Helpers/Helpers.cs b/HelpersLib/Helpers/Helpers.cs index 5c525eec8..30b5bfbb3 100644 --- a/HelpersLib/Helpers/Helpers.cs +++ b/HelpersLib/Helpers/Helpers.cs @@ -25,6 +25,7 @@ You should have received a copy of the GNU General Public License using Microsoft.Win32; using System; +using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.IO; @@ -32,6 +33,7 @@ You should have received a copy of the GNU General Public License using System.Media; using System.Net; using System.Net.NetworkInformation; +using System.Reflection; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Text; @@ -258,6 +260,17 @@ public static string[] GetEnumNamesProper() return newNames; } + // returns a list of public static fields of the class' type (similar to enum values) + public static T[] GetValueFields() + { + var res = new List(); + foreach (FieldInfo fi in typeof(T).GetFields(BindingFlags.Static | BindingFlags.Public)) { + if (fi.FieldType != typeof(T)) continue; + res.Add((T)fi.GetValue(null)); + } + return res.ToArray(); + } + // Example: "TopLeft" becomes "Top left" public static string GetProperName(string name) { diff --git a/HelpersLib/HelpersLib.csproj b/HelpersLib/HelpersLib.csproj index be3136106..3085d8222 100644 --- a/HelpersLib/HelpersLib.csproj +++ b/HelpersLib/HelpersLib.csproj @@ -74,6 +74,7 @@ + @@ -85,6 +86,7 @@ + @@ -101,6 +103,7 @@ + diff --git a/HelpersLib/NameParser.cs b/HelpersLib/NameParser.cs index 033197cc5..e5b1eca36 100644 --- a/HelpersLib/NameParser.cs +++ b/HelpersLib/NameParser.cs @@ -33,66 +33,36 @@ You should have received a copy of the GNU General Public License namespace HelpersLib { - public enum ReplacementVariables + public class ReplCodeMenuEntry : CodeMenuEntry { - [Description("Title of active window")] - t, - [Description("Process name of active window")] - pn, - [Description("Current year")] - y, - [Description("Current month")] - mo, - [Description("Current month name (Local language)")] - mon, - [Description("Current month name (English)")] - mon2, - [Description("Current day")] - d, - [Description("Current hour")] - h, - [Description("Current minute")] - mi, - [Description("Current second")] - s, - [Description("Current millisecond")] - ms, - [Description("Gets AM/PM")] - pm, - [Description("Current week name (Local language)")] - w, - [Description("Current week name (English)")] - w2, - [Description("Unix timestamp")] - unix, - [Description("Auto increment number")] - i, - [Description("Random number 0 to 9")] - rn, - [Description("Random alphanumeric char")] - ra, - [Description("Gets image width")] - width, - [Description("Gets image height")] - height, - [Description("User name")] - un, - [Description("User login name")] - uln, - [Description("Computer name")] - cn, - [Description("New line")] - n - } + public ReplCodeMenuEntry(string value, string description) : base(value, description) { } - public static class ReplacementExtension - { - public const char Prefix = '%'; + public override String ToPrefixString() { return '%' + _value; } - public static string ToPrefixString(this ReplacementVariables replacement) - { - return Prefix + replacement.ToString(); - } + public static readonly ReplCodeMenuEntry t = new ReplCodeMenuEntry("t", "Title of active window"); + public static readonly ReplCodeMenuEntry pn = new ReplCodeMenuEntry("pn", "Process name of active window"); + public static readonly ReplCodeMenuEntry y = new ReplCodeMenuEntry("y", "Current year"); + public static readonly ReplCodeMenuEntry mo = new ReplCodeMenuEntry("mo", "Current month"); + public static readonly ReplCodeMenuEntry mon = new ReplCodeMenuEntry("mon", "Current month name (Local language)"); + public static readonly ReplCodeMenuEntry mon2 = new ReplCodeMenuEntry("mon2", "Current month name (English)"); + public static readonly ReplCodeMenuEntry d = new ReplCodeMenuEntry("d", "Current day"); + public static readonly ReplCodeMenuEntry h = new ReplCodeMenuEntry("h", "Current hour"); + public static readonly ReplCodeMenuEntry mi = new ReplCodeMenuEntry("mi", "Current minute"); + public static readonly ReplCodeMenuEntry s = new ReplCodeMenuEntry("s", "Current second"); + public static readonly ReplCodeMenuEntry ms = new ReplCodeMenuEntry("ms", "Current millisecond"); + public static readonly ReplCodeMenuEntry pm = new ReplCodeMenuEntry("pm", "Gets AM/PM"); + public static readonly ReplCodeMenuEntry w = new ReplCodeMenuEntry("w", "Current week name (Local language)"); + public static readonly ReplCodeMenuEntry w2 = new ReplCodeMenuEntry("w2", "Current week name (English)"); + public static readonly ReplCodeMenuEntry unix = new ReplCodeMenuEntry("unix", "Unix timestamp"); + public static readonly ReplCodeMenuEntry i = new ReplCodeMenuEntry("i", "Auto increment number"); + public static readonly ReplCodeMenuEntry rn = new ReplCodeMenuEntry("rn", "Random number 0 to 9"); + public static readonly ReplCodeMenuEntry ra = new ReplCodeMenuEntry("ra", "Random alphanumeric char"); + public static readonly ReplCodeMenuEntry width = new ReplCodeMenuEntry("width", "Gets image width"); + public static readonly ReplCodeMenuEntry height = new ReplCodeMenuEntry("height", "Gets image height"); + public static readonly ReplCodeMenuEntry un = new ReplCodeMenuEntry("un", "User name"); + public static readonly ReplCodeMenuEntry uln = new ReplCodeMenuEntry("uln", "User login name"); + public static readonly ReplCodeMenuEntry cn = new ReplCodeMenuEntry("cn", "Computer name"); + public static readonly ReplCodeMenuEntry n = new ReplCodeMenuEntry("n", "New line"); } public enum NameParserType @@ -144,12 +114,12 @@ public string Parse(string pattern) { windowText = windowText.Remove(MaxTitleLength); } - sb.Replace(ReplacementVariables.t.ToPrefixString(), windowText); + sb.Replace(ReplCodeMenuEntry.t.ToPrefixString(), windowText); } if (ProcessName != null) { - sb.Replace(ReplacementVariables.pn.ToPrefixString(), ProcessName); + sb.Replace(ReplCodeMenuEntry.pn.ToPrefixString(), ProcessName); } string width = string.Empty, height = string.Empty; @@ -160,20 +130,20 @@ public string Parse(string pattern) height = Picture.Height.ToString(); } - sb.Replace(ReplacementVariables.width.ToPrefixString(), width); - sb.Replace(ReplacementVariables.height.ToPrefixString(), height); + sb.Replace(ReplCodeMenuEntry.width.ToPrefixString(), width); + sb.Replace(ReplCodeMenuEntry.height.ToPrefixString(), height); DateTime dt = DateTime.Now; - sb.Replace(ReplacementVariables.mon2.ToPrefixString(), CultureInfo.InvariantCulture.DateTimeFormat.GetMonthName(dt.Month)) - .Replace(ReplacementVariables.mon.ToPrefixString(), CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(dt.Month)) - .Replace(ReplacementVariables.y.ToPrefixString(), dt.Year.ToString()) - .Replace(ReplacementVariables.mo.ToPrefixString(), Helpers.AddZeroes(dt.Month)) - .Replace(ReplacementVariables.d.ToPrefixString(), Helpers.AddZeroes(dt.Day)); + sb.Replace(ReplCodeMenuEntry.mon2.ToPrefixString(), CultureInfo.InvariantCulture.DateTimeFormat.GetMonthName(dt.Month)) + .Replace(ReplCodeMenuEntry.mon.ToPrefixString(), CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(dt.Month)) + .Replace(ReplCodeMenuEntry.y.ToPrefixString(), dt.Year.ToString()) + .Replace(ReplCodeMenuEntry.mo.ToPrefixString(), Helpers.AddZeroes(dt.Month)) + .Replace(ReplCodeMenuEntry.d.ToPrefixString(), Helpers.AddZeroes(dt.Day)); string hour; - if (sb.ToString().Contains(ReplacementVariables.pm.ToPrefixString())) + if (sb.ToString().Contains(ReplCodeMenuEntry.pm.ToPrefixString())) { hour = Helpers.HourTo12(dt.Hour); } @@ -182,35 +152,35 @@ public string Parse(string pattern) hour = Helpers.AddZeroes(dt.Hour); } - sb.Replace(ReplacementVariables.h.ToPrefixString(), hour) - .Replace(ReplacementVariables.mi.ToPrefixString(), Helpers.AddZeroes(dt.Minute)) - .Replace(ReplacementVariables.s.ToPrefixString(), Helpers.AddZeroes(dt.Second)) - .Replace(ReplacementVariables.ms.ToPrefixString(), Helpers.AddZeroes(dt.Millisecond, 3)) - .Replace(ReplacementVariables.w2.ToPrefixString(), CultureInfo.InvariantCulture.DateTimeFormat.GetDayName(dt.DayOfWeek)) - .Replace(ReplacementVariables.w.ToPrefixString(), CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(dt.DayOfWeek)) - .Replace(ReplacementVariables.pm.ToPrefixString(), (dt.Hour >= 12 ? "PM" : "AM")); + sb.Replace(ReplCodeMenuEntry.h.ToPrefixString(), hour) + .Replace(ReplCodeMenuEntry.mi.ToPrefixString(), Helpers.AddZeroes(dt.Minute)) + .Replace(ReplCodeMenuEntry.s.ToPrefixString(), Helpers.AddZeroes(dt.Second)) + .Replace(ReplCodeMenuEntry.ms.ToPrefixString(), Helpers.AddZeroes(dt.Millisecond, 3)) + .Replace(ReplCodeMenuEntry.w2.ToPrefixString(), CultureInfo.InvariantCulture.DateTimeFormat.GetDayName(dt.DayOfWeek)) + .Replace(ReplCodeMenuEntry.w.ToPrefixString(), CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(dt.DayOfWeek)) + .Replace(ReplCodeMenuEntry.pm.ToPrefixString(), (dt.Hour >= 12 ? "PM" : "AM")); - sb.Replace(ReplacementVariables.unix.ToPrefixString(), DateTime.UtcNow.ToUnix().ToString()); + sb.Replace(ReplCodeMenuEntry.unix.ToPrefixString(), DateTime.UtcNow.ToUnix().ToString()); - if (sb.ToString().Contains(ReplacementVariables.i.ToPrefixString())) + if (sb.ToString().Contains(ReplCodeMenuEntry.i.ToPrefixString())) { AutoIncrementNumber++; - sb.Replace(ReplacementVariables.i.ToPrefixString(), AutoIncrementNumber.ToString()); + sb.Replace(ReplCodeMenuEntry.i.ToPrefixString(), AutoIncrementNumber.ToString()); } - sb.Replace(ReplacementVariables.un.ToPrefixString(), Environment.UserName); - sb.Replace(ReplacementVariables.uln.ToPrefixString(), Environment.UserDomainName); - sb.Replace(ReplacementVariables.cn.ToPrefixString(), Environment.MachineName); + sb.Replace(ReplCodeMenuEntry.un.ToPrefixString(), Environment.UserName); + sb.Replace(ReplCodeMenuEntry.uln.ToPrefixString(), Environment.UserDomainName); + sb.Replace(ReplCodeMenuEntry.cn.ToPrefixString(), Environment.MachineName); if (Type == NameParserType.Text) { - sb.Replace(ReplacementVariables.n.ToPrefixString(), Environment.NewLine); + sb.Replace(ReplCodeMenuEntry.n.ToPrefixString(), Environment.NewLine); } string result = sb.ToString(); - result = result.ReplaceAll(ReplacementVariables.rn.ToPrefixString(), () => Helpers.GetRandomChar(Helpers.Numbers).ToString()); - result = result.ReplaceAll(ReplacementVariables.ra.ToPrefixString(), () => Helpers.GetRandomChar(Helpers.Alphanumeric).ToString()); + result = result.ReplaceAll(ReplCodeMenuEntry.rn.ToPrefixString(), () => Helpers.GetRandomChar(Helpers.Numbers).ToString()); + result = result.ReplaceAll(ReplCodeMenuEntry.ra.ToPrefixString(), () => Helpers.GetRandomChar(Helpers.Alphanumeric).ToString()); if (Type == NameParserType.FolderPath) { @@ -236,64 +206,5 @@ public string Parse(string pattern) return result; } - - public static ContextMenuStrip CreateCodesMenu(TextBox tb, params ReplacementVariables[] ignoreList) - { - ContextMenuStrip cms = new ContextMenuStrip - { - Font = new Font("Lucida Console", 8), - AutoClose = false, - Opacity = 0.9, - ShowImageMargin = false - }; - - var variables = Helpers.GetEnums().Where(x => !ignoreList.Contains(x)). - Select(x => new - { - Name = ReplacementExtension.Prefix + Enum.GetName(typeof(ReplacementVariables), x), - Description = x.GetDescription(), - Enum = x - }); - - foreach (var variable in variables) - { - ToolStripMenuItem tsmi = new ToolStripMenuItem { Text = string.Format("{0} - {1}", variable.Name, variable.Description), Tag = variable.Name }; - tsmi.Click += (sender, e) => - { - string text = ((ToolStripMenuItem)sender).Tag.ToString(); - tb.AppendTextToSelection(text); - }; - cms.Items.Add(tsmi); - } - - cms.Items.Add(new ToolStripSeparator()); - - ToolStripMenuItem tsmiClose = new ToolStripMenuItem("Close"); - tsmiClose.Click += (sender, e) => cms.Close(); - cms.Items.Add(tsmiClose); - - tb.MouseDown += (sender, e) => - { - if (cms.Items.Count > 0) cms.Show(tb, new Point(tb.Width + 1, 0)); - }; - - tb.Leave += (sender, e) => - { - if (cms.Visible) cms.Close(); - }; - - tb.KeyDown += (sender, e) => - { - if ((e.KeyCode == Keys.Enter || e.KeyCode == Keys.Escape) && cms.Visible) - { - cms.Close(); - e.SuppressKeyPress = true; - } - }; - - tb.Disposed += (sender, e) => cms.Dispose(); - - return cms; - } } } \ No newline at end of file diff --git a/ImageEffectsLib/WatermarkForm.cs b/ImageEffectsLib/WatermarkForm.cs index ab9b758a4..6300243c1 100644 --- a/ImageEffectsLib/WatermarkForm.cs +++ b/ImageEffectsLib/WatermarkForm.cs @@ -41,7 +41,7 @@ public WatermarkForm(WatermarkConfig watermarkConfig) { InitializeComponent(); config = watermarkConfig; - NameParser.CreateCodesMenu(txtWatermarkText, ReplacementVariables.t, ReplacementVariables.pn); + CodeMenu.Create(txtWatermarkText, ReplCodeMenuEntry.t, ReplCodeMenuEntry.pn); } private void WatermarkUI_Load(object sender, EventArgs e) diff --git a/ShareX/Forms/ApplicationSettingsForm.cs b/ShareX/Forms/ApplicationSettingsForm.cs index c993a990f..b84c06f8b 100644 --- a/ShareX/Forms/ApplicationSettingsForm.cs +++ b/ShareX/Forms/ApplicationSettingsForm.cs @@ -69,8 +69,8 @@ private void LoadSettings() cbUseCustomScreenshotsPath.Checked = Program.Settings.UseCustomScreenshotsPath; txtCustomScreenshotsPath.Text = Program.Settings.CustomScreenshotsPath; txtSaveImageSubFolderPattern.Text = Program.Settings.SaveImageSubFolderPattern; - NameParser.CreateCodesMenu(txtSaveImageSubFolderPattern, ReplacementVariables.t, ReplacementVariables.pn, ReplacementVariables.i, - ReplacementVariables.width, ReplacementVariables.height, ReplacementVariables.n); + CodeMenu.Create(txtSaveImageSubFolderPattern, ReplCodeMenuEntry.t, ReplCodeMenuEntry.pn, ReplCodeMenuEntry.i, + ReplCodeMenuEntry.width, ReplCodeMenuEntry.height, ReplCodeMenuEntry.n); // Proxy cbProxyMethod.Items.AddRange(Enum.GetNames(typeof(ProxyMethod))); diff --git a/ShareX/Forms/ClipboardFormatForm.cs b/ShareX/Forms/ClipboardFormatForm.cs index 70527931b..e101b3297 100644 --- a/ShareX/Forms/ClipboardFormatForm.cs +++ b/ShareX/Forms/ClipboardFormatForm.cs @@ -44,7 +44,7 @@ public ClipboardFormatForm(ClipboardFormat cbf) ClipboardFormat = cbf; txtDescription.Text = cbf.Description ?? ""; txtFormat.Text = cbf.Format ?? ""; - NameParser.CreateCodesMenu(txtFormat); + CodeMenu.Create(txtFormat); lblExample.Text = "Supported variables: $result, $url, $shorturl, $thumbnailurl, $deletionurl, $filepath, $filename, $filenamenoext, $thumbnailfilename, $thumbnailfilenamenoext, $folderpath, $foldername, $uploadtime and other variables such as %y-%mo-%d etc."; } diff --git a/ShareX/Forms/ExternalProgramForm.Designer.cs b/ShareX/Forms/ExternalProgramForm.Designer.cs index 642307d58..d6c8863cf 100644 --- a/ShareX/Forms/ExternalProgramForm.Designer.cs +++ b/ShareX/Forms/ExternalProgramForm.Designer.cs @@ -37,6 +37,8 @@ private void InitializeComponent() this.btnPathBrowse = new System.Windows.Forms.Button(); this.btnOK = new System.Windows.Forms.Button(); this.btnCancel = new System.Windows.Forms.Button(); + this.lblExtensions = new System.Windows.Forms.Label(); + this.txtExtensions = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // lblName @@ -99,7 +101,7 @@ private void InitializeComponent() // // btnOK // - this.btnOK.Location = new System.Drawing.Point(160, 88); + this.btnOK.Location = new System.Drawing.Point(156, 125); this.btnOK.Name = "btnOK"; this.btnOK.Size = new System.Drawing.Size(75, 23); this.btnOK.TabIndex = 7; @@ -109,7 +111,7 @@ private void InitializeComponent() // // btnCancel // - this.btnCancel.Location = new System.Drawing.Point(240, 88); + this.btnCancel.Location = new System.Drawing.Point(237, 125); this.btnCancel.Name = "btnCancel"; this.btnCancel.Size = new System.Drawing.Size(75, 23); this.btnCancel.TabIndex = 8; @@ -117,12 +119,30 @@ private void InitializeComponent() this.btnCancel.UseVisualStyleBackColor = true; this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); // + // lblExtensions + // + this.lblExtensions.AutoSize = true; + this.lblExtensions.Location = new System.Drawing.Point(16, 88); + this.lblExtensions.Name = "lblExtensions"; + this.lblExtensions.Size = new System.Drawing.Size(61, 13); + this.lblExtensions.TabIndex = 9; + this.lblExtensions.Text = "Extensions:"; + // + // txtExtensions + // + this.txtExtensions.Location = new System.Drawing.Point(88, 85); + this.txtExtensions.Name = "txtExtensions"; + this.txtExtensions.Size = new System.Drawing.Size(224, 20); + this.txtExtensions.TabIndex = 10; + // // ExternalProgramForm // this.AcceptButton = this.btnOK; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(327, 121); + this.ClientSize = new System.Drawing.Size(327, 160); + this.Controls.Add(this.txtExtensions); + this.Controls.Add(this.lblExtensions); this.Controls.Add(this.btnCancel); this.Controls.Add(this.btnOK); this.Controls.Add(this.btnPathBrowse); @@ -152,5 +172,7 @@ private void InitializeComponent() private System.Windows.Forms.Button btnPathBrowse; private System.Windows.Forms.Button btnOK; private System.Windows.Forms.Button btnCancel; + private System.Windows.Forms.Label lblExtensions; + private System.Windows.Forms.TextBox txtExtensions; } } \ No newline at end of file diff --git a/ShareX/Forms/ExternalProgramForm.cs b/ShareX/Forms/ExternalProgramForm.cs index ffca8aa90..c1c8eb678 100644 --- a/ShareX/Forms/ExternalProgramForm.cs +++ b/ShareX/Forms/ExternalProgramForm.cs @@ -45,6 +45,8 @@ public ExternalProgramForm(ExternalProgram fileAction) txtName.Text = fileAction.Name ?? ""; txtPath.Text = fileAction.Path ?? ""; txtArguments.Text = fileAction.Args ?? ""; + CodeMenu.Create(txtExtensions); + txtExtensions.Text = fileAction.Extensions ?? ""; } private void btnPathBrowse_Click(object sender, EventArgs e) @@ -57,6 +59,7 @@ private void btnOK_Click(object sender, EventArgs e) FileAction.Name = txtName.Text; FileAction.Path = txtPath.Text; FileAction.Args = txtArguments.Text; + FileAction.Extensions = txtExtensions.Text; DialogResult = DialogResult.OK; } diff --git a/ShareX/Forms/TaskSettingsForm.Designer.cs b/ShareX/Forms/TaskSettingsForm.Designer.cs index 2172f7b24..96f9936ba 100644 --- a/ShareX/Forms/TaskSettingsForm.Designer.cs +++ b/ShareX/Forms/TaskSettingsForm.Designer.cs @@ -171,6 +171,7 @@ private void InitializeComponent() this.tpAdvanced = new System.Windows.Forms.TabPage(); this.pgTaskSettings = new System.Windows.Forms.PropertyGrid(); this.chkUseDefaultAdvancedSettings = new System.Windows.Forms.CheckBox(); + this.chActionsExtensions = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.tcHotkeySettings.SuspendLayout(); this.tpTask.SuspendLayout(); this.cmsDestinations.SuspendLayout(); @@ -391,41 +392,41 @@ private void InitializeComponent() this.tsmiURLShorteners, this.tsmiURLSharingServices}); this.cmsDestinations.Name = "cmsDestinations"; - this.cmsDestinations.Size = new System.Drawing.Size(182, 114); + this.cmsDestinations.Size = new System.Drawing.Size(174, 114); // // tsmiImageUploaders // this.tsmiImageUploaders.Image = global::ShareX.Properties.Resources.image; this.tsmiImageUploaders.Name = "tsmiImageUploaders"; - this.tsmiImageUploaders.Size = new System.Drawing.Size(181, 22); + this.tsmiImageUploaders.Size = new System.Drawing.Size(173, 22); this.tsmiImageUploaders.Text = "Image uploaders"; // // tsmiTextUploaders // this.tsmiTextUploaders.Image = global::ShareX.Properties.Resources.notebook; this.tsmiTextUploaders.Name = "tsmiTextUploaders"; - this.tsmiTextUploaders.Size = new System.Drawing.Size(181, 22); + this.tsmiTextUploaders.Size = new System.Drawing.Size(173, 22); this.tsmiTextUploaders.Text = "Text uploaders"; // // tsmiFileUploaders // this.tsmiFileUploaders.Image = global::ShareX.Properties.Resources.application_block; this.tsmiFileUploaders.Name = "tsmiFileUploaders"; - this.tsmiFileUploaders.Size = new System.Drawing.Size(181, 22); + this.tsmiFileUploaders.Size = new System.Drawing.Size(173, 22); this.tsmiFileUploaders.Text = "File uploaders"; // // tsmiURLShorteners // this.tsmiURLShorteners.Image = global::ShareX.Properties.Resources.edit_scale; this.tsmiURLShorteners.Name = "tsmiURLShorteners"; - this.tsmiURLShorteners.Size = new System.Drawing.Size(181, 22); + this.tsmiURLShorteners.Size = new System.Drawing.Size(173, 22); this.tsmiURLShorteners.Text = "URL shorteners"; // // tsmiURLSharingServices // this.tsmiURLSharingServices.Image = global::ShareX.Properties.Resources.globe_share; this.tsmiURLSharingServices.Name = "tsmiURLSharingServices"; - this.tsmiURLSharingServices.Size = new System.Drawing.Size(181, 22); + this.tsmiURLSharingServices.Size = new System.Drawing.Size(173, 22); this.tsmiURLSharingServices.Text = "URL sharing services"; // // btnTask @@ -1468,7 +1469,8 @@ private void InitializeComponent() this.lvActions.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.chActionsName, this.chActionsPath, - this.chActionsArgs}); + this.chActionsArgs, + this.chActionsExtensions}); this.lvActions.FullRowSelect = true; this.lvActions.Location = new System.Drawing.Point(8, 40); this.lvActions.MultiSelect = false; @@ -1482,17 +1484,17 @@ private void InitializeComponent() // chActionsName // this.chActionsName.Text = "Name"; - this.chActionsName.Width = 100; + this.chActionsName.Width = 90; // // chActionsPath // this.chActionsPath.Text = "Path"; - this.chActionsPath.Width = 250; + this.chActionsPath.Width = 220; // // chActionsArgs // this.chActionsArgs.Text = "Args"; - this.chActionsArgs.Width = 134; + this.chActionsArgs.Width = 114; // // btnActionsEdit // @@ -1737,7 +1739,7 @@ private void InitializeComponent() this.cbClipboardUploadShareURL.AutoSize = true; this.cbClipboardUploadShareURL.Location = new System.Drawing.Point(16, 64); this.cbClipboardUploadShareURL.Name = "cbClipboardUploadShareURL"; - this.cbClipboardUploadShareURL.Size = new System.Drawing.Size(366, 17); + this.cbClipboardUploadShareURL.Size = new System.Drawing.Size(343, 17); this.cbClipboardUploadShareURL.TabIndex = 3; this.cbClipboardUploadShareURL.Text = "If clipboard contains a URL then share it using URL sharing service"; this.cbClipboardUploadShareURL.UseVisualStyleBackColor = true; @@ -1865,6 +1867,11 @@ private void InitializeComponent() this.chkUseDefaultAdvancedSettings.UseVisualStyleBackColor = true; this.chkUseDefaultAdvancedSettings.CheckedChanged += new System.EventHandler(this.chkUseDefaultAdvancedSettings_CheckedChanged); // + // chActionsExtensions + // + this.chActionsExtensions.Text = "Extensions"; + this.chActionsExtensions.Width = 75; + // // TaskSettingsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -2080,6 +2087,7 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox cbClipboardUploadShareURL; private System.Windows.Forms.TabPage tpRectangleAnnotate; private System.Windows.Forms.PropertyGrid pgRectangleAnnotate; + private System.Windows.Forms.ColumnHeader chActionsExtensions; diff --git a/ShareX/Forms/TaskSettingsForm.cs b/ShareX/Forms/TaskSettingsForm.cs index 8a53598db..688fd8511 100644 --- a/ShareX/Forms/TaskSettingsForm.cs +++ b/ShareX/Forms/TaskSettingsForm.cs @@ -199,8 +199,8 @@ public TaskSettingsForm(TaskSettings hotkeySetting, bool isDefault = false) // Upload / Name pattern txtNameFormatPattern.Text = TaskSettings.UploadSettings.NameFormatPattern; txtNameFormatPatternActiveWindow.Text = TaskSettings.UploadSettings.NameFormatPatternActiveWindow; - NameParser.CreateCodesMenu(txtNameFormatPattern, ReplacementVariables.n); - NameParser.CreateCodesMenu(txtNameFormatPatternActiveWindow, ReplacementVariables.n); + CodeMenu.Create(txtNameFormatPattern, ReplCodeMenuEntry.n); + CodeMenu.Create(txtNameFormatPatternActiveWindow, ReplCodeMenuEntry.n); cbFileUploadUseNamePattern.Checked = TaskSettings.UploadSettings.FileUploadUseNamePattern; // Upload / Clipboard upload @@ -798,6 +798,7 @@ private void AddFileAction(ExternalProgram fileAction) lvi.Checked = fileAction.IsActive; lvi.SubItems.Add(fileAction.Path ?? ""); lvi.SubItems.Add(fileAction.Args ?? ""); + lvi.SubItems.Add(fileAction.Extensions ?? ""); lvActions.Items.Add(lvi); } @@ -815,6 +816,7 @@ private void btnActionsEdit_Click(object sender, EventArgs e) lvi.Text = fileAction.Name ?? ""; lvi.SubItems[1].Text = fileAction.Path ?? ""; lvi.SubItems[2].Text = fileAction.Args ?? ""; + lvi.SubItems[3].Text = fileAction.Extensions ?? ""; } } } diff --git a/UploadersLib/Forms/UploadersConfigForm.cs b/UploadersLib/Forms/UploadersConfigForm.cs index 6ae5b46af..fc1961635 100644 --- a/UploadersLib/Forms/UploadersConfigForm.cs +++ b/UploadersLib/Forms/UploadersConfigForm.cs @@ -111,11 +111,11 @@ private void FormSettings() ttlvMain.MainTabControl = tcUploaders; ttlvMain.FocusListView(); - NameParser.CreateCodesMenu(txtDropboxPath, ReplacementVariables.n, ReplacementVariables.t, ReplacementVariables.pn); - NameParser.CreateCodesMenu(txtCopyPath, ReplacementVariables.n, ReplacementVariables.t, ReplacementVariables.pn); - NameParser.CreateCodesMenu(txtAmazonS3ObjectPrefix, ReplacementVariables.n, ReplacementVariables.t, ReplacementVariables.pn); - NameParser.CreateCodesMenu(txtMediaFirePath, ReplacementVariables.n, ReplacementVariables.t, ReplacementVariables.pn); - NameParser.CreateCodesMenu(txtCustomUploaderArgValue, ReplacementVariables.n); + CodeMenu.Create(txtDropboxPath, ReplCodeMenuEntry.n, ReplCodeMenuEntry.t, ReplCodeMenuEntry.pn); + CodeMenu.Create(txtCopyPath, ReplCodeMenuEntry.n, ReplCodeMenuEntry.t, ReplCodeMenuEntry.pn); + CodeMenu.Create(txtAmazonS3ObjectPrefix, ReplCodeMenuEntry.n, ReplCodeMenuEntry.t, ReplCodeMenuEntry.pn); + CodeMenu.Create(txtMediaFirePath, ReplCodeMenuEntry.n, ReplCodeMenuEntry.t, ReplCodeMenuEntry.pn); + CodeMenu.Create(txtCustomUploaderArgValue, ReplCodeMenuEntry.n); txtCustomUploaderLog.AddContextMenu();