diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2023-02-06 17:30:38 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-02-19 01:09:09 +0100 |
commit | af03cf9e8091e8fcbe50d07f1a7707ae59f16de4 (patch) | |
tree | 6e8e191e22ef7087fcfa8949618684b61db817cc /Userland/Applications/FileManager | |
parent | f0c2dcdbac1be71bf997c19e8a771ff3a2459673 (diff) | |
download | serenity-af03cf9e8091e8fcbe50d07f1a7707ae59f16de4.zip |
FileManager: Use PathBreadcrumbbar instead of Breadcrumbbar :^)
Diffstat (limited to 'Userland/Applications/FileManager')
-rw-r--r-- | Userland/Applications/FileManager/FileManagerWindow.gml | 17 | ||||
-rw-r--r-- | Userland/Applications/FileManager/main.cpp | 93 |
2 files changed, 13 insertions, 97 deletions
diff --git a/Userland/Applications/FileManager/FileManagerWindow.gml b/Userland/Applications/FileManager/FileManagerWindow.gml index 9a298be04d..7718968602 100644 --- a/Userland/Applications/FileManager/FileManagerWindow.gml +++ b/Userland/Applications/FileManager/FileManagerWindow.gml @@ -14,21 +14,6 @@ } @GUI::Toolbar { - name: "location_toolbar" - visible: false - - @GUI::Label { - text: "Location: " - autosize: true - } - - @GUI::TextBox { - name: "location_textbox" - fixed_height: 22 - } - } - - @GUI::Toolbar { name: "breadcrumb_toolbar" @GUI::Label { @@ -36,7 +21,7 @@ autosize: true } - @GUI::Breadcrumbbar { + @GUI::PathBreadcrumbbar { name: "breadcrumbbar" } } diff --git a/Userland/Applications/FileManager/main.cpp b/Userland/Applications/FileManager/main.cpp index 4f3b96a657..de36bdec3a 100644 --- a/Userland/Applications/FileManager/main.cpp +++ b/Userland/Applications/FileManager/main.cpp @@ -28,7 +28,6 @@ #include <LibGUI/ActionGroup.h> #include <LibGUI/Application.h> #include <LibGUI/BoxLayout.h> -#include <LibGUI/Breadcrumbbar.h> #include <LibGUI/Clipboard.h> #include <LibGUI/Desktop.h> #include <LibGUI/FileIconProvider.h> @@ -38,6 +37,7 @@ #include <LibGUI/Menubar.h> #include <LibGUI/MessageBox.h> #include <LibGUI/Painter.h> +#include <LibGUI/PathBreadcrumbbar.h> #include <LibGUI/Progressbar.h> #include <LibGUI/Splitter.h> #include <LibGUI/Statusbar.h> @@ -590,14 +590,10 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr auto& toolbar_container = *widget->find_descendant_of_type_named<GUI::ToolbarContainer>("toolbar_container"); auto& main_toolbar = *widget->find_descendant_of_type_named<GUI::Toolbar>("main_toolbar"); - auto& location_toolbar = *widget->find_descendant_of_type_named<GUI::Toolbar>("location_toolbar"); - location_toolbar.layout()->set_margins({ 3, 6 }); - - auto& location_textbox = *widget->find_descendant_of_type_named<GUI::TextBox>("location_textbox"); auto& breadcrumb_toolbar = *widget->find_descendant_of_type_named<GUI::Toolbar>("breadcrumb_toolbar"); breadcrumb_toolbar.layout()->set_margins({ 0, 6 }); - auto& breadcrumbbar = *widget->find_descendant_of_type_named<GUI::Breadcrumbbar>("breadcrumbbar"); + auto& breadcrumbbar = *widget->find_descendant_of_type_named<GUI::PathBreadcrumbbar>("breadcrumbbar"); auto& splitter = *widget->find_descendant_of_type_named<GUI::HorizontalSplitter>("splitter"); auto& tree_view = *widget->find_descendant_of_type_named<GUI::TreeView>("tree_view"); @@ -617,10 +613,6 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr auto directory_view = TRY(splitter.try_add<DirectoryView>(DirectoryView::Mode::Normal)); directory_view->set_name("directory_view"); - location_textbox.on_escape_pressed = [&] { - directory_view->set_focus(true); - }; - // Open the root directory. FIXME: This is awkward. tree_view.toggle_index(directories_model->index(0, 0, {})); @@ -643,11 +635,6 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr progressbar.set_frame_shadow(Gfx::FrameShadow::Sunken); progressbar.set_frame_thickness(1); - location_textbox.on_return_pressed = [&] { - if (directory_view->open(location_textbox.text())) - location_textbox.set_focus(false); - }; - auto refresh_tree_view = [&] { directories_model->invalidate(); @@ -682,10 +669,7 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr }); auto open_child_directory_action = GUI::Action::create("Open &Child Directory", { Mod_Alt, Key_Down }, [&](GUI::Action const&) { - auto segment_index = breadcrumbbar.selected_segment(); - if (!segment_index.has_value() || *segment_index >= breadcrumbbar.segment_count() - 1) - return; - breadcrumbbar.set_selected_segment(*segment_index + 1); + breadcrumbbar.select_child_segment(); }); RefPtr<GUI::Action> layout_toolbar_action; @@ -700,7 +684,7 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr toolbar_container.set_visible(true); } else { main_toolbar.set_visible(false); - if (!location_toolbar.is_visible() && !breadcrumb_toolbar.is_visible()) + if (!breadcrumb_toolbar.is_visible()) toolbar_container.set_visible(false); } show_toolbar = action.is_checked(); @@ -713,11 +697,9 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr layout_location_action = GUI::Action::create_checkable("&Location Bar", [&](auto& action) { if (action.is_checked()) { breadcrumb_toolbar.set_visible(true); - location_toolbar.set_visible(false); toolbar_container.set_visible(true); } else { breadcrumb_toolbar.set_visible(false); - location_toolbar.set_visible(false); if (!main_toolbar.is_visible()) toolbar_container.set_visible(false); } @@ -747,13 +729,11 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr layout_folderpane_action->set_checked(show_folderpane); tree_view.set_visible(show_folderpane); - location_textbox.on_focusout = [&] { + breadcrumbbar.on_hide_location_box = [&] { if (show_location) breadcrumb_toolbar.set_visible(true); if (!(show_location || show_toolbar)) toolbar_container.set_visible(false); - - location_toolbar.set_visible(false); }; auto view_type_action_group = make<GUI::ActionGroup>(); @@ -1040,10 +1020,8 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr auto go_to_location_action = GUI::Action::create("Go to &Location...", { Mod_Ctrl, Key_L }, Key_F6, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/go-to.png"sv)), [&](auto&) { toolbar_container.set_visible(true); - location_toolbar.set_visible(true); - breadcrumb_toolbar.set_visible(false); - location_textbox.select_all(); - location_textbox.set_focus(true); + breadcrumb_toolbar.set_visible(true); + breadcrumbbar.show_location_text_box(); }); auto go_menu = TRY(window->try_add_menu("&Go")); @@ -1086,17 +1064,12 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr (void)TRY(main_toolbar.try_add_action(directory_view->view_as_table_action())); (void)TRY(main_toolbar.try_add_action(directory_view->view_as_columns_action())); - breadcrumbbar.on_segment_change = [&](auto segment_index) { - if (!segment_index.has_value()) - return; - auto selected_path = breadcrumbbar.segment_data(*segment_index); + breadcrumbbar.on_path_change = [&](auto selected_path) { if (Core::DeprecatedFile::is_directory(selected_path)) { directory_view->open(selected_path); } else { dbgln("Breadcrumb path '{}' doesn't exist", selected_path); - breadcrumbbar.remove_end_segments(*segment_index); - auto existing_path_segment = breadcrumbbar.find_segment_with_data(directory_view->path()); - breadcrumbbar.set_selected_segment(existing_path_segment.value()); + breadcrumbbar.set_current_path(directory_view->path()); } }; @@ -1104,43 +1077,10 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr auto icon = GUI::FileIconProvider::icon_for_path(new_path); auto* bitmap = icon.bitmap_for_size(16); window->set_icon(bitmap); - location_textbox.set_icon(bitmap); window->set_title(DeprecatedString::formatted("{} - File Manager", new_path)); - location_textbox.set_text(new_path); - - { - LexicalPath lexical_path(new_path); - auto segment_index_of_new_path_in_breadcrumbbar = breadcrumbbar.find_segment_with_data(new_path); - - if (segment_index_of_new_path_in_breadcrumbbar.has_value()) { - auto new_segment_index = segment_index_of_new_path_in_breadcrumbbar.value(); - breadcrumbbar.set_selected_segment(new_segment_index); - - // If the path change was because the directory we were in was deleted, - // remove the breadcrumbs for it. - if ((new_segment_index + 1 < breadcrumbbar.segment_count()) - && !Core::DeprecatedFile::is_directory(breadcrumbbar.segment_data(new_segment_index + 1))) { - breadcrumbbar.remove_end_segments(new_segment_index + 1); - } - } else { - breadcrumbbar.clear_segments(); - - breadcrumbbar.append_segment("/", GUI::FileIconProvider::icon_for_path("/").bitmap_for_size(16), "/", "/"); - StringBuilder builder; - - for (auto& part : lexical_path.parts()) { - // NOTE: We rebuild the path as we go, so we have something to pass to GUI::FileIconProvider. - builder.append('/'); - builder.append(part); - - breadcrumbbar.append_segment(part, GUI::FileIconProvider::icon_for_path(builder.string_view()).bitmap_for_size(16), builder.string_view(), builder.string_view()); - } - - breadcrumbbar.set_selected_segment(breadcrumbbar.segment_count() - 1); - } - } + breadcrumbbar.set_current_path(new_path); if (!is_reacting_to_tree_view_selection_change) { auto new_index = directories_model->index(new_path, GUI::FileSystemModel::Column::Name); @@ -1308,21 +1248,12 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr } }; - breadcrumbbar.on_segment_drop = [&](size_t segment_index, GUI::DropEvent const& event) { - bool const has_accepted_drop = handle_drop(event, breadcrumbbar.segment_data(segment_index), window).release_value_but_fixme_should_propagate_errors(); + breadcrumbbar.on_paths_drop = [&](auto path, GUI::DropEvent const& event) { + bool const has_accepted_drop = handle_drop(event, path, window).release_value_but_fixme_should_propagate_errors(); if (has_accepted_drop) refresh_tree_view(); }; - breadcrumbbar.on_segment_drag_enter = [&](size_t, GUI::DragEvent& event) { - if (event.mime_types().contains_slow("text/uri-list")) - event.accept(); - }; - - breadcrumbbar.on_doubleclick = [&](GUI::MouseEvent const&) { - go_to_location_action->activate(); - }; - tree_view.on_drop = [&](GUI::ModelIndex const& index, GUI::DropEvent const& event) { auto const& target_node = directories_model->node(index); bool const has_accepted_drop = handle_drop(event, target_node.full_path(), window).release_value_but_fixme_should_propagate_errors(); |