Added Text/URL input to custom uploader arguments/headers value auto complete list

This commit is contained in:
Jaex 2017-08-18 22:50:47 +03:00
parent f295d58a6a
commit 46b3ccebfd
5 changed files with 76 additions and 15 deletions

View file

@ -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}]

View file

@ -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<TEntry>(TextBox tb, params TEntry[] ignoreList) where TEntry : CodeMenuEntry
{
return Create(tb, ignoreList, (CodeMenuItem[])null);
}
public static ContextMenuStrip Create<TEntry>(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<TEntry>().Where(x => !ignoreList.Contains(x)).
Select(x => new
{
Name = x.ToPrefixString(),
Description = x.Description,
Category = x.Category
});
List<CodeMenuItem> items = new List<CodeMenuItem>();
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<TEntry>().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);
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#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;
}
}
}

View file

@ -205,6 +205,7 @@
<Compile Include="ListViewColumnSorter.cs" />
<Compile Include="MimeTypes.cs" />
<Compile Include="NameParser\CodeMenuEntryPixelInfo.cs" />
<Compile Include="NameParser\CodeMenuItem.cs" />
<Compile Include="Native\LayeredForm.cs">
<SubType>Form</SubType>
</Compile>

View file

@ -95,8 +95,13 @@ private void InitializeControls()
CodeMenu.Create<CodeMenuEntryFilename>(txtDropboxPath, CodeMenuEntryFilename.n, CodeMenuEntryFilename.t, CodeMenuEntryFilename.pn);
CodeMenu.Create<CodeMenuEntryFilename>(txtAmazonS3ObjectPrefix, CodeMenuEntryFilename.n, CodeMenuEntryFilename.t, CodeMenuEntryFilename.pn);
CodeMenu.Create<CodeMenuEntryFilename>(txtMediaFirePath, CodeMenuEntryFilename.n, CodeMenuEntryFilename.t, CodeMenuEntryFilename.pn);
CodeMenu.Create<CodeMenuEntryFilename>(txtCustomUploaderArgValue, CodeMenuEntryFilename.n, CodeMenuEntryFilename.t, CodeMenuEntryFilename.pn);
CodeMenu.Create<CodeMenuEntryFilename>(txtCustomUploaderHeaderValue, CodeMenuEntryFilename.n, CodeMenuEntryFilename.t, CodeMenuEntryFilename.pn);
CodeMenuItem customUploaderInput = new CodeMenuItem("$input$", "Text/URL input");
CodeMenu.Create<CodeMenuEntryFilename>(txtCustomUploaderArgValue,
new CodeMenuEntryFilename[] { CodeMenuEntryFilename.n, CodeMenuEntryFilename.t, CodeMenuEntryFilename.pn }, new CodeMenuItem[] { customUploaderInput });
CodeMenu.Create<CodeMenuEntryFilename>(txtCustomUploaderHeaderValue,
new CodeMenuEntryFilename[] { CodeMenuEntryFilename.n, CodeMenuEntryFilename.t, CodeMenuEntryFilename.pn }, new CodeMenuItem[] { customUploaderInput });
// FTP
cbFTPURLPathProtocol.Items.AddRange(Helpers.GetEnumDescriptions<BrowserProtocol>());