Class: RubyCurses::PopupMenu

Inherits:
PMenu show all
Defined in:
lib/rbcurse/extras/widgets/rpopupmenu.rb

Instance Attribute Summary

Attributes inherited from PMenu

#col, #current_menu, #enabled, #items, #panel, #parent, #row, #row_margin, #width, #window

Attributes inherited from PMenuItem

#accelerator, #col, #enabled, #mnemonic, #parent, #row, #width

Instance Method Summary collapse

Methods inherited from PMenu

#add, #add_separator, #array_width, #check_mnemonics, #clear_menus, #create_action_component, #create_window, #fire, #get_item, #handle_key, #highlight, #insert, #insert_separator, #on_enter, #on_leave, #remove, #repaint, #select_item, #select_next_item, #select_prev_item, #to_s

Methods inherited from PMenuItem

#command, #fire, #highlight, #on_enter, #on_leave, #repaint, #text, #to_s

Constructor Details

#initialize(text, &block) ⇒ PopupMenu

Returns a new instance of PopupMenu.



485
486
487
488
489
490
491
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 485

def initialize text, &block
  @row_margin = 0
  @@row = 0
  @@col = 0
  super
  instance_eval &block if block_given?
end

Instance Method Details

#destroyObject



524
525
526
527
528
529
530
531
532
533
534
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 524

def destroy
  $log.debug "DESTRY popup "
  @visible = false
  panel = @window.panel
  Ncurses::Panel.del_panel(panel.pointer) if !panel.nil?   
  @window.delwin if !@window.nil? # FFI
  @items.each do |item|
    item.destroy
  end
  @window = nil
end

#handle_keysObject

popup



499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 499

def handle_keys  # popup
  @toggle_key ||= 27 # default switch off with ESC, if nothing else defined
  begin
  catch(:menubarclose) do
  while((ch = @window.getchar()) != @toggle_key )
    case ch
    when -1
      next
    else
      ret = handle_key ch
      $log.debug " POPUP got #{ret} added 2009-01-21 18:18 "
      break if ret == :CLOSE
    end
    Ncurses::Panel.update_panels();
    Ncurses.doupdate();

    @window.wrefresh
  end
  end # catch
  ensure
    #ensure is required becos one can throw a :close
  @@menus = [] # added 2009-01-23 13:21 
  destroy  # Note that we destroy the menu bar upon exit
  end
end

#show(component, x, y) ⇒ Object



492
493
494
495
496
497
498
# File 'lib/rbcurse/extras/widgets/rpopupmenu.rb', line 492

def show component, x, y
  @component = component
  @@row = component.row
  @@col = component.col
  create_window
  handle_keys
end