Skip to content

Commit

Permalink
macosx: Make bookmark method a toggle in library menu controller
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra authored and fkuehne committed Jul 13, 2024
1 parent 6c6dac1 commit 6909294
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions modules/gui/macosx/library/VLCLibraryMenuController.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ - (void)createLibraryMenu
NSMenuItem *informationItem = [[NSMenuItem alloc] initWithTitle:_NS("Information...") action:@selector(showInformation:) keyEquivalent:@""];
informationItem.target = self;

NSMenuItem * const bookmarkItem = [[NSMenuItem alloc] initWithTitle:_NS("Bookmark")
action:@selector(bookmark:)
NSMenuItem * const bookmarkItem = [[NSMenuItem alloc] initWithTitle:_NS("Toggle Bookmark")
action:@selector(toggleBookmark:)
keyEquivalent:@""];
bookmarkItem.target = self;

Expand Down Expand Up @@ -260,7 +260,7 @@ - (void)showInformation:(id)sender
[_informationWindowController toggleWindow:sender];
}

- (void)bookmark:(id)sender
- (void)toggleBookmark:(id)sender
{
if (self.representedInputItems == nil ||
self.representedInputItems.count != 1 ||
Expand All @@ -269,14 +269,19 @@ - (void)bookmark:(id)sender
}

VLCInputItem * const inputItem = self.representedInputItems.firstObject;
NSString * const inputItemMRL = inputItem.MRL;
NSUserDefaults * const defaults = NSUserDefaults.standardUserDefaults;
NSMutableArray<NSString *> * const bookmarkedLocations =
[defaults stringArrayForKey:VLCLibraryBookmarkedLocationsKey].mutableCopy;
NSNotificationCenter * const defaultCenter = NSNotificationCenter.defaultCenter;

[bookmarkedLocations addObject:inputItem.MRL];
if ([bookmarkedLocations containsObject:inputItemMRL]) {
[bookmarkedLocations removeObject:inputItemMRL];
} else {
[bookmarkedLocations addObject:inputItemMRL];
}
[defaults setObject:bookmarkedLocations forKey:VLCLibraryBookmarkedLocationsKey];
[defaultCenter postNotificationName:VLCLibraryBookmarkedLocationsChanged object:inputItem.MRL];
[defaultCenter postNotificationName:VLCLibraryBookmarkedLocationsChanged object:inputItemMRL];
}

- (void)setRepresentedItems:(NSArray<VLCLibraryRepresentedItem *> *)items
Expand Down

0 comments on commit 6909294

Please sign in to comment.