Class: Wx::TextCompleterSimple

Inherits:
TextCompleter show all
Defined in:
lib/wx/doc/gen/text_entry.rb

Overview

A simpler base class for custom completer objects.

This class may be simpler to use than the base TextCompleter as it allows to implement only a single virtual method instead of two of them (at the price of storing all completions in a temporary array). Here is a simple example of a custom completer that completes the names of some chess pieces. Of course, as the total list here has only four items it would have been much simpler to just specify the array containing all the completions in this example but the same approach could be used when the total number of completions is much higher provided the number of possibilities for each word is still relatively small:

class MyTextCompleter < Wx::TextCompleterSimple

    def get_completions(prefix)
      firstWord = prefix.split(' ').shift
      if firstWord == 'white'
        ['white pawn', 'white rook']
      elsif firstWord == 'black'
        ['black king', 'black queen']
      else
        ['white', 'black']
      end
    end

  end
  ...
  text_ctrl = ...
  text_ctrl.auto_complete(MyTextCompleter.new)

Instance Method Summary collapse

Methods inherited from TextCompleter

#get_next, #start

Instance Method Details

#get_completions(prefix) ⇒ Array<String> Also known as: completions

Pure virtual method returning all possible completions for the given prefix.

The custom completer should examine the provided prefix and return all the possible completions for it in the output array res. Please notice that the returned values should start with the prefix, otherwise they will be simply ignored, making adding them to the array in the first place useless. Notice that this function may be called from thread other than main one (this is currently always the case under MSW) so the appropriate synchronization mechanism should be used to protect the shared data.

Parameters:

  • prefix (String)

    The possibly empty prefix that the user had already entered.

Returns:

  • (Array<String>)


430
# File 'lib/wx/doc/gen/text_entry.rb', line 430

def get_completions(prefix) end