1
// RunInTerminalAction.boo
3
// GNOME Do is the legal property of its developers. Please refer to the
4
// 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/>.
24
import System.Diagnostics
27
class RunInTerminalAction (AbstractAction):
29
last_command_found as string
33
return "Run in Terminal"
35
Description as string:
37
return "Runs a command in GNOME Terminal."
41
return "gnome-terminal"
43
SupportedItemTypes as (Type):
45
return (typeof (ITextItem),
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)
55
def Perform (items as (IItem), modItems as (IItem)) as (IItem):
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}")
65
def CommandLineFoundOnPath ([required] cmd as string) as bool:
66
cmd = cmd.Split (char (' '))[0]
67
if cmd == last_command_found: return true
69
// If the command is found, fine.
71
last_command_found = cmd
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