Skip to content

Commit 0267eba

Browse files
author
ddauer
committed
Imported latest revision (r14) from old repository
git-svn-id: http://shortcutrecorder.googlecode.com/svn/trunk@2 95fa3068-9819-0410-9c96-7759cbfcbc6e
1 parent 226cae1 commit 0267eba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+7890
-0
lines changed

Demo/AppController.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// AppController.h
3+
// ShortcutRecorder
4+
//
5+
// Copyright 2006 Contributors. All rights reserved.
6+
//
7+
// License: BSD
8+
//
9+
// Contributors:
10+
// David Dauer
11+
// Jesper
12+
13+
#import <Cocoa/Cocoa.h>
14+
#import "SRRecorderControl.h"
15+
16+
@class PTHotKey;
17+
18+
@interface AppController : NSObject
19+
{
20+
IBOutlet NSWindow *mainWindow;
21+
IBOutlet SRRecorderControl *shortcutRecorder;
22+
23+
IBOutlet NSButton *allowedModifiersCommandCheckBox;
24+
IBOutlet NSButton *allowedModifiersOptionCheckBox;
25+
IBOutlet NSButton *allowedModifiersShiftCheckBox;
26+
IBOutlet NSButton *allowedModifiersControlCheckBox;
27+
28+
IBOutlet NSButton *requiredModifiersCommandCheckBox;
29+
IBOutlet NSButton *requiredModifiersOptionCheckBox;
30+
IBOutlet NSButton *requiredModifiersShiftCheckBox;
31+
IBOutlet NSButton *requiredModifiersControlCheckBox;
32+
33+
IBOutlet SRRecorderControl *delegateDisallowRecorder;
34+
35+
IBOutlet NSButton *globalHotKeyCheckBox;
36+
IBOutlet NSTextView *globalHotKeyLogView;
37+
38+
IBOutlet NSTextField *delegateDisallowReasonField;
39+
40+
PTHotKey *globalHotKey;
41+
}
42+
43+
- (IBAction)allowedModifiersChanged:(id)sender;
44+
- (IBAction)requiredModifiersChanged:(id)sender;
45+
46+
- (IBAction)toggleGlobalHotKey:(id)sender;
47+
48+
@end

