Exemplo n.º 1
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);
        }