Class: RubyCurses::TabbedPane

Inherits:
Widget show all
Defined in:
lib/rbhex/core/widgets/rtabbedpane.rb

Instance Attribute Summary collapse

Attributes inherited from Widget

#_object_created, #col_offset, #cols_panned, #config, #curpos, #focussed, #form, #id, #key_label, #parent_component, #row_offset, #rows_panned, #state

Instance Method Summary collapse

Methods inherited from Widget

#action_manager, #changed, #click, #color_pair, #destroy, #enter, #event_list, #focus, #get_preferred_size, #getvalue, #getvalue_for_paint, #height, #height=, #hide, #leave, #modified?, #move, #override_graphic, #process_key, #remove, #repaint_all, #repaint_required, #rowcol, #set_buffer_modified, #set_buffering, #set_form, #set_modified, #setformrowcol, #setrowcol, #show, #text_variable, #unbind_key, #width, #width=

Methods included from Io

#__create_footer_window, #clear_this, #get_file, #print_this, #rb_getchar, #rb_gets, #rbgetstr, #warn

Methods included from Utils

#OLDdefine_key, #_process_key, #bind_key, #bind_keys, #clean_string!, #define_key, #define_prefix_command, #display_app_help, #get_attrib, #get_color, #keycode_tos, #last_line, #one_line_window, #parse_formatted_text, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #view, #wrap_text

Methods included from ConfigSetup

#cget, #config_setup, #configure, #variable_set

Methods included from EventHandler

#bind, #fire_handler, #fire_property_change

Constructor Details

#initialize(form = nil, config = {}, &block) ⇒ TabbedPane

Returns a new instance of TabbedPane.

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 33

def initialize form=nil, config={}, &block
  @_events ||= []
  @_events.push(:PRESS)
  @button_gap = 2
  init_vars
  super
  @focusable = true
  @editable  = true
  @col_offset = 2
  raise ArgumentError, "NewTabbedPane : row or col not set: r: #{@row} c: #{@col} "  unless @row && @col
end

Instance Attribute Details

#button_rowObject (readonly)

Returns the value of attribute button_row.



28
29
30
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 28

def button_row
  @button_row
end

#current_tabObject (readonly)

index of tab that is currently open



30
31
32
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 30

def current_tab
  @current_tab
end

Instance Method Details

#command(*args, &block) ⇒ Object

a shortcut for binding a command to a press of an action button The block will be passed This is only relevant if you have asked for buttons to be created, which is only relevant in a TabbedWindow ActionEvent has source event and action_command



60
61
62
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 60

def command *args, &block
  bind :PRESS, *args, &block
end

#DEPRECATED_handle_key(ch) ⇒ Object

:nodoc



339
340
341
342
343
344
345
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 339

def DEPRECATED_handle_key ch # :nodoc
  map_keys unless @keys_mapped
  ret = process_key ch, self
  @multiplier = 0
  return :UNHANDLED if ret == :UNHANDLED
  return 0
end

#goto_component(comp) ⇒ Object

set focus on given component Sometimes you have the handle to component, and you want to move focus to it



322
323
324
325
326
327
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 322

def goto_component comp
  return if comp == @current_component
  leave_current_component
  @current_component = comp
  set_form_row
end

#goto_first_itemObject

takes focus to first item (after buttons)



205
206
207
208
209
210
211
212
213
214
215
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 205

def goto_first_item
  bc = @buttons.count
  @components[bc..-1].each { |c|
    if c.focusable
      leave_current_component
      @current_component = c
      set_form_row
      break
    end
  }
end

#goto_last_itemObject

takes focus to last item



218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 218

def goto_last_item
  bc = @buttons.count
  f = nil
  @components[bc..-1].each { |c|
    if c.focusable
      f = c
    end
  }
  if f
    leave_current_component
    @current_component = f
    set_form_row
  end
end

#goto_next_componentObject

take focus to the next component or item Called from DOWN, RIGHT or Tab



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 234

