Class: RubyCurses::ResultsetBrowser

Inherits:
Object
  • Object
show all
Includes:
ConfigSetup, Utils
Defined in:
lib/rbcurse/experimental/widgets/resultsetbrowser.rb

Overview

< Widget

Since:

  • 1.4.1

Instance Method Summary collapse

Constructor Details

#initialize(win, config = {}, &block) ⇒ ResultsetBrowser

Returns a new instance of ResultsetBrowser.

Since:

  • 1.4.1



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rbcurse/experimental/widgets/resultsetbrowser.rb', line 27

def initialize win, config={}, &block
  @should_print_border = true
  @v_window = win #form.window
  @window = @v_window
  @focusable = true
  @editable  = true
  @old_index = @current_index = 0
  @fields = nil
  config_setup config 
  instance_eval &block if block_given?
  init_vars
end

Instance Method Details

#columns=(columns) ⇒ Object

Since:

  • 1.4.1



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rbcurse/experimental/widgets/resultsetbrowser.rb', line 63

def columns=(columns)
  @columns = columns
  h = @columns.count + 2
  w = 150 
  #row = 1
  #col = 1
  row = @row + @border_offset
  col = @col + @border_offset
  @v_form.set_pad_dimensions(row, col, h, w)
  @v_form.should_print_border(false) # this should use dimensions of object not window. # 2011-10-12 15:48:14
  # currently I don't have space for any buttons or anything.  The form takes all space of the window
  # not of the object defined.
  # I should be able to tell Scrollform to use only thismuch of window.
end

#data=(rows) ⇒ Object

Since:

  • 1.4.1



60
61
62
# File 'lib/rbcurse/experimental/widgets/resultsetbrowser.rb', line 60

def data=(rows)
  @rows = rows
end

#handle_key(ch) ⇒ Object

Since:

  • 1.4.1



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/rbcurse/experimental/widgets/resultsetbrowser.rb', line 81

def handle_key ch
  map_keys unless @mapped
  $log.debug "XXX: RB HK got ch "
  ret =  @v_form.handle_key ch
  #set_form_row
  if ret == :UNHANDLED
    @v_form.process_key ch, self
  end
  repaint
  @v_window.wrefresh
end

#init_varsObject

Since:

  • 1.4.1



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rbcurse/experimental/widgets/resultsetbrowser.rb', line 44

def init_vars
  @row ||= 0
  @col ||= 0
  @height ||= 15
  @width ||= 50
  @field_offset = 14   # where actual Field should start (leaving space for label)
  @row_offset ||= 0
  @col_offset ||= 1
  @border_offset = 0
  if @should_print_border
    @border_offset = 1
  end
  @v_form = RubyCurses::ScrollForm.new @v_window
  @v_form.display_h(@height-1-@border_offset*2) if @height
  @v_form.display_w(@width-1-@border_offset*2)  if @width
end

#map_keysObject

Since:

  • 1.4.1



39
40
41
42
43
# File 'lib/rbcurse/experimental/widgets/resultsetbrowser.rb', line 39

def map_keys
  @v_form.bind_key(?\C-n) { @current_index += 1 if @current_index < @rows.count-1 }
  @v_form.bind_key(?\C-p) {  @current_index -= 1  if @current_index > 0 }
  @mapped = true
end

#repaintObject

Since:

  • 1.4.1



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/rbcurse/experimental/widgets/resultsetbrowser.rb', line 92

def repaint
  @fields ||= _create_fields
  #alert "old #{@old_index} , #{@current_index} "
  if @old_index != @current_index
    #alert "index change"
    row = @rows[@current_index]
    @columns.each_with_index { |e, i|  
      value = row[i]
      len = value.to_s.length
      type=@rows[0].types[i]
      if type == "TEXT"
        value = value.gsub(/\n/," ") if value
      end
      f = @fields[i]
      @fields[i].set_buffer(value)
      if f.display_length < len && len < (@width - @field_offset)
        @fields[i].display_length len
      end
    }
    @v_form.repaint
    @window.wrefresh
    Ncurses::Panel.update_panels
    @old_index = @current_index
  end
end

#set_form_rowObject

currently I don’t have space for any buttons or anything. The form takes all space of the window not of the object defined. I should be able to tell Scrollform to use only thismuch of window.

Since:

  • 1.4.1



77
78
79
80
# File 'lib/rbcurse/experimental/widgets/resultsetbrowser.rb', line 77

def set_form_row
  f = @v_form.get_current_field
  f.set_form_row
end

#unused_on_enterObject

maybe not required since we don’t have 2 forms now

Since:

  • 1.4.1



118
119
120
121
122
123
124
125
# File 'lib/rbcurse/experimental/widgets/resultsetbrowser.rb', line 118

def unused_on_enter
  if $current_key == KEY_BTAB
    c = @v_form.widgets.count-1
    @v_form.select_field c
  else
    @v_form.select_field 0
  end
end