Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 28fb236bfd
Fetching contributors…

Cannot retrieve contributors at this time

file 34 lines (29 sloc) 0.812 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#
# keyboard_handler.rb
# CobraMenu
#
# Created by Leigh Caplan on 7/5/10.
# Copyright (c) 2010 Onehub, Inc. All rights reserved.
#

class KeyboardHandler < NSView

  def initWithFrame(frame)
    super
    return self
  end

  def drawRect(rect)
  end

  def performKeyEquivalent(event)
    action_map = {'x' => 'cut', 'c' => 'copy', 'v' => 'paste', 'a' => 'selectAll', 'q' => 'terminate'}
    
    if (event.modifierFlags & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask
      if action = action_map[event.charactersIgnoringModifiers]
        if window.firstResponder.respond_to?(action)
          NSApp.sendAction("#{action}:", :to => self.window.firstResponder(), :from => self)
        else
          NSApp.send("#{action}", self)
        end
      end
    else
      super
    end
  end
end
Something went wrong with that request. Please try again.