ruby-****@sourc*****
ruby-****@sourc*****
2003年 11月 22日 (土) 05:42:00 JST
------------------------- REMOTE_ADDR = 208.197.227.51 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/?tut-treeview-selection-contextmenu ------------------------- = Context Menus 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 functions provided in your context menu can also be accessed 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: + 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) }