Esempio n. 1
0
        /// <summary>
        /// Actual code performed when action is executed in Do
        /// </summary>
        /// <param name="items">
        /// Items. ITextItem <see cref="Item"/>
        /// </param>
        /// <param name="modItems">
        /// Modifier Items. None <see cref="Item"/>
        /// </param>
        public override IEnumerable <Item> Perform(IEnumerable <Item> items, IEnumerable <Item> modItems)
        {
            GoogleSearch googleSearch = new GoogleSearch();

            googleSearch.setSafeSearchLevel
                (InlineGoogleSearchConfig.SearchRestrictions);
            googleSearch.setQuery((items.First() as ITextItem).Text);
            IEnumerable <GoogleSearchResult> results = googleSearch.Search();

            if (!results.Any())
            {
                Gtk.Application.Invoke((o, e) => Services.Notifications.Notify(Name, "No Results Found"));
            }
            else
            {
                Services.Environment.OpenUrl(HttpUtility.UrlDecode(results.First().url));
            }
            yield break;
        }
Esempio n. 2
0
        /// <summary>
        /// Actual code performed when action is executed in Do
        /// </summary>
        /// <param name="items">
        /// Items. ITextItem <see cref="Item"/>
        /// </param>
        /// <param name="modItems">
        /// Modifier Items. None <see cref="Item"/>
        /// </param>
        /// <returns>
        /// Array of Bookmark Items. URLs to search results <see cref="Item"/>
        /// </returns>
        public override IEnumerable <Item> Perform(IEnumerable <Item> items, IEnumerable <Item> modItems)
        {
            string query     = (items.First() as ITextItem).Text;
            string searchURL = "http://google.com/search?q=" + HttpUtility.UrlEncode(query);

            if (InlineGoogleSearchConfig.InheritSSL)
            {
                searchURL += "&safe=" + InlineGoogleSearchConfig.SearchRestrictions;
            }

            if (!InlineGoogleSearchConfig.ReturnResults)
            {
                Services.Environment.OpenUrl(searchURL);
                yield break;
            }

            if (InlineGoogleSearchConfig.ShowSearchFirst)
            {
                yield return(new BookmarkItem(query + " - Google Search",
                                              searchURL));
            }

            GoogleSearch googleSearch = new GoogleSearch();

            googleSearch.setSafeSearchLevel(InlineGoogleSearchConfig.SearchRestrictions);
            googleSearch.setQuery(query);
            IEnumerable <GoogleSearchResult> results = googleSearch.Search();


            if (!results.Any())
            {
                Gtk.Application.Invoke((o, e) => Services.Notifications.Notify(Name, "No Results Found"));
            }

            foreach (GoogleSearchResult result in results)
            {
                yield return(new BookmarkItem(result.titleNoFormatting, HttpUtility.UrlDecode(result.url)));
            }
        }