Browse Source

Finished implementing removal of visited menuitems and reloading when list is empty.

Thomas Buck 11 years ago
parent
commit
cb6b763241
4 changed files with 25 additions and 15 deletions
  1. 19
    11
      RedditBar/AppDelegate.m
  2. 1
    1
      RedditBar/RedditBar-Info.plist
  3. 2
    1
      RedditBar/RedditItem.h
  4. 3
    2
      RedditBar/RedditItem.m

+ 19
- 11
RedditBar/AppDelegate.m View File

147
 -(void)openAndRemoveAndReloadWithIndex:(NSInteger)index Comments:(Boolean)comments Both:(Boolean)both {
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) {
151
         url = [rItem comments];
151
         url = [rItem comments];
152
-    else
152
+        [rItem setVisitedComments:TRUE];
153
+    } else {
153
         url = [rItem link];
154
         url = [rItem link];
155
+        [rItem setVisitedLink:TRUE];
156
+    }
154
     [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
157
     [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
155
     if (both) {
158
     if (both) {
156
-        if (!comments)
159
+        if (!comments) {
157
             url = [rItem comments];
160
             url = [rItem comments];
158
-        else
161
+            [rItem setVisitedComments:TRUE];
162
+        } else {
159
             url = [rItem link];
163
             url = [rItem link];
164
+            [rItem setVisitedLink:TRUE];
165
+        }
160
         [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
166
         [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
161
     }
167
     }
162
     
168
     
163
     if (currentState.removeVisited) {
169
     if (currentState.removeVisited) {
164
-        // TODO remove selfpost, remove submenu if link & comments visited
165
-        //[statusMenu removeItem:[menuItems objectAtIndex:i]];
166
-        
167
-        Boolean removed = TRUE;
168
-        Boolean listNowEmpty = TRUE;
170
+        Boolean removed = FALSE;
171
+        if ((rItem.isSelf && (rItem.visitedLink || rItem.visitedComments)) || ((!rItem.isSelf) && rItem.visitedLink && rItem.visitedComments)) {
172
+            [statusMenu removeItem:[menuItems objectAtIndex:index]];
173
+            removed = TRUE;
174
+        }
169
         
175
         
170
-        if (removed && listNowEmpty) {
176
+        if (removed && ([statusMenu numberOfItems] <= 10)) {
171
             [self reloadNextList:nil];
177
             [self reloadNextList:nil];
172
         } else {
178
         } else {
173
             if (removed && currentState.reloadAfterVisit) {
179
             if (removed && currentState.reloadAfterVisit) {
221
 -(void)clearMenuItems {
227
 -(void)clearMenuItems {
222
     if (menuItems != nil) {
228
     if (menuItems != nil) {
223
         for (NSUInteger i = 0; i < [menuItems count]; i++) {
229
         for (NSUInteger i = 0; i < [menuItems count]; i++) {
224
-            [statusMenu removeItem:[menuItems objectAtIndex:i]];
230
+            NSMenuItem *item = [menuItems objectAtIndex:i];
231
+            if ([statusMenu indexOfItem:item] != -1)
232
+                [statusMenu removeItem:item];
225
         }
233
         }
226
         menuItems = nil;
234
         menuItems = nil;
227
     }
235
     }

+ 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>290</string>
24
+	<string>298</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>

+ 2
- 1
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
+@property (atomic) BOOL visitedLink;
39
+@property (atomic) BOOL visitedComments;
39
 
40
 
40
 +(RedditItem *)itemWithName:(NSString *)name Link:(NSString *)link Comments:(NSString *)comments Self:(BOOL)isSelf;
41
 +(RedditItem *)itemWithName:(NSString *)name Link:(NSString *)link Comments:(NSString *)comments Self:(BOOL)isSelf;
41
 
42
 

+ 3
- 2
RedditBar/RedditItem.m View File

30
 
30
 
31
 @implementation RedditItem
31
 @implementation RedditItem
32
 
32
 
33
-@synthesize name, fullName, link, comments, isSelf, visitedCount;
33
+@synthesize name, fullName, link, comments, isSelf, visitedLink, visitedComments;
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
+    [i setVisitedLink:FALSE];
42
+    [i setVisitedComments:FALSE];
42
     return i;
43
     return i;
43
 }
44
 }
44
 
45
 

Loading…
Cancel
Save