diff --git a/.editorconfig b/.editorconfig index e5dcee46c..85430333b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,7 +9,6 @@ insert_final_newline = false # C# files [*.cs] indent_size = 4 -charset = utf-8 # Xml project files [*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] diff --git a/ShareX.HelpersLib/NameParser/CodeMenu.cs b/ShareX.HelpersLib/NameParser/CodeMenu.cs index 8a689a19c..9668866a7 100644 --- a/ShareX.HelpersLib/NameParser/CodeMenu.cs +++ b/ShareX.HelpersLib/NameParser/CodeMenu.cs @@ -24,6 +24,7 @@ #endregion License Information (GPL v3) using ShareX.HelpersLib.Properties; +using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms; @@ -33,6 +34,11 @@ namespace ShareX.HelpersLib public static class CodeMenu { public static ContextMenuStrip Create(TextBox tb, params TEntry[] ignoreList) where TEntry : CodeMenuEntry + { + return Create(tb, ignoreList, (CodeMenuItem[])null); + } + + public static ContextMenuStrip Create(TextBox tb, TEntry[] ignoreList, CodeMenuItem[] extraItems) where TEntry : CodeMenuEntry { ContextMenuStrip cms = new ContextMenuStrip { @@ -42,34 +48,38 @@ public static class CodeMenu ShowImageMargin = false }; - var variables = Helpers.GetValueFields().Where(x => !ignoreList.Contains(x)). - Select(x => new - { - Name = x.ToPrefixString(), - Description = x.Description, - Category = x.Category - }); + List items = new List(); - foreach (var variable in variables) + if (extraItems != null) { - ToolStripMenuItem tsmi = new ToolStripMenuItem { Text = string.Format("{0} - {1}", variable.Name, variable.Description), Tag = variable.Name }; + items.AddRange(extraItems); + } + + var variables = Helpers.GetValueFields().Where(x => !ignoreList.Contains(x)). + Select(x => new CodeMenuItem(x.ToPrefixString(), x.Description, x.Category)); + + items.AddRange(variables); + + foreach (var item in items) + { + ToolStripMenuItem tsmi = new ToolStripMenuItem { Text = $"{item.Name} - {item.Description}", Tag = item.Name }; tsmi.Click += (sender, e) => { string text = ((ToolStripMenuItem)sender).Tag.ToString(); tb.AppendTextToSelection(text); }; - if (string.IsNullOrWhiteSpace(variable.Category)) + if (string.IsNullOrWhiteSpace(item.Category)) { cms.Items.Add(tsmi); } else { ToolStripMenuItem tsmiParent; - int index = cms.Items.IndexOfKey(variable.Category); + int index = cms.Items.IndexOfKey(item.Category); if (0 > index) { - tsmiParent = new ToolStripMenuItem { Text = variable.Category, Tag = variable.Category, Name = variable.Category }; + tsmiParent = new ToolStripMenuItem { Text = item.Category, Tag = item.Category, Name = item.Category }; tsmiParent.HideImageMargin(); cms.Items.Add(tsmiParent); } diff --git a/ShareX.HelpersLib/NameParser/CodeMenuItem.cs b/ShareX.HelpersLib/NameParser/CodeMenuItem.cs new file mode 100644 index 000000000..771ab3222 --- /dev/null +++ b/ShareX.HelpersLib/NameParser/CodeMenuItem.cs @@ -0,0 +1,46 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2017 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ShareX.HelpersLib +{ + public class CodeMenuItem + { + public string Name { get; set; } + public string Description { get; set; } + public string Category { get; set; } + + public CodeMenuItem(string name, string description, string category = null) + { + Name = name; + Description = description; + Category = category; + } + } +} \ No newline at end of file diff --git a/ShareX.HelpersLib/ShareX.HelpersLib.csproj b/ShareX.HelpersLib/ShareX.HelpersLib.csproj index 8c7bfc492..368f741a2 100644 --- a/ShareX.HelpersLib/ShareX.HelpersLib.csproj +++ b/ShareX.HelpersLib/ShareX.HelpersLib.csproj @@ -205,6 +205,7 @@ + Form diff --git a/ShareX.UploadersLib/Forms/UploadersConfigForm.cs b/ShareX.UploadersLib/Forms/UploadersConfigForm.cs index 9f2585d9e..b2b766f26 100644 --- a/ShareX.UploadersLib/Forms/UploadersConfigForm.cs +++ b/ShareX.UploadersLib/Forms/UploadersConfigForm.cs @@ -95,8 +95,13 @@ private void InitializeControls() CodeMenu.Create(txtDropboxPath, CodeMenuEntryFilename.n, CodeMenuEntryFilename.t, CodeMenuEntryFilename.pn); CodeMenu.Create(txtAmazonS3ObjectPrefix, CodeMenuEntryFilename.n, CodeMenuEntryFilename.t, CodeMenuEntryFilename.pn); CodeMenu.Create(txtMediaFirePath, CodeMenuEntryFilename.n, CodeMenuEntryFilename.t, CodeMenuEntryFilename.pn); - CodeMenu.Create(txtCustomUploaderArgValue, CodeMenuEntryFilename.n, CodeMenuEntryFilename.t, CodeMenuEntryFilename.pn); - CodeMenu.Create(txtCustomUploaderHeaderValue, CodeMenuEntryFilename.n, CodeMenuEntryFilename.t, CodeMenuEntryFilename.pn); + + CodeMenuItem customUploaderInput = new CodeMenuItem("$input$", "Text/URL input"); + + CodeMenu.Create(txtCustomUploaderArgValue, + new CodeMenuEntryFilename[] { CodeMenuEntryFilename.n, CodeMenuEntryFilename.t, CodeMenuEntryFilename.pn }, new CodeMenuItem[] { customUploaderInput }); + CodeMenu.Create(txtCustomUploaderHeaderValue, + new CodeMenuEntryFilename[] { CodeMenuEntryFilename.n, CodeMenuEntryFilename.t, CodeMenuEntryFilename.pn }, new CodeMenuItem[] { customUploaderInput }); // FTP cbFTPURLPathProtocol.Items.AddRange(Helpers.GetEnumDescriptions());