Search code examples
macoswebviewrubymotion

How to enable cmd+r to reload/refresh embedded OS X app WebView?


I am embedding a WebKit WebView in my RubyMotion OS X app.

@web_view = WebView.alloc.initWithFrame(NSMakeRect(0, 0, 1000, 500))
@web_view.setAutoresizingMask(NSViewMinXMargin|NSViewMaxXMargin|NSViewMinYMargin|NSViewMaxYMargin|NSViewWidthSizable|NSViewHeightSizable)
@web_view.setMainFrameURL('http://localhost:3000')
@mainWindow.contentView.addSubview(@web_view)

It seems by default, I can right click to display a menu which allows me to reload/refresh the page. However, ⌘ + R does not work. How can I add this functionality?


Solution

  • I think you can reload the webpages if you add `reload' action into main menu.

    addMenu('View') do
      item = addItemWithTitle('Show Toolbar', action: 'toggleToolbarShown:', keyEquivalent: 't')
      item.keyEquivalentModifierMask = NSCommandKeyMask|NSAlternateKeyMask
      addItemWithTitle('Customize Toolbar…', action: 'runToolbarCustomizationPalette:', keyEquivalent: '')
    
      # add Reload action
      addItemWithTitle('Reload', action: 'reload:', keyEquivalent: 'r')
    end