Sfoglia il codice sorgente

Implemented PrefController. Watch for TODOs…

Thomas Buck 11 anni fa
parent
commit
a5d255f48f
5 ha cambiato i file con 190 aggiunte e 4 eliminazioni
  1. 127
    4
      Prefs.xib
  2. 2
    0
      RedditBar/AppDelegate.h
  3. 5
    0
      RedditBar/AppDelegate.m
  4. 12
    0
      RedditBar/PrefController.h
  5. 44
    0
      RedditBar/PrefController.m

+ 127
- 4
Prefs.xib Vedi File

@@ -4,17 +4,140 @@
4 4
         <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/>
5 5
     </dependencies>
6 6
     <objects>
7
-        <customObject id="-2" userLabel="File's Owner" customClass="PrefController"/>
7
+        <customObject id="-2" userLabel="File's Owner" customClass="PrefController">
8
+            <connections>
9
+                <outlet property="password" destination="ARP-lb-J16" id="EDd-om-ciF"/>
10
+                <outlet property="subreddits" destination="EhP-FS-8dT" id="td1-kv-jQm"/>
11
+                <outlet property="subscriptions" destination="vW5-Cp-Bm1" id="gja-K0-7Uh"/>
12
+                <outlet property="username" destination="0mi-88-o94" id="4bB-K2-q5m"/>
13
+                <outlet property="win" destination="1" id="g0G-6q-WjE"/>
14
+            </connections>
15
+        </customObject>
8 16
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
9 17
         <customObject id="-3" userLabel="Application"/>
10
-        <window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" oneShot="NO" releasedWhenClosed="NO" wantsToBeColor="NO" animationBehavior="default" id="1">
18
+        <window title="Reddit Bar Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" oneShot="NO" releasedWhenClosed="NO" wantsToBeColor="NO" animationBehavior="default" id="1">
11 19
             <windowStyleMask key="styleMask" titled="YES" closable="YES"/>
12 20
             <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
13
-            <rect key="contentRect" x="196" y="240" width="480" height="270"/>
21
+            <rect key="contentRect" x="196" y="240" width="340" height="320"/>
14 22
             <rect key="screenRect" x="0.0" y="0.0" width="1920" height="1058"/>
15 23
             <view key="contentView" id="2">
16
-                <rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
24
+                <rect key="frame" x="0.0" y="0.0" width="340" height="320"/>
17 25
                 <autoresizingMask key="autoresizingMask"/>
