module Redcar
class TodoList
class TodoController
include HtmlController
def initialize(path)
@path = path
end
def title
"Todo List"
end
def debug
false
end
# Open a text file in a new edit tab
def open_file(path)
path = path.to_s
#check for line number
idx = path.rindex(":")
line = 1
unless idx.nil?
# line number found
line = path[idx+1,path.length]
# convert path to actual file path
path = path[0,idx]
end
if File.exists?(path)
puts "Opening #{path} in new tab" if debug
Project::FileOpenCommand.new(path).run
tab = Redcar.app.focussed_notebook_tab
#check if line is a number
if numeric?(line)
line = line.to_i - 1
if line >= 0
document = tab.edit_view.document
if line <= document.line_count.to_i
puts "scrolling to line number: #{line}" if debug
offset = document.offset_at_line(line)
document.cursor_offset = offset
document.scroll_to_line(line)
end
end
end
tab.focus
end
false
end
def numeric?(object)
true if Integer(object) rescue false
end
def parse_path(path,tag)
idx = tag.length
if TodoList.storage['require_colon']
idx += 1
end
path = path[idx,path.length]
display_path = path[@path.length+1,path.length]
case Redcar.platform
when :osx, :linux
display_path = display_path.gsub("//","/")
when :windows
display_path = display_path.gsub("//","\\")
end
puts "Final path: #{path}" if debug
puts "Path for display: #{display_path}" if debug
[path, display_path]
end
def populate_list
@thread = Thread.new do
sleep 1
execute(<<-JAVASCRIPT)
$("#status").html("Searching...");
$("#tags").html(" ");
JAVASCRIPT
s = Time.now
@tag_list = TodoList::FileParser.new.parse_files(@path) || {}
i = 0
total = @tag_list.to_a.length.to_i - 1
TodoList.storage['tags'].each do |tag|
table_id = "#{tag}_table"
html=<<-HTML
#{tag} |
---|