Explorar el Código

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

Thomas Buck hace 11 años
padre
commit
cb6b763241
Se han modificado 4 ficheros con 25 adiciones y 15 borrados
  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 Ver fichero

@@ -147,27 +147,33 @@
147 147
 -(void)openAndRemoveAndReloadWithIndex:(NSInteger)index Comments:(Boolean)comments Both:(Boolean)both {
148 148
     RedditItem *rItem = [redditItems objectAtIndex:index];
149 149
     NSString *url;
150
-    if (comments)
150
+    if (comments) {
151 151
         url = [rItem comments];
152
-    else
152
+        [rItem setVisitedComments:TRUE];
153
+    } else {
153 154
         url = [rItem link];
155
+        [rItem setVisitedLink:TRUE];
156
+    }
154 157
     [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
155 158
     if (both) {
156
-        if (!comments)
159
+        if (!comments) {
157 160
             url = [rItem comments];
158
-        else
161
+            [rItem setVisitedComments:TRUE];
162
+        } else {
159 163
             url = [rItem link];
164
+            [rItem setVisitedLink:TRUE];
165
+        }
160 166
         [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
161 167
     }
162 168
     
163 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 177
             [self reloadNextList:nil];
172 178
         } else {
173 179
             if (removed && currentState.reloadAfterVisit) {
@@ -221,7 +227,9 @@
221 227
 -(void)clearMenuItems {
222 228
     if (menuItems != nil) {
223 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 234
         menuItems = nil;
227 235
     }

+ 1
- 1
RedditBar/RedditBar-Info.plist Ver fichero

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

+ 2
- 1
RedditBar/RedditItem.h Ver fichero

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

+ 3
- 2
RedditBar/RedditItem.m Ver fichero

@@ -30,7 +30,7 @@
30 30
 
31 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 35
 +(RedditItem *)itemWithName:(NSString *)name Link:(NSString *)link Comments:(NSString *)comments Self:(BOOL)isSelf {
36 36
     RedditItem *i = [[RedditItem alloc] init];
@@ -38,7 +38,8 @@
38 38
     [i setLink:link];
39 39
     [i setComments:comments];
40 40
     [i setIsSelf:isSelf];
41
-    [i setVisitedCount:0];
41
+    [i setVisitedLink:FALSE];
42
+    [i setVisitedComments:FALSE];
42 43
     return i;
43 44
 }
44 45
 

Loading…
Cancelar
Guardar