瀏覽代碼

LibGUI+FileManager: Move `has_{parent,child}_segment` logic into BCB

Sam Atkins 2 年之前
父節點
當前提交
f5cf41eb5d
共有 2 個文件被更改,包括 5 次插入2 次删除
  1. 2 2
      Userland/Applications/FileManager/main.cpp
  2. 3 0
      Userland/Libraries/LibGUI/Breadcrumbbar.h

+ 2 - 2
Userland/Applications/FileManager/main.cpp

@@ -1155,8 +1155,8 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr
         paste_action->set_enabled(can_write_in_path && GUI::Clipboard::the().fetch_mime_type() == "text/uri-list");
         go_forward_action->set_enabled(directory_view->path_history_position() < directory_view->path_history_size() - 1);
         go_back_action->set_enabled(directory_view->path_history_position() > 0);
-        open_parent_directory_action->set_enabled(new_path != "/");
-        open_child_directory_action->set_enabled(breadcrumbbar.selected_segment().has_value() && *breadcrumbbar.selected_segment() < breadcrumbbar.segment_count() - 1);
+        open_parent_directory_action->set_enabled(breadcrumbbar.has_parent_segment());
+        open_child_directory_action->set_enabled(breadcrumbbar.has_child_segment());
         directory_view->view_as_table_action().set_enabled(can_read_in_path);
         directory_view->view_as_icons_action().set_enabled(can_read_in_path);
         directory_view->view_as_columns_action().set_enabled(can_read_in_path);

+ 3 - 0
Userland/Libraries/LibGUI/Breadcrumbbar.h

@@ -29,6 +29,9 @@ public:
     void set_selected_segment(Optional<size_t> index);
     Optional<size_t> selected_segment() const { return m_selected_segment; }
 
+    bool has_parent_segment() const { return m_selected_segment.has_value() && m_selected_segment.value() > 0; }
+    bool has_child_segment() const { return m_selected_segment.has_value() && m_selected_segment.value() < m_segments.size() - 1; }
+
     Function<void(Optional<size_t> index)> on_segment_change;
     Function<void(size_t index)> on_segment_click;
     Function<void(size_t index, DropEvent&)> on_segment_drop;