3
* GNOME Do is the legal property of its developers. Please refer to the
4
* COPYRIGHT file distributed with this source distribution.
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
using System.Text.RegularExpressions;
27
/// Given an ITextItem, DefineWordAction will look up the Text
28
/// contents of the ITextItem using the gnome-dictionary.
30
public class DefineWordAction : AbstractAction
33
/// Should match those and only those strings that can be
34
/// looked up in a dictionary.
35
/// YES: "war", "peace", "hoi polloi"
36
/// NO: "war9", "2 + 4", "___1337__"
38
const string wordPattern = @"^([^\W0-9_]+([ -][^\W0-9_]+)?)$";
42
public DefineWordAction ()
44
wordRegex = new Regex (wordPattern, RegexOptions.Compiled);
47
public override string Name {
48
get { return Catalog.GetString ("Define"); }
51
public override string Description
53
get { return Catalog.GetString ("Define a given word."); }
56
public override string Icon
58
get { return "accessories-dictionary"; }
61
public override Type[] SupportedItemTypes
71
/// Use wordRegex to determine whether item is definable.
73
/// <param name="item">
74
/// A <see cref="IItem"/> to define.
77
/// A <see cref="System.Boolean"/> indicating whether or not IITem
80
public override bool SupportsItem (IItem item)
85
if (item is ITextItem) {
86
word = (item as ITextItem).Text;
88
return !string.IsNullOrEmpty (word) && wordRegex.IsMatch (word);
91
public override IItem[] Perform (IItem[] items, IItem[] modifierItems)
94
foreach (IItem item in items) {
95
if (item is ITextItem) {
96
word = (item as ITextItem).Text;
100
cmd = string.Format ("gnome-dictionary --look-up \"{0}\"", word);
101
System.Diagnostics.Process.Start (cmd);