Class: Finder

Inherits:
Findview show all
Defined in:
ext/ae-editor/ae-editor.rb

Constant Summary

Constants included from TkResizable

TkResizable::MIN_HEIGHT, TkResizable::MIN_WIDTH

Instance Attribute Summary collapse

Attributes inherited from TkBaseTitledFrame

#frame, #top

Instance Method Summary collapse

Methods inherited from TkFloatTitledFrame

#head_buttons, #hide, #on_close=, #show_grabbed, #title

Methods included from TkResizable

#resizing_do_move_obj, #resizing_do_press, #start_resizing, #stop_resizing

Methods included from TkMovable

#moving_do_move_obj, #moving_do_press, #start_moving, #stop_moving

Methods inherited from TkBaseTitledFrame

#add_button, #add_menu_button, #create_frame, #head_buttons, #menu_button

Constructor Details

#initialize(_frame, _controller) ⇒ Finder

Returns a new instance of Finder.



4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
# File 'ext/ae-editor/ae-editor.rb', line 4078

def initialize(_frame, _controller)
  super(_frame)
  #@l_file.configure('text'=>_title)
  #Tk.tk_call('wm', 'title', self, _title )
  @controller = _controller
  @forwards = true
  @find_action = proc{
    do_find_next
    hide
  }
  @b_go.bind('1', @find_action)
  
	 @b_replace.bind('1', proc{do_replace})  
  
	 @b_replace_all.bind('1', proc{do_replace_all})  

  @e_what_entry.bind_append('KeyRelease'){|e|
    case e.keysym
    when 'Return'
      @find_action.call
      Tk.callback_break
    else
      widget_state
    end
  }
  e2 =  TkWinfo.children(@e_with)[0]
  e2.bind_append('KeyPress'){|e|
      widget_state
  }
  @last_index='insert'
  
  @goto_line_dialog = GoToLine.new(_frame).hide
  @goto_line_dialog.on_close=proc{@goto_line_dialog.hide}

  @goto_line_dialog.b_go.bind('1',proc{go_line})
  @goto_line_dialog.e_line.bind_append('KeyRelease'){|e|
    case e.keysym
    when 'Return'
      go_line
      Tk.callback_break
    end
  }

end

Instance Attribute Details

#e_whatObject (readonly)

Returns the value of attribute e_what.



4077
4078
4079
# File 'ext/ae-editor/ae-editor.rb', line 4077

def e_what
  @e_what
end

Instance Method Details

#do_find(_istart = nil) ⇒ Object



4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
# File 'ext/ae-editor/ae-editor.rb', line 4208

def do_find(_istart=nil)
  @forwards =  @cb_back.cget('onvalue') != @cb_back.cget('variable').value.to_i
  _found = false
  @idx1 = nil
  @idx2 = nil
  if @e_what.text.length > 0
    update_combo(@e_what.text)
    if !_istart && self.editor.text.index('insert')!=nil
      _istart ='insert'
    elsif defined?(@last_index)
    		_istart = @last_index
    else
      _istart = '1.0'
    end
    
    # propagate some search options
    options = []
    if !@forwards
      options << 'backwards'
    end
    if @cb_reg.cget('onvalue')==@cb_reg.cget('variable').value.to_i
      options << 'regexp'
    end
    if @cb_ignore_case.cget('onvalue')==@cb_ignore_case.cget('variable').value.to_i
      options << 'nocase'
    end
    _index = self.editor.text.tksearch(options,@e_what.text,_istart)
    
    if _index && _index.length>0
      self.editor.text.see(_index)
      _row, _col = _index.split('.')
      _index_sel_end = _row.to_i.to_s+'.'+(_col.to_i+@e_what.text.length).to_i.to_s
      if @forwards
        @last_index= _index_sel_end
      else
        @last_index= _row.to_i.to_s+'.'+(_col.to_i-1).to_i.to_s
      end
      self.editor.text.tag_add('sel', _index,_index_sel_end)
      self.editor.text.set_insert(_index)
      @idx1 =_index
              @idx2 =_index_sel_end
      _found = true
      @controller.bookmark_add(self.editor.file, _index)
    else
      _message = '"'+@e_what.value+'" not found'
      TkDialog2.new('message'=>_message, 'buttons'=>['Ok']).show()
    end

  else
    self.show()
  end
  self.editor.text.focus
  return _found
