ruby-****@sourc*****
ruby-****@sourc*****
2012年 10月 31日 (水) 06:11:45 JST
------------------------- REMOTE_ADDR = 74.14.158.59 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-mnstbs-mnui ------------------------- @@ -253,7 +253,8 @@ Here we define the top menu items. Note, that the second item saved in variable 'mitem2' is the sub-menu, hence no signal handling is required for this menu item. -2-{{br}} Next we proceed to the first sub-menu on the top menu, which we created in step #1 (well, on our top menu we have only one sub-menu item, but in general there could be more on every menu and/or sub-menu). The difference between, how we passed menu items to our 'mk_submenu' method in the earlier 'menuitems-n-submenus-1.rb' program and now, here in 'menuitems-n-submenus-2.rb' is, that instead of a list which was collected into the array parameter earlier, now we build a hash in which keys are the menu items, and the value is supposed to be the the callback proc for final (leaf) menu items which are passed in as String objects, and((*nul*))for the sub-menus and separators which are of type Gtk::Menu and Gtk::MenuItem respectively. - + + # (2. menu building step) top_menus_1st_submenu_hash = { sub_submenu1 => nil, # demands that 'sub_submenu1' is created by now => {{ step 3 }}. @@ -262,9 +263,19 @@ "t1-test2" => t1_test2_lambda, } - The first menu item on our context menu's sub-menu is also a sub-menu with the name 'sub_submenu1'. The next item this sub-sub menu is the separator (see: 9.1.1.1 ((<Menu Item Separators|tut-gtk2-mnstbs-popup#For Separators in menus use MenuItem with no label>))). Indeed, we need no callback here either, so just like for the the menu object stored in 'sub_submenu1' variable, the value for its hash entry is((*nil.*))As the comment in the third line above suggests, we will, next, need to make sure that the 'sub_submenu1' variable exists. This determines our next step #3. + The first menu item on our context menu's sub-menu is also a sub-menu with the name 'sub_submenu1'. The next item this sub-sub menu is the separator (see: 9.1.1.1 ((<Menu Item Separators|tut-gtk2-mnstbs-popup#For Separators in menus use MenuItem with no label>))). Indeed, we need no callback here either, so just like for the the menu object stored in 'sub_submenu1' variable, the value for its hash entry is((*nil.*))As the comment in the third line above suggests, we will, next, need to make sure that the 'sub_submenu1' variable exists. This determines our next step #3, which will have to be located in the source code before this step (#2). + -3-{{br}} Because the in the variable 'sub_submenu1' is also stored a menu, i.e. the submenu with two final (leaf) menu items, called 't1-test1' and 't1-test2', which will both potentially need different callback procs, step 3 first has to build the appropriate hash array and use it as the argument in the call to our 'mk_submenu' helper method. Finally, after this sub-sub menu is created, we also need to give it the((*name,*))so when it is used in the 'mk_submenu' method as the menu object, we will be able to assign this name to the menu item, which wil represent the sub-menu. Let's see the code that needs to be written in this step #3: + + # (3. menu building step) + submenu1_menuitems_n_calbacks_hash = { + "sub-sub1:item-1" => ss1_item_1_lambda, + "sub-sub1:item-2" => ss1_item_2_lambda, + } + sub_submenu1 = mk_submenu(submenu1_menuitems_n_calbacks_hash, true) + sub_submenu1.name = "sub-sub menu1"