1
// OpenSearchItemAction.cs
3
// GNOME Do is the legal property of its developers, whose names are too numerous
4
// to list here. Please refer to the COPYRIGHT file distributed with this
5
// source distribution.
7
// This program is free software: you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation, either version 3 of the License, or
10
// (at your option) any later version.
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21
using System.Collections.Generic;
29
namespace Do.Plugins.OpenSearch
31
public class OpenSearchAction : AbstractAction
33
static OpenSearchAction()
35
OpenSearch.GetOpenSearchItems ();
38
public override string Name
40
get { return Catalog.GetString ("Search Web"); }
43
public override string Description
45
get { return Catalog.GetString ("Searches the web using OpenSearch plugins."); }
48
public override string Icon
50
get { return "web-browser"; }
53
public override Type[] SupportedItemTypes
62
public override bool SupportsItem (IItem item)
64
if (item is ITextItem)
69
public override Type[] SupportedModifierItemTypes
73
typeof (OpenSearchItem),
78
public override IItem[] DynamicModifierItemsForItem (IItem item)
82
List<IItem> items = new List<IItem>();
83
foreach(IItem openSearchItem in OpenSearch.GetOpenSearchItems ()) {
84
items.Add (openSearchItem);
86
return items.ToArray ();
94
public override IItem[] Perform (IItem[] items, IItem[] modifierItems)
96
List<string> searchTerms;
98
if (modifierItems.Length > 0)
100
searchTerms = new List<string> ();
101
foreach (IItem item in items) {
102
searchTerms.Add ((item as ITextItem).Text);
105
foreach (string searchTerm in searchTerms) {
106
string url = BuildSearchUrl ((modifierItems[0] as IOpenSearchItem), searchTerm);
107
Util.Environment.Open (url);
113
private static string BuildSearchUrl (IOpenSearchItem openSearchItem, string searchTerm)
115
return openSearchItem.UrlTemplate.Replace ("{searchTerms}", HttpUtility.UrlEncode(searchTerm));