ruby-****@sourc*****
ruby-****@sourc*****
2012年 10月 31日 (水) 09:17:52 JST
------------------------- REMOTE_ADDR = 74.14.158.59 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-mnstbs-mnui ------------------------- @@ -289,16 +289,19 @@ sub-sub1:item-1 ........ ss1_item_1_lambda sub-sub1:item-2 ........ ss1_item_2_lambda - Once we are sure our menu design is correct, we can proceed to step #4 - creating the callback procedures. Since these procedures will are needed in our previous steps, we are required to place them high enough in our program listing, to be visible at the time they are used. To be on the safe side we will place the code creating these procs just before our step #1 above. Following is the code segment presenting the entire step #4 in our program example: + -4-{{br}} Once we are sure our menu design is correct, we can proceed to step #4 - creating the callback procedures. According to the way our menu item callbacks will be implemented, which we anticipated already above in section 9.4.1.2 entitled '((<Signal Handling Mechanisms And Callbacks With Sub-menus|tut-gtk2-mnstbs-mnui#Signal Handling Mechanisms And Callbacks With Sub-menus>))', and because our menu design requires that the callback procedures we create are some kind of proc objects, we decided to use lambdas for these callbacks. We can the store these lambdas as Proc objects in the variables, identified above in step #3.a under the column Callbacks. + + Since these procedures will are needed in our previous steps, we are required to place them high enough in our program listing, to be visible at the time they are used. To be on the safe side we will place the code creating these procs just before our step #1 above. Following is the code segment presenting the entire step #4 in our program example: # (4. menu building step) # These lambdas, or procs can indeed be different for ech menu item t1_test1_lambda = lambda {|p, w| puts "item: #{p} selected; w=#{w.class}" } t1_test2_lambda = lambda {|p, w| puts "item: #{p} selected; w=#{w.class}" } ss1_item_1_lambda = lambda {|p, w| puts "item: #{p} selected; w=#{w.class}" } - ss1_item_2_lambda = lambda {|p, w| puts "item: #{p} selected; w=#{w.class}" } + ss1_item_2_lambda = lambda {|p, w| puts "item: #{p} selected; w=#{w.class}" } + - We conclude our menu design with the final step #5. The location of this code in our program listing should be at the end of the entire menu building process. In this code segment we assign all the sub-menus found in the top level menu. Again, in our case, the top menu has only two items, the first which is the leaf or final menu item called 'Test1', stored in variable 'mitem1', and the second menu item called 'Test2', stored in variable 'mitem2' and which actually represents the first sub-menu in the top level context menu. Following is the code from step #5: + -5-{{br}} We conclude our menu design with the final step #5. The location of this code in our program listing should be at the end of the entire menu building process. In this code segment we assign all the sub-menus found in the top level menu. Again, in our case, the top menu has only two items, the first which is the leaf or final menu item called 'Test1', stored in variable 'mitem1', and the second menu item called 'Test2', stored in variable 'mitem2' and which actually represents the first sub-menu in the top level context menu. Following is the code from step #5: # (5. menu building step) mitem2.submenu = mk_submenu(top_menus_1st_submenu_hash, true)