From 7b1728b521e1f28f76283959447559299e04a805 Mon Sep 17 00:00:00 2001 From: Daniel Barber Date: Fri, 17 Jan 2020 14:35:47 -0500 Subject: [PATCH] Clear search field on disconnect --- .../Window/Base.lproj/Main.storyboard | 63 ++++++++++--------- .../Components/Window/WindowController.swift | 15 +++++ 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/Persephone/Components/Window/Base.lproj/Main.storyboard b/Persephone/Components/Window/Base.lproj/Main.storyboard index 28861cb..44103c8 100644 --- a/Persephone/Components/Window/Base.lproj/Main.storyboard +++ b/Persephone/Components/Window/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -208,7 +208,7 @@ - + @@ -230,7 +230,7 @@ - + @@ -257,7 +257,7 @@ - + @@ -279,7 +279,7 @@ - + @@ -295,7 +295,7 @@ - + @@ -308,7 +308,7 @@ - + @@ -339,6 +339,7 @@ + @@ -408,7 +409,7 @@ - + @@ -442,7 +443,7 @@ - + @@ -454,7 +455,7 @@ - + @@ -467,7 +468,7 @@ - + @@ -476,7 +477,7 @@ - + @@ -484,7 +485,7 @@ - + @@ -527,7 +528,7 @@ - + @@ -592,7 +593,7 @@ - + @@ -603,7 +604,7 @@ - + @@ -614,7 +615,7 @@ - + @@ -646,31 +647,31 @@ - + - + - + - + - + - + @@ -711,7 +712,7 @@ - + @@ -719,7 +720,7 @@ - + @@ -746,12 +747,12 @@ - + - + @@ -764,7 +765,7 @@ - + @@ -804,8 +805,8 @@ - - + + diff --git a/Persephone/Components/Window/WindowController.swift b/Persephone/Components/Window/WindowController.swift index f77e094..9c3e53e 100644 --- a/Persephone/Components/Window/WindowController.swift +++ b/Persephone/Components/Window/WindowController.swift @@ -27,6 +27,8 @@ class WindowController: NSWindowController { @IBOutlet var shuffleState: NSButton! @IBOutlet var repeatState: NSButton! + @IBOutlet weak var searchQuery: NSSearchField! + override func windowDidLoad() { super.windowDidLoad() window?.titleVisibility = .hidden @@ -39,6 +41,8 @@ class WindowController: NSWindowController { } App.store.dispatch(MainWindowDidOpenAction()) + + NotificationCenter.default.addObserver(self, selector: #selector(willDisconnect), name: .willDisconnect, object: nil) trackProgress.font = .timerFont trackRemaining.font = .timerFont @@ -116,6 +120,17 @@ class WindowController: NSWindowController { trackRemaining.stringValue = time.formattedTime } + + func clearSearchQuery() { + searchQuery.stringValue = "" + } + + @objc func willDisconnect() { + DispatchQueue.main.async { + App.store.dispatch(ClearState()) + self.clearSearchQuery() + } + } // TODO: Refactor this using a gesture recognizer @IBAction func changeTrackProgress(_ sender: NSSlider) {