{"id":2285,"date":"2021-04-07T13:46:38","date_gmt":"2021-04-07T17:46:38","guid":{"rendered":"https:\/\/anvil-of-time.com\/?p=2285"},"modified":"2021-04-07T13:46:38","modified_gmt":"2021-04-07T17:46:38","slug":"100-days-of-powerbuilder-tutorial-day-8-adding-a-menu","status":"publish","type":"post","link":"https:\/\/anvil-of-time.com\/powerbuilder\/100-days-of-powerbuilder-tutorial-day-8-adding-a-menu\/","title":{"rendered":"100 Days of PowerBuilder &#8211; Tutorial &#8211; Day 8 &#8211; Adding a Menu"},"content":{"rendered":"<p>This is part of my project &#8216;100 Days of PowerBuilder&#8217; which is a series of discussions focused on basic PowerBuilder development.<\/p>\r\n<!-- \/wp:paragraph -->\r\n\r\n<!-- wp:paragraph -->\r\n<p><em>Note: This article is written with examples created in PowerBuilder 2019 R3. Most steps\/examples will be identical with any version going back to 9.<\/em><\/p>\r\n<!-- \/wp:paragraph -->\r\n\r\n<!-- wp:paragraph -->\r\n<p>Let&#8217;s take a look at menus.\u00a0 We will create a simple menu for our main application window created earlier.\u00a0 Choose File &#8211; New &#8211; PB Object &#8211; Menu then click OK.<\/p>\r\n<p><a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial001.png\"><img loading=\"lazy\" class=\"size-full wp-image-2287 alignnone\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial001.png\" alt=\"\" width=\"956\" height=\"481\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial001.png 956w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial001-300x151.png 300w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial001-768x386.png 768w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial001-150x75.png 150w\" sizes=\"(max-width: 956px) 100vw, 956px\" \/><\/a><\/p>\r\n<p>Now you have your newly created menu object called &#8216;untitled0&#8217;.\u00a0 Notice the Menu Style on the Appearance tab of the Properties is &#8216;traditionalmenu!&#8217;; change this to contemporarymenu! to open up the various other options.<\/p>\r\n<p><a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial003.png\"><img loading=\"lazy\" class=\"size-full wp-image-2288 alignnone\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial003.png\" alt=\"\" width=\"371\" height=\"561\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial003.png 371w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial003-198x300.png 198w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial003-99x150.png 99w\" sizes=\"(max-width: 371px) 100vw, 371px\" \/><\/a> \u00a0<\/p>\r\n<p>Now save the menu to the &#8216;firstapp&#8217; pbl as m_main.<\/p>\r\n<p><a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial008.png\"><img loading=\"lazy\" class=\"size-full wp-image-2290 alignnone\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial008.png\" alt=\"\" width=\"328\" height=\"369\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial008.png 328w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial008-267x300.png 267w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial008-133x150.png 133w\" sizes=\"(max-width: 328px) 100vw, 328px\" \/><\/a><\/p>\r\n<p>Right click on the &#8216;m_main&#8217; menu item and choose Insert Submenu Item; give it the name &#8216;File&#8217;.<\/p>\r\n<p><a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial009.png\"><img loading=\"lazy\" class=\"size-full wp-image-2291 alignnone\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial009.png\" alt=\"\" width=\"209\" height=\"235\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial009.png 209w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial009-133x150.png 133w\" sizes=\"(max-width: 209px) 100vw, 209px\" \/><\/a><\/p>\r\n<p>Then save the menu.\u00a0 Now associate the menu with the main window of the application by opening the w_main object and clicking on the elipsis button next to the MenuName property. \u00a0<\/p>\r\n<p><a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial010.png\"><img loading=\"lazy\" class=\"size-full wp-image-2292 alignnone\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial010.png\" alt=\"\" width=\"657\" height=\"366\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial010.png 657w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial010-300x167.png 300w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial010-150x84.png 150w\" sizes=\"(max-width: 657px) 100vw, 657px\" \/><\/a><\/p>\r\n<p>Now save the window and run the application.\u00a0 You should see the menu:<\/p>\r\n<p><a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial011.png\"><img loading=\"lazy\" class=\"size-full wp-image-2293 alignnone\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial011.png\" alt=\"\" width=\"405\" height=\"305\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial011.png 405w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial011-300x226.png 300w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial011-150x113.png 150w\" sizes=\"(max-width: 405px) 100vw, 405px\" \/><\/a><\/p>\r\n<p>Now granted the menu doesn&#8217;t do anything at all now but at least we know we have correctly associated it with the window.\u00a0 Go back and open the menu painter.\u00a0 Right click on the &#8216;File&#8217; menu item and choose Insert Submenu Item.\u00a0 Give it the name &#8216;Save&#8217;.\u00a0 \u00a0Once the control loses focus notice the visual example and the Name property are changed to reflect the menu item text.<\/p>\r\n<p><a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial013.png\"><img loading=\"lazy\" class=\"size-large wp-image-2295 alignnone\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial013.png\" alt=\"\" width=\"345\" height=\"168\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial013.png 345w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial013-300x146.png 300w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial013-150x73.png 150w\" sizes=\"(max-width: 345px) 100vw, 345px\" \/><\/a> <a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial012.png\"><img loading=\"lazy\" class=\"size-full wp-image-2296 alignnone\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial012.png\" alt=\"\" width=\"962\" height=\"217\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial012.png 962w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial012-300x68.png 300w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial012-768x173.png 768w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial012-150x34.png 150w\" sizes=\"(max-width: 962px) 100vw, 962px\" \/><\/a><\/p>\r\n<p>Now associate a menu icon with this option by clicking on the elipsis button next to MenuImage.<\/p>\r\n<p><a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial015.png\"><img loading=\"lazy\" class=\"size-full wp-image-2297 alignnone\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial015.png\" alt=\"\" width=\"675\" height=\"584\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial015.png 675w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial015-300x260.png 300w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial015-150x130.png 150w\" sizes=\"(max-width: 675px) 100vw, 675px\" \/><\/a><\/p>\r\n<p>Then choosing PB menu or toolbar icons<\/p>\r\n<p><a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial016.png\"><img loading=\"lazy\" class=\"size-full wp-image-2298 alignnone\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial016.png\" alt=\"\" width=\"677\" height=\"582\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial016.png 677w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial016-300x258.png 300w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/D8tutorial016-150x129.png 150w\" sizes=\"(max-width: 677px) 100vw, 677px\" \/><\/a><\/p>\r\n<p>Search for &#8216;Save&#8217; and then select the Save1! image, click OK, then save the menu. Open the w_main window again and add an event called &#8216;we_save&#8217; and insert the following:<\/p>\r\n<pre><code>\/\/ save the window then exit.\r\n\/\/\r\n\/\/insert save checking logic\r\nclose(THIS)<\/code><\/pre>\r\n<p><code><\/code><code><\/code><\/p>\r\n<p><code><\/code> Save the window and go back the the menu. In the clicked event of the Save menu option place the following:<\/p>\r\n<pre><code>parentwindow.triggerevent \"we_save\"<\/code><\/pre>\r\n<p>Now run the application.\u00a0 From the main menu click on &#8216;File&#8217; and then &#8216;Save&#8217;.\u00a0 You should be prompted for closing the window (same functionality as from the earlier window example). Now reopen the w_main window, go to the event list and delete the &#8216;we_save&#8217; event and then save the window.<\/p>\r\n<p><a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/d8tutorial017.png\"><img loading=\"lazy\" class=\"size-full wp-image-2299 alignnone\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/d8tutorial017.png\" alt=\"\" width=\"196\" height=\"300\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/d8tutorial017.png 196w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2021\/04\/d8tutorial017-98x150.png 98w\" sizes=\"(max-width: 196px) 100vw, 196px\" \/><\/a><\/p>\r\n<p>Now run the application and choose Save from the File menu.\u00a0 Nothing should happen now.\u00a0 This shows how the triggerevent method on menus can be used to create generic functionality.\u00a0 Non existing events can be triggered in PowerScript without the application crashing as would be the case of a function call.<\/p>\r\n<p><strong>Using Menu Methods<\/strong><\/p>\r\n<p>I consider it best practice to use menus primarily to trigger events on their parent windows.\u00a0 Although menus can have their own methods to do whatever processing is desired,\u00a0 I don&#8217;t believe there are any compelling reasons to architect an application this way \u00a0<\/p>","protected":false},"excerpt":{"rendered":"<p>This is part of my project &#8216;100 Days of PowerBuilder&#8217; which is a series of discussions focused on basic PowerBuilder development. Note: This article is written with examples created in PowerBuilder 2019 R3. Most steps\/examples will be identical with any version going back to 9. Let&#8217;s take a look at menus.\u00a0 We will create a&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[86,3],"tags":[62],"_links":{"self":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/2285"}],"collection":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/comments?post=2285"}],"version-history":[{"count":7,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/2285\/revisions"}],"predecessor-version":[{"id":2305,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/2285\/revisions\/2305"}],"wp:attachment":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/media?parent=2285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/categories?post=2285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/tags?post=2285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}