Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions bevy_editor_panes/bevy_asset_browser/src/io/task.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{AssetBrowserLocation, DirectoryContent, DirectoryContentOrder, Entry};
use crate::{AssetBrowserLocation, DirectoryContent, Entry};
use bevy::{
asset::io::AssetSourceBuilders,
prelude::*,
Expand All @@ -20,12 +20,9 @@ pub(crate) fn fetch_task_is_running(
pub(crate) fn poll_task(
mut commands: Commands,
mut task_query: Query<(Entity, &mut FetchDirectoryContentTask)>,
content_order: Res<DirectoryContentOrder>,
) {
let (task_entity, mut task) = task_query.single_mut().unwrap();
if let Some(mut content) = block_on(poll_once(&mut task.0)) {
content_order.sort(&mut content);

if let Some(content) = block_on(poll_once(&mut task.0)) {
commands.entity(task_entity).despawn();
commands.insert_resource(content);
}
Expand Down
26 changes: 15 additions & 11 deletions bevy_editor_panes/bevy_asset_browser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ impl Plugin for AssetBrowserPanePlugin {
)
.add_systems(
Update,
ui::directory_content::refresh_ui
(
ui::directory_content::sort_directory_content,
ui::directory_content::refresh_ui,
)
.run_if(directory_content_as_changed)
.after(io::task::poll_task),
.after(io::task::poll_task)
.chain(),
)
.add_systems(
Update,
Expand Down Expand Up @@ -103,15 +107,6 @@ pub enum DirectoryContentOrder {
/// Ordered reverse alphabetically with respect to folders
ReverseAlphabetical,
}
impl DirectoryContentOrder {
/// Sorts a given [`DirectoryContent`] with the current method
pub fn sort(&self, content: &mut DirectoryContent) {
match self {
Self::Alphabetical => content.0.sort_by(alphabetical_sort),
Self::ReverseAlphabetical => content.0.sort_by(reverse_alphabetical_sort),
}
}
}

/// One entry of [`DirectoryContent`]
#[derive(Debug, Clone, PartialEq, Eq)]
Expand All @@ -127,6 +122,15 @@ pub enum Entry {
/// The content of the directory pointed by [`AssetBrowserLocation`]
#[derive(Resource, Default, Debug, Clone, PartialEq, Eq)]
pub struct DirectoryContent(pub Vec<Entry>);
impl DirectoryContent {
/// Sorts the directory by the given [`DirectoryContentOrder`]
pub fn sort(&mut self, order: &DirectoryContentOrder) {
match order {
DirectoryContentOrder::Alphabetical => self.0.sort_by(alphabetical_sort),
DirectoryContentOrder::ReverseAlphabetical => self.0.sort_by(reverse_alphabetical_sort),
}
}
}

/// Check if the [`DirectoryContent`] has changed, which relate to the content of the current [`AssetBrowserLocation`]
pub(crate) fn directory_content_as_changed(directory_content: Res<DirectoryContent>) -> bool {
Expand Down
11 changes: 10 additions & 1 deletion bevy_editor_panes/bevy_asset_browser/src/ui/directory_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use bevy_context_menu::{ContextMenu, ContextMenuOption};
use bevy_editor_styles::Theme;
use bevy_scroll_box::{ScrollBox, ScrollBoxContent, spawn_scroll_box};

use crate::{AssetBrowserLocation, DefaultSourceFilePath, DirectoryContent, Entry, io};
use crate::{
AssetBrowserLocation, DefaultSourceFilePath, DirectoryContent, DirectoryContentOrder, Entry, io,
};

use crate::ui::nodes::{spawn_file_node, spawn_folder_node, spawn_source_node};

Expand Down Expand Up @@ -76,6 +78,13 @@ fn asset_browser_context_menu() -> ContextMenu {
])
}

pub(crate) fn sort_directory_content(
mut directory_content: ResMut<DirectoryContent>,
directory_content_order: Res<DirectoryContentOrder>,
) {
directory_content.sort(&directory_content_order);
}

/// Refresh the UI with the content of the current [`AssetBrowserLocation`]
pub(crate) fn refresh_ui(
mut commands: Commands,
Expand Down
Loading