Browse Source

Store settings. Commented out status bar icon for now.

Thomas Buck 9 years ago
parent
commit
1424ce4ca5
5 changed files with 130 additions and 27 deletions
  1. 3
    2
      OtaClock/AppDelegate.m
  2. 28
    1
      OtaClock/Base.lproj/MainMenu.xib
  3. 3
    1
      OtaClock/Info.plist
  4. 0
    2
      OtaClock/MainView.m
  5. 96
    21
      OtaClock/MainWindow.m

+ 3
- 2
OtaClock/AppDelegate.m View File

21
 
21
 
22
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
22
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
23
     // Create Status Bar Item
23
     // Create Status Bar Item
24
+    /*
24
     statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
25
     statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
25
     statusItem.image = [NSImage imageNamed:@"Menu"];
26
     statusItem.image = [NSImage imageNamed:@"Menu"];
26
     statusItem.highlightMode = YES;
27
     statusItem.highlightMode = YES;
27
-    statusItem.menu = mainMenu; // Use same menu used for right-clicks
28
+    statusItem.menu = mainMenu; */ // Use same menu used for right-clicks
28
 }
29
 }
29
 
30
 
30
 - (void)applicationWillTerminate:(NSNotification *)aNotification {
31
 - (void)applicationWillTerminate:(NSNotification *)aNotification {
31
     // Remove Status Bar Item
32
     // Remove Status Bar Item
32
-    [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
33
+    //[[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
33
 }
34
 }
34
 
35
 
35
 @end
36
 @end

+ 28
- 1
OtaClock/Base.lproj/MainMenu.xib View File

70
                 </menuItem>
70
                 </menuItem>
71
             </items>
71
             </items>
72
         </menu>
72
         </menu>
73
-        <window title="OtaClock" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g" customClass="MainWindow">
73
+        <window title="OtaClock" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" frameAutosaveName="OtaClock" animationBehavior="default" id="QvC-M9-y7g" customClass="MainWindow">
74
             <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
74
             <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
75
             <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
75
             <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
76
             <rect key="contentRect" x="335" y="390" width="235" height="196"/>
76
             <rect key="contentRect" x="335" y="390" width="235" height="196"/>
82
                     <outlet property="menu" destination="v1Z-w4-vhP" id="c20-yu-LsO"/>
82
                     <outlet property="menu" destination="v1Z-w4-vhP" id="c20-yu-LsO"/>
83
                 </connections>
83
                 </connections>
84
             </view>
84
             </view>
85
+            <connections>
86
+                <outlet property="changeSize1" destination="Acr-Ff-Lm2" id="qUp-XP-Ffo"/>
87
+                <outlet property="changeSize2" destination="sRn-WM-cKW" id="luN-Dk-xw4"/>
88
+                <outlet property="changeSize3" destination="Ynv-fd-dtQ" id="QeL-wH-eAC"/>
89
+                <outlet property="changeSize4" destination="rKj-Pe-N3u" id="tmN-AZ-egV"/>
90
+                <outlet property="changeSize5" destination="Qji-aB-KLD" id="a79-d3-RIN"/>
91
+                <outlet property="keepOnTopItem" destination="bk2-WG-9eq" id="vBf-vA-eXc"/>
92
+                <outlet property="lockPositionItem" destination="YfQ-b7-bXC" id="CYs-rk-6GP"/>
93
+            </connections>
85
             <point key="canvasLocation" x="129.5" y="81"/>
94
             <point key="canvasLocation" x="129.5" y="81"/>
86
         </window>
95
         </window>
87
         <menu id="v1Z-w4-vhP">
96
         <menu id="v1Z-w4-vhP">
102
                                     <action selector="changeSize:" target="QvC-M9-y7g" id="Nvd-gD-ixJ"/>
111
                                     <action selector="changeSize:" target="QvC-M9-y7g" id="Nvd-gD-ixJ"/>
103
                                 </connections>
112
                                 </connections>
104
                             </menuItem>
113
                             </menuItem>
114
+                            <menuItem title="3x" id="Ynv-fd-dtQ">
115
+                                <modifierMask key="keyEquivalentModifierMask"/>
116
+                                <connections>
117
+                                    <action selector="changeSize:" target="QvC-M9-y7g" id="Nrc-zM-1sT"/>
118
+                                </connections>
119
+                            </menuItem>
120
+                            <menuItem title="4x" id="rKj-Pe-N3u">
121
+                                <modifierMask key="keyEquivalentModifierMask"/>
122
+                                <connections>
123
+                                    <action selector="changeSize:" target="QvC-M9-y7g" id="QoN-cm-k5P"/>
124
+                                </connections>
125
+                            </menuItem>
126
+                            <menuItem title="5x" id="Qji-aB-KLD">
127
+                                <modifierMask key="keyEquivalentModifierMask"/>
128
+                                <connections>
129
+                                    <action selector="changeSize:" target="QvC-M9-y7g" id="Y9P-XF-cjZ"/>
130
+                                </connections>
131
+                            </menuItem>
105
                         </items>
132
                         </items>
106
                     </menu>
133
                     </menu>
107
                 </menuItem>
134
                 </menuItem>

+ 3
- 1
OtaClock/Info.plist View File

19
 	<key>CFBundleSignature</key>
19
 	<key>CFBundleSignature</key>
20
 	<string>????</string>
20
 	<string>????</string>
21
 	<key>CFBundleVersion</key>
21
 	<key>CFBundleVersion</key>
22
-	<string>30</string>
22
+	<string>52</string>
23
 	<key>LSApplicationCategoryType</key>
23
 	<key>LSApplicationCategoryType</key>
24
 	<string>public.app-category.utilities</string>
24
 	<string>public.app-category.utilities</string>
25
 	<key>LSMinimumSystemVersion</key>
25
 	<key>LSMinimumSystemVersion</key>
26
 	<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
26
 	<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
27
+	<key>LSUIElement</key>
28
+	<true/>
27
 	<key>NSHumanReadableCopyright</key>
29
 	<key>NSHumanReadableCopyright</key>
28
 	<string>Copyright © 2006 Konami Digital Entertainment Co., Ltd.</string>
30
 	<string>Copyright © 2006 Konami Digital Entertainment Co., Ltd.</string>
29
 	<key>NSMainNibFile</key>
31
 	<key>NSMainNibFile</key>

+ 0
- 2
OtaClock/MainView.m View File

16
 @synthesize otaconImage;
16
 @synthesize otaconImage;
17
 
17
 
18
 -(void)awakeFromNib {
18
 -(void)awakeFromNib {
19
-    NSLog(@"MainView:awakeFromNib %@ %@", self, [self window]);
20
-    
21
     // Load background image
19
     // Load background image
22
     self.otaconImage = [NSImage imageNamed:@"Otacon"];
20
     self.otaconImage = [NSImage imageNamed:@"Otacon"];
23
     
21
     

+ 96
- 21
OtaClock/MainWindow.m View File

8
 
8
 
9
 #import "MainWindow.h"
9
 #import "MainWindow.h"
10
 
10
 
11
+#define RESIZE_START 1
12
+#define RESIZE_END 5
13
+#define RESIZE_STEP 1
14
+
15
+#define CONFIG_START_SCALE @"window_scale"
16
+#define CONFIG_KEEP_POSITION @"keep_position"
17
+#define CONFIG_KEEP_ON_TOP @"keep_on_top"
18
+
11
 @interface MainWindow ()
19
 @interface MainWindow ()
12
 
20
 
13
 @property (assign) NSSize defaultSize;
21
 @property (assign) NSSize defaultSize;
22
+@property (assign) NSInteger startScale;
23
+
24
+@property (weak) IBOutlet NSMenuItem *lockPositionItem;
25
+@property (weak) IBOutlet NSMenuItem *keepOnTopItem;
26
+
27
+@property (weak) IBOutlet NSMenuItem *changeSize1;
28
+@property (weak) IBOutlet NSMenuItem *changeSize2;
29
+@property (weak) IBOutlet NSMenuItem *changeSize3;
30
+@property (weak) IBOutlet NSMenuItem *changeSize4;
31
+@property (weak) IBOutlet NSMenuItem *changeSize5;
14
 
32
 
15
 @end
33
 @end
16
 
34
 
18
 
36
 
19
 @synthesize dragStart;
37
 @synthesize dragStart;
20
 @synthesize keepPosition;
38
 @synthesize keepPosition;
39
+
21
 @synthesize defaultSize;
40
 @synthesize defaultSize;
41
+@synthesize startScale;
42
+
43
+// TODO window position should be remembered!
22
 
44
 
23
 - (id)initWithContentRect:(NSRect)contentRect
45
 - (id)initWithContentRect:(NSRect)contentRect
24
                styleMask:(NSUInteger)aStyle
46
                styleMask:(NSUInteger)aStyle
29
         [self setAlphaValue:1.0];
51
         [self setAlphaValue:1.0];
30
         [self setOpaque:NO];
52
         [self setOpaque:NO];
31
         
53
         
54
+        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
55
+        
32
         // load and see if window should be kept on top
56
         // load and see if window should be kept on top
33
-        // also set proper button state
34
-        //[self setLevel:NSFloatingWindowLevel];
57
+        if ([defaults objectForKey:CONFIG_KEEP_ON_TOP] != nil) {
58
+            if ([defaults boolForKey:CONFIG_KEEP_ON_TOP]) {
59
+                [self setLevel:NSFloatingWindowLevel];
60
+            }
61
+        }
35
         
62
         
36
         // load and see if window pos should be fixed
63
         // load and see if window pos should be fixed
37
-        // also set proper button state
38
-        self.keepPosition = NO;
64
+        if ([defaults objectForKey:CONFIG_KEEP_POSITION] == nil) {
65
+            keepPosition = NO;
66
+        } else {
67
+            keepPosition = [defaults boolForKey:CONFIG_KEEP_POSITION];
68
+        }
69
+        
70
+        // load window scale factor
71
+        if ([defaults objectForKey:CONFIG_START_SCALE] == nil) {
72
+            startScale = 1;
73
+        } else {
74
+            startScale = [defaults integerForKey:CONFIG_START_SCALE];
75
+        }
39
     }
76
     }
40
     return self;
77
     return self;
41
 }