def goto_next_component
  if @current_component != nil
    leave_current_component
    if on_last_component?
      @_entered = false
      return :UNHANDLED
    end
    @current_index = @components.index(@current_component)
    index = @current_index + 1
    index.upto(@components.length-1) do |i|
      f = @components[i]
      if f.focusable
        @current_index = i
        @current_component = f
        return set_form_row
      end
    end
  end
  @_entered = false
  return :UNHANDLED
end

#goto_prev_componentObject

take focus to prev component or item Called from LEFT, UP or Back Tab



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 257

def goto_prev_component
  if @current_component != nil
    leave_current_component
    if on_first_component?
      @_entered = false
      return :UNHANDLED
    end
    @current_index = @components.index(@current_component)
    index = @current_index -= 1
    index.downto(0) do |i|
      f = @components[i]
      if f.focusable
        @current_index = i
        @current_component = f
        return set_form_row
      end
    end
  end
  return :UNHANDLED
end

#handle_key(ch) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 116

def handle_key ch
  $log.debug " NEWTABBED handle_key #{ch} "
  return if @components.empty?
  _multiplier = ($multiplier == 0 ? 1 : $multiplier )

  # should this go here 2011-10-19
  unless @_entered
    $log.warn "WARN: calling ON_ENTER since in this situation it was not called"
    on_enter
  end
  #if ch == KEY_TAB
    #$log.debug "NEWTABBED GOTO NEXT"
    #return goto_next_component
  #elsif ch == KEY_BTAB
    #return goto_prev_component
  #end
  comp = @current_component
  $log.debug " NEWTABBED handle_key #{ch}: #{comp}"
  if comp
    ret = comp.handle_key(ch)
    $log.debug " NEWTABBED handle_key#{ch}: #{comp} returned #{ret} "
    if ret != :UNHANDLED
      comp.repaint # NOTE: if we don;t do this, then it won't get repainted. I will have to repaint ALL
      # in repaint of this.
      return ret
    end
    $log.debug "XXX NEWTABBED key unhandled by comp #{comp.name} "
  else
    Ncurses.beep
    $log.warn "XXX NEWTABBED key unhandled NULL comp"
  end
  case ch
  when ?\C-c.getbyte(0)
    $multiplier = 0
    return 0
  when ?0.getbyte(0)..?9.getbyte(0)
    $log.debug " VIM coming here to set multiplier #{$multiplier} "
    $multiplier *= 10 ; $multiplier += (ch-48)
    return 0
  end
  ret = process_key ch, self
  # allow user to map left and right if he wants
  if ret == :UNHANDLED
    case ch
    when KEY_UP, KEY_BTAB
      # form will pick this up and do needful
      return goto_prev_component #unless on_first_component?
    when KEY_LEFT
      # if i don't check for first component, key will go back to form,
      # but not be processes. so focussed remain here, but be false.
      # In case of returnign an unhandled TAB, on_leave will happen and cursor will move to
      # previous component outside of this.
      return goto_prev_component unless on_first_component?
    when KEY_RIGHT, KEY_TAB
      return goto_next_component #unless on_last_component?
    when KEY_DOWN
      if on_a_button?
        return goto_first_item
      else
        return goto_next_component #unless on_last_component?
      end
    else
      #@_entered = false
      return :UNHANDLED
    end
  end

  $multiplier = 0
  return 0
end

#insert_tab(index, title, config = {}, &block) ⇒ Object

insert a tab at index, with title



67
68
69
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 67

def insert_tab index, title, config={}, &block
  @tabs.insert(index, Tab.new(title, self, config, &block) )
end

#leave_current_componentObject

leave the component we are on. This should be followed by all containers, so that the on_leave action of earlier comp can be displayed, such as dimming components selections



297
298
299
300
301
302
303
304
305
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 297

def leave_current_component
  @current_component.on_leave
  # NOTE this is required, since repaint will just not happen otherwise
  # Some components are erroneously repainting all, after setting this to true so it is
  # working there.
  @current_component.repaint_required true
  $log.debug " after on_leave VIMS XXX #{@current_component.focussed}   #{@current_component.name}"
  @current_component.repaint
end

#on_a_button?Boolean

returns true if user on an action button

Returns:

  • (Boolean)

    true or false



