Class: AckInFilesListener

Inherits:
SearchInFilesListener show all
Defined in:
ext/ae-search-in-files/ext/ack-in-files/ack-in-files.rb

Instance Method Summary collapse

Methods inherited from SearchInFilesListener

#on_before_search_in_files, #update_all_combo, #update_dir_combo, #update_filter_combo, #update_what_combo

Constructor Details

#initialize(_service) ⇒ AckInFilesListener

Returns a new instance of AckInFilesListener.



13
14
15
16
# File 'ext/ae-search-in-files/ext/ack-in-files/ack-in-files.rb', line 13

def initialize(_service)
  @service = _service
  create_find 'Ack in files'
end

Instance Method Details

#do_findObject

overwrite



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
50
51
52
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
# File 'ext/ae-search-in-files/ext/ack-in-files/ack-in-files.rb', line 22

def do_find # overwrite
  return if @find.e_what.text.strip.length == 0  || @find.e_filter.text.strip.length == 0  || @find.e_dir.text.strip.length == 0
  @find.hide
  if !defined?(@search_output)
    @search_output = SearchOutput.new(@service)
  else
    @service.frame.show
  end
  begin
    # unfortunately, it uses regex instead of glob. Oh well.
    # ack -i ignore case
    #   -H, --with-filename   Print the filename for each match
    #  -G REGEX              Only search files that match REGEX
    # ack -i -G .tcl Event
    # ack -i -G .rb "Ack" "c:/dev/ruby/arcadia"
    command = %!ack -i -G "#{@find.e_filter.text.gsub('*', '.*')}" "#{@find.e_what.text}" "#{@find.e_dir.text}"!

    _search_title = 'ack result for : "'+@find.e_what.text+'" in :"'+@find.e_dir.text+'"'+' ['+@find.e_filter.text+'] ' + command
    _filter = @find.e_dir.text+'/**/'+@find.e_filter.text
    _node = @search_output.new_result(_search_title, '')
    progress_stop=false
    @progress_bar = TkProgressframe.new(@service.arcadia.layout.root, 2)
    @progress_bar.title('Running')

    answer = `#{command}`
    answer_lines = answer.split("\n")
    @progress_bar.destroy # destroy the old one
    @progress_bar = TkProgressframe.new(@service.arcadia.layout.root, answer_lines.length)		  
    @progress_bar.title('Parsing')
    @progress_bar.on_cancel=proc{progress_stop=true}

    # a now looks like
    # "C:/dev/ruby/arcadia/conf/arcadia.res.rb:184:mzWCUixPU0sEqgO/8AoIsQbpkAbCQWpVeLJUpzhXd6v9eWZV1G1DosCBogAO"
    # ...
    answer_lines.each{|line|
      # we'll assume no :number: in the path...if not it will mess us right up
      line =~ /(.*):(\d+):(.*)/
      _filename = $1
      _lineno = $2
      _text = $3
      @search_output.add_result(_node, _filename, _lineno, _text)
      @progress_bar.progress
      break if progress_stop # early out
    }
    if answer_lines == []
      @search_output.new_result('None found', '')
    end
    
  rescue Exception => e
    Arcadia.console(self, 'msg'=>e.message + e.backtrace.inspect, 'level'=>'error')
    #Arcadia.new_error_msg(self, e.message)
  ensure
    @progress_bar.destroy if @progress_bar
  end

end

#on_before_ack_in_files(_event) ⇒ Object



18
19
20
# File 'ext/ae-search-in-files/ext/ack-in-files/ack-in-files.rb', line 18

def on_before_ack_in_files(_event)
  on_before_search_in_files(_event)
end