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, #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


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
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'ext/ae-search-in-files/ae-search-in-files.rb', line 95

def do_find
  return if @find.e_what.value.strip.length == 0  || @find.e_filter.value.strip.length == 0  || @find.e_dir.value.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.value # save it away TODO make it into a message
      _search_title = Arcadia.text('ext.search_in_files.search_result_title', [@find.e_what.value, @find.e_dir.value, @find.e_filter.value])
      _filter = @find.e_dir.value+'/**/'+@find.e_filter.value
      _files = Dir[_filter]
      _node = @search_output.new_result(_search_title, _files.length)
      progress_stop=false
      hint = "#{Arcadia.text('ext.search_in_files.progress.title')} '#{@find.e_what.value}' into '#{@find.e_dir.value}'"
      progress_bar = self.frame.root.add_progress(self.frame.name, _files.length, proc{progress_stop=true}, hint)
      pattern = Regexp.new(@find.e_what.value)
      _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
      self.frame.root.destroy_progress(self.frame.name, progress_bar) if progress_bar
      #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.value=_event.dir
    end
    @find.show
  end
end

#update_all_comboObject

def update_filter_combo(_txt)

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

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

89
90
91
92
93
# File 'ext/ae-search-in-files/ae-search-in-files.rb', line 89

def update_all_combo
  update_combo(@find.e_what)
  update_combo(@find.e_filter)
  update_combo(@find.e_dir)
end

#update_combo(_combobox = nil) ⇒ Object


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

def update_combo(_combobox=nil)
  return if _combobox.nil?
  values = _combobox.cget('values')
  if (values != nil && !values.include?(_combobox.value))
    values << _combobox.value
    _combobox.values=values
  end
end