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.



6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
# File 'ext/ae-editor/ae-editor.rb', line 6265

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'){|e|
    case e.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'){|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.



6264
6265
6266
# File 'ext/ae-editor/ae-editor.rb', line 6264

def e_what
  @e_what
end

Instance Method Details

#do_find(_istart = nil) ⇒ Object



6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
# File 'ext/ae-editor/ae-editor.rb', line 6406

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



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

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

#do_replaceObject



6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
# File 'ext/ae-editor/ae-editor.rb', line 6308

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



6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
# File 'ext/ae-editor/ae-editor.rb', line 6320

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



6353
6354
6355
6356
6357
6358
# File 'ext/ae-editor/ae-editor.rb', line 6353

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

#go_lineObject



6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
# File 'ext/ae-editor/ae-editor.rb', line 6365

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



6391
6392
6393
6394
# File 'ext/ae-editor/ae-editor.rb', line 6391

def show
  super
  use(@controller.raised)
end

#show_go_to_line_dialogObject



6360
6361
6362
6363
# File 'ext/ae-editor/ae-editor.rb', line 6360

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

#update_combo(_combobox = nil) ⇒ Object



6396
6397
6398
6399
6400
6401
6402
6403
6404
# File 'ext/ae-editor/ae-editor.rb', line 6396

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



6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
# File 'ext/ae-editor/ae-editor.rb', line 6380

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



6342
6343
6344
6345
6346
6347
6348
6349
6350
# File 'ext/ae-editor/ae-editor.rb', line 6342

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