Class: SearchInFiles

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

Overview

ae-search-in-files.rb - Arcadia Ruby ide

by Antonio Galeone <[email protected]>

Direct Known Subclasses

AckInFiles

Instance Attribute Summary

Attributes inherited from ArcadiaExt

#arcadia, #name

Instance Method Summary collapse

Methods inherited from ArcadiaExt

#add_to_conf_property, #array_conf, #conf, #conf_array, #conf_default, #del_from_conf_property, #exec, #float_frame, #frame, #frame_def_visible?, #frame_domain, #frame_domain_default, #frame_visible?, #hide_frame, #initialize, #maximize, #maximized?, #resize, #restore_default_conf

Constructor Details

This class inherits a constructor from ArcadiaExt

Instance Method Details

#do_findObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'ext/ae-search-in-files/ae-search-in-files.rb', line 81

def do_find
  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)
  end
  self.frame.show_anyway
  Thread.new do
    begin    
      MonitorLastUsedDir.set_last @find.e_dir.text # save it away TODO make it into a message
      _search_title = Arcadia.text('ext.search_in_files.search_result_title', [@find.e_what.text, @find.e_dir.text, @find.e_filter.text])
      _filter = @find.e_dir.text+'/**/'+@find.e_filter.text
      _files = Dir[_filter]
      _node = @search_output.new_result(_search_title, _files.length)
      progress_stop=false
      progress_bar = TkProgressframe.new(self.arcadia.layout.root, _files.length)		  
      progress_bar.title(Arcadia.text('ext.search_in_files.progress.title'))
      progress_bar.on_cancel=proc{progress_stop=true}
      #@progress_bar.on_cancel=proc{cancel}
      pattern = Regexp.new(@find.e_what.text)
      _files.each do |_filename|
          next if File.ftype(_filename) != 'file'
          begin
            File.open(_filename) do |file|
              file.grep(pattern) do |line|
                @search_output.add_result(_node, _filename, file.lineno.to_s, line)
                break if progress_stop
              end
            end
          rescue ArgumentError => e
            # bynary file probably
          rescue Exception => e
            Arcadia.console(self, 'msg'=>"#{_filename} :#{e.class}: #{e.message}", 'level'=>'error')
          ensure
            progress_bar.progress
            break if progress_stop
          end
      end
    rescue Exception => e
      Arcadia.console(self, 'msg'=>e.message, 'level'=>'error')
      #Arcadia.new_error_msg(self, e.message)
    ensure
      progress_bar.destroy if progress_bar
      self.frame.show_anyway
    end
  end
end

#on_before_build(_event) ⇒ Object



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

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

#on_before_search_in_files(_event) ⇒ Object



13
14
15
16
17
18
19
20
# File 'ext/ae-search-in-files/ae-search-in-files.rb', line 13

def on_before_search_in_files(_event)
  if _event.what.nil?
    if _event.dir
      @find.e_dir.text(_event.dir)
    end
    @find.show
  end
end

#update_all_comboObject



75
76
77
78
79
# File 'ext/ae-search-in-files/ae-search-in-files.rb', line 75

def update_all_combo
  update_what_combo(@find.e_what.text)
  update_filter_combo(@find.e_filter.text)
  update_dir_combo(@find.e_dir.text)
end

#update_dir_combo(_txt) ⇒ Object



68
69
70
71
72
73
# File 'ext/ae-search-in-files/ae-search-in-files.rb', line 68

def update_dir_combo(_txt)
  values = @find.e_dir.cget('values')
  if (values != nil && !values.include?(_txt))
    @find.e_dir.insert('end', _txt)
  end
end

#update_filter_combo(_txt) ⇒ Object



61
62
63
64
65
66
# File 'ext/ae-search-in-files/ae-search-in-files.rb', line 61

def update_filter_combo(_txt)
  values = @find.e_filter.cget('values')
  if (values != nil && !values.include?(_txt))
    @find.e_filter.insert('end', _txt)
  end
end

#update_what_combo(_txt) ⇒ Object



54
55
56
57
58
59
# File 'ext/ae-search-in-files/ae-search-in-files.rb', line 54

def update_what_combo(_txt)
  values = @find.e_what.cget('values')
  if (values != nil && !values.include?(_txt))
    @find.e_what.insert('end', _txt)
  end
end