317
318
319
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 317

def on_a_button?
  @components.index(@current_component) < @buttons.count
end

#on_enterObject

on enter processing Very often the first may be a label !



188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 188

def on_enter
  # if BTAB, the last comp
  if $current_key == KEY_BTAB
    @current_component = @components.last
  else
    @current_component = @components.first
  end
  return unless @current_component
  $log.debug " NEWTABBED came to ON_ENTER #{@current_component} "
  set_form_row
  @_entered = true
end

#on_first_component?Boolean

is focus on first component

Returns:

  • (Boolean)


308
309
310
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 308

def on_first_component?
  @current_component == @components.first
end

#on_last_component?Boolean

is focus on last component

Returns:

  • (Boolean)


312
313
314
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 312

def on_last_component?
  @current_component == @components.last
end

#on_leaveObject



200
201
202
203
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 200

def on_leave
  @_entered = false
  super
end

#remove_allObject

remove all tabs



76
77
78
79
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 76

def remove_all
  @tabs = []
  self
end

#remove_tab(tab) ⇒ Object

remove given tab



71
72
73
74
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 71

def remove_tab tab
  @tabs.delete tab
  self
end

#remove_tab_at(index = @current_tab) ⇒ Object

remove tab at given index, defaulting to current



81
82
83
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 81

def remove_tab_at index = @current_tab
  @tabs.delete_at index
end

#repaintObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 85

def repaint
  @current_tab ||= 0
  @button_row ||=  @row + 2
  @separator_row = @button_row + 1 # hope we have it by now, where to print separator
  @separator_row0 = @button_row - 1 unless @button_row == @row + 1
  @separator_row2 = @row + @height - 3 # hope we have it by now, where to print separator
  #return unless @repaint_required
  if @buttons.empty?
    _create_buttons
    @components = @buttons.dup
    @components.push(*@tabs[@current_tab].items)
    create_action_buttons
    @components.push(*@action_buttons)
  elsif @tab_changed
    @components = @buttons.dup
    @components.push(*@tabs[@current_tab].items)
    @components.push(*@action_buttons)
    @tab_changed = false
  end
  # if some major change has happened then repaint everything
  if @repaint_required
    $log.debug " NEWTAB repaint graphic #{@graphic} "
    print_borders unless @suppress_borders # do this once only, unless everything changes
    print_separator1
    @components.each { |e| e.repaint_all(true); e.repaint }
  else
    @components.each { |e| e.repaint }
  end # if repaint_required
  print_border if (@suppress_borders == false && @repaint_all) # do this once only, unless everything changes
  @repaint_required = false
end

#set_current_tab(t) ⇒ Object

set current tab to given tab

Returns:

  • self



330
331
332
333
334
335
336
337
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 330

def set_current_tab t
  return if @current_tab == t
  @current_tab = t
  goto_component @components[t]
  @tab_changed = true
  @repaint_required = true
  self
end

#set_form_colObject

private



289
290
291
292
293
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 289

def set_form_col
  return if @current_component.nil?
  $log.debug " #{@name} NEWTABBED  set_form_col calling sfc for #{@current_component.name} "
  @current_component.set_form_col
end

#set_form_rowObject

private



278
279
280
281
282
283
284
285
286
287
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 278

def set_form_row
  return :UNHANDLED if @current_component.nil?
  $log.debug " NEWTABBED on enter sfr #{@current_component} "
  @current_component.on_enter
  @current_component.set_form_row # why was this missing in vimsplit. is it
  # that on_enter does a set_form_row
  @current_component.set_form_col # XXX
  @current_component.repaint
  # XXX compo should do set_form_row and col if it has that
end

#tab(title, config = {}, &block) ⇒ Object Also known as: add_tab

Add a tab

Parameters:

  • String

    name of tab, may have ampersand for hotkey/accelerator



47
48
49
50
51
52
# File 'lib/rbhex/core/widgets/rtabbedpane.rb', line 47

def tab title, config={}, &block
  #@tab_components[title]=[]
  #@tabs << Tab.new(title, self, config, &block)
  insert_tab @tabs.count, title, config, &block
  self
end