Browse Source

Added Submenu Item to open both link & comments

Thomas Buck 11 years ago
parent
commit
84d4b7e123

+ 27
- 5
RedditBar/AppDelegate.m View File

@@ -144,7 +144,7 @@
144 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 148
     RedditItem *rItem = [redditItems objectAtIndex:index];
149 149
     NSString *url;
150 150
     if (comments)
@@ -152,6 +152,13 @@
152 152
     else
153 153
         url = [rItem link];
154 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 163
     if (currentState.removeVisited) {
157 164
         // TODO remove selfpost, remove submenu if link & comments visited
@@ -172,12 +179,26 @@
172 179
 
173 180
 -(IBAction)linkToOpen:(id)sender {
174 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 183
         for (NSUInteger i = 0; i < [menuItems count]; i++) {
177 184
             NSMenuItem *item = [menuItems objectAtIndex:i];
178 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 202
                 break;
182 203
             }
183 204
         }
@@ -185,7 +206,7 @@
185 206
         for (NSUInteger i = 0; i < [menuItems count]; i++) {
186 207
             NSMenuItem *item = [menuItems objectAtIndex:i];
187 208
             if (sender == item) {
188
-                [self openAndRemoveAndReloadWithIndex:i Comments:FALSE];
209
+                [self openAndRemoveAndReloadWithIndex:i Comments:FALSE Both:FALSE];
189 210
                 break;
190 211
             }
191 212
         }
@@ -228,6 +249,7 @@
228 249
         NSMenu *submenu = [[NSMenu alloc] init];
229 250
         [submenu addItemWithTitle:NSLocalizedString(@"Link...", @"Link item") action:@selector(linkToOpen:) keyEquivalent:@""];
230 251
         [submenu addItemWithTitle:NSLocalizedString(@"Comments...", @"comment item") action:@selector(linkToOpen:) keyEquivalent:@""];
252
+        [submenu addItemWithTitle:NSLocalizedString(@"Both", @"Link & Comment item") action:@selector(linkToOpen:) keyEquivalent:@""];
231 253
         [item setSubmenu:submenu];
232 254
     }
233 255
     return item;

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

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

+ 1
- 0
RedditBar/RedditItem.h View File

@@ -35,6 +35,7 @@
35 35
 @property (atomic, retain) NSString *link; // link itself
36 36
 @property (atomic, retain) NSString *comments; // link to comments, or nil if isSelf is true
37 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 40
 +(RedditItem *)itemWithName:(NSString *)name Link:(NSString *)link Comments:(NSString *)comments Self:(BOOL)isSelf;
40 41
 

+ 2
- 1
RedditBar/RedditItem.m View File

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

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

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

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


Loading…
Cancel
Save