Demo/AppController.m

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//
2+
// AppController.m
3+
// ShortcutRecorder
4+
//
5+
// Copyright 2006 Contributors. All rights reserved.
6+
//
7+
// License: BSD
8+
//
9+
// Contributors:
10+
// David Dauer
11+
// Jesper
12+
13+
#import "AppController.h"
14+
#import "PTHotKeyCenter.h"
15+
#import "PTHotKey.h"
16+
17+
@implementation AppController
18+
19+
- (void)awakeFromNib
20+
{
21+
[mainWindow center];
22+
}
23+
24+
#pragma mark -
25+
26+
- (IBAction)allowedModifiersChanged:(id)sender
27+
{
28+
unsigned int newFlags = 0;
29+
30+
if ([allowedModifiersCommandCheckBox state]) newFlags += NSCommandKeyMask;
31+
if ([allowedModifiersOptionCheckBox state]) newFlags += NSAlternateKeyMask;
32+
if ([allowedModifiersControlCheckBox state]) newFlags += NSControlKeyMask;
33+
if ([allowedModifiersShiftCheckBox state]) newFlags += NSShiftKeyMask;
34+
35+
[shortcutRecorder setAllowedFlags: newFlags];
36+
}
37+
38+
- (IBAction)requiredModifiersChanged:(id)sender
39+
{
40+
unsigned int newFlags = 0;
41+
42+
if ([requiredModifiersCommandCheckBox state]) newFlags += NSCommandKeyMask;
43+
if ([requiredModifiersOptionCheckBox state]) newFlags += NSAlternateKeyMask;
44+
if ([requiredModifiersControlCheckBox state]) newFlags += NSControlKeyMask;
45+
if ([requiredModifiersShiftCheckBox state]) newFlags += NSShiftKeyMask;
46+
47+
[shortcutRecorder setRequiredFlags: newFlags];
48+
}
49+
50+
- (IBAction)toggleGlobalHotKey:(id)sender
51+
{
52+
if (globalHotKey != nil)
53+
{
54+
[[PTHotKeyCenter sharedCenter] unregisterHotKey: globalHotKey];
55+
[globalHotKey release];
56+
globalHotKey = nil;
57+
}
58+
59+
if (![globalHotKeyCheckBox state]) return;
60+
61+
globalHotKey = [[PTHotKey alloc] initWithIdentifier:@"SRTest"
62+
keyCombo:[PTKeyCombo keyComboWithKeyCode:[shortcutRecorder keyCombo].code
63+
modifiers:[shortcutRecorder cocoaToCarbonFlags: [shortcutRecorder keyCombo].flags]]];
64+
65+
[globalHotKey setTarget: self];
66+
[globalHotKey setAction: @selector(hitHotKey:)];
67+
68+
[[PTHotKeyCenter sharedCenter] registerHotKey: globalHotKey];
69+
}
70+
71+
#pragma mark -
72+
73+
- (BOOL)shortcutRecorder:(SRRecorderControl *)aRecorder isKeyCode:(signed short)keyCode andFlagsTaken:(unsigned int)flags reason:(NSString **)aReason
74+
{
75+
if (aRecorder == shortcutRecorder)
76+
{
77+
BOOL isTaken = NO;
78+
79+
KeyCombo kc = [delegateDisallowRecorder keyCombo];
80+
81+
if (kc.code == keyCode && kc.flags == flags) isTaken = YES;
82+
83+
*aReason = [delegateDisallowReasonField stringValue];
84+
85+
return isTaken;
86+
}
87+
88+
return NO;
89+
}
90+
91+
- (void)shortcutRecorder:(SRRecorderControl *)aRecorder keyComboDidChange:(KeyCombo)newKeyCombo
92+
{
93+
if (aRecorder == shortcutRecorder)
94+
{
95+
[self toggleGlobalHotKey: aRecorder];
96+
}
97+
}
98+
99+
- (void)hitHotKey:(PTHotKey *)hotKey
100+
{
101+
NSMutableAttributedString *logString = [globalHotKeyLogView textStorage];
102+
[[logString mutableString] appendString: [NSString stringWithFormat: @"%@ pressed. \n", [shortcutRecorder keyComboString]]];
103+
104+
[globalHotKeyLogView scrollPoint: NSMakePoint(0, [globalHotKeyLogView frame].size.height)];
105+
}
106+
107+
@end
192 Bytes
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"Space" = "Space";
2+
"Use old shortcut" = "Use old shortcut";
3+
"Type shortcut" = "Type shortcut";
4+
"Click to record shortcut" = "Click to record shortcut";
5+
"Pad %@" = "Pad %@";
6+
"The key combination %@ couldn't be used!" = "The key combination %@ couldn't be used!";
7+
"The key combination \"%@\" couldn't be used, because %@." = "The key combination \"%@\" couldn't be used, because %@.";
8+
"The key combination \"%@\" couldn't be used, because it's already used by a system-wide keyboard shortcut. (If you really want to use this key combination, most shortcuts can be changed in the Keyboard & Mouse panel in System Preferences.)" = "The key combination \"%@\" couldn't be used, because it's already used by a system-wide keyboard shortcut. (If you really want to use this key combination, most shortcuts can be changed in the Keyboard & Mouse panel in System Preferences.)";
9+
"The key combination \"%@\" couldn't be used, because it's already used by the menu item \"%@\"." = "The key combination \"%@\" couldn't be used, because it's already used by the menu item \"%@\".";
10+
"Command + " = "Command + ";
11+
"Option + " = "Option + ";
12+
"Shift + " = "Shift + ";
13+
"Control + " = "Control + ";

Demo/English.lproj/MainMenu.nib/classes.nib

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IBPaletteDependency</key>
6+
<array>
7+
<string>ShortcutRecorder</string>
8+
</array>
9+
</dict>
10+
</plist>

Demo/English.lproj/MainMenu.nib/info.nib

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
24.2 KB
Binary file not shown.

Demo/HotKey/PTHotKey.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// PTHotKey.h
3+
// Protein
4+
//
5+
// Created by Quentin Carnicelli on Sat Aug 02 2003.
6+
// Copyright (c) 2003 Quentin D. Carnicelli. All rights reserved.
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
#import "PTKeyCombo.h"
11+
12+
@interface PTHotKey : NSObject
13+
{
14+
NSString* mIdentifier;
15+
NSString* mName;
16+
PTKeyCombo* mKeyCombo;
17+
id mTarget;
18+
SEL mAction;
19+
}
20+
21+
- (id)initWithIdentifier: (id)identifier keyCombo: (PTKeyCombo*)combo;
22+
- (id)init;
23+
24+
- (void)setIdentifier: (id)ident;
25+
- (id)identifier;
26+
27+
- (void)setName: (NSString*)name;
28+
- (NSString*)name;
29+
30+
- (void)setKeyCombo: (PTKeyCombo*)combo;
31+
- (PTKeyCombo*)keyCombo;
32+
33+
- (void)setTarget: (id)target;
34+
- (id)target;
35+
- (void)setAction: (SEL)action;
36+
- (SEL)action;
37+
38+
- (void)invoke;
39+
40+
@end

0 commit comments

Comments
 (0)