Browse Source

Added Submenu Item to open both link & comments

Thomas Buck 10 years ago
parent
commit
84d4b7e123

+ 27
- 5
RedditBar/AppDelegate.m View File

144
     [self reloadListWithOptions];
144
     [self reloadListWithOptions];
145
 }
145
 }
146
 
146
 
147
--(void)openAndRemoveAndReloadWithIndex:(NSInteger)index Comments:(Boolean)comments {
147
+-(void)openAndRemoveAndReloadWithIndex:(NSInteger)index Comments:(Boolean)comments Both:(Boolean)both {
148
     RedditItem *rItem = [redditItems objectAtIndex:index];
148
     RedditItem *rItem = [redditItems objectAtIndex:index];
149
     NSString *url;
149
     NSString *url;
150
     if (comments)
150
     if (comments)
152
     else
152
     else
153
         url = [rItem link];
153
         url = [rItem link];
154
     [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
154
     [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
155
+    if (both) {
156
+        if (!comments)
157
+            url = [rItem comments];
158
+        else
159
+            url = [rItem link];
160
+        [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
161
+    }
155
     
162
     
156
     if (currentState.removeVisited) {
163
     if (currentState.removeVisited) {
157
         // TODO remove selfpost, remove submenu if link & comments visited
164
         // TODO remove selfpost, remove submenu if link & comments visited
172
 
179
 
173
 -(IBAction)linkToOpen:(id)sender {
180
 -(IBAction)linkToOpen:(id)sender {
174
     NSString *title = [(NSMenuItem *)sender title];
181
     NSString *title = [(NSMenuItem *)sender title];
175
-    if ([title isEqualToString:NSLocalizedString(@"Link...", nil)] || [title isEqualToString:NSLocalizedString(@"Comments...", nil)]) {
182
+    if ([title isEqualToString:NSLocalizedString(@"Link...", nil)] || [title isEqualToString:NSLocalizedString(@"Comments...", nil)] || [title isEqualToString:NSLocalizedString(@"Both", nil)]) {
176
         for (NSUInteger i = 0; i < [menuItems count]; i++) {
183
         for (NSUInteger i = 0; i < [menuItems count]; i++) {
177
             NSMenuItem *item = [menuItems objectAtIndex:i];
184
             NSMenuItem *item = [menuItems objectAtIndex:i];
178
             NSMenu *submenu = item.submenu;
185
             NSMenu *submenu = item.submenu;
179
-            if ((submenu != nil) && (sender == [submenu itemAtIndex:([title isEqualToString:NSLocalizedString(@"Link...", nil)] ? 0 : 1)])) {
180
-                [self openAndRemoveAndReloadWithIndex:i Comments:[title isEqualToString:NSLocalizedString(@"Comments...", nil)]];
186
+            Boolean isComments = [title isEqualToString:NSLocalizedString(@"Comments...", nil)];
187
+            Boolean isBoth = [title isEqualToString:NSLocalizedString(@"Both", nil)];
188
+            if (isBoth) {
189
+                isComments = !isComments; // Open comments first, then link
190
+            }
191
+            
192
+            NSInteger index;
193
+            if ([title isEqualToString:NSLocalizedString(@"Link...", nil)])
194
+                index = 0;
195
+            else if ([title isEqualToString:NSLocalizedString(@"Comments...", nil)])
196
+                index = 1;
197
+            else
198
+                index = 2;
199
+            
200
+            if ((submenu != nil) && (sender == [submenu itemAtIndex:index])) {
201
+                [self openAndRemoveAndReloadWithIndex:i Comments:isComments Both:isBoth];
181
                 break;
202
                 break;
182
             }
203
             }
183
         }
204
         }
185
         for (NSUInteger i = 0; i < [menuItems count]; i++) {
206
         for (NSUInteger i = 0; i < [menuItems count]; i++) {
186
             NSMenuItem *item = [menuItems objectAtIndex:i];
207
             NSMenuItem *item = [menuItems objectAtIndex:i];
187
             if (sender == item) {
208
             if (sender == item) {
188
-                [self openAndRemoveAndReloadWithIndex:i Comments:FALSE];
209
+                [self openAndRemoveAndReloadWithIndex:i Comments:FALSE Both:FALSE];
189
                 break;
210
                 break;
190
             }
211
             }
191
         }
212
         }
228
         NSMenu *submenu = [[NSMenu alloc] init];
249
         NSMenu *submenu = [[NSMenu alloc] init];
229
         [submenu addItemWithTitle:NSLocalizedString(@"Link...", @"Link item") action:@selector(linkToOpen:) keyEquivalent:@""];
250
         [submenu addItemWithTitle:NSLocalizedString(@"Link...", @"Link item") action:@selector(linkToOpen:) keyEquivalent:@""];
230
         [submenu addItemWithTitle:NSLocalizedString(@"Comments...", @"comment item") action:@selector(linkToOpen:) keyEquivalent:@""];
251
         [submenu addItemWithTitle:NSLocalizedString(@"Comments...", @"comment item") action:@selector(linkToOpen:) keyEquivalent:@""];
252
+        [submenu addItemWithTitle:NSLocalizedString(@"Both", @"Link & Comment item") action:@selector(linkToOpen:) keyEquivalent:@""];
231
         [item setSubmenu:submenu];
253
         [item setSubmenu:submenu];
232
     }
254
     }
233
     return item;
255
     return item;

+ 1
- 1
RedditBar/RedditBar-Info.plist View File

21
 	<key>CFBundleSignature</key>
21
 	<key>CFBundleSignature</key>
22
 	<string>????</string>
22
 	<string>????</string>
23
 	<key>CFBundleVersion</key>
23
 	<key>CFBundleVersion</key>
24
-	<string>286</string>
24
+	<string>290</string>
25
 	<key>LSApplicationCategoryType</key>
25
 	<key>LSApplicationCategoryType</key>
26
 	<string>public.app-category.utilities</string>
26
 	<string>public.app-category.utilities</string>
27
 	<key>LSMinimumSystemVersion</key>
27
 	<key>LSMinimumSystemVersion</key>

+ 1
- 0
RedditBar/RedditItem.h View File

35
 @property (atomic, retain) NSString *link; // link itself
35
 @property (atomic, retain) NSString *link; // link itself
36
 @property (atomic, retain) NSString *comments; // link to comments, or nil if isSelf is true
36
 @property (atomic, retain) NSString *comments; // link to comments, or nil if isSelf is true
37
 @property (atomic) BOOL isSelf; // link or selfpost
37
 @property (atomic) BOOL isSelf; // link or selfpost
38
+@property (atomic) NSInteger visitedCount; // used to keep track if both link & comments were opened to then remove item
38
 
39
 
39
 +(RedditItem *)itemWithName:(NSString *)name Link:(NSString *)link Comments:(NSString *)comments Self:(BOOL)isSelf;
40
 +(RedditItem *)itemWithName:(NSString *)name Link:(NSString *)link Comments:(NSString *)comments Self:(BOOL)isSelf;
40
 
41
 

+ 2
- 1
RedditBar/RedditItem.m View File

30
 
30
 
31
 @implementation RedditItem
31
 @implementation RedditItem
32
 
32
 
33
-@synthesize name, fullName, link, comments, isSelf;
33
+@synthesize name, fullName, link, comments, isSelf, visitedCount;
34
 
34
 
35
 +(RedditItem *)itemWithName:(NSString *)name Link:(NSString *)link Comments:(NSString *)comments Self:(BOOL)isSelf {
35
 +(RedditItem *)itemWithName:(NSString *)name Link:(NSString *)link Comments:(NSString *)comments Self:(BOOL)isSelf {
36
     RedditItem *i = [[RedditItem alloc] init];
36
     RedditItem *i = [[RedditItem alloc] init];
38
     [i setLink:link];
38
     [i setLink:link];
39
     [i setComments:comments];
39
     [i setComments:comments];
40
     [i setIsSelf:isSelf];
40
     [i setIsSelf:isSelf];
41
+    [i setVisitedCount:0];
41
     return i;
42
     return i;
42
 }
43
 }
43
 
44
 

+ 3
- 0
RedditBar/de.lproj/Localizable.strings View File

1
 /* Pref Error */
1
 /* Pref Error */
2
 "Authentication Error" = "Authentfizierungsfehler";
2
 "Authentication Error" = "Authentfizierungsfehler";
3
 
3
 
4
+/* Link & Comment item */
5
+"Both" = "Beide";
6
+
4
 /* comment item */
7
 /* comment item */
5
 "Comments..." = "Kommentare...";
8
 "Comments..." = "Kommentare...";
6
 
9
 

BIN
RedditBar/en.lproj/Localizable.strings View File


Loading…
Cancel
Save