diff options
author | TheFightingCatfish <seekingblues@gmail.com> | 2021-08-11 23:43:52 +0800 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-26 22:02:15 +0200 |
commit | d2af27d2d046111f3828914257e2f4dff065e365 (patch) | |
tree | ad593c6db1af71310c8167a7505f4c3801a58d80 /Userland/Applications | |
parent | ce66c40160a53a168c5cb13db54b52349e25fbc7 (diff) | |
download | serenity-d2af27d2d046111f3828914257e2f4dff065e365.zip |
FileManager: Change the cwd when opening a directory
The `open()` function of DirectoryView should change the current working
directory, so that the "Go to Location" menu item can process relative
paths correctly. Update other functions in DirectoryView to use `open()`
when opening a directory.
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/FileManager/DirectoryView.cpp | 32 | ||||
-rw-r--r-- | Userland/Applications/FileManager/DirectoryView.h | 2 | ||||
-rw-r--r-- | Userland/Applications/FileManager/main.cpp | 3 |
3 files changed, 17 insertions, 20 deletions
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 = [&] { |