diff --git a/Userland/Applications/FileManager/DirectoryView.cpp b/Userland/Applications/FileManager/DirectoryView.cpp index 688cd83d9f..35bf4a5f07 100644 --- a/Userland/Applications/FileManager/DirectoryView.cpp +++ b/Userland/Applications/FileManager/DirectoryView.cpp @@ -355,17 +355,20 @@ void DirectoryView::add_path_to_history(String path) m_path_history_position = m_path_history.size() - 1; } -void DirectoryView::open(String const& path) +bool DirectoryView::open(String const& path) { auto real_path = Core::File::real_path_for(path); + if (real_path.is_null() || !Core::File::is_directory(path)) + return false; + chdir(real_path.characters()); if (model().root_path() == real_path) { - model().invalidate(); - return; + refresh(); + } else { + set_active_widget(¤t_view()); + model().set_root_path(real_path); } - - set_active_widget(¤t_view()); - model().set_root_path(real_path); + return true; } void DirectoryView::set_status_message(StringView const& message) @@ -376,8 +379,7 @@ void DirectoryView::set_status_message(StringView const& message) void DirectoryView::open_parent_directory() { - auto path = String::formatted("{}/..", model().root_path()); - model().set_root_path(path); + open(".."); } void DirectoryView::refresh() @@ -387,19 +389,13 @@ void DirectoryView::refresh() void DirectoryView::open_previous_directory() { - if (m_path_history_position > 0) { - set_active_widget(¤t_view()); - m_path_history_position--; - model().set_root_path(m_path_history[m_path_history_position]); - } + if (m_path_history_position > 0) + open(m_path_history[--m_path_history_position]); } void DirectoryView::open_next_directory() { - if (m_path_history_position < m_path_history.size() - 1) { - set_active_widget(¤t_view()); - m_path_history_position++; - model().set_root_path(m_path_history[m_path_history_position]); - } + if (m_path_history_position < m_path_history.size() - 1) + open(m_path_history[++m_path_history_position]); } void DirectoryView::update_statusbar() diff --git a/Userland/Applications/FileManager/DirectoryView.h b/Userland/Applications/FileManager/DirectoryView.h index f1168b5d04..5410dec6a5 100644 --- a/Userland/Applications/FileManager/DirectoryView.h +++ b/Userland/Applications/FileManager/DirectoryView.h @@ -49,7 +49,7 @@ public: virtual ~DirectoryView() override; - void open(String const& path); + bool open(String const& path); String path() const { return model().root_path(); } void open_parent_directory(); void open_previous_directory(); diff --git a/Userland/Applications/FileManager/main.cpp b/Userland/Applications/FileManager/main.cpp index 7396b96682..e5fb98c96d 100644 --- a/Userland/Applications/FileManager/main.cpp +++ b/Userland/Applications/FileManager/main.cpp @@ -495,7 +495,8 @@ int run_in_windowed_mode(String initial_location, String entry_focused_on_init) progressbar.set_frame_thickness(1); location_textbox.on_return_pressed = [&] { - directory_view.open(location_textbox.text()); + if (directory_view.open(location_textbox.text())) + location_textbox.set_focus(false); }; auto refresh_tree_view = [&] {