예제 #1
0
 private void btnCustomWebBrowserPathFileDialog_Click(object sender, EventArgs e)
 {
     if (WebBrowserUtility.TrySelectWebBrowserPath(optionPage.CustomWebBrowserPath, out var newPath))
     {
         optionPage.CustomWebBrowserPath = newPath;
         txtboxCustomWebBrowserPath.Text = optionPage.CustomWebBrowserPath;
     }
 }
        public void QueryToWebBrowser(int index, string keyword, bool test = false)
        {
            var optionPage = GetDialogPage(typeof(OptionPage)) as OptionPage;
            var queryData  = optionPage.Queries[index];

            if (queryData.TemplateType == QueryTemplateType.None ||
                string.IsNullOrEmpty(queryData.QueryFormat))
            {
                return;
            }

            string errorType    = string.Empty;
            string errorMessage = null;
            string url          = null;

            try
            {
                var dte            = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
                var keywordEncoded = string.IsNullOrEmpty(keyword) ? string.Empty : WebUtility.UrlEncode(keyword);
                url = queryData.QueryFormat.Replace("{QUERY}", keywordEncoded);
                WebBrowserUtility.NavigateUrl(dte, url, optionPage.WebBrowserType, optionPage.CustomWebBrowserPath);
            }
            catch (FormatException ex)
            {
                errorMessage = string.Format("Invalid Query Format.\r\n\r\n\"{0}\"", queryData.QueryFormat);
                errorType    = ex.GetType().Name;
            }
            catch (Exception ex)
            {
                if (optionPage.WebBrowserType == WebBrowserType.CustomWebBrowser)
                {
                    errorMessage = string.Format("Invalid Custom Web Browser.\r\n\r\n\"{0}\"", optionPage.CustomWebBrowserPath);
                }
                else
                {
                    errorMessage = string.Format("Invalid Query.\r\n\r\n\"{0}\"", url);
                }
                errorType = ex.GetType().Name;
            }

            if (errorMessage != null)
            {
                MessageBox.Show(errorMessage, errorType);
                if (!test)
                {
                    ShowOptionPage(typeof(OptionPage));
                }
            }
        }
예제 #3
0
        private void dropdownWebBrowserType_SelectedIndexChanged(object sender, EventArgs e)
        {
            var currentType = (WebBrowserType)dropdownWebBrowserType.SelectedIndex;

            if (optionPage.WebBrowserType == currentType)
            {
                return;
            }

            if (currentType == WebBrowserType.CustomWebBrowser &&
                string.IsNullOrEmpty(optionPage.CustomWebBrowserPath))
            {
                if (!WebBrowserUtility.TrySelectWebBrowserPath(optionPage.CustomWebBrowserPath, out var newPath))
                {
                    optionPage.CustomWebBrowserPath      = newPath;
                    txtboxCustomWebBrowserPath.Text      = optionPage.CustomWebBrowserPath;
                    dropdownWebBrowserType.SelectedIndex = (int)optionPage.WebBrowserType;
                    return;
                }
            }

            optionPage.WebBrowserType = currentType;
            UpdateCustomWebBrowserUI();
        }