end

#do_find_nextObject



4263
4264
4265
4266
4267
4268
# File 'ext/ae-editor/ae-editor.rb', line 4263

def do_find_next
  if @idx1 != nil
  		self.editor.text.tag_remove('sel',@idx1,@idx2)
  end
  do_find(@last_index)
end

#do_replaceObject



4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
# File 'ext/ae-editor/ae-editor.rb', line 4123

def do_replace
  if do_find_next
      _message = 'Replace "'+@e_what.value+'" with "'+@e_with.value+'" ?'
      if TkDialog2.new('message'=>_message, 'buttons'=>['Yes','No']).show() == 0
        self.editor.text.delete(@idx1,@idx2)
        self.editor.text.insert(@idx1,@e_with.value)
        self.editor.check_modify
      end
  end
end

#do_replace_allObject



4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
# File 'ext/ae-editor/ae-editor.rb', line 4134

def do_replace_all
  while do_find_next
      _message = 'Replace "'+@e_what.value+'" with "'+@e_with.value+'" ?'
      _rc = TkDialog2.new('message'=>_message, 'buttons'=>['Yes','No','Annulla']).show()
      if _rc == 0
        self.editor.text.delete(@idx1,@idx2)
        self.editor.text.insert(@idx1,@e_with.value)
        self.editor.check_modify
      elsif _rc == 2
        break
      end
  end
end

#editorObject



4159
4160
4161
4162
4163
4164
# File 'ext/ae-editor/ae-editor.rb', line 4159

def editor
  if @editor_caller == nil
    @editor_caller = @controller.raised
  end
  return @editor_caller
end

#go_lineObject



4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
# File 'ext/ae-editor/ae-editor.rb', line 4171

def go_line
  if @goto_line_dialog.e_line.value.length > 0
    _row = @goto_line_dialog.e_line.value
    _index = _row.strip+'.1'
    self.editor.text.see(_index)
    self.editor.text.tag_remove('selected','1.0','end')
    self.editor.text.tag_add('selected',_index,_index+' lineend')
    #self.editor.text.tag_add('sel', _index,_index+' lineend')
    self.editor.text.set_insert(_index)
    @controller.bookmark_add(self.editor.file, _index)
  @goto_line_dialog.hide
  end
  #self.hide()
end

#showObject



4196
4197
4198
4199
# File 'ext/ae-editor/ae-editor.rb', line 4196

def show
  super
  use(@controller.raised)
end

#show_go_to_line_dialogObject



4166
4167
4168
4169
# File 'ext/ae-editor/ae-editor.rb', line 4166

def show_go_to_line_dialog
  use(@controller.raised)
  @goto_line_dialog.show
end

#update_combo(_txt) ⇒ Object



4201
4202
4203
4204
4205
4206
# File 'ext/ae-editor/ae-editor.rb', line 4201

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

#use(_editor) ⇒ Object



4186
4187
4188
4189
4190
4191
4192
4193
4194
# File 'ext/ae-editor/ae-editor.rb', line 4186

def use(_editor)
  if (_editor != @editor_caller)
    @last_index='insert'
    @editor_caller = _editor
    _title = File.basename(_editor.file) 
    title(_title)
    @goto_line_dialog.title(_title) if @goto_line_dialog
  end
end

#widget_stateObject



4148
4149
4150
4151
4152
4153
4154
4155
4156
# File 'ext/ae-editor/ae-editor.rb', line 4148

def widget_state
 		if (@e_what.value.length > 0) && (@e_with.value.length > 0)
 			@b_replace.configure('state'=>'active')
 			@b_replace_all.configure('state'=>'active')
 		else
 			@b_replace.configure('state'=>'disabled')
 			@b_replace_all.configure('state'=>'disabled')
 		end
end