diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 64f54ac9e..cba4d782e 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -11,6 +11,8 @@ user-facing: places if the window or view is resized * added localization support for "dimensions". this allows for per-locale sizing of ui components +* directory browser now remembers which directories were previously selected, + making up navigation in the settings view smoother * added a "list_header_highlighted_background" and "list_header_highlighted_foreground" color theme variables * tweaked the win32 icon so it looks a bit better on the taskbar diff --git a/src/musikbox/app/layout/SettingsLayout.cpp b/src/musikbox/app/layout/SettingsLayout.cpp index 2e9d49075..b207eaf82 100755 --- a/src/musikbox/app/layout/SettingsLayout.cpp +++ b/src/musikbox/app/layout/SettingsLayout.cpp @@ -459,9 +459,12 @@ void SettingsLayout::RemoveSelectedDirectory() { } void SettingsLayout::DrillIntoSelectedDirectory() { - this->browseAdapter->Select(this->browseList->GetSelectedIndex()); - this->browseList->SetSelectedIndex(0); + size_t selectIndexAt = this->browseAdapter->Select( + this->browseList.get(), this->browseList->GetSelectedIndex()); + this->browseList->OnAdapterChanged(); + this->browseList->SetSelectedIndex(selectIndexAt); + this->browseList->ScrollTo(selectIndexAt); } bool SettingsLayout::KeyPress(const std::string& key) { diff --git a/src/musikbox/app/model/DirectoryAdapter.cpp b/src/musikbox/app/model/DirectoryAdapter.cpp index f89376184..e8f459be8 100755 --- a/src/musikbox/app/model/DirectoryAdapter.cpp +++ b/src/musikbox/app/model/DirectoryAdapter.cpp @@ -98,12 +98,20 @@ DirectoryAdapter::~DirectoryAdapter() { } -void DirectoryAdapter::Select(size_t index) { +size_t DirectoryAdapter::Select(cursespp::ListWindow* window, size_t index) { bool hasParent = dir.has_parent_path(); + size_t selectedIndex = 0; + if (hasParent && index == 0) { + if (selectedIndexStack.size()) { + selectedIndex = this->selectedIndexStack.top(); + this->selectedIndexStack.pop(); + } + this->dir = this->dir.parent_path(); } else { + selectedIndexStack.push(window->GetSelectedIndex()); dir /= this->subdirs[hasParent ? index - 1 : index]; } @@ -114,12 +122,14 @@ void DirectoryAdapter::Select(size_t index) { { dir = path(); buildDriveList(subdirs); - return; + return selectedIndex; } #endif buildDirectoryList(dir, subdirs, showDotfiles); + + return selectedIndex; } std::string DirectoryAdapter::GetFullPathAt(size_t index) { diff --git a/src/musikbox/app/model/DirectoryAdapter.h b/src/musikbox/app/model/DirectoryAdapter.h index f036479a7..a7ce3c2ed 100755 --- a/src/musikbox/app/model/DirectoryAdapter.h +++ b/src/musikbox/app/model/DirectoryAdapter.h @@ -35,8 +35,10 @@ #pragma once #include +#include #include #include +#include namespace musik { namespace box { @@ -48,7 +50,7 @@ namespace musik { virtual size_t GetEntryCount(); virtual EntryPtr GetEntry(cursespp::ScrollableWindow* window, size_t index); - void Select(size_t index); + size_t Select(cursespp::ListWindow* window, size_t index); std::string GetFullPathAt(size_t index); void SetDotfilesVisible(bool visible); @@ -56,6 +58,7 @@ namespace musik { private: boost::filesystem::path dir; std::vector subdirs; + std::stack selectedIndexStack; bool showDotfiles; }; }