diff options
author | Andrzej Rybczak <andrzej@rybczak.net> | 2020-12-21 11:14:26 +0100 |
---|---|---|
committer | Andrzej Rybczak <andrzej@rybczak.net> | 2020-12-21 11:14:26 +0100 |
commit | 40c40d8c7f011688b0014501be7fd5789fcf2569 (patch) | |
tree | ee3f73c126adf908c9bf07edc8ee8149d384f77f /src | |
parent | 3d5d1f4d54a426cc4a4ca839b313597ab668a3ce (diff) |
Fix crash on startup with Browser as the initial screen
Diffstat (limited to 'src')
-rw-r--r-- | src/screens/browser.cpp | 25 | ||||
-rw-r--r-- | src/screens/browser.h | 1 |
2 files changed, 12 insertions, 14 deletions
diff --git a/src/screens/browser.cpp b/src/screens/browser.cpp index e165206c..8fce2d89 100644 --- a/src/screens/browser.cpp +++ b/src/screens/browser.cpp @@ -129,7 +129,8 @@ std::vector<MPD::Song> BrowserWindow::getSelectedSongs() /**********************************************************************/ Browser::Browser() -: m_update_request(true) +: m_redraw_header(false) +, m_update_request(true) , m_local_browser(false) , m_scroll_beginning(0) , m_current_directory("/") @@ -165,8 +166,7 @@ void Browser::resize() void Browser::switchTo() { SwitchTo::execute(this); - update(); - drawHeader(); + m_redraw_header = true; } std::wstring Browser::title() @@ -181,7 +181,6 @@ void Browser::update() if (m_update_request) { m_update_request = false; - bool directory_changed = false; do { try @@ -194,17 +193,17 @@ void Browser::update() // If current directory doesn't exist, try getting its // parent until we either succeed or reach the root. if (err.code() == MPD_SERVER_ERROR_NO_EXIST) - { m_current_directory = getParentDirectory(m_current_directory); - directory_changed = true; - } else throw; } } while (w.empty() && !inRootDirectory()); - if (directory_changed) - drawHeader(); + } + if (m_redraw_header) + { + drawHeader(); + m_redraw_header = false; } } @@ -432,10 +431,7 @@ void Browser::locateSong(const MPD::Song &s) { // Try to change to relevant directory. if (m_current_directory != s.getDirectory()) - { getDirectory(s.getDirectory()); - drawHeader(); - } // Highlight the item. auto begin = w.beginV(), end = w.endV(); @@ -462,7 +458,6 @@ bool Browser::enterDirectory() if (item.type() == MPD::Item::Type::Directory) { getDirectory(item.directory().path()); - drawHeader(); result = true; } } @@ -479,7 +474,10 @@ void Browser::getDirectory(std::string directory) // Reset the position if we change directories. if (m_current_directory != directory) + { w.reset(); + m_redraw_header = true; + } // Check if it's a parent directory. if (isStringParentDirectory(directory)) @@ -550,7 +548,6 @@ void Browser::changeBrowseMode() m_current_directory = "/"; w.reset(); getDirectory(m_current_directory); - drawHeader(); } void Browser::remove(const MPD::Item &item) diff --git a/src/screens/browser.h b/src/screens/browser.h index 5c90c144..56ef3a42 100644 --- a/src/screens/browser.h +++ b/src/screens/browser.h @@ -95,6 +95,7 @@ struct Browser: Screen<BrowserWindow>, Filterable, HasSongs, Searchable, Tabbabl static void fetchSupportedExtensions(); private: + bool m_redraw_header; bool m_update_request; bool m_local_browser; size_t m_scroll_beginning; |