diff --git a/Core/Handling/ContextMenuBase.cs b/Core/Handling/ContextMenuBase.cs index a3da730f..7ccab7f9 100644 --- a/Core/Handling/ContextMenuBase.cs +++ b/Core/Handling/ContextMenuBase.cs @@ -28,6 +28,7 @@ abstract class ContextMenuBase : IContextMenuHandler{ private const CefMenuCommand MenuSaveMedia = (CefMenuCommand)26506; private const CefMenuCommand MenuSaveTweetImages = (CefMenuCommand)26507; private const CefMenuCommand MenuSearchInBrowser = (CefMenuCommand)26508; + private const CefMenuCommand MenuReadApplyROT13 = (CefMenuCommand)26509; private const CefMenuCommand MenuOpenDevTools = (CefMenuCommand)26599; protected ContextInfo.LinkInfo LastLink { get; private set; } @@ -57,6 +58,8 @@ public virtual void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser bro if (parameters.TypeFlags.HasFlag(ContextMenuType.Selection) && !parameters.TypeFlags.HasFlag(ContextMenuType.Editable)){ model.AddItem(MenuSearchInBrowser, "Search in browser"); model.AddSeparator(); + model.AddItem(MenuReadApplyROT13, "Apply ROT13"); + model.AddSeparator(); } bool hasTweetImage = LastLink.IsImage; @@ -173,6 +176,11 @@ void ViewImage(string path){ TwitterUtils.DownloadImages(LastChirp.Images, LastChirp.Authors.LastOrDefault(), ImageQuality); break; + case MenuReadApplyROT13: + string selection = parameters.SelectionText; + control.InvokeAsyncSafe(() => FormMessage.Information("ROT13", StringUtils.ConvertRot13(selection), FormMessage.OK)); + return true; + case MenuSearchInBrowser: string query = parameters.SelectionText; control.InvokeAsyncSafe(() => BrowserUtils.OpenExternalSearch(query)); diff --git a/Core/Handling/ContextMenuBrowser.cs b/Core/Handling/ContextMenuBrowser.cs index 4515ad4f..d754960a 100644 --- a/Core/Handling/ContextMenuBrowser.cs +++ b/Core/Handling/ContextMenuBrowser.cs @@ -16,7 +16,7 @@ sealed class ContextMenuBrowser : ContextMenuBase{ private const CefMenuCommand MenuOpenQuotedTweetUrl = (CefMenuCommand)26612; private const CefMenuCommand MenuCopyQuotedTweetUrl = (CefMenuCommand)26613; private const CefMenuCommand MenuScreenshotTweet = (CefMenuCommand)26614; - private const CefMenuCommand MenuInputApplyROT13 = (CefMenuCommand)26615; + private const CefMenuCommand MenuWriteApplyROT13 = (CefMenuCommand)26615; private const CefMenuCommand MenuSearchInColumn = (CefMenuCommand)26616; private const string TitleReloadBrowser = "Reload browser"; @@ -44,7 +44,7 @@ public override void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser br if (isSelecting){ if (isEditing){ model.AddSeparator(); - model.AddItem(MenuInputApplyROT13, "Apply ROT13"); + model.AddItem(MenuWriteApplyROT13, "Apply ROT13"); } model.AddSeparator(); @@ -141,7 +141,7 @@ public override bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser b SetClipboardText(form, LastChirp.QuoteUrl); return true; - case MenuInputApplyROT13: + case MenuWriteApplyROT13: form.InvokeAsyncSafe(form.ApplyROT13); return true; diff --git a/Core/Utils/StringUtils.cs b/Core/Utils/StringUtils.cs index 156c03e6..1bda5774 100644 --- a/Core/Utils/StringUtils.cs +++ b/Core/Utils/StringUtils.cs @@ -19,6 +19,14 @@ public static string ConvertPascalCaseToScreamingSnakeCase(string str){ return Regex.Replace(str, @"(\p{Ll})(\P{Ll})|(\P{Ll})(\P{Ll}\p{Ll})", "$1$3_$2$4").ToUpper(); } + public static string ConvertRot13(string str){ + return Regex.Replace(str, @"[a-zA-Z]", match => { + int code = match.Value[0]; + int start = code <= 90 ? 65 : 97; + return ((char)(start+(code-start+13)%26)).ToString(); + }); + } + public static int CountOccurrences(string source, string substring){ int count = 0, index = 0;