diff options
| author | Tomáš Znamenáček | 2015-01-08 10:47:25 +0100 | 
|---|---|---|
| committer | Tomáš Znamenáček | 2015-01-08 10:47:25 +0100 | 
| commit | d2a371c92e7570042f52cced866c383ebe6e4268 (patch) | |
| tree | 394c16e48b486e184ecfe56fc09d9e3a26622adb | |
| parent | 4a32eca2e6717e778294d492e66c484392cfc2ec (diff) | |
| download | MASShortcut-d2a371c92e7570042f52cced866c383ebe6e4268.tar.bz2 | |
Documented the recording control behaviour and implemented Cmd-W/Q.
| -rw-r--r-- | Framework/MASShortcutView.m | 17 | ||||
| -rw-r--r-- | Spec.md | 15 | 
2 files changed, 28 insertions, 4 deletions
| diff --git a/Framework/MASShortcutView.m b/Framework/MASShortcutView.m index a449829..aace67e 100644 --- a/Framework/MASShortcutView.m +++ b/Framework/MASShortcutView.m @@ -373,18 +373,27 @@ void *kUserDataHint = &kUserDataHint;          NSEventMask eventMask = (NSKeyDownMask | NSFlagsChangedMask);          eventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:eventMask handler:^(NSEvent *event) { +            // Create a shortcut from the event              MASShortcut *shortcut = [MASShortcut shortcutWithEvent:event]; -            if ((shortcut.modifierFlags == 0) && ((shortcut.keyCode == kVK_Delete) || (shortcut.keyCode == kVK_ForwardDelete))) { -                // Delete shortcut + +            // If the shortcut is a plain Delete or Backspace, clear the current shortcut and cancel recording +            if (!shortcut.modifierFlags && ((shortcut.keyCode == kVK_Delete) || (shortcut.keyCode == kVK_ForwardDelete))) {                  weakSelf.shortcutValue = nil;                  weakSelf.recording = NO;                  event = nil;              } -            else if (shortcut.keyCode == kVK_Escape && !shortcut.modifierFlags) { -                // Cancel recording + +            // If the shortcut is a plain Esc, cancel recording +            else if (!shortcut.modifierFlags && shortcut.keyCode == kVK_Escape) {                  weakSelf.recording = NO;                  event = nil;              } + +            // If the shortcut is Cmd-W or Cmd-Q, cancel recording and pass the event through +            else if ((shortcut.modifierFlags == NSCommandKeyMask) && (shortcut.keyCode == kVK_ANSI_W || shortcut.keyCode == kVK_ANSI_Q)) { +                weakSelf.recording = NO; +            } +              else {                  // Verify possible shortcut                  if (shortcut.keyCodeString.length > 0) { @@ -0,0 +1,15 @@ +This is an attempt to specify some of the parts of the library so that it’s easier to spot bugs and regressions. + +The specification is expected to grow incrementally, as the developers update various parts of the code. If you hack on a part of the library that would benefit from a precise specification and is not documented here yet, please consider adding to the specification. + +Please stay high-level when writing the spec, do not document particular classes or other implementation details. The spec should be usable as a testing scenario – you should be able to walk through the spec and verify correct code behaviour on the library demo app. + +# Recording Shortcuts + +* If a shortcut has no modifiers and is not a function key (F1–F20), it must be rejected. (Examples: `A`, Shift-A.) +* If the shortcut is plain Esc without modifiers, it must be rejected and cancels the recording. +* If the shortcut is plain Backspace or plain Delete, it must be rejected, clears the recorded shortcut and cancels the recording. +* If the shortcut is Cmd-W or Cmd-Q, the recording must be cancelled and the keypress passed through to the system, closing the window or quitting the app. +* If a shortcut is already taken by system and is enabled, it must be rejected. (Examples: Cmd-S, Cmd-N. TBD: What exactly does it mean that the shortcut is “enabled”?) +* TBD: Option-key handling. +* All other shortcuts must be accepted. (Examples: Ctrl-Esc, Cmd-Delete, F16.)
\ No newline at end of file | 
