From 44afb98f896eb9133c739a41466d0bd97ce74e10 Mon Sep 17 00:00:00 2001 From: Daniel Barber Date: Sat, 8 Jun 2019 18:20:39 -0400 Subject: [PATCH] Wire up main queue menu options --- Persephone/AppDelegate.swift | 21 +++++++++++++ .../Controllers/QueueViewController.swift | 10 ++++++ .../Resources/Base.lproj/Main.storyboard | 31 ++++++++++++++++--- Persephone/State/Actions/UIActions.swift | 4 +++ Persephone/State/Reducers/UIReducer.swift | 3 ++ Persephone/State/UIState.swift | 2 ++ 6 files changed, 66 insertions(+), 5 deletions(-) diff --git a/Persephone/AppDelegate.swift b/Persephone/AppDelegate.swift index c828494..e013915 100644 --- a/Persephone/AppDelegate.swift +++ b/Persephone/AppDelegate.swift @@ -135,6 +135,27 @@ class AppDelegate: NSObject, App.store.dispatch(MPDPrevTrackAction()) } + @IBAction func removeQueueSongMenuAction(_ sender: NSMenuItem) { + guard let queueItem = App.store.state.uiState.selectedQueueItem + else { return } + + App.store.dispatch(MPDRemoveTrack(queuePos: queueItem.queuePos)) + } + @IBAction func clearQueueMenuAction(_ sender: NSMenuItem) { + let alert = NSAlert() + alert.alertStyle = .informational + alert.messageText = "Are you sure you want to clear the queue?" + alert.informativeText = "You can’t undo this action." + alert.addButton(withTitle: "Clear") + alert.addButton(withTitle: "Cancel") + + let result = alert.runModal() + + if result == .alertFirstButtonReturn { + App.store.dispatch(UpdateQueueAction(queue: [])) + } + } + @IBAction func playSelectedSongAction(_ sender: NSMenuItem) { guard let song = App.store.state.uiState.selectedSong else { return } diff --git a/Persephone/Controllers/QueueViewController.swift b/Persephone/Controllers/QueueViewController.swift index ec3cb90..bf41fd5 100644 --- a/Persephone/Controllers/QueueViewController.swift +++ b/Persephone/Controllers/QueueViewController.swift @@ -93,6 +93,16 @@ class QueueViewController: NSViewController, } } + func outlineViewSelectionDidChange(_ notification: Notification) { + if queueView.selectedRow >= 1 { + let queueItem = dataSource.queue[queueView.selectedRow - 1] + + App.store.dispatch(SetSelectedQueueItem(selectedQueueItem: queueItem)) + } else { + App.store.dispatch(SetSelectedQueueItem(selectedQueueItem: nil)) + } + } + func cellForSongTitle(_ outlineView: NSOutlineView, with queueItem: QueueItem) -> NSView { let cellView = outlineView.makeView( withIdentifier: .queueSongTitle, diff --git a/Persephone/Resources/Base.lproj/Main.storyboard b/Persephone/Resources/Base.lproj/Main.storyboard index b11f160..b477c31 100644 --- a/Persephone/Resources/Base.lproj/Main.storyboard +++ b/Persephone/Resources/Base.lproj/Main.storyboard @@ -79,8 +79,18 @@ - + + + + + + + + + + + @@ -88,13 +98,13 @@ - + - + @@ -575,7 +585,7 @@ - + @@ -795,6 +805,7 @@ + @@ -822,8 +833,18 @@ + + + + + + + + + + - + diff --git a/Persephone/State/Actions/UIActions.swift b/Persephone/State/Actions/UIActions.swift index 16db011..7cc2135 100644 --- a/Persephone/State/Actions/UIActions.swift +++ b/Persephone/State/Actions/UIActions.swift @@ -18,6 +18,10 @@ struct DatabaseUpdateStartedAction: Action {} struct DatabaseUpdateFinishedAction: Action {} +struct SetSelectedQueueItem: Action { + let selectedQueueItem: QueueItem? +} + struct SetSelectedSong: Action { let selectedSong: Song? } diff --git a/Persephone/State/Reducers/UIReducer.swift b/Persephone/State/Reducers/UIReducer.swift index 3011e98..c7dc494 100644 --- a/Persephone/State/Reducers/UIReducer.swift +++ b/Persephone/State/Reducers/UIReducer.swift @@ -30,6 +30,9 @@ func uiReducer(action: Action, state: UIState?) -> UIState { case let action as SetSelectedSong: state.selectedSong = action.selectedSong + case let action as SetSelectedQueueItem: + state.selectedQueueItem = action.selectedQueueItem + default: break } diff --git a/Persephone/State/UIState.swift b/Persephone/State/UIState.swift index 46f436d..16ef4a6 100644 --- a/Persephone/State/UIState.swift +++ b/Persephone/State/UIState.swift @@ -20,4 +20,6 @@ struct UIState: StateType { var databaseUpdating: Bool = false var selectedSong: Song? + + var selectedQueueItem: QueueItem? }