{"id":2186,"date":"2020-09-13T17:10:42","date_gmt":"2020-09-13T21:10:42","guid":{"rendered":"http:\/\/michaelrowe01.com\/?p=2186"},"modified":"2022-12-15T06:46:04","modified_gmt":"2022-12-15T11:46:04","slug":"adding-menus-and-keyboard-shortcuts","status":"publish","type":"post","link":"https:\/\/michaelrowe01.com\/index.php\/blog\/adding-menus-and-keyboard-shortcuts\/","title":{"rendered":"Adding Menus and Keyboard Shortcuts"},"content":{"rendered":"\n<p>As I continue to work on Wasted Time, I now have added working keyboard shortcuts, and menu items to both the iPad and macOS versions.  I can&#8217;t wait for Big Sur and iPadOS 14 to come up so I can release these to the world.<\/p>\n\n\n\n<p>First a few screenshots<\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-3 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"660\" height=\"523\" src=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Screen-Shot-2020-09-13-at-17.00.18.png?resize=660%2C523&#038;ssl=1\" alt=\"\" data-id=\"2187\" data-full-url=\"https:\/\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Screen-Shot-2020-09-13-at-17.00.18.png\" data-link=\"https:\/\/michaelrowe01.com\/?attachment_id=2187\" class=\"wp-image-2187\" srcset=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Screen-Shot-2020-09-13-at-17.00.18.png?w=839&amp;ssl=1 839w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Screen-Shot-2020-09-13-at-17.00.18.png?resize=300%2C238&amp;ssl=1 300w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Screen-Shot-2020-09-13-at-17.00.18.png?resize=768%2C609&amp;ssl=1 768w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"660\" height=\"533\" src=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Screen-Shot-2020-09-13-at-17.00.24.png?resize=660%2C533&#038;ssl=1\" alt=\"\" data-id=\"2188\" data-full-url=\"https:\/\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Screen-Shot-2020-09-13-at-17.00.24.png\" data-link=\"https:\/\/michaelrowe01.com\/?attachment_id=2188\" class=\"wp-image-2188\" srcset=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Screen-Shot-2020-09-13-at-17.00.24.png?resize=1024%2C827&amp;ssl=1 1024w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Screen-Shot-2020-09-13-at-17.00.24.png?resize=300%2C242&amp;ssl=1 300w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Screen-Shot-2020-09-13-at-17.00.24.png?resize=768%2C620&amp;ssl=1 768w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Screen-Shot-2020-09-13-at-17.00.24.png?resize=1536%2C1241&amp;ssl=1 1536w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Screen-Shot-2020-09-13-at-17.00.24.png?w=1654&amp;ssl=1 1654w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Screen-Shot-2020-09-13-at-17.00.24.png?w=1320&amp;ssl=1 1320w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"660\" height=\"461\" src=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Simulator-Screen-Shot-iPad-Pro-11-inch-2nd-generation-2020-09-13-at-16.56.43.png?resize=660%2C461&#038;ssl=1\" alt=\"\" data-id=\"2189\" data-full-url=\"https:\/\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Simulator-Screen-Shot-iPad-Pro-11-inch-2nd-generation-2020-09-13-at-16.56.43.png\" data-link=\"https:\/\/michaelrowe01.com\/?attachment_id=2189\" class=\"wp-image-2189\" srcset=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Simulator-Screen-Shot-iPad-Pro-11-inch-2nd-generation-2020-09-13-at-16.56.43.png?resize=1024%2C715&amp;ssl=1 1024w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Simulator-Screen-Shot-iPad-Pro-11-inch-2nd-generation-2020-09-13-at-16.56.43.png?resize=300%2C210&amp;ssl=1 300w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Simulator-Screen-Shot-iPad-Pro-11-inch-2nd-generation-2020-09-13-at-16.56.43.png?resize=768%2C536&amp;ssl=1 768w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Simulator-Screen-Shot-iPad-Pro-11-inch-2nd-generation-2020-09-13-at-16.56.43.png?resize=1536%2C1073&amp;ssl=1 1536w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Simulator-Screen-Shot-iPad-Pro-11-inch-2nd-generation-2020-09-13-at-16.56.43.png?resize=2048%2C1431&amp;ssl=1 2048w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Simulator-Screen-Shot-iPad-Pro-11-inch-2nd-generation-2020-09-13-at-16.56.43.png?w=1320&amp;ssl=1 1320w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2020\/09\/Simulator-Screen-Shot-iPad-Pro-11-inch-2nd-generation-2020-09-13-at-16.56.43.png?w=1980&amp;ssl=1 1980w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/figure><\/li><\/ul><figcaption class=\"blocks-gallery-caption\">Menus across iPadOS and macOS<\/figcaption><\/figure>\n\n\n\n<p>The code ended up not being to difficult, once I figured it out.  Of course, that is almost always the case.  Moving from all the programming habits I developed in college and the few years that I made my living as developer, to modern languages and architectures, has been hard.  While I fully understand the concepts, putting it in practice can be difficult. So let&#8217;s look at the code behind the Menu Builder function in Swift:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    override func buildMenu(with builder: UIMenuBuilder) {\n        super.buildMenu(with: builder)\n        \n        \/\/ Ensure that the builder is modifying the menu bar system.\n        guard builder.system == UIMenuSystem.main else { return }\n        \n        \/\/ Meeting Menu\n        let advanceMeetingStatus = UIKeyCommand(title: \"Advance Meeting Status\", action: #selector(handleKeyAdvanceMeetingStatus(sender:)), input: UIKeyCommand.inputRightArrow, modifierFlags: .alternate, propertyList: UIKeyCommand.inputRightArrow)\n        let incrementParticipants = UIKeyCommand(title: \"Increment Participants\", action: #selector(handleKeyIncrementParticipants(sender:)), input: UIKeyCommand.inputUpArrow, modifierFlags: .alternate, propertyList: UIKeyCommand.inputUpArrow)\n        let decrementParticipants = UIKeyCommand(title: \"Decrement Participants\", action: #selector(handleKeyDecrementParticipants(sender:)), input: UIKeyCommand.inputDownArrow, modifierFlags: .alternate, propertyList: UIKeyCommand.inputDownArrow)\n        let cancelMeeting = UIKeyCommand(title: \"End Meeting Immediately\", action: #selector(handleKeyCancelMeeting(sender:)), input: UIKeyCommand.inputLeftArrow, modifierFlags: .alternate, propertyList: UIKeyCommand.inputLeftArrow)\n       \n        let advanceMeetingItem = UIMenu(title: \"Advance Meeting\", image: nil, identifier: UIMenu.Identifier(\"advanceMeetingStatus\"), options: .displayInline, children: &#91;advanceMeetingStatus])\n        let incrementParticipantsItem = UIMenu(title: \"Add Participants\", image: nil, identifier: UIMenu.Identifier(\"incrementParticipants\"), options: .displayInline, children: &#91;incrementParticipants])\n        let decrementParticipantsItem = UIMenu(title: \"Remove Participants\", image: nil, identifier: UIMenu.Identifier(\"decrementParticipants\"), options: .displayInline, children: &#91;decrementParticipants])\n        let cancelMeetingItem = UIMenu(title: \"Cancel Meeting\", image: nil, identifier: UIMenu.Identifier(\"cancelMeeting\"), options: .displayInline, children: &#91;cancelMeeting])\n        \n        \n        let meetingMenu = UIMenu(title: \"Meeting\", children: &#91;advanceMeetingItem,incrementParticipantsItem,decrementParticipantsItem,cancelMeetingItem])\n       \n        \/\/ View Menu\n        let meetingView = UIKeyCommand(title: \"Meeting View\", action: #selector(handleKeyCommand1(sender:)), input: \"1\", modifierFlags: .command, propertyList: 1)\n        let setupView = UIKeyCommand(title: \"Setup View\", action: #selector(handleKeyCommand2(sender:)), input: \"2\", modifierFlags: .command, propertyList: 2)\n        let totalsView = UIKeyCommand(title: \"Totals View\", action: #selector(handleKeyCommand3(sender:)), input: \"3\", modifierFlags: .command, propertyList: 3)\n        let helpView = UIKeyCommand(title: \"Help View\", action: #selector(handleKeyCommand4(sender:)), input: \"4\", modifierFlags: .command, propertyList: 4)\n        \n        let meetingViewItem = UIMenu(title: \"Meeting View\", image: nil, identifier: UIMenu.Identifier(\"meetingView\"), options: .displayInline, children: &#91;meetingView])\n        let setupViewItem = UIMenu(title: \"Setup View\", image: nil, identifier: UIMenu.Identifier(\"setupView\"), options: .displayInline, children: &#91;setupView])\n        let totalsViewItem = UIMenu(title: \"Totals View\", image: nil, identifier: UIMenu.Identifier(\"totalsView\"), options: .displayInline, children: &#91;totalsView])\n        let helpViewItem = UIMenu(title: \"Help View\", image: nil, identifier: UIMenu.Identifier(\"helpView\"), options: .displayInline, children: &#91;helpView])\n        \n        let tabsMenu = UIMenu(title: \"Tabs\", children: &#91;meetingViewItem, setupViewItem, totalsViewItem, helpViewItem])\n        \n        builder.insertSibling(meetingMenu, afterMenu: .edit)\n        builder.insertSibling(tabsMenu, afterMenu: .edit)\n        builder.remove(menu: .file)\n        builder.remove(menu: .edit)\n        builder.remove(menu: .format)\n        builder.remove(menu: .help)\n        \n    }<\/code><\/pre>\n\n\n\n<p>The net of this code is to build up the actions, then the items, and then attach the items to a new UIMenu object. I add the various items ad children to the UIMenu, and then insert the UIMenu after the file menu.  Since I don&#8217;t use the file menu, I then remove it, along with edit, format and help.<\/p>\n\n\n\n<p>Not too hard.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I continue to work on Wasted Time, I now have added working keyboard shortcuts, and menu items to both the iPad and macOS versions. I can&#8217;t wait for Big Sur and iPadOS 14 to come up so I can release these to the world. First a few screenshots The code ended up not being [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_wp_convertkit_post_meta":{"form":"-1","landing_page":"0","tag":"0","restrict_content":"0"},"hide_page_title":"","footnotes":""},"categories":[2,3],"tags":[548,561,257,566,427],"class_list":["post-2186","post","type-post","status-publish","format-standard","hentry","category-blog","category-personal-softwareandit","tag-big-sur","tag-ipados14","tag-macos","tag-menus","tag-wastedtime"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/2186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/comments?post=2186"}],"version-history":[{"count":2,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/2186\/revisions"}],"predecessor-version":[{"id":2191,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/2186\/revisions\/2191"}],"wp:attachment":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/media?parent=2186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/categories?post=2186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/tags?post=2186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}