Class: Find

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) ⇒ Find

Returns a new instance of Find.



3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
# File 'ext/ae-editor/ae-editor.rb', line 3688

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.



3687
3688
3689
# File 'ext/ae-editor/ae-editor.rb', line 3687

def e_what
  @e_what
end

Instance Method Details

#do_find(_istart = nil) ⇒ Object



3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
# File 'ext/ae-editor/ae-editor.rb', line 3815

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
    if @forwards
      if @cb_reg.cget('onvalue')==@cb_reg.cget('variable').value.to_i
        _index = self.editor.text.tksearch(['regexp'],@e_what.text,_istart)
      else
        _index = self.editor.text.search(@e_what.text,_istart)
      end
    else

      if @cb_reg.cget('onvalue')==@cb_reg.cget('variable').value.to_i
        _index = self.editor.text.tksearch(['regexp','backwards'],@e_what.text,_istart)
      else
        _index = self.editor.text.tksearch(['backwards'],@e_what.text,_istart)
      end
    end
    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



3870
3871
3872
3873
3874
3875
# File 'ext/ae-editor/ae-editor.rb', line 3870

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

#do_replaceObject



3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
# File 'ext/ae-editor/ae-editor.rb', line 3733

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



3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
# File 'ext/ae-editor/ae-editor.rb', line 3744

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



3769
3770
3771
3772
3773
3774
# File 'ext/ae-editor/ae-editor.rb', line 3769

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

#go_lineObject



3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
# File 'ext/ae-editor/ae-editor.rb', line 3780

def go_line
  if @goto_line_dialog.e_line.value.length > 0
    _row = @goto_line_dialog.e_line.value
    _index = _row+'.1'
    self.editor.text.see(_index)
    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



3803
3804
3805
3806
# File 'ext/ae-editor/ae-editor.rb', line 3803

def show
  super
  use(@controller.raised)
end

#show_go_to_line_dialogObject



3776
3777
3778
# File 'ext/ae-editor/ae-editor.rb', line 3776

def show_go_to_line_dialog
  @goto_line_dialog.show
end

#update_combo(_txt) ⇒ Object



3808
3809
3810
3811
3812
3813
# File 'ext/ae-editor/ae-editor.rb', line 3808

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



3793
3794
3795
3796
3797
3798
3799
3800
3801
# File 'ext/ae-editor/ae-editor.rb', line 3793

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



3758
3759
3760
3761
3762
3763
3764
3765
3766
# File 'ext/ae-editor/ae-editor.rb', line 3758

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