From 14b7a607a8fd8d8f8753e9217d953a4e24777d89 Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Tue, 12 Dec 2023 00:36:02 -0500 Subject: [PATCH] parse_filter --- src/main.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 84df954..2123ad4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -622,15 +622,9 @@ impl egui_dock::TabViewer for TabViewer<'_> { Some(settings::Value::String(path)) => wasi_to_path(path), _ => None, }; - let filter_pieces: Vec = - 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, @@ -1149,3 +1143,18 @@ impl DebuggerTimerState { self.reset(); } } + +// -------------------------------------------------------- + +fn parse_filter(filter: &str) -> egui_file::Filter { + let variants: Vec> = 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))) + }) +}