mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +00:00
refactor: improved filtering functionality
This commit is contained in:
+2
-24
@@ -1,4 +1,4 @@
|
|||||||
use crate::gui::{SUPPORTED_EXTENSIONS, SoundpadGui};
|
use crate::gui::SoundpadGui;
|
||||||
use egui::{
|
use egui::{
|
||||||
Align, AtomExt, Button, CollapsingHeader, Color32, ComboBox, CursorIcon, FontFamily, Label,
|
Align, AtomExt, Button, CollapsingHeader, Color32, ComboBox, CursorIcon, FontFamily, Label,
|
||||||
Layout, RichText, ScrollArea, Sense, Slider, TextEdit, Ui, Vec2,
|
Layout, RichText, ScrollArea, Sense, Slider, TextEdit, Ui, Vec2,
|
||||||
@@ -376,37 +376,15 @@ impl SoundpadGui {
|
|||||||
ui.set_min_height(area_size.y);
|
ui.set_min_height(area_size.y);
|
||||||
|
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
let mut files: Vec<PathBuf> = self.app_state.files.iter().cloned().collect();
|
let files = self.get_filtered_files();
|
||||||
files.sort();
|
|
||||||
|
|
||||||
for entry_path in files {
|
for entry_path in files {
|
||||||
if entry_path.is_dir() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if !SUPPORTED_EXTENSIONS
|
|
||||||
.contains(&entry_path.extension().unwrap_or_default().to_str().unwrap())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let file_name = entry_path
|
let file_name = entry_path
|
||||||
.file_name()
|
.file_name()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let search_query = self
|
|
||||||
.app_state
|
|
||||||
.search_query
|
|
||||||
.to_lowercase()
|
|
||||||
.trim()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
if !file_name.to_lowercase().contains(search_query.as_str()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut file_button_text = RichText::new(file_name);
|
let mut file_button_text = RichText::new(file_name);
|
||||||
if let Some(current_file) = &self.app_state.selected_file {
|
if let Some(current_file) = &self.app_state.selected_file {
|
||||||
if current_file.eq(&entry_path) {
|
if current_file.eq(&entry_path) {
|
||||||
|
|||||||
@@ -145,6 +145,47 @@ impl SoundpadGui {
|
|||||||
pub fn stop(&mut self, id: Option<u32>) {
|
pub fn stop(&mut self, id: Option<u32>) {
|
||||||
make_request_async(Request::stop(id));
|
make_request_async(Request::stop(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_filtered_files(&self) -> Vec<PathBuf> {
|
||||||
|
let mut files: Vec<PathBuf> = self.app_state.files.iter().cloned().collect();
|
||||||
|
files.sort();
|
||||||
|
|
||||||
|
let search_query = self.app_state.search_query.to_lowercase();
|
||||||
|
let search_query = search_query.trim();
|
||||||
|
|
||||||
|
files
|
||||||
|
.into_iter()
|
||||||
|
.filter(|entry_path| {
|
||||||
|
if entry_path.is_dir() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !SUPPORTED_EXTENSIONS.contains(
|
||||||
|
&entry_path
|
||||||
|
.extension()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_str()
|
||||||
|
.unwrap_or_default(),
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !search_query.is_empty() {
|
||||||
|
let file_name = entry_path
|
||||||
|
.file_name()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_string_lossy()
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
if !file_name.to_lowercase().contains(search_query) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run() -> Result<(), Box<dyn Error>> {
|
pub async fn run() -> Result<(), Box<dyn Error>> {
|
||||||
|
|||||||
Reference in New Issue
Block a user