~do-plugins/do-plugins/trunk

« back to all changes in this revision

Viewing changes to GNOME-Terminal/RunInTerminalAction.boo

  • Committer: Christopher James Halse Rogers
  • Date: 2008-04-03 22:32:04 UTC
  • mto: This revision was merged to the branch mainline in revision 87.
  • Revision ID: chalserogers@gmail.com-20080403223204-yh7zudzdzs3xwi7r
Revert deleted GNOME-Screenshot, GNOME-Terminal, GmailContactItemSource, and Tasque plugins

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// RunInTerminalAction.boo
 
2
//
 
3
// GNOME Do is the legal property of its developers. Please refer to the
 
4
// COPYRIGHT file distributed with this
 
5
// source distribution.
 
6
//
 
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.
 
11
//
 
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.
 
16
//
 
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/>.
 
19
 
 
20
namespace GNOME
 
21
 
 
22
import System
 
23
import System.IO
 
24
import System.Diagnostics
 
25
import Do.Universe
 
26
 
 
27
class RunInTerminalAction (AbstractAction):
 
28
 
 
29
        last_command_found as string
 
30
 
 
31
        Name as string:
 
32
                get:
 
33
                        return "Run in Terminal"
 
34
        
 
35
        Description as string:
 
36
                get:
 
37
                        return "Runs a command in GNOME Terminal."
 
38
        
 
39
        Icon as string:
 
40
                get:
 
41
                        return "gnome-terminal"
 
42
        
 
43
        SupportedItemTypes as (Type):
 
44
                get:
 
45
                        return (typeof (ITextItem),
 
46
                                        typeof (FileItem),)
 
47
        
 
48
        def SupportsItem (item as IItem) as bool:
 
49
                if item isa ITextItem:
 
50
                        return CommandLineFoundOnPath ((item as ITextItem).Text)
 
51
                elif item isa FileItem:
 
52
                        return FileItem.IsExecutable (item as FileItem)
 
53
                return false
 
54
 
 
55
        def Perform (items as (IItem), modItems as (IItem)) as (IItem):
 
56
                for item in items:
 
57
                        cmd = ""
 
58
                        if item isa ITextItem:
 
59
                                cmd = (item as ITextItem).Text
 
60
                        elif item isa IFileItem:
 
61
                                cmd = (item as IFileItem).Path
 
62
                        Process.Start ("gnome-terminal -x ${cmd}")
 
63
                return null
 
64
 
 
65
        def CommandLineFoundOnPath ([required] cmd as string) as bool:
 
66
                cmd = cmd.Split (char (' '))[0]
 
67
                if cmd == last_command_found: return true
 
68
                
 
69
                // If the command is found, fine.
 
70
                if File.Exists (cmd):
 
71
                        last_command_found = cmd
 
72
                        return true
 
73
                
 
74
                // Otherwise, try to find the command file in path.
 
75
                path = Environment.GetEnvironmentVariable ("PATH") or ""
 
76
                for p in path.Split (char (':')):
 
77
                        if File.Exists (Path.Combine (p, cmd)):
 
78
                                last_command_found = cmd
 
79
                                return true
 
80
                return false
 
81
 
 
82