Class: AckInFiles

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

Overview

ack-in-files.rb - Arcadia Ruby ide

by Roger D. Pack

Instance Attribute Summary

Attributes inherited from ArcadiaExt

#arcadia, #name

Instance Method Summary collapse

Methods inherited from SearchInFiles

#on_before_search_in_files, #update_all_combo, #update_combo

Methods inherited from ArcadiaExt

#add_to_conf_property, #array_conf, #conf, #conf_array, #conf_default, #del_from_conf_property, #destroy_frame, #exec, #float_frame, #frame, #frame_def_visible?, #frame_domain, #frame_domain_default, #frame_raised?, #frame_title, #frame_visible?, #hide_frame, #hinner_dialog, #hinner_splitted_dialog, #hinner_splitted_dialog_titled, #initialize, #maximize, #maximized?, #resize, #restore_default_conf

Constructor Details

This class inherits a constructor from ArcadiaExt

Instance Method Details

#do_findObject

overwrite


17
18
19
20
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'ext/ae-search-in-files/ext/ack-in-files/ack-in-files.rb', line 17

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(self)
  else
    self.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 = Arcadia.text('ext.search_in_files.ack_result_title', [@find.e_what.text, @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(self.arcadia.layout.root, 2)
    @progress_bar.title(Arcadia.text('ext.search_in_files.progress.title.1'))

    answer = `#{command}`
    answer_lines = answer.split("\n")
    @progress_bar.destroy # destroy the old one
    @progress_bar = TkProgressframe.new(self.arcadia.layout.root, answer_lines.length)		  
    @progress_bar.title(Arcadia.text('ext.search_in_files.progress.title.2'))
    @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(Arcadia.text('ext.search_in_files.no_search_result'), '')
    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


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

def on_before_ack_in_files(_event)
  on_before_search_in_files(_event)
end

#on_before_build(_event) ⇒ Object


8
9
10
11
# File 'ext/ae-search-in-files/ext/ack-in-files/ack-in-files.rb', line 8

def on_before_build(_event)
  create_find Arcadia.text('ext.search_in_files.title.1')
  Arcadia.attach_listener(self, AckInFilesEvent)
end