26
+                <subviews>
27
+                    <textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="0mi-88-o94">
28
+                        <rect key="frame" x="120" y="280" width="200" height="22"/>
29
+                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
30
+                        <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="xlI-hU-MqM">
31
+                            <font key="font" metaFont="system"/>
32
+                            <color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
33
+                            <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
34
+                        </textFieldCell>
35
+                    </textField>
36
+                    <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="f72-fM-yQc">
37
+                        <rect key="frame" x="18" y="283" width="96" height="17"/>
38
+                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
39
+                        <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Username: " id="GTO-OP-MYS">
40
+                            <font key="font" metaFont="system"/>
41
+                            <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
42
+                            <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
43
+                        </textFieldCell>
44
+                    </textField>
45
+                    <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="JMQ-a6-DKC">
46
+                        <rect key="frame" x="18" y="251" width="96" height="17"/>
47
+                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
48
+                        <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Password:" id="m11-YF-fEa">
49
+                            <font key="font" metaFont="system"/>
50
+                            <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
51
+                            <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
52
+                        </textFieldCell>
53
+                    </textField>
54
+                    <secureTextField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ARP-lb-J16">
55
+                        <rect key="frame" x="120" y="248" width="200" height="22"/>
56
+                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
57
+                        <secureTextFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="We7-pG-rAt">
58
+                            <font key="font" metaFont="system"/>
59
+                            <color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
60
+                            <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
61
+                            <allowedInputSourceLocales>
62
+                                <string>NSAllRomanInputSourcesLocaleIdentifier</string>
63
+                            </allowedInputSourceLocales>
64
+                        </secureTextFieldCell>
65
+                    </secureTextField>
66
+                    <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qwZ-cF-1JN">
67
+                        <rect key="frame" x="224" y="13" width="102" height="32"/>
68
+                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
69
+                        <buttonCell key="cell" type="push" title="Save" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Mqa-FJ-C43">
70
+                            <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
71
+                            <font key="font" metaFont="system"/>
72
+                        </buttonCell>
73
+                        <connections>
74
+                            <action selector="buttonSave:" target="-2" id="thy-nQ-Nld"/>
75
+                        </connections>
76
+                    </button>
77
+                    <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vO2-NN-i1n">
78
+                        <rect key="frame" x="14" y="13" width="102" height="32"/>
79
+                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
80
+                        <buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="TjO-Z6-Vng">
81
+                            <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
82
+                            <font key="font" metaFont="system"/>
83
+                            <string key="keyEquivalent" base64-UTF8="YES">
84
+Gw
85
+</string>
86
+                        </buttonCell>
87
+                        <connections>
88
+                            <action selector="performClose:" target="1" id="A62-EW-ZrT"/>
89
+                        </connections>
90
+                    </button>
91
+                    <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="R9P-ZH-hHZ">
92
+                        <rect key="frame" x="18" y="216" width="96" height="17"/>
93
+                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
94
+                        <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Subreddits:" id="Cmr-7n-CaG">
95
+                            <font key="font" metaFont="system"/>
96
+                            <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
97
+                            <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
98
+                        </textFieldCell>
99
+                    </textField>
100
+                    <scrollView fixedFrame="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8ew-wY-1Yh">
101
+                        <rect key="frame" x="20" y="61" width="300" height="147"/>
102
+                        <autoresizingMask key="autoresizingMask"/>
103
+                        <clipView key="contentView" ambiguous="YES" misplaced="YES" copiesOnScroll="NO" id="ENU-Jw-8fO">
104
+                            <rect key="frame" x="1" y="1" width="298" height="145"/>
105
+                            <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
106
+                            <subviews>
107
+                                <textView ambiguous="YES" editable="NO" importsGraphics="NO" richText="NO" findStyle="panel" allowsUndo="YES" verticallyResizable="YES" allowsNonContiguousLayout="YES" id="EhP-FS-8dT">
108
+                                    <rect key="frame" x="0.0" y="0.0" width="298" height="145"/>
109
+                                    <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
110
+                                    <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
111
+                                    <size key="minSize" width="298" height="145"/>
112
+                                    <size key="maxSize" width="463" height="10000000"/>
113
+                                    <color key="insertionPointColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
114
+                                    <size key="minSize" width="298" height="145"/>
115
+                                    <size key="maxSize" width="463" height="10000000"/>
116
+                                </textView>
117
+                            </subviews>
118
+                            <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
119
+                        </clipView>
120
+                        <scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="YES" id="b1U-AL-HNy">
121
+                            <rect key="frame" x="-100" y="-100" width="87" height="18"/>
122
+                            <autoresizingMask key="autoresizingMask"/>
123
+                        </scroller>
124
+                        <scroller key="verticalScroller" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="z7j-r6-B6f">
125
+                            <rect key="frame" x="283" y="1" width="16" height="145"/>
126
+                            <autoresizingMask key="autoresizingMask"/>
127
+                        </scroller>
128
+                    </scrollView>
129
+                    <button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="XZM-90-hQ8">
130
+                        <rect key="frame" x="118" y="215" width="204" height="18"/>
131
+                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
132
+                        <buttonCell key="cell" type="check" title="Subscriptions" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="vW5-Cp-Bm1">
133
+                            <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
134
+                            <font key="font" metaFont="system"/>
135
+                        </buttonCell>
136
+                        <connections>
137
+                            <action selector="toggleSubs:" target="-2" id="TPd-6W-xQv"/>
138
+                        </connections>
139
+                    </button>
140
+                </subviews>
18 141
             </view>
