~bas-dotbas/do/win32-next

« back to all changes in this revision

Viewing changes to Do.Addins/src/Do.Universe/DefineWordCommand.cs

  • Committer: djsiegel at gmail
  • Date: 2007-10-13 21:55:22 UTC
  • Revision ID: djsiegel@gmail.com-20071013215522-n0vjgog0tyjfnpno
Restructured plugins library.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// GCRunCommand.cs created with MonoDevelop
 
2
// User: dave at 12:54 AM 8/18/2007
 
3
//
 
4
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
 
5
//
 
6
 
 
7
using System;
 
8
using System.Text.RegularExpressions;
 
9
 
 
10
namespace Do.Universe
 
11
{
 
12
        
 
13
        public class DefineWordCommand : ICommand
 
14
        {
 
15
        
 
16
                const string wordPattern = @"^([^\W0-9_]+([ -][^\W0-9_]+)?)$";
 
17
 
 
18
                Regex wordRegex;
 
19
                
 
20
                public DefineWordCommand ()
 
21
                {
 
22
                        wordRegex = new Regex (wordPattern, RegexOptions.Compiled);
 
23
                }
 
24
                
 
25
                public string Name {
 
26
                        get { return "Define"; }
 
27
                }
 
28
                
 
29
                public string Description {
 
30
                        get { return "Define a given word."; }
 
31
                }
 
32
                
 
33
                public string Icon {
 
34
                        get { return "accessories-dictionary.png"; }
 
35
                }
 
36
                
 
37
                public Type[] SupportedTypes {
 
38
                        get {
 
39
                                return new Type[] {
 
40
                                        typeof (ITextItem),
 
41
                                };
 
42
                        }
 
43
                }
 
44
                
 
45
                public Type[] SupportedModifierTypes {
 
46
                        get { return null; }
 
47
                }
 
48
 
 
49
                public bool SupportsItem (IItem item) {
 
50
                        string word;
 
51
 
 
52
                        word = null;
 
53
                        if (item is ITextItem) {
 
54
                                word = (item as ITextItem).Text;
 
55
                        }
 
56
 
 
57
                        if (word != null) {
 
58
                                return wordRegex.IsMatch (word);
 
59
                        }
 
60
                        return false;
 
61
                }
 
62
                
 
63
                public void Perform (IItem[] items, IItem[] modifierItems)
 
64
                {
 
65
                        string word, cmd;
 
66
                        foreach (IItem item in items) {
 
67
                                if (item is ITextItem) {
 
68
                                        word = (item as ITextItem).Text;
 
69
                                } else {
 
70
                                        continue;
 
71
                                }
 
72
 
 
73
                                cmd = string.Format ("gnome-dictionary --look-up \"{0}\"", word);
 
74
                                try {
 
75
                                        System.Diagnostics.Process.Start (cmd);
 
76
                                } catch (Exception e) {
 
77
                                        Console.WriteLine ("Failed to define word: \"{0}\"", e.Message);
 
78
                                }
 
79
                        }
 
80
                }
 
81
        
 
82
                
 
83
        }
 
84
        
 
85
}