From 13a4191b939409c5d841bac1713d2dee34add909 Mon Sep 17 00:00:00 2001 From: relikd Date: Tue, 11 Dec 2018 16:45:05 +0100 Subject: [PATCH] User preferences: Short article names, Tick marks and Open few --- README.md | 8 +- .../General Tab/SettingsGeneral.xib | 96 ++++++++++--------- baRSS/Preferences/General Tab/UserPrefs.h | 4 + baRSS/Preferences/General Tab/UserPrefs.m | 19 ++++ baRSS/Status Bar Menu/BarMenu.m | 9 +- baRSS/Status Bar Menu/NSMenuItem+Ext.m | 8 +- 6 files changed, 90 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 2c46bb5..a667c83 100644 --- a/README.md +++ b/README.md @@ -31,14 +31,14 @@ ToDo - [ ] Preferences - [x] Choose favorite web browser - [x] Show list of installed browsers - - [ ] Choose status bar icon? - - [ ] Tick mark feed items based on prefs - - [ ] Open a few links (# editable) + - [ ] ~~Choose status bar icon?~~ + - [x] Tick mark feed items based on prefs + - [x] Open a few links (# editable) - [x] Performance: Update menu partially - [x] Start on login - [x] Make it system default application - [ ] Display license info (e.g., RSXML) - - [ ] Short article names + - [x] Short article names - [ ] Import / Export (all feeds) - [ ] Support for `.opml` format - [ ] Append or replace diff --git a/baRSS/Preferences/General Tab/SettingsGeneral.xib b/baRSS/Preferences/General Tab/SettingsGeneral.xib index ec93e5f..b667ff9 100644 --- a/baRSS/Preferences/General Tab/SettingsGeneral.xib +++ b/baRSS/Preferences/General Tab/SettingsGeneral.xib @@ -38,7 +38,7 @@ - + @@ -272,7 +272,7 @@ - + @@ -281,7 +281,7 @@ - + @@ -290,7 +290,7 @@ - + @@ -299,7 +299,7 @@ - + @@ -308,7 +308,7 @@ - + @@ -316,20 +316,6 @@ - - - - - - - - - - - - - - @@ -356,7 +342,7 @@ - + @@ -368,7 +354,7 @@ - + @@ -380,7 +366,7 @@ - + @@ -392,9 +378,9 @@ + + + + + + + + + + - - - diff --git a/baRSS/Preferences/General Tab/UserPrefs.h b/baRSS/Preferences/General Tab/UserPrefs.h index b5467b5..f50d4d5 100644 --- a/baRSS/Preferences/General Tab/UserPrefs.h +++ b/baRSS/Preferences/General Tab/UserPrefs.h @@ -25,6 +25,10 @@ @interface UserPrefs : NSObject + (BOOL)defaultYES:(NSString*)key; + (BOOL)defaultNO:(NSString*)key; + + (NSString*)getHttpApplication; + (void)setHttpApplication:(NSString*)bundleID; + ++ (NSUInteger)openFewLinksLimit; // Change with: 'defaults write de.relikd.baRSS openFewLinksLimit -int 10' ++ (NSUInteger)shortArticleNamesLimit; // Change with: 'defaults write de.relikd.baRSS shortArticleNamesLimit -int 50' @end diff --git a/baRSS/Preferences/General Tab/UserPrefs.m b/baRSS/Preferences/General Tab/UserPrefs.m index 5cfbee7..0421776 100644 --- a/baRSS/Preferences/General Tab/UserPrefs.m +++ b/baRSS/Preferences/General Tab/UserPrefs.m @@ -37,6 +37,13 @@ return [[NSUserDefaults standardUserDefaults] boolForKey:key]; } +/// @return Return @c defaultInt if key is not set. Otherwise, return user defaults property from plist. ++ (NSInteger)defaultInt:(NSInteger)defaultInt forKey:(NSString*)key { + NSInteger ret = [[NSUserDefaults standardUserDefaults] integerForKey:key]; + if (ret > 0) return ret; + return defaultInt; +} + /// @return User configured custom browser. Or @c nil if not set yet. (which will fallback to default browser) + (NSString*)getHttpApplication { return [[NSUserDefaults standardUserDefaults] stringForKey:@"defaultHttpApplication"]; @@ -47,4 +54,16 @@ [[NSUserDefaults standardUserDefaults] setObject:bundleID forKey:@"defaultHttpApplication"]; } +#pragma mark - Hidden Plist Properties - + +/// @return The limit on how many links should be opened at the same time, if user holds the option key. ++ (NSUInteger)openFewLinksLimit { + return (NSUInteger)[self defaultInt:10 forKey:@"openFewLinksLimit"]; +} + +/// @return The limit on when to truncate article titles (Short names setting must be active). ++ (NSUInteger)shortArticleNamesLimit { + return (NSUInteger)[self defaultInt:60 forKey:@"shortArticleNamesLimit"]; +} + @end diff --git a/baRSS/Status Bar Menu/BarMenu.m b/baRSS/Status Bar Menu/BarMenu.m index d5db652..68e0cde 100644 --- a/baRSS/Status Bar Menu/BarMenu.m +++ b/baRSS/Status Bar Menu/BarMenu.m @@ -79,8 +79,6 @@ /// Update menu bar icon and text according to unread count and user preferences. - (void)updateBarIcon { - // TODO: Option: icon choice - // TODO: Show paused icon if no internet connection dispatch_async(dispatch_get_main_queue(), ^{ if (self.unreadCountTotal > 0 && [UserPrefs defaultYES:@"globalUnreadCount"]) { self.barItem.title = [NSString stringWithFormat:@"%ld", self.unreadCountTotal]; @@ -88,7 +86,7 @@ self.barItem.title = @""; } BOOL hasNet = [FeedDownload allowNetworkConnection]; - if (self.unreadCountTotal > 0 && [UserPrefs defaultYES:@"tintMenuBarIcon"]) { + if (self.unreadCountTotal > 0 && hasNet && [UserPrefs defaultYES:@"tintMenuBarIcon"]) { self.barItem.image = [RSSIcon systemBarIcon:16 tint:[NSColor rssOrange] noConnection:!hasNet]; } else { self.barItem.image = [RSSIcon systemBarIcon:16 tint:nil noConnection:!hasNet]; @@ -259,7 +257,8 @@ MenuItemTag scope = [menu scope]; NSMenuItem *item1 = [NSMenuItem itemWithTitle:NSLocalizedString(@"Open all unread", nil) action:@selector(openAllUnread:) target:self tag:TagOpenAllUnread | scope]; - NSMenuItem *item2 = [item1 alternateWithTitle:[NSString stringWithFormat:NSLocalizedString(@"Open a few unread (%d)", nil), 3]]; + NSMenuItem *item2 = [item1 alternateWithTitle:[NSString stringWithFormat:@"%@ (%lu)", + NSLocalizedString(@"Open a few unread", nil), [UserPrefs openFewLinksLimit]]]; NSMenuItem *item3 = [NSMenuItem itemWithTitle:NSLocalizedString(@"Mark all read", nil) action:@selector(markAllReadOrUnread:) target:self tag:TagMarkAllRead | scope]; NSMenuItem *item4 = [NSMenuItem itemWithTitle:NSLocalizedString(@"Mark all unread", nil) @@ -349,7 +348,7 @@ NSMutableArray *urls = [NSMutableArray array]; __block int maxItemCount = INT_MAX; if (sender.isAlternate) - maxItemCount = 3; // TODO: read from preferences + maxItemCount = (int)[UserPrefs openFewLinksLimit]; NSManagedObjectContext *moc = [StoreCoordinator createChildContext]; [sender iterateSorted:YES inContext:moc overDescendentFeeds:^(Feed *feed, BOOL *cancel) { diff --git a/baRSS/Status Bar Menu/NSMenuItem+Ext.m b/baRSS/Status Bar Menu/NSMenuItem+Ext.m index 6dedffa..d5c8ce9 100644 --- a/baRSS/Status Bar Menu/NSMenuItem+Ext.m +++ b/baRSS/Status Bar Menu/NSMenuItem+Ext.m @@ -151,9 +151,15 @@ typedef NS_ENUM(char, DisplaySetting) { */ - (void)setFeedArticle:(FeedArticle*)fa { self.title = fa.title; + // TODO: It should be enough to get user prefs once per menu build + if ([UserPrefs defaultNO:@"feedShortNames"]) { + NSUInteger limit = [UserPrefs shortArticleNamesLimit]; + if (self.title.length > limit) + self.title = [NSString stringWithFormat:@"%@…", [self.title substringToIndex:limit-1]]; + } self.tag = ScopeFeed; self.enabled = (fa.link.length > 0); - self.state = (fa.unread ? NSControlStateValueOn : NSControlStateValueOff); + self.state = (fa.unread && [UserPrefs defaultYES:@"feedTickMark"] ? NSControlStateValueOn : NSControlStateValueOff); self.representedObject = fa.objectID; //mi.toolTip = item.abstract; // TODO: Do regex during save, not during display. Its here for testing purposes ...