From 405ee48d301036a30752c6086a1e8cf29681d1bf Mon Sep 17 00:00:00 2001 From: Jaex Date: Wed, 19 Nov 2014 20:27:46 +0200 Subject: [PATCH] Text watermark context menu to show name parsing shortcuts --- HelpersLib/CodeMenu.cs | 33 ++++++++++++++ HelpersLib/HelpersLib.csproj | 1 + HelpersLib/UITypeEditors/NameParserEditor.cs | 48 ++++++++++++++++++++ ImageEffectsLib/Drawings/DrawText.cs | 2 +- 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 HelpersLib/UITypeEditors/NameParserEditor.cs diff --git a/HelpersLib/CodeMenu.cs b/HelpersLib/CodeMenu.cs index 82ad114a2..88706a717 100644 --- a/HelpersLib/CodeMenu.cs +++ b/HelpersLib/CodeMenu.cs @@ -90,5 +90,38 @@ public static ContextMenuStrip Create(TextBox tb, params TEntry[] ignore return cms; } + + public static ContextMenuStrip Create(params TEntry[] ignoreList) + where TEntry : CodeMenuEntry + { + ContextMenuStrip cms = new ContextMenuStrip + { + Font = new Font("Lucida Console", 8), + AutoClose = true, + 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 }; + cms.Items.Add(tsmi); + } + + cms.Items.Add(new ToolStripSeparator()); + + ToolStripMenuItem tsmiClose = new ToolStripMenuItem(Resources.CodeMenu_Create_Close); + tsmiClose.Click += (sender, e) => cms.Close(); + cms.Items.Add(tsmiClose); + + return cms; + } } } \ No newline at end of file diff --git a/HelpersLib/HelpersLib.csproj b/HelpersLib/HelpersLib.csproj index c26d951ca..455af2bf2 100644 --- a/HelpersLib/HelpersLib.csproj +++ b/HelpersLib/HelpersLib.csproj @@ -253,6 +253,7 @@ + diff --git a/HelpersLib/UITypeEditors/NameParserEditor.cs b/HelpersLib/UITypeEditors/NameParserEditor.cs new file mode 100644 index 000000000..030fb62ab --- /dev/null +++ b/HelpersLib/UITypeEditors/NameParserEditor.cs @@ -0,0 +1,48 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (C) 2007-2014 ShareX Developers + + 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.ComponentModel; +using System.Drawing; +using System.Drawing.Design; +using System.Windows.Forms; + +namespace HelpersLib +{ + public class NameParserEditor : UITypeEditor + { + public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) + { + return UITypeEditorEditStyle.Modal; + } + + public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) + { + Point pos = Cursor.Position; + CodeMenu.Create(ReplCodeMenuEntry.t, ReplCodeMenuEntry.pn).Show(pos.X, pos.Y); + return value; + } + } +} \ No newline at end of file diff --git a/ImageEffectsLib/Drawings/DrawText.cs b/ImageEffectsLib/Drawings/DrawText.cs index 77f61871e..19e9a08d8 100644 --- a/ImageEffectsLib/Drawings/DrawText.cs +++ b/ImageEffectsLib/Drawings/DrawText.cs @@ -57,7 +57,7 @@ public Point Offset [DefaultValue(true), Description("If text watermark size bigger than source image then don't draw it.")] public bool AutoHide { get; set; } - [DefaultValue("getsharex.com")] + [DefaultValue("getsharex.com"), Editor(typeof(NameParserEditor), typeof(UITypeEditor))] public string Text { get; set; } private FontSafe textFontSafe = new FontSafe();