Class: Finder
Constant Summary
Constants included
from TkResizable
TkResizable::MIN_HEIGHT, TkResizable::MIN_WIDTH
Instance Attribute Summary collapse
#frame, #top
Instance Method Summary
collapse
#head_buttons, #hide, #on_close=, #show_grabbed, #title
#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
#add_fixed_button, #add_fixed_menu_button, #add_fixed_sep, #create_frame, #head_buttons, #menu_button, #visible?
Constructor Details
#initialize(_frame, _controller) ⇒ Finder
Returns a new instance of Finder.
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
|
# File 'ext/ae-editor/ae-editor.rb', line 4667
def initialize(_frame, _controller)
super(_frame)
@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_what ⇒ Object
Returns the value of attribute e_what.
4666
4667
4668
|
# File 'ext/ae-editor/ae-editor.rb', line 4666
def e_what
@e_what
end
|
Instance Method Details
#do_find(_istart = nil) ⇒ Object
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
|
# File 'ext/ae-editor/ae-editor.rb', line 4797
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
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_next ⇒ Object
4852
4853
4854
4855
4856
4857
|
# File 'ext/ae-editor/ae-editor.rb', line 4852
def do_find_next
if @idx1 != nil
self.editor.text.tag_remove('sel',@idx1,@idx2)
end
do_find(@last_index)
end
|
#do_replace ⇒ Object
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
|
# File 'ext/ae-editor/ae-editor.rb', line 4712
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_all ⇒ Object
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
|
# File 'ext/ae-editor/ae-editor.rb', line 4723
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
|
#editor ⇒ Object
4748
4749
4750
4751
4752
4753
|
# File 'ext/ae-editor/ae-editor.rb', line 4748
def editor
if @editor_caller == nil
@editor_caller = @controller.raised
end
return @editor_caller
end
|
#go_line ⇒ Object
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
|
# File 'ext/ae-editor/ae-editor.rb', line 4760
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.set_insert(_index)
@controller.bookmark_add(self.editor.file, _index)
@goto_line_dialog.hide
end
end
|
#show ⇒ Object
4785
4786
4787
4788
|
# File 'ext/ae-editor/ae-editor.rb', line 4785
def show
super
use(@controller.raised)
end
|
#show_go_to_line_dialog ⇒ Object
4755
4756
4757
4758
|
# File 'ext/ae-editor/ae-editor.rb', line 4755
def show_go_to_line_dialog
use(@controller.raised)
@goto_line_dialog.show
end
|
#update_combo(_txt) ⇒ Object
4790
4791
4792
4793
4794
4795
|
# File 'ext/ae-editor/ae-editor.rb', line 4790
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
4775
4776
4777
4778
4779
4780
4781
4782
4783
|
# File 'ext/ae-editor/ae-editor.rb', line 4775
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
|
4737
4738
4739
4740
4741
4742
4743
4744
4745
|
# File 'ext/ae-editor/ae-editor.rb', line 4737
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
|