Class: Redcar::Runnables
- Inherits:
-
Object
show all
- Defined in:
- plugins/runnables/lib/runnables.rb,
plugins/runnables/lib/runnables/commands.rb,
plugins/runnables/lib/runnables/output_processor.rb,
plugins/runnables/lib/runnables/running_process_checker.rb,
plugins/runnables/lib/runnables/tree_mirror/tree_mirror.rb,
plugins/runnables/lib/runnables/command_output_controller.rb,
plugins/runnables/lib/runnables/tree_mirror/nodes/runnable.rb,
plugins/runnables/lib/runnables/tree_mirror/tree_controller.rb,
plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb,
plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_type_group.rb
Defined Under Namespace
Classes: AppendParamsAndRunCommand, CommandOutputController, HelpItem, OutputProcessor, RunAlternateEditTabCommand, RunEditTabCommand, Runnable, RunnableGroup, RunnableTypeGroup, RunningProcessChecker, ShowRunnables, TreeController, TreeMirror
Constant Summary
- TREE_TITLE =
"Runnables"
- PARAMS =
"__PARAMS__"
- DISPLAY_PARAMS =
"__?__"
- DISPLAY_NEXT_PARAMS =
"_____"
- LINE_HOLDER =
"__LINE__"
- PATH_HOLDER =
"__PATH__"
- NAME_HOLDER =
"__NAME__"
Class Method Summary
(collapse)
Class Method Details
+ (Object) close_window_guard(win)
166
167
168
169
170
171
|
# File 'plugins/runnables/lib/runnables.rb', line 166
def self.close_window_guard(win)
Runnables::RunningProcessChecker.new(
win.notebooks.map(&:tabs).flatten.select {|t| t.is_a?(HtmlTab)},
"Kill them and close the window?"
).check
end
|
+ (Object) file_mappings(project)
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'plugins/runnables/lib/runnables.rb', line 84
def self.file_mappings(project)
file_runners = []
if project
runnable_file_paths = project.config_files("runnables/*.json")
runnable_file_paths.each do |path|
json = File.read(path)
this_file_runners = JSON(json)["file_runners"]
file_runners += this_file_runners || []
end
end
file_runners
end
|
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'plugins/runnables/lib/runnables.rb', line 105
def self.keymaps
linwin = Keymap.build("main", [:linux, :windows]) do
link "Ctrl+Alt+Shift+R", Runnables::ShowRunnables
link "Ctrl+R", Runnables::RunEditTabCommand
link "Ctrl+Alt+R", Runnables::RunAlternateEditTabCommand
end
osx = Keymap.build("main", :osx) do
link "Cmd+Alt+Shift+R", Runnables::ShowRunnables
link "Cmd+R", Runnables::RunEditTabCommand
link "Cmd+Alt+R", Runnables::RunAlternateEditTabCommand
end
[linwin,osx]
end
|
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'plugins/runnables/lib/runnables.rb', line 120
def self.
Menu::Builder.build do
"Project" do
group(:priority => 15) {
separator
item "Runnables", Runnables::ShowRunnables
item "Run Tab", Runnables::RunEditTabCommand
item "Alternate Run Tab", Runnables::RunAlternateEditTabCommand
separator
}
end
end
end
|
+ (Object) previous_tab_for(command)
97
98
99
100
101
102
103
|
# File 'plugins/runnables/lib/runnables.rb', line 97
def self.previous_tab_for(command)
Redcar.app.all_tabs.detect do |t|
t.respond_to?(:html_view) &&
t.html_view.controller.is_a?(CommandOutputController) &&
t.html_view.controller.cmd == command
end
end
|
+ (Object) project_closed(project, window)
173
174
175
176
177
178
|
# File 'plugins/runnables/lib/runnables.rb', line 173
def self.project_closed(project,window)
rtree = window.treebook.trees.detect { |t|
t.tree_mirror.is_a? Runnables::TreeMirror
}
rtree.close if rtree
end
|
+ (Object) quit_guard
159
160
161
162
163
164
|
# File 'plugins/runnables/lib/runnables.rb', line 159
def self.quit_guard
Runnables::RunningProcessChecker.new(
Redcar.app.all_tabs.select {|t| t.is_a?(HtmlTab)},
"Kill all and quit?"
).check
end
|
+ (Object) run_process(path, command, title, output = "tab")
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'plugins/runnables/lib/runnables.rb', line 21
def self.run_process(path, command, title, output = "tab")
window = Redcar.app.focussed_window
command = Runnables.substitute_variables(window,command)
return unless command
if Runnables.storage['save_project_before_running'] == true
window.notebooks.each do |notebook|
notebook.tabs.each do |tab|
tab.edit_view.document.save! if tab.is_a?(EditTab) and tab.edit_view.document.modified?
end
end
end
controller = CommandOutputController.new(path, command, title)
if output == "none"
controller.run
else
if tab = previous_tab_for(command)
tab.html_view.controller.run
tab.focus
else
if output == "window"
Redcar.app.new_window
end
tab = window.new_tab(HtmlTab)
tab.html_view.controller = controller
tab.icon = :cog
tab.focus
end
end
end
|
134
135
136
137
138
139
140
141
142
|
# File 'plugins/runnables/lib/runnables.rb', line 134
def self.(node)
Menu::Builder.build do
if not node.nil? and node.is_a?(Runnable)
item("Run with parameters") do
AppendParamsAndRunCommand.new(node).run
end
end
end
end
|
151
152
153
154
155
156
157
|
# File 'plugins/runnables/lib/runnables.rb', line 151
def self.storage
@storage ||= begin
storage = Plugin::Storage.new('runnables')
storage.set_default('save_project_before_running', false)
storage
end
end
|
+ (Object) substitute_variables(window, command)
Replaces placeholders in commands with values, like __PATH__, __LINE__,
__NAME__ and __PARAMS__
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'plugins/runnables/lib/runnables.rb', line 53
def self.substitute_variables(window,command)
tab = window.focussed_notebook_tab
if tab and tab.is_a?(EditTab)
if command.include?(PATH_HOLDER)
path = tab.edit_view.document.path
command.gsub!(PATH_HOLDER, path)
if command.include?(LINE_HOLDER)
line = tab.edit_view.document.cursor_line + 1
command.gsub!(LINE_HOLDER, line.to_s)
end
end
if command.include?(NAME_HOLDER)
name = File.basename(tab.edit_view.document.path)
idx = name.rindex(".") if name.include?(".")
name = name[0,idx] if idx
command.gsub!(NAME_HOLDER, name.to_s)
end
end
while command.include?(PARAMS)
msg = command.sub(PARAMS,DISPLAY_PARAMS)
msg = msg.gsub(PARAMS,DISPLAY_NEXT_PARAMS)
msg = "" if msg == DISPLAY_PARAMS
msg_title = "Enter Command Parameters"
out = Redcar::Application::Dialog.input(msg_title,msg)
params = out[:value] || ""
return if out[:button] == :cancel
command = command.sub(PARAMS,params)
end
command
end
|
144
145
146
147
148
149
|
# File 'plugins/runnables/lib/runnables.rb', line 144
def self.toolbars
ToolBar::Builder.build do
item "Runnables", :command => Runnables::ShowRunnables, :icon => File.join(Redcar.icons_directory,"cog.png"), :barname => :project
item "Run Tab", :command => Runnables::RunEditTabCommand, :icon => File.join(Redcar.icons_directory, "control.png"), :barname => :project
end
end
|