Пример #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);
        }
Пример #2
0
        public virtual bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
        {
            switch (commandId)
            {
            case MenuOpenLinkUrl:
                OpenBrowser(browserControl.AsControl(), IsLink ? ContextInfo.Value : parameters.LinkUrl);
                break;

            case MenuCopyLinkUrl:
                SetClipboardText(browserControl.AsControl(), IsLink ? ContextInfo.Value : parameters.UnfilteredLinkUrl);
                break;

            case MenuCopyUsername:
                Match match = TwitterUtils.RegexAccount.Match(parameters.UnfilteredLinkUrl);
                SetClipboardText(browserControl.AsControl(), match.Success ? match.Groups[1].Value : parameters.UnfilteredLinkUrl);
                break;

            case MenuOpenMediaUrl:
                OpenBrowser(browserControl.AsControl(), TwitterUtils.GetMediaLink(GetMediaLink(parameters), ImageQuality));
                break;

            case MenuCopyMediaUrl:
                SetClipboardText(browserControl.AsControl(), TwitterUtils.GetMediaLink(GetMediaLink(parameters), ImageQuality));
                break;

            case MenuViewImage:
                string url  = GetMediaLink(parameters);
                string file = Path.Combine(BrowserCache.CacheFolder, TwitterUtils.GetImageFileName(url));

                void ViewFile()
                {
                    string ext = Path.GetExtension(file);

                    if (TwitterUtils.ValidImageExtensions.Contains(ext))
                    {
                        WindowsUtils.OpenAssociatedProgram(file);
                    }
                    else
                    {
                        FormMessage.Error("Image Download", "Invalid file extension " + ext, FormMessage.OK);
                    }
                }

                if (File.Exists(file))
                {
                    ViewFile();
                }
                else
                {
                    BrowserUtils.DownloadFileAsync(TwitterUtils.GetMediaLink(url, ImageQuality), file, ViewFile, ex => {
                        FormMessage.Error("Image Download", "An error occurred while downloading the image: " + ex.Message, FormMessage.OK);
                    });
                }

                break;

            case MenuSaveMedia:
                if (IsVideo)
                {
                    TwitterUtils.DownloadVideo(GetMediaLink(parameters), lastHighlightedTweetAuthors.LastOrDefault());
                }
                else
                {
                    TwitterUtils.DownloadImage(GetMediaLink(parameters), lastHighlightedTweetAuthors.LastOrDefault(), ImageQuality);
                }

                break;

            case MenuSaveTweetImages:
                TwitterUtils.DownloadImages(lastHighlightedTweetImageList, lastHighlightedTweetAuthors.LastOrDefault(), ImageQuality);
                break;

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

            return(false);
        }