feat: add menu option to toggle hidden articles

This commit is contained in:
relikd
2025-12-03 14:48:39 +01:00
parent a0a5b5b82d
commit c2fda881b1

View File

@@ -14,6 +14,10 @@
@property (strong) NSStatusItem *statusItem; @property (strong) NSStatusItem *statusItem;
@property (assign) NSInteger unreadCountTotal; @property (assign) NSInteger unreadCountTotal;
@property (weak) NSMenuItem *updateAllItem; @property (weak) NSMenuItem *updateAllItem;
/// Set to `true` if user toggled the `"Show Hidden Articles"` menu option.
@property (assign) BOOL optShowHidden;
/// Set to `true` if menu bar was opened while holding down option-key.
@property (assign) BOOL holdingOptKey;
@end @end
@implementation BarStatusItem @implementation BarStatusItem
@@ -150,9 +154,10 @@
#pragma mark - Main Menu Handling #pragma mark - Main Menu Handling
-(void)menuWillOpen:(NSMenu *)menu { -(void)menuWillOpen:(NSMenu *)menu {
self.holdingOptKey = NSEvent.modifierFlags & NSEventModifierFlagOption;
_mainMenu = menu; // autoreleased once closed _mainMenu = menu; // autoreleased once closed
self.barMenu = [[BarMenu alloc] initWithStatusItem:self]; self.barMenu = [[BarMenu alloc] initWithStatusItem:self];
self.barMenu.showHidden = NSEvent.modifierFlags & NSEventModifierFlagOption; self.barMenu.showHidden = self.optShowHidden || self.holdingOptKey;
[self insertMainMenuHeader:menu]; [self insertMainMenuHeader:menu];
[self.barMenu menuNeedsUpdate:menu]; [self.barMenu menuNeedsUpdate:menu];
@@ -166,6 +171,7 @@
self.barMenu = nil; self.barMenu = nil;
self.statusItem.menu = [[NSMenu alloc] initWithTitle:@"M"]; self.statusItem.menu = [[NSMenu alloc] initWithTitle:@"M"];
self.statusItem.menu.delegate = self; self.statusItem.menu.delegate = self;
self.holdingOptKey = NO;
} }
- (void)insertMainMenuHeader:(NSMenu*)menu { - (void)insertMainMenuHeader:(NSMenu*)menu {
@@ -174,6 +180,18 @@
pause.target = self; pause.target = self;
if ([UpdateScheduler isPaused]) if ([UpdateScheduler isPaused])
pause.title = NSLocalizedString(@"Resume Updates", nil); pause.title = NSLocalizedString(@"Resume Updates", nil);
// 'show hidden articles' item
NSMenuItem *toggleHidden = [menu addItemWithTitle:NSLocalizedString(@"Show Hidden Articles", nil) action:@selector(toggleHiddenArticles) keyEquivalent:@"h"];
toggleHidden.target = self;
toggleHidden.enabled = !self.holdingOptKey && (UserPrefsBool(Pref_groupUnreadOnly) || UserPrefsBool(Pref_feedUnreadOnly));
[toggleHidden setState:self.barMenu.showHidden ? NSControlStateValueOn : NSControlStateValueOff];
if (!toggleHidden.enabled) {
toggleHidden.toolTip = self.holdingOptKey
? NSLocalizedString(@"Option disabled because overwritten by holding down option-key.", nil)
: NSLocalizedString(@"Option disabled because appearance setting for “Show only unread” is disabled.", nil);
}
// 'Update all feeds' item // 'Update all feeds' item
if (UserPrefsBool(Pref_globalUpdateAll)) { if (UserPrefsBool(Pref_globalUpdateAll)) {
NSMenuItem *updateAll = [menu addItemWithTitle:NSLocalizedString(@"Update all feeds", nil) action:@selector(updateAllFeeds) keyEquivalent:@""]; NSMenuItem *updateAll = [menu addItemWithTitle:NSLocalizedString(@"Update all feeds", nil) action:@selector(updateAllFeeds) keyEquivalent:@""];
@@ -191,6 +209,12 @@
[self updateBarIcon]; [self updateBarIcon];
} }
/// Called when user clicks on 'Show Hidden Articles' (main menu only).
- (void)toggleHiddenArticles {
self.optShowHidden = !self.optShowHidden;
self.barMenu.showHidden = self.optShowHidden;
}
/// Called when user clicks on 'Update all feeds' (main menu only). /// Called when user clicks on 'Update all feeds' (main menu only).
- (void)updateAllFeeds { - (void)updateAllFeeds {
// [self asyncReloadUnreadCount]; // should not be necessary // [self asyncReloadUnreadCount]; // should not be necessary