[ruby-gnome2-doc-cvs] [Hiki] update - tut-treeview-selection-contextmenu

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2004年 4月 3日 (土) 07:40:56 JST


-------------------------
REMOTE_ADDR = 200.216.151.125
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/en/?tut-treeview-selection-contextmenu
-------------------------
- {{link "tut-treeview-selection-doubleclick", nil, "tut-treeview", "tut-treeview-resources"}}
  = Context Menus
+ {{link "tut-treeview-selection-doubleclick", nil, "tut-treeview", "tut-treeview-resources"}}
  
  Context menus are context-dependent menus that pop up when a user right-clicks on a list or tree and usually let the user do something with the selected items or manipulate the list or tree in other ways.
  
  Right-clicks on a tree view are caught just like mouse button clicks are caught with any other widgets, namely by connecting to the tree view's "button_press_event" signal handler (which is a Gtk::Widget signal, and as Gtk::TreeView is derived from Gtk::Widget it has this signal as well). Additionally, you should also connect to the "popup-menu" signal, so users can access your context menu without a mouse. The "popup-menu" signal is emitted when the user presses Shift-F10. Also, you should make sure that all actions provided in your context menu can also be performed by other means such as the application's main menu. See the ((<GNOME Human Interface Guidelines (HIG)|URL: http://developer.gnome.org/projects/gup/hig/>)) for more details. Straight from the a-snippet-of-code-says-more-than-a-thousand-words-department, some code to look at: 
  
    # Create a menu
    menu = Gtk::Menu.new
  
    # Add an item with a silly callback
    item = Gtk::MenuItem.new("Do Something")
    item.signal_connect("activate") { puts "Did something!" }
    menu.append(item)
  
    menu.show_all
  
    # Popup the menu on right click
    view.signal_connect("button_press_event") do |widget, event|
      if event.kind_of? Gdk::EventButton and event.button == 3
        menu.popup(nil, nil, event.button, event.time)
      end
    end
  
    # Popup the menu on Shift-F10
    view.signal_connect("popup_menu") { menu.popup(nil, nil, 0, Gdk::Event::CURRENT_TIME) }





ruby-gnome2-cvs メーリングリストの案内
Back to archive index