19 142
         </window>
20 143
     </objects>

+ 2
- 0
RedditBar/AppDelegate.h Vedi File

@@ -20,4 +20,6 @@
20 20
 
21 21
 -(IBAction)showPreferences:(id)sender;
22 22
 
23
+-(void)prefReturnName:(NSString *)name Pass:(NSString *)pass subscriptions:(Boolean)subscriptions subreddits:(NSString *)subreddits;
24
+
23 25
 @end

+ 5
- 0
RedditBar/AppDelegate.m Vedi File

@@ -27,7 +27,12 @@
27 27
 -(IBAction)showPreferences:(id)sender {
28 28
     [NSApp activateIgnoringOtherApps:YES];
29 29
     prefWindow = [[PrefController alloc] initWithWindowNibName:@"Prefs"];
30
+    [prefWindow setParent:self];
30 31
     [prefWindow showWindow:self];
31 32
 }
32 33
 
34
+-(void)prefReturnName:(NSString *)name Pass:(NSString *)pass subscriptions:(Boolean)subscriptions subreddits:(NSString *)subreddits {
35
+    
36
+}
37
+
33 38
 @end

+ 12
- 0
RedditBar/PrefController.h Vedi File

@@ -10,4 +10,16 @@
10 10
 
11 11
 @interface PrefController : NSWindowController
12 12
 
13
+@property (weak) IBOutlet NSTextField *username;
14
+@property (weak) IBOutlet NSSecureTextField *password;
15
+@property (atomic, retain) IBOutlet NSButtonCell *subscriptions;
16
+@property (atomic, retain) IBOutlet NSTextView *subreddits;
17
+@property (atomic, retain) IBOutlet NSWindow *win;
18
+@property (atomic, retain) NSObject *parent;
19
+
20
+-(IBAction)buttonSave:(id)sender;
21
+-(IBAction)toggleSubs:(id)sender;
22
+
23
+-(void)setParent:(NSObject *)par;
24
+
13 25
 @end

+ 44
- 0
RedditBar/PrefController.m Vedi File

@@ -7,7 +7,51 @@
7 7
 //
8 8
 
9 9
 #import "PrefController.h"
10
+#import "AppDelegate.h"
10 11
 
11 12
 @implementation PrefController
12 13
 
14
+@synthesize username, password, subscriptions, subreddits, win, parent;
15
+
16
+-(Boolean)isValidList:(NSString *)input validated:(NSString **)output {
17
+    // TODO: Check if subreddit input is valid
18
+    *output = input;
19
+    return TRUE;
20
+}
21
+
22
+-(IBAction)buttonSave:(id)sender {
23
+    Boolean subs;
24
+    NSString *reddits;
25
+    if (subscriptions.state != 0) {
26
+        subs = TRUE;
27
+    } else {
28
+        subs = FALSE;
29
+        if (![self isValidList:subreddits.textStorage.string validated:&reddits]) {
30
+            // TODO show error message
31
+            return;
32
+        }
33
+    }
34
+    AppDelegate *app = (AppDelegate *)parent;
35
+    [app prefReturnName:username.stringValue Pass:password.stringValue subscriptions:subs subreddits:reddits];
36
+    [win performClose:self];
37
+}
38
+
39
+-(IBAction)toggleSubs:(id)sender {
40
+    if (subscriptions.state != 0) {
41
+        // Use subscriptions
42
+        [subreddits setEditable:FALSE];
43
+        [subreddits setString:@""];
44
+    } else {
45
+        // Use userlist
46
+        [subreddits setEditable:TRUE];
47
+        [subreddits setString:@"One Subreddit per line!"];
48
+    }
49
+}
50
+
51
+-(void)showWindow:(id)sender {
52
+    [super showWindow:sender];
53
+    
54
+    
55
+}
56
+
13 57
 @end

Loading…
Annulla
Salva