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, #hide_if_visible, #on_arcadia, #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_fixed_button, #add_fixed_menu_button, #add_fixed_panel, #add_fixed_progress, #add_fixed_sep, #create_frame, #head_buttons, #menu_button, #visible?

Constructor Details

#initialize(_frame, _controller) ⇒ Finder

Returns a new instance of Finder.



6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
# File 'ext/ae-editor/ae-editor.rb', line 6372

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{
    hide
    do_find_next
  }
  @b_go.bind('1', @find_action)
  
	 @b_replace.bind('1', proc{hide; do_replace})  
  
	 @b_replace_all.bind('1', proc{hide; do_replace_all})  

#    @e_what_entry.bind_append('KeyRelease'){|e|
  @e_what.bind_append('KeyRelease', "%K"){|_keysym|
    case _keysym
    when 'Return'
      @find_action.call
      Tk.callback_break
    else
      widget_state
    end
  }

  @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', "%K"){|_keysym|
    case _keysym
    when 'Return'
      go_line
      Tk.callback_break
    end
  }

end

Instance Attribute Details

#e_whatObject (readonly)

Returns the value of attribute e_what.



6371
6372
6373
# File 'ext/ae-editor/ae-editor.rb', line 6371

def e_what
  @e_what
end

Instance Method Details

#do_find(_istart = nil) ⇒ Object



6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
# File 'ext/ae-editor/ae-editor.rb', line 6513

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.value.length > 0
    update_combo(@e_what)
    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.value,_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.value.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.chrono_bookmark_add(self.editor.file, _index)
    else
      Arcadia.hinner_dialog(self, 'type'=>'ok', 'msg'=> Arcadia.text('ext.editor.search.notfound',[@e_what.value, self.editor.tab_title]))
    end

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

#do_find_nextObject



6568
6569
6570
6571
6572
6573
# File 'ext/ae-editor/ae-editor.rb', line 6568

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

#do_replaceObject



6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
# File 'ext/ae-editor/ae-editor.rb', line 6415

def do_replace
  if do_find_next        
      _message = Arcadia.text('ext.editor.search.d.replace.msg', [@e_what.value, @e_with.value])
      if Arcadia.hinner_dialog(self, 'type'=>'yes_no', 'msg'=> _message, 'title' => "Replace", 'level' => 'question')=='yes'
        self.editor.text.delete(@idx1,@idx2)
        self.editor.text.insert(@idx1,@e_with.value)
        self.editor.check_modify
      end
  end
  update_combo(@e_with) if @e_with.value.length > 0
end

#do_replace_allObject



6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
# File 'ext/ae-editor/ae-editor.rb', line 6427

def do_replace_all
  show_dialog = true
  founds = []
  while do_find_next
      break if founds.include?(@idx1)
      founds << @idx1
      if show_dialog
        _message = Arcadia.text('ext.editor.search.d.replace.msg', [@e_what.value, @e_with.value])
        _rc = Arcadia.hinner_dialog(self, 'type'=>'yes_yesall_no_cancel', 'msg'=> _message, 'title' => "Replace", 'level' => 'question')
      end
      if _rc == 'yes' || _rc == 'yesall'
        self.editor.text.delete(@idx1,@idx2)
        self.editor.text.insert(@idx1,@e_with.value)
        self.editor.check_modify
        show_dialog = _rc != 'yesall'
      elsif _rc == 'cancel'
        break
      end
  end
  update_combo(@e_with) if @e_with.value.length > 0
end

#editorObject



6460
6461
6462
6463
6464
6465
# File 'ext/ae-editor/ae-editor.rb', line 6460

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

#go_lineObject



6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
# File 'ext/ae-editor/ae-editor.rb', line 6472

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.chrono_bookmark_add(self.editor.file, _index)
  @goto_line_dialog.hide
  end
  #self.hide()
end

#showObject



6498
6499
6500
6501
# File 'ext/ae-editor/ae-editor.rb', line 6498

def show
  super
  use(@controller.raised)
end

#show_go_to_line_dialogObject



6467
6468
6469
6470
# File 'ext/ae-editor/ae-editor.rb', line 6467

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

#update_combo(_combobox = nil) ⇒ Object



6503
6504
6505
6506
6507
6508
6509
6510
6511
# File 'ext/ae-editor/ae-editor.rb', line 6503

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
#    @e_what.insert('end', @e_what.value)
  end
end

#use(_editor) ⇒ Object



6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
# File 'ext/ae-editor/ae-editor.rb', line 6487

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

#widget_stateObject



6449
6450
6451
6452
6453
6454
6455
6456
6457
# File 'ext/ae-editor/ae-editor.rb', line 6449

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