78
 }
44
     defaultSize = size;
81
     defaultSize = size;
45
     NSRect frame = [self frame];
82
     NSRect frame = [self frame];
46
     frame.size = defaultSize;
83
     frame.size = defaultSize;
84
+    
85
+    frame.size.width *= startScale;
86
+    frame.size.height *= startScale;
87
+    
88
+    // We need to do all initialization of view state in here, because they are not ready in init
89
+    if (keepPosition) [self.lockPositionItem setState:NSOnState];
90
+    if ([self level] == NSFloatingWindowLevel) [self.keepOnTopItem setState:NSOnState];
91
+    if (startScale == 1) [self.changeSize1 setState:NSOnState];
92
+    if (startScale == 2) [self.changeSize2 setState:NSOnState];
93
+    if (startScale == 3) [self.changeSize3 setState:NSOnState];
94
+    if (startScale == 4) [self.changeSize4 setState:NSOnState];
95
+    if (startScale == 5) [self.changeSize5 setState:NSOnState];
96
+    
47
     [self setFrame:frame display:YES];
97
     [self setFrame:frame display:YES];
48
 }
98
 }
49
 
99
 
50
 - (IBAction)changeSize:(NSMenuItem *)sender {
100
 - (IBAction)changeSize:(NSMenuItem *)sender {
51
     NSRect frame = [self frame];
101
     NSRect frame = [self frame];
52
     
102
     
53
-    if ([[sender title] isEqualToString:@"1x"]) {
54
-        frame.size = defaultSize;
55
-    } else if ([[sender title] isEqualToString:@"2x"]) {
56
-        NSSize newSize = defaultSize;
57
-        newSize.height *= 2;
58
-        newSize.width *= 2;
59
-        frame.size = newSize;
60
-    } else {
61
-        NSLog(@"Unknown changeSize sender: %@", sender);
62
-        return;
103
+    [self.changeSize1 setState:NSOffState];
104
+    [self.changeSize2 setState:NSOffState];
105
+    [self.changeSize3 setState:NSOffState];
106
+    [self.changeSize4 setState:NSOffState];
107
+    [self.changeSize5 setState:NSOffState];
108
+    
109
+    BOOL found = NO;
110
+    for (int i = RESIZE_START; i <= RESIZE_END; i += RESIZE_STEP) {
111
+        NSString *title = [NSString stringWithFormat:@"%dx", i];
112
+        if ([[sender title] isEqualToString:title]) {
113
+            [sender setState:NSOnState];
114
+            NSSize newSize = defaultSize;
115
+            newSize.height *= i;
116
+            newSize.width *= i;
117
+            frame.size = newSize;
118
+            found = YES;
119
+            
120
+            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
121
+            [defaults setInteger:i forKey:CONFIG_START_SCALE];
122
+            [defaults synchronize];
123
+        }
63
     }
124
     }
64
     
125
     
65
-    [self setFrame:frame display:YES];
126
+    if (found == NO) {
127
+        NSLog(@"Unknown changeSize sender: %@", sender);
128
+    } else {
129
+        [self setFrame:frame display:YES];
130
+    }
66
 }
131
 }
