Add icons to the built-in picker for Open (#30893)
 Release Notes: - Added icons to the built-in picker for `Open` dialog
This commit is contained in:
parent
d61a544400
commit
2f3564b85f
1 changed files with 20 additions and 2 deletions
|
@ -1,9 +1,12 @@
|
||||||
|
use crate::file_finder_settings::FileFinderSettings;
|
||||||
|
use file_icons::FileIcons;
|
||||||
use futures::channel::oneshot;
|
use futures::channel::oneshot;
|
||||||
use fuzzy::{StringMatch, StringMatchCandidate};
|
use fuzzy::{StringMatch, StringMatchCandidate};
|
||||||
use picker::{Picker, PickerDelegate};
|
use picker::{Picker, PickerDelegate};
|
||||||
use project::{DirectoryItem, DirectoryLister};
|
use project::{DirectoryItem, DirectoryLister};
|
||||||
|
use settings::Settings;
|
||||||
use std::{
|
use std::{
|
||||||
path::{MAIN_SEPARATOR_STR, Path, PathBuf},
|
path::{self, MAIN_SEPARATOR_STR, Path, PathBuf},
|
||||||
sync::{
|
sync::{
|
||||||
Arc,
|
Arc,
|
||||||
atomic::{self, AtomicBool},
|
atomic::{self, AtomicBool},
|
||||||
|
@ -349,8 +352,9 @@ impl PickerDelegate for OpenPathDelegate {
|
||||||
ix: usize,
|
ix: usize,
|
||||||
selected: bool,
|
selected: bool,
|
||||||
_window: &mut Window,
|
_window: &mut Window,
|
||||||
_: &mut Context<Picker<Self>>,
|
cx: &mut Context<Picker<Self>>,
|
||||||
) -> Option<Self::ListItem> {
|
) -> Option<Self::ListItem> {
|
||||||
|
let settings = FileFinderSettings::get_global(cx);
|
||||||
let m = self.matches.get(ix)?;
|
let m = self.matches.get(ix)?;
|
||||||
let directory_state = self.directory_state.as_ref()?;
|
let directory_state = self.directory_state.as_ref()?;
|
||||||
let candidate = directory_state.match_candidates.get(*m)?;
|
let candidate = directory_state.match_candidates.get(*m)?;
|
||||||
|
@ -361,9 +365,23 @@ impl PickerDelegate for OpenPathDelegate {
|
||||||
.map(|string_match| string_match.positions.clone())
|
.map(|string_match| string_match.positions.clone())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let file_icon = maybe!({
|
||||||
|
if !settings.file_icons {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let icon = if candidate.is_dir {
|
||||||
|
FileIcons::get_folder_icon(false, cx)?
|
||||||
|
} else {
|
||||||
|
let path = path::Path::new(&candidate.path.string);
|
||||||
|
FileIcons::get_icon(&path, cx)?
|
||||||
|
};
|
||||||
|
Some(Icon::from_path(icon).color(Color::Muted))
|
||||||
|
});
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
ListItem::new(ix)
|
ListItem::new(ix)
|
||||||
.spacing(ListItemSpacing::Sparse)
|
.spacing(ListItemSpacing::Sparse)
|
||||||
|
.start_slot::<Icon>(file_icon)
|
||||||
.inset(true)
|
.inset(true)
|
||||||
.toggle_state(selected)
|
.toggle_state(selected)
|
||||||
.child(HighlightedLabel::new(
|
.child(HighlightedLabel::new(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue