plugins/runnables/lib/runnables.rb in redcar-0.3.10.1dev vs plugins/runnables/lib/runnables.rb in redcar-0.4
- old
+ new
@@ -21,21 +21,41 @@
end
end
end
controller = CommandOutputController.new(path, command, title)
if output == "none"
- controller.run
- else #default to new tab
- if output == "window"
- Project::Manager.open_project_for_path(".")
- end
- tab = Redcar.app.focussed_window.new_tab(HtmlTab)
- tab.html_view.controller = controller
- tab.focus
+ 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 = Redcar.app.focussed_window.new_tab(HtmlTab)
+ tab.html_view.controller = controller
+ tab.focus
+ end
end
end
+
+ 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
+ def self.keymaps
+ map = Keymap.build("main", [:osx, :linux, :windows]) do
+ link "Ctrl+R", Runnables::RunEditTabCommand
+ end
+ [map, map]
+ end
+
def self.menus
Menu::Builder.build do
sub_menu "Project", :priority => 15 do
group(:priority => 15) {
separator
@@ -47,13 +67,29 @@
end
class TreeMirror
include Redcar::Tree::Mirror
+ attr_accessor :last_loaded
+
def initialize(project)
- runnable_file_paths = project.config_files("runnables/*.json")
-
+ @project = project
+ end
+
+ def runnable_file_paths
+ @project.config_files("runnables/*.json")
+ end
+
+ def last_updated
+ runnable_file_paths.map{ |p| File.mtime(p) }.max
+ end
+
+ def changed?
+ !last_loaded || last_loaded < last_updated
+ end
+
+ def load
groups = {}
runnable_file_paths.each do |path|
runnables = []
name = File.basename(path,".json")
json = File.read(path)
@@ -61,24 +97,24 @@
runnables += this_runnables || []
groups[name.to_s] = runnables.to_a
end
if groups.any?
- @top = groups.map do |name, runnables|
+ groups.map do |name, runnables|
RunnableGroup.new(name,runnables)
end
else
- @top = [HelpItem.new]
+ [HelpItem.new]
end
end
-
+
def title
TREE_TITLE
end
-
+
def top
- @top
+ load
end
end
def self.storage
@storage ||= begin
@@ -191,10 +227,11 @@
end
class ShowRunnables < Redcar::Command
def execute
if tree = win.treebook.trees.detect {|tree| tree.tree_mirror.title == TREE_TITLE }
+ tree.refresh
win.treebook.focus_tree(tree)
else
project = Project::Manager.in_window(win)
tree = Tree.new(
TreeMirror.new(project),
@@ -227,12 +264,12 @@
command_schema = file_mapping["command"]
output = file_mapping["output"]
if output.nil?
output = "tab"
end
- command = command_schema.gsub("__PATH__", tab.edit_view.document.mirror.path)
- puts command
- Runnables.run_process(project.home_dir,command, "Run File", output)
+ path = tab.edit_view.document.mirror.path
+ command = command_schema.gsub("__PATH__", path)
+ Runnables.run_process(project.home_dir,command, "Running #{File.basename(path)}", output)
end
end
end
end
end