From 00075b1c8a8b0d51b0cc565f22cfba39414bd8c3 Mon Sep 17 00:00:00 2001 From: Christopher Dumas Date: Thu, 23 May 2019 14:15:57 -0700 Subject: Added functionality to make back and forward buttons work in FileManager. Also fixed it so that directories don't get double-opened (first when they are opened, and second when the selection changes to match in the file tree view) --- Applications/FileManager/DirectoryView.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'Applications/FileManager/DirectoryView.cpp') diff --git a/Applications/FileManager/DirectoryView.cpp b/Applications/FileManager/DirectoryView.cpp index 5265943129..cf8187ecd4 100644 --- a/Applications/FileManager/DirectoryView.cpp +++ b/Applications/FileManager/DirectoryView.cpp @@ -108,8 +108,18 @@ void DirectoryView::set_view_mode(ViewMode mode) ASSERT_NOT_REACHED(); } +void DirectoryView::add_path_to_history(const String& path) +{ + if (m_path_history_position < m_path_history.size()) + m_path_history.resize(m_path_history_position + 1); + + m_path_history.append(path); + m_path_history_position = m_path_history.size() - 1; +} + void DirectoryView::open(const String& path) { + add_path_to_history(path); model().open(path); } @@ -121,10 +131,27 @@ void DirectoryView::set_status_message(const String& message) void DirectoryView::open_parent_directory() { - model().open(String::format("%s/..", model().path().characters())); + auto path = String::format("%s/..", model().path().characters()); + add_path_to_history(path); + model().open(path); } void DirectoryView::refresh() { model().update(); } + +void DirectoryView::open_previous_directory() +{ + if (m_path_history_position > 0) { + m_path_history_position--; + model().open(m_path_history[m_path_history_position]); + } +} +void DirectoryView::open_next_directory() +{ + if (m_path_history_position < m_path_history.size() - 1) { + m_path_history_position++; + model().open(m_path_history[m_path_history_position]); + } +} -- cgit v1.2.3