module Canis::FieldHistory

Public Class Methods

extended(obj) click to toggle source
# File lib/canis/core/include/rhistory.rb, line 23
def self.extended(obj)

  obj.instance_exec {
    @history ||= []
    $history_key ||= ?\M-h
    # ensure that the field is not overriding this in handle_key
    bind_key($history_key) { _show_history }
    # widget should have CHANGED event, or this will either give error, or just not work
    # else please update history whenever you want a value to be retrieved
    bind(:CHANGED) { @history << @text if @text && (!@history.include? @text) }
  }
end

Public Instance Methods

history(arr) click to toggle source

pass the array of history values Trying out a change where an item can also be sent in. I am lost, i want the initialization to happen once.

# File lib/canis/core/include/rhistory.rb, line 39
def history arr
  return @history unless arr
  if arr.is_a? Array
    @history = arr 
  else
    @history << arr unless @history.include? arr
  end
end
history=(x) click to toggle source
# File lib/canis/core/include/rhistory.rb, line 47
def history=(x); history(x); end
history_config(config={}) click to toggle source

pass in some configuration for histroy such as row and column to show popup on

# File lib/canis/core/include/rhistory.rb, line 50
def history_config config={}
  @_history_config = config
end

Private Instance Methods

_show_history() click to toggle source

popup the hist

# File lib/canis/core/include/rhistory.rb, line 57
def _show_history
  return unless @history
  return  if @history.empty?
  list = @history
  @_history_config ||= {}
  #list = ["No history"]  if @history.empty?
  raise ArgumentError, "show_history got nil list" unless list
  # calculate r and c
  # col if fine, except for when there's a label.
  wcol = 0 # taking care of when dialog uses history 2012-01-4
  wcol = self.form.window.left if self.form
  c = wcol + ( @field_col || @col) # this is also dependent on window coords, as in a status_window or messagebox
  sz = @history.size
  wrow = 0
  wrow = self.form.window.top if self.form
  crow = wrow + @row
  # if list can be displayed above, then fit it just above
  if crow > sz + 2
    r = crow - sz - 2
  else
    # else fit it in next row
    r = crow + 1
  end
  #r = @row - 10
  #if @row < 10
    #r = @row + 1
  #end
  r = @_history_config[:row] || r
  c = @_history_config[:col] || c
  ret = popuplist(list, :row => r, :col => c, :title  => " History ", :color => :white, :bgcolor => :cyan)
  if ret
    self.text = list[ret] 
    self.set_form_col 
  end
  @form.repaint if @form
  @window.wrefresh if @window
end