1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-05 02:34:07 +02:00

Add 'Apply ROT13' to non-editable selections to allow decoding tweets

This commit is contained in:
chylex 2018-05-16 12:40:49 +02:00
parent 00bfa68a57
commit a3e9b15a8a
3 changed files with 19 additions and 3 deletions

View File

@ -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));

View File

@ -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;

View File

@ -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;