Skip to content

Commit

Permalink
proper menu setup in track queue
Browse files Browse the repository at this point in the history
  • Loading branch information
jcm93 committed Aug 29, 2017
1 parent 2b4ffc1 commit 7d223e4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 30 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class TrackQueueTableView: TableViewYouCanPressSpacebarOn {
let clickedRow = self.row(at: localLocation)
if clickedRow != -1 {
trackQueueViewController?.determineRightMouseDownTarget(clickedRow)
} else {
trackQueueViewController?.rightMouseDownTarget = nil
}
super.rightMouseDown(with: theEvent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class FromSourceDividerCell: NSTableCellView {}

class FromSourceCell: NSTableCellView {}

class TrackQueueViewController: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
class TrackQueueViewController: NSViewController, NSTableViewDelegate, NSTableViewDataSource, NSMenuDelegate {

var trackQueue: [TrackQueueView] = [TrackQueueView]()
var mainWindowController: MainWindowController?
Expand All @@ -90,6 +90,32 @@ class TrackQueueViewController: NSViewController, NSTableViewDelegate, NSTableVi
var rightMouseDownTarget: IndexSet?
var upcomingTrack: Track?

var createPlaylistMenuItem = NSMenuItem(title: "Create Playlist From Selection", action: #selector(makePlaylistFromSelection), keyEquivalent: "")
var removePlaylistMenuItem = NSMenuItem(title: "Remove From Queue", action: #selector(removeFromQueue), keyEquivalent: "")
var separatorMenuItem = NSMenuItem.separator()
var shuffleUpcomingMenuItem = NSMenuItem(title: "Shuffle Upcoming Tracks", action: #selector(shuffleUpcoming), keyEquivalent: "")
var clearQueueMenuItem = NSMenuItem(title: "Clear Upcoming", action: #selector(clearUpcoming), keyEquivalent: "")

var normalMenuItems: [NSMenuItem]!

func menuWillOpen(_ menu: NSMenu) {
menu.removeAllItems()
var menuItems = [NSMenuItem]()
if let items = self.rightMouseDownTarget?.map({ return self.trackQueue[$0] }).filter({ return $0.track != nil }), items.count > 0 {
menuItems.append(contentsOf: [self.createPlaylistMenuItem, self.removePlaylistMenuItem])
}
if currentTrackIndex != nil, self.trackQueue.count > currentTrackIndex! + 1 {
let futureTracks = self.trackQueue[currentTrackIndex!..<self.trackQueue.count - 1]
if menuItems.count > 0 {
menuItems.append(self.separatorMenuItem)
}
menuItems.append(contentsOf: [self.shuffleUpcomingMenuItem, self.clearQueueMenuItem])
}
for item in menuItems {
menu.addItem(item)
}
}

func reloadData() {
tableView?.reloadData()
}
Expand Down Expand Up @@ -733,6 +759,8 @@ class TrackQueueViewController: NSViewController, NSTableViewDelegate, NSTableVi
tableView.trackQueueViewController = self
// Do view setup here.
tableView.scroll(NSPoint(x: 0, y: tableView.frame.height))
self.tableView.menu?.delegate = self
self.normalMenuItems = [self.createPlaylistMenuItem, self.removePlaylistMenuItem, self.separatorMenuItem, self.shuffleUpcomingMenuItem, self.clearQueueMenuItem]
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,35 +265,7 @@ MgA3AEEARwBQAFcAXABkAHkAewB9AH8AgQCJAJAAlQCgAKMApQCnAKkArgC5AMIAygDNANYA2wDoAOwA
</connections>
<point key="canvasLocation" x="623" y="506.5"/>
</customView>
<menu id="WI7-MJ-gex">
<items>
<menuItem title="Create Playlist from Selection" id="1ta-ZA-vfC">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="makePlaylistFromTrackQueueSelection:" target="-2" id="aTd-0E-kPp"/>
</connections>
</menuItem>
<menuItem title="Remove from Queue" id="yJe-cq-6n0">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="removeFromQueue:" target="-2" id="fCt-Rs-umB"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="ljj-Ui-lvw"/>
<menuItem title="Shuffle Upcoming" id="jwt-jW-MQB">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="shuffleUpcoming:" target="-2" id="zvE-bp-w9L"/>
</connections>
</menuItem>
<menuItem title="Clear" id="1Ry-7D-3RY">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="clearUpcoming:" target="-2" id="VVd-mQ-b0E"/>
</connections>
</menuItem>
</items>
</menu>
<menu id="WI7-MJ-gex"/>
</objects>
<resources>
<image name="Playlist" width="24" height="24"/>
Expand Down

0 comments on commit 7d223e4

Please sign in to comment.