Beispiel #1
0
        public virtual bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
        {
            Control control = browserControl.AsControl();

            switch (commandId)
            {
            case MenuOpenLinkUrl:
                OpenBrowser(control, Context.LinkUrl);
                break;

            case MenuCopyLinkUrl:
                SetClipboardText(control, Context.UnsafeLinkUrl);
                break;

            case MenuCopyUsername: {
                string url   = Context.UnsafeLinkUrl;
                Match  match = TwitterUtils.RegexAccount.Match(url);

                SetClipboardText(control, match.Success ? match.Groups[1].Value : url);
                control.InvokeAsyncSafe(analytics.AnalyticsFile.CopiedUsernames.Trigger);
                break;
            }

            case MenuOpenMediaUrl:
                OpenBrowser(control, TwitterUtils.GetMediaLink(Context.MediaUrl, ImageQuality));
                break;

            case MenuCopyMediaUrl:
                SetClipboardText(control, TwitterUtils.GetMediaLink(Context.MediaUrl, ImageQuality));
                break;

            case MenuViewImage: {
                string url = Context.MediaUrl;

                control.InvokeAsyncSafe(() => {
                        TwitterUtils.ViewImage(url, ImageQuality);
                        analytics.AnalyticsFile.ViewedImages.Trigger();
                    });

                break;
            }

            case MenuSaveMedia: {
                bool   isVideo  = Context.Types.HasFlag(ContextInfo.ContextType.Video);
                string url      = Context.MediaUrl;
                string username = Context.Chirp.Authors.LastOrDefault();

                control.InvokeAsyncSafe(() => {
                        if (isVideo)
                        {
                            TwitterUtils.DownloadVideo(url, username);
                            analytics.AnalyticsFile.DownloadedVideos.Trigger();
                        }
                        else
                        {
                            TwitterUtils.DownloadImage(url, username, ImageQuality);
                            analytics.AnalyticsFile.DownloadedImages.Trigger();
                        }
                    });

                break;
            }

            case MenuSaveTweetImages: {
                string[] urls     = Context.Chirp.Images;
                string   username = Context.Chirp.Authors.LastOrDefault();

                control.InvokeAsyncSafe(() => {
                        TwitterUtils.DownloadImages(urls, username, ImageQuality);
                        analytics.AnalyticsFile.DownloadedImages.Trigger();
                    });

                break;
            }

            case MenuReadApplyROT13:
                string selection = parameters.SelectionText;
                control.InvokeAsyncSafe(() => FormMessage.Information("ROT13", StringUtils.ConvertRot13(selection), FormMessage.OK));
                control.InvokeAsyncSafe(analytics.AnalyticsFile.UsedROT13.Trigger);
                return(true);

            case MenuSearchInBrowser:
                string query = parameters.SelectionText;
                control.InvokeAsyncSafe(() => BrowserUtils.OpenExternalSearch(query));
                DeselectAll(frame);
                break;

            case MenuOpenDevTools:
                browserControl.ShowDevTools();
                break;
            }

            return(false);
        }