Class: Find
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_button, #add_menu_button, #create_frame, #head_buttons, #menu_button
Constructor Details
#initialize(_frame, _controller) ⇒ Find
Returns a new instance of Find.
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
|
# File 'ext/ae-editor/ae-editor.rb', line 3604
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.
3603
3604
3605
|
# File 'ext/ae-editor/ae-editor.rb', line 3603
def e_what
@e_what
end
|
Instance Method Details
#do_find(_istart = nil) ⇒ Object
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
|
# File 'ext/ae-editor/ae-editor.rb', line 3731
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_next ⇒ Object
3786
3787
3788
3789
3790
3791
|
# File 'ext/ae-editor/ae-editor.rb', line 3786
def do_find_next
if @idx1 != nil
self.editor.text.tag_remove('sel',@idx1,@idx2)
end
do_find(@last_index)
end
|
#do_replace ⇒ Object
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
|
# File 'ext/ae-editor/ae-editor.rb', line 3649
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
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
|
# File 'ext/ae-editor/ae-editor.rb', line 3660
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
3685
3686
3687
3688
3689
3690
|
# File 'ext/ae-editor/ae-editor.rb', line 3685
def editor
if @editor_caller == nil
@editor_caller = @controller.raised
end
return @editor_caller
end
|
#go_line ⇒ Object
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
|
# File 'ext/ae-editor/ae-editor.rb', line 3696
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
end
|
#show ⇒ Object
3719
3720
3721
3722
|
# File 'ext/ae-editor/ae-editor.rb', line 3719
def show
super
use(@controller.raised)
end
|
#show_go_to_line_dialog ⇒ Object
3692
3693
3694
|
# File 'ext/ae-editor/ae-editor.rb', line 3692
def show_go_to_line_dialog
@goto_line_dialog.show
end
|
#update_combo(_txt) ⇒ Object
3724
3725
3726
3727
3728
3729
|
# File 'ext/ae-editor/ae-editor.rb', line 3724
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
3709
3710
3711
3712
3713
3714
3715
3716
3717
|
# File 'ext/ae-editor/ae-editor.rb', line 3709
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
|
3674
3675
3676
3677
3678
3679
3680
3681
3682
|
# File 'ext/ae-editor/ae-editor.rb', line 3674
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
|