Parcourir la source

Store settings. Commented out status bar icon for now.

Thomas Buck il y a 9 ans
Parent
révision
1424ce4ca5
5 fichiers modifiés avec 130 ajouts et 27 suppressions
  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 Voir le fichier

@@ -21,15 +21,16 @@
21 21
 
22 22
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
23 23
     // Create Status Bar Item
24
+    /*
24 25
     statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
25 26
     statusItem.image = [NSImage imageNamed:@"Menu"];
26 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 31
 - (void)applicationWillTerminate:(NSNotification *)aNotification {
31 32
     // Remove Status Bar Item
32
-    [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
33
+    //[[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
33 34
 }
34 35
 
35 36
 @end

+ 28
- 1
OtaClock/Base.lproj/MainMenu.xib Voir le fichier

@@ -70,7 +70,7 @@
70 70
                 </menuItem>
71 71
             </items>
72 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 74
             <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
75 75
             <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
76 76
             <rect key="contentRect" x="335" y="390" width="235" height="196"/>
@@ -82,6 +82,15 @@
82 82
                     <outlet property="menu" destination="v1Z-w4-vhP" id="c20-yu-LsO"/>
83 83
                 </connections>
84 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 94
             <point key="canvasLocation" x="129.5" y="81"/>
86 95
         </window>
87 96
         <menu id="v1Z-w4-vhP">
@@ -102,6 +111,24 @@
102 111
                                     <action selector="changeSize:" target="QvC-M9-y7g" id="Nvd-gD-ixJ"/>
103 112
                                 </connections>
104 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 132
                         </items>
106 133
                     </menu>
107 134
                 </menuItem>

+ 3
- 1
OtaClock/Info.plist Voir le fichier

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

+ 0
- 2
OtaClock/MainView.m Voir le fichier

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

+ 96
- 21
OtaClock/MainWindow.m Voir le fichier

@@ -8,9 +8,27 @@
8 8
 
9 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 19
 @interface MainWindow ()
12 20
 
13 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 33
 @end
16 34
 
@@ -18,7 +36,11 @@
18 36
 
19 37
 @synthesize dragStart;
20 38
 @synthesize keepPosition;
39
+
21 40
 @synthesize defaultSize;
41
+@synthesize startScale;
42
+
43
+// TODO window position should be remembered!
22 44
 
23 45
 - (id)initWithContentRect:(NSRect)contentRect
24 46
                styleMask:(NSUInteger)aStyle
@@ -29,13 +51,28 @@
29 51
         [self setAlphaValue:1.0];
30 52
         [self setOpaque:NO];
31 53
         
54
+        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
55
+        
32 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 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 77
     return self;
41 78
 }
@@ -44,25 +81,53 @@
44 81
     defaultSize = size;
45 82
     NSRect frame = [self frame];
46 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 97
     [self setFrame:frame display:YES];
48 98
 }
49 99
 
50 100
 - (IBAction)changeSize:(NSMenuItem *)sender {
51 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 133
 - (IBAction)lockPosition:(NSMenuItem *)sender {
@@ -72,13 +137,19 @@
72 137
         state = NSOnState;
73 138
         [sender setState:state];
74 139
         self.keepPosition = YES;
75
-        // store...
140
+        
141
+        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
142
+        [defaults setBool:YES forKey:CONFIG_KEEP_POSITION];
143
+        [defaults synchronize];
76 144
     } else {
77 145
         // Unlock position
78 146
         state = NSOffState;
79 147
         [sender setState:state];
80 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,13 +160,19 @@
89 160
         state = NSOnState;
90 161
         [sender setState:state];
91 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 167
     } else {
94 168
         // Don't keep window on top
95 169
         state = NSOffState;
96 170
         [sender setState:state];
97 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,8 +182,6 @@
105 182
 
106 183
 - (void)mouseDown:(NSEvent *)theEvent {
107 184
     self.dragStart = [theEvent locationInWindow];
108
-    
109
-    NSLog(@"Mouse at %f %f", self.dragStart.x, self.dragStart.y);
110 185
 }
111 186
 
112 187
 - (void)mouseDragged:(NSEvent *)theEvent {

Chargement…
Annuler
Enregistrer