Module: QDA::GUI::FindableText

Included in:
CompositeText, DocTextViewer
Defined in:
lib/weft/wxgui/controls/textcontrols.rb

Defined Under Namespace

Classes: UsefulFindReplaceData

Instance Method Summary collapse

Instance Method Details

#get_subjectObject



199
200
201
202
203
204
205
206
207
208
209
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 199

def get_subject()
  if @f_data.up?
    subject = get_range( 0, insertion_point )
  else
    subject = get_range( insertion_point, last_position )
  end
  if @f_data.no_matchcase?
    subject.downcase!
  end
  return subject
end

#initialize(*args) ⇒ Object



175
176
177
178
179
180
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 175

def initialize(*args)
  super(*args)
  @f_dialog = nil
  @f_data   = UsefulFindReplaceData.new(1)
  @hooked = nil
end

#on_find(evt) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 219

def on_find(evt)
  # query? bug in WxRuby 0.6.0 FindReplaceData#get_flags - 
  # doesn't get automatically updated as documented
  @f_data.flags = evt.flags

  # get the string we're searching for, bail out if nothing there
  sought  = @f_data.find_string()
  return if sought.empty?
  
  sought.downcase! if @f_data.no_matchcase?

  # get part of our contents in the right case ready to 
  return unless subject = get_subject()
  adjustment = 0
  # hack to avoid recapturing when searching down
  if searching_down? and string_selection == sought
    adjustment = sought.length
    subject = subject[adjustment .. -1]
  end
  
  point = searching_down? ? subject.index( sought ) :
                            subject.rindex( sought ) 
  if point
    if searching_up?
      self.insertion_point = true_point( point )
    else
      self.insertion_point = true_insertion_point + point + adjustment
    end
    
    sel_start = true_index_to_pos( insertion_point )
    sel_end   = true_index_to_pos( insertion_point + sought.length )
    self.set_selection( sel_end, sel_start )
  end
end

#on_find_close(evt) ⇒ Object



254
255
256
257
258
259
260
261
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 254

def on_find_close(evt)
  if @f_dialog
    @f_dialog.destroy()
    @f_dialog = nil
  end
  self.set_focus()
  evt.skip()
end

#searching_down?Boolean

Returns:

  • (Boolean)


211
212
213
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 211

def searching_down?
  @f_data.down?
end

#searching_up?Boolean

Returns:

  • (Boolean)


215
216
217
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 215

def searching_up?
  @f_data.up?
end

#start_find(parent_win) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/weft/wxgui/controls/textcontrols.rb', line 182

def start_find(parent_win)
  if not @f_dialog
    @f_dialog = Wx::FindReplaceDialog.new( parent_win, @f_data,
                                           "Find text", Wx::FR_NOWHOLEWORD )
  end
  if not @hooked
    # TextCtrl doesn't receive evt_find, so route through parent
    parent_win.evt_find(-1) { | e | on_find(e) }
    parent_win.evt_find_next(-1) { | e | on_find(e) }
    parent_win.evt_find_close(-1) { | e | on_find_close(e) }
    # ensure dialog is destroyed when parent is closed
    parent_win.evt_close() { | e | on_find_close(e) }
    @hooked = parent_win
  end
  @f_dialog.show()
end