[vlc-commits] macosx/library: add right-click menu
Felix Paul Kühne
git at videolan.org
Mon Apr 29 19:26:42 CEST 2019
vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Sat Apr 20 12:17:35 2019 +0200| [57c2c462859d7c48a8bf1c6858fda3c7e0bc29ab] | committer: Felix Paul Kühne
macosx/library: add right-click menu
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=57c2c462859d7c48a8bf1c6858fda3c7e0bc29ab
---
.../package/macosx/VLC.xcodeproj/project.pbxproj | 6 ++
modules/gui/macosx/Makefile.am | 2 +
modules/gui/macosx/UI/VLCLibraryWindow.xib | 2 +-
.../gui/macosx/library/VLCLibraryMenuController.h | 35 +++++++++
.../gui/macosx/library/VLCLibraryMenuController.m | 90 ++++++++++++++++++++++
modules/gui/macosx/library/VLCLibraryWindow.h | 3 +
modules/gui/macosx/library/VLCLibraryWindow.m | 34 ++++++++
po/POTFILES.in | 2 +
8 files changed, 173 insertions(+), 1 deletion(-)
diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
index 33b07afb76..56076c2ca1 100644
--- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj
+++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
@@ -151,6 +151,7 @@
7DFBDCA82269E77500B700A5 /* VLCLibraryController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCA72269E77500B700A5 /* VLCLibraryController.m */; };
7DFBDCAB2269E77F00B700A5 /* VLCLibraryModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCAA2269E77F00B700A5 /* VLCLibraryModel.m */; };
7DFBDCAE2269ED0C00B700A5 /* VLCLibraryDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCAD2269ED0C00B700A5 /* VLCLibraryDataSource.m */; };
+ 7DFBDCB1226A518400B700A5 /* VLCLibraryMenuController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCB0226A518400B700A5 /* VLCLibraryMenuController.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -512,6 +513,8 @@
7DFBDCAA2269E77F00B700A5 /* VLCLibraryModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryModel.m; sourceTree = "<group>"; };
7DFBDCAC2269ED0C00B700A5 /* VLCLibraryDataSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryDataSource.h; sourceTree = "<group>"; };
7DFBDCAD2269ED0C00B700A5 /* VLCLibraryDataSource.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryDataSource.m; sourceTree = "<group>"; };
+ 7DFBDCAF226A518400B700A5 /* VLCLibraryMenuController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryMenuController.h; sourceTree = "<group>"; };
+ 7DFBDCB0226A518400B700A5 /* VLCLibraryMenuController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryMenuController.m; sourceTree = "<group>"; };
8E49720006417F6800370C9F /* VLCInformationWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCInformationWindowController.h; sourceTree = "<group>"; };
8E49720106417F6800370C9F /* VLCInformationWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCInformationWindowController.m; sourceTree = "<group>"; };
8E55FB7F0459B0FD00FB3317 /* VLCOutput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCOutput.h; sourceTree = "<group>"; };
@@ -924,6 +927,8 @@
7DFBDCAA2269E77F00B700A5 /* VLCLibraryModel.m */,
7DFBDCAC2269ED0C00B700A5 /* VLCLibraryDataSource.h */,
7DFBDCAD2269ED0C00B700A5 /* VLCLibraryDataSource.m */,
+ 7DFBDCAF226A518400B700A5 /* VLCLibraryMenuController.h */,
+ 7DFBDCB0226A518400B700A5 /* VLCLibraryMenuController.m */,
);
path = library;
sourceTree = "<group>";
@@ -1594,6 +1599,7 @@
7D0F63FF2201F63400FDB91F /* VLCPlaylistTableCellView.m in Sources */,
1C3113D11E508C6900D4DD76 /* prefs.m in Sources */,
1C3113D31E508C6900D4DD76 /* VLCResumeDialogController.m in Sources */,
+ 7DFBDCB1226A518400B700A5 /* VLCLibraryMenuController.m in Sources */,
1C3113D51E508C6900D4DD76 /* VLCTextfieldPanelController.m in Sources */,
7DFBDCAE2269ED0C00B700A5 /* VLCLibraryDataSource.m in Sources */,
1C3113D71E508C6900D4DD76 /* VLCPopupPanelController.m in Sources */,
diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am
index 4d8f33a5f6..db919c84a7 100644
--- a/modules/gui/macosx/Makefile.am
+++ b/modules/gui/macosx/Makefile.am
@@ -50,6 +50,8 @@ libmacosx_plugin_la_SOURCES = \
gui/macosx/library/VLCLibraryController.m \
gui/macosx/library/VLCLibraryDataSource.h \
gui/macosx/library/VLCLibraryDataSource.m \
+ gui/macosx/library/VLCLibraryMenuController.h \
+ gui/macosx/library/VLCLibraryMenuController.m \
gui/macosx/library/VLCLibraryModel.h \
gui/macosx/library/VLCLibraryModel.m \
gui/macosx/library/VLCLibraryWindow.h \
diff --git a/modules/gui/macosx/UI/VLCLibraryWindow.xib b/modules/gui/macosx/UI/VLCLibraryWindow.xib
index c2f0f996b2..005b6cd1ec 100644
--- a/modules/gui/macosx/UI/VLCLibraryWindow.xib
+++ b/modules/gui/macosx/UI/VLCLibraryWindow.xib
@@ -49,7 +49,7 @@
<rect key="frame" x="0.0" y="0.0" width="242" height="291"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
- <collectionView selectable="YES" id="B8x-e8-7zp">
+ <collectionView selectable="YES" id="B8x-e8-7zp" customClass="VLCLibraryCollectionView">
<rect key="frame" x="0.0" y="0.0" width="242" height="291"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumInteritemSpacing="10" minimumLineSpacing="10" id="Rag-cM-k1g">
diff --git a/modules/gui/macosx/library/VLCLibraryMenuController.h b/modules/gui/macosx/library/VLCLibraryMenuController.h
new file mode 100644
index 0000000000..912eb8759c
--- /dev/null
+++ b/modules/gui/macosx/library/VLCLibraryMenuController.h
@@ -0,0 +1,35 @@
+/*****************************************************************************
+ * VLCLibraryMenuController.h: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan -dot- org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+ at interface VLCLibraryMenuController : NSObject
+
+ at property (readwrite, weak) NSCollectionView *libraryCollectionView;
+
+- (void)popupMenuWithEvent:(NSEvent *)theEvent forView:(NSView *)theView;
+
+ at end
+
+NS_ASSUME_NONNULL_END
diff --git a/modules/gui/macosx/library/VLCLibraryMenuController.m b/modules/gui/macosx/library/VLCLibraryMenuController.m
new file mode 100644
index 0000000000..751c4d9431
--- /dev/null
+++ b/modules/gui/macosx/library/VLCLibraryMenuController.m
@@ -0,0 +1,90 @@
+/*****************************************************************************
+ * VLCLibraryMenuController.m: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan -dot- org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "VLCLibraryMenuController.h"
+
+#import "main/VLCMain.h"
+#import "library/VLCLibraryController.h"
+#import "library/VLCLibraryModel.h"
+
+#import "extensions/NSString+Helpers.h"
+
+ at interface VLCLibraryMenuController ()
+{
+ NSMenu *_libraryMenu;
+ NSIndexPath *_actionIndexPath;
+}
+ at end
+
+ at implementation VLCLibraryMenuController
+
+- (instancetype)init
+{
+ self = [super init];
+ if (self) {
+ _libraryMenu = [[NSMenu alloc] initWithTitle:@""];
+ [_libraryMenu addItemWithTitle:_NS("Play") action:@selector(play:) keyEquivalent:@""];
+ [[_libraryMenu itemAtIndex:0] setTarget:self];
+ [_libraryMenu addItemWithTitle:_NS("Add Media...") action:@selector(addMedia:) keyEquivalent:@""];
+ [[_libraryMenu itemAtIndex:1] setTarget:self];
+ [_libraryMenu addItemWithTitle:_NS("Reveal in Finder") action:@selector(revealInFinder:) keyEquivalent:@""];
+ [[_libraryMenu itemAtIndex:2] setTarget:self];
+ }
+ return self;
+}
+
+- (void)popupMenuWithEvent:(NSEvent *)theEvent forView:(NSView *)theView
+{
+ _actionIndexPath = [self.libraryCollectionView indexPathForItemAtPoint:[NSEvent mouseLocation]];
+
+ [NSMenu popUpContextMenu:_libraryMenu withEvent:theEvent forView:theView];
+}
+
+#pragma mark - actions
+
+- (void)play:(id)sender
+{
+
+}
+
+- (void)addMedia:(id)sender
+{
+
+}
+
+- (void)revealInFinder:(id)sender
+{
+ VLCMediaLibraryMediaItem *mediaItem = [[[[VLCMain sharedInstance] libraryController] libraryModel] mediaItemAtIndexPath:_actionIndexPath];
+ if (mediaItem == nil) {
+ return;
+ }
+ VLCMediaLibraryFile *firstFile = mediaItem.files.firstObject;
+
+ if (firstFile) {
+ NSURL *URL = [NSURL URLWithString:firstFile.MRL];
+ if (URL) {
+ [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[URL]];
+ }
+ }
+}
+
+ at end
diff --git a/modules/gui/macosx/library/VLCLibraryWindow.h b/modules/gui/macosx/library/VLCLibraryWindow.h
index 3d4a208142..e1497fcbd7 100644
--- a/modules/gui/macosx/library/VLCLibraryWindow.h
+++ b/modules/gui/macosx/library/VLCLibraryWindow.h
@@ -30,6 +30,9 @@ NS_ASSUME_NONNULL_BEGIN
@end
+ at interface VLCLibraryCollectionView : NSCollectionView
+ at end
+
@interface VLCLibraryWindow : VLCVideoWindowCommon
@property (readwrite, weak) IBOutlet NSSegmentedControl *segmentedTitleControl;
diff --git a/modules/gui/macosx/library/VLCLibraryWindow.m b/modules/gui/macosx/library/VLCLibraryWindow.m
index d650ca07a2..9da9eb7c06 100644
--- a/modules/gui/macosx/library/VLCLibraryWindow.m
+++ b/modules/gui/macosx/library/VLCLibraryWindow.m
@@ -32,6 +32,7 @@
#import "library/VLCLibraryDataSource.h"
#import "library/VLCLibraryCollectionViewItem.h"
#import "library/VLCLibraryModel.h"
+#import "library/VLCLibraryMenuController.h"
#import "windows/mainwindow/VLCControlsBarCommon.h"
#import "windows/video/VLCFSPanelController.h"
@@ -209,3 +210,36 @@ static const float f_playlist_row_height = 72.;
}
@end
+
+ at interface VLCLibraryCollectionView()
+{
+ VLCLibraryMenuController *_menuController;
+}
+
+ at end
+
+ at implementation VLCLibraryCollectionView
+
+-(void)mouseDown:(NSEvent *)theEvent
+{
+ if (theEvent.modifierFlags & NSControlKeyMask) {
+ if (!_menuController) {
+ _menuController = [[VLCLibraryMenuController alloc] init];
+ }
+ [_menuController popupMenuWithEvent:theEvent forView:self];
+ }
+
+ [super mouseDown:theEvent];
+}
+
+- (void)rightMouseDown:(NSEvent *)theEvent
+{
+ if (!_menuController) {
+ _menuController = [[VLCLibraryMenuController alloc] init];
+ }
+ [_menuController popupMenuWithEvent:theEvent forView:self];
+
+ [super rightMouseDown:theEvent];
+}
+
+ at end
diff --git a/po/POTFILES.in b/po/POTFILES.in
index cdcbabda04..8ac1398cc7 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -468,6 +468,8 @@ modules/gui/macosx/library/VLCLibraryController.h
modules/gui/macosx/library/VLCLibraryController.m
modules/gui/macosx/library/VLCLibraryDataSource.h
modules/gui/macosx/library/VLCLibraryDataSource.m
+modules/gui/macosx/library/VLCLibraryMenuController.h
+modules/gui/macosx/library/VLCLibraryMenuController.m
modules/gui/macosx/library/VLCLibraryModel.h
modules/gui/macosx/library/VLCLibraryModel.m
modules/gui/macosx/library/VLCLibraryWindow.h
More information about the vlc-commits
mailing list