forked from eczarny/spectacle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpectacleWindowActionController.m
124 lines (87 loc) · 3.72 KB
/
SpectacleWindowActionController.m
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#import "SpectacleWindowActionController.h"
#import "SpectacleWindowPositionManager.h"
#import "SpectacleHotKeyManager.h"
#import "SpectacleUtilities.h"
#import "SpectacleConstants.h"
@interface SpectacleWindowActionController ()
@property (nonatomic) SpectacleWindowPositionManager *windowPositionManager;
@property (nonatomic) SpectacleHotKeyManager *hotKeyManager;
@end
#pragma mark -
@implementation SpectacleWindowActionController
- (id)init {
if (self = [super init]) {
_windowPositionManager = SpectacleWindowPositionManager.sharedManager;
_hotKeyManager = SpectacleHotKeyManager.sharedManager;
}
return self;
}
#pragma mark -
- (void)registerHotKeys {
NSUserDefaults *userDefaults = NSUserDefaults.standardUserDefaults;
NSMutableDictionary *hotKeysFromUserDefaults = [NSMutableDictionary new];
for (NSString *hotKeyName in SpectacleUtilities.hotKeyNames) {
hotKeysFromUserDefaults[hotKeyName] = [userDefaults dataForKey: hotKeyName];
}
NSArray *hotKeys = [SpectacleUtilities hotKeysFromDictionary: hotKeysFromUserDefaults action: ^(ZKHotKey *hotKey) {
[_windowPositionManager moveFrontMostWindowWithAction: [_windowPositionManager windowActionForHotKey: hotKey]];
}];
[_hotKeyManager registerHotKeys: hotKeys];
}
#pragma mark -
- (IBAction)moveFrontMostWindowToCenter: (id)sender {
[_windowPositionManager moveFrontMostWindowWithAction: SpectacleWindowActionCenter];
}
#pragma mark -
- (IBAction)moveFrontMostWindowToFullscreen: (id)sender {
[_windowPositionManager moveFrontMostWindowWithAction: SpectacleWindowActionFullscreen];
}
#pragma mark -
- (IBAction)moveFrontMostWindowToLeftHalf: (id)sender {
[_windowPositionManager moveFrontMostWindowWithAction: SpectacleWindowActionLeftHalf];
}
- (IBAction)moveFrontMostWindowToRightHalf: (id)sender {
[_windowPositionManager moveFrontMostWindowWithAction: SpectacleWindowActionRightHalf];
}
- (IBAction)moveFrontMostWindowToTopHalf: (id)sender {
[_windowPositionManager moveFrontMostWindowWithAction: SpectacleWindowActionTopHalf];
}
- (IBAction)moveFrontMostWindowToBottomHalf: (id)sender {
[_windowPositionManager moveFrontMostWindowWithAction: SpectacleWindowActionBottomHalf];
}
#pragma mark -
- (IBAction)moveFrontMostWindowToUpperLeft: (id)sender {
[_windowPositionManager moveFrontMostWindowWithAction: SpectacleWindowActionUpperLeft];
}
- (IBAction)moveFrontMostWindowToLowerLeft: (id)sender {
[_windowPositionManager moveFrontMostWindowWithAction: SpectacleWindowActionLowerLeft];
}
#pragma mark -
- (IBAction)moveFrontMostWindowToUpperRight: (id)sender {
[_windowPositionManager moveFrontMostWindowWithAction: SpectacleWindowActionUpperRight];
}
- (IBAction)moveFrontMostWindowToLowerRight: (id)sender {
[_windowPositionManager moveFrontMostWindowWithAction: SpectacleWindowActionLowerRight];
}
#pragma mark -
- (IBAction)moveFrontMostWindowToNextDisplay: (id)sender {
[_windowPositionManager moveFrontMostWindowWithAction: SpectacleWindowActionNextDisplay];
}
- (IBAction)moveFrontMostWindowToPreviousDisplay: (id)sender {
[_windowPositionManager moveFrontMostWindowWithAction: SpectacleWindowActionPreviousDisplay];
}
#pragma mark -
- (IBAction)moveFrontMostWindowToNextThird: (id)sender {
[_windowPositionManager moveFrontMostWindowWithAction: SpectacleWindowActionNextThird];
}
- (IBAction)moveFrontMostWindowToPreviousThird: (id)sender {
[_windowPositionManager moveFrontMostWindowWithAction: SpectacleWindowActionPreviousThird];
}
#pragma mark -
- (IBAction)undoLastWindowAction: (id)sender {
[_windowPositionManager undoLastWindowAction];
}
- (IBAction)redoLastWindowAction: (id)sender {
[_windowPositionManager redoLastWindowAction];
}
@end