Class: RubyCurses::PopupMenu

Inherits:
Menu show all
Defined in:
lib/rbcurse/rpopupmenu.rb

Instance Attribute Summary

Attributes inherited from Menu

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

Attributes inherited from MenuItem

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

Instance Method Summary collapse

Methods inherited from Menu

#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 MenuItem

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

Constructor Details

#initialize(text, &block) ⇒ PopupMenu

Returns a new instance of PopupMenu.



483
484
485
486
487
488
489
# File 'lib/rbcurse/rpopupmenu.rb', line 483

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

Instance Method Details

#destroyObject



522
523
524
525
526
527
528
529
530
531
532
# File 'lib/rbcurse/rpopupmenu.rb', line 522

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

#handle_keysObject

popup



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

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



490
491
492
493
494
495
496
# File 'lib/rbcurse/rpopupmenu.rb', line 490

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