Skip to content

Commit

Permalink
parse_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKnauth committed Dec 19, 2023
1 parent 688763e commit 14b7a60
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,15 +622,9 @@ impl egui_dock::TabViewer for TabViewer<'_> {
Some(settings::Value::String(path)) => wasi_to_path(path),
_ => None,
};
let filter_pieces: Vec<String> =
filter.split('*').map(String::from).collect();
if ui.button(&*setting.description).clicked() {
let mut dialog = FileDialog::open_file(current_path).filter(
Box::new(move |p: &Path| {
let s = p.to_string_lossy();
filter_pieces.iter().all(|f| s.contains(f))
}),
);
let mut dialog = FileDialog::open_file(current_path)
.filter(parse_filter(filter));
dialog.open();
self.state.open_file_dialog = Some((
dialog,
Expand Down Expand Up @@ -1149,3 +1143,18 @@ impl DebuggerTimerState {
self.reset();
}
}

// --------------------------------------------------------

fn parse_filter(filter: &str) -> egui_file::Filter {
let variants: Vec<Vec<String>> = filter
.split(';')
.map(|variant| variant.split('*').map(String::from).collect())
.collect();
Box::new(move |p: &Path| {
let name = p.file_name().unwrap_or_default().to_string_lossy();
variants
.iter()
.any(|pieces| pieces.iter().all(|piece| name.contains(piece)))
})
}

0 comments on commit 14b7a60

Please sign in to comment.