67
 
132
 
68
 - (IBAction)lockPosition:(NSMenuItem *)sender {
133
 - (IBAction)lockPosition:(NSMenuItem *)sender {
72
         state = NSOnState;
137
         state = NSOnState;
73
         [sender setState:state];
138
         [sender setState:state];
74
         self.keepPosition = YES;
139
         self.keepPosition = YES;
75
-        // store...
140
+        
141
+        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
142
+        [defaults setBool:YES forKey:CONFIG_KEEP_POSITION];
143
+        [defaults synchronize];
76
     } else {
144
     } else {
77
         // Unlock position
145
         // Unlock position
78
         state = NSOffState;
146
         state = NSOffState;
79
         [sender setState:state];
147
         [sender setState:state];
80
         self.keepPosition = NO;
148
         self.keepPosition = NO;
81
-        // store...
149
+        
150
+        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
151
+        [defaults setBool:NO forKey:CONFIG_KEEP_POSITION];
152
+        [defaults synchronize];
82
     }
153
     }
83
 }
154
 }
84
 
155
 
89
         state = NSOnState;
160
         state = NSOnState;
90
         [sender setState:state];
161
         [sender setState:state];
91
         [self setLevel:NSFloatingWindowLevel];
162
         [self setLevel:NSFloatingWindowLevel];
92
-        // store...
163
+        
164
+        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
165
+        [defaults setBool:YES forKey:CONFIG_KEEP_ON_TOP];
166
+        [defaults synchronize];
93
     } else {
167
     } else {
94
         // Don't keep window on top
168
         // Don't keep window on top
95
         state = NSOffState;
169
         state = NSOffState;
96
         [sender setState:state];
170
         [sender setState:state];
97
         [self setLevel:NSNormalWindowLevel];
171
         [self setLevel:NSNormalWindowLevel];
98
-        // store...
172
+        
173
+        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
174
+        [defaults setBool:NO forKey:CONFIG_KEEP_ON_TOP];
175
+        [defaults synchronize];
99
     }
176
     }
100
 }
177
 }
101
 
178
 
105
 
182
 
106
 - (void)mouseDown:(NSEvent *)theEvent {
183
 - (void)mouseDown:(NSEvent *)theEvent {
107
     self.dragStart = [theEvent locationInWindow];
184
     self.dragStart = [theEvent locationInWindow];
108
-    
109
-    NSLog(@"Mouse at %f %f", self.dragStart.x, self.dragStart.y);
110
 }
185
 }
111
 
186
 
112
 - (void)mouseDragged:(NSEvent *)theEvent {
187
 - (void)mouseDragged:(NSEvent *)theEvent {

Loading…
Cancel
Save