This commit is contained in:
Alexander Mohr 2025-05-03 14:36:08 +02:00
parent 54354c298f
commit b001611aaa
2 changed files with 124 additions and 143 deletions

View file

@ -410,8 +410,6 @@ fn setup_key_event_handler<T: Clone + 'static + Send>(
ui.window.add_controller(key_controller); ui.window.add_controller(key_controller);
} }
#[allow(clippy::too_many_arguments)] // todo refactor this?
fn handle_key_press<T: Clone + 'static>( fn handle_key_press<T: Clone + 'static>(
ui: &Rc<UiElements<T>>, ui: &Rc<UiElements<T>>,
meta: &Rc<MetaData<T>>, meta: &Rc<MetaData<T>>,
@ -874,7 +872,9 @@ fn set_menu_visibility_for_search<T: Clone>(
menu_item.visible = true; menu_item.visible = true;
fb.set_visible(menu_item.visible); fb.set_visible(menu_item.visible);
} }
} else { return;
}
let query = if config.insensitive() { let query = if config.insensitive() {
query.to_owned().to_lowercase() query.to_owned().to_lowercase()
} else { } else {
@ -923,7 +923,6 @@ fn set_menu_visibility_for_search<T: Clone>(
} }
} }
} }
}
fn select_first_visible_child<T: Clone>( fn select_first_visible_child<T: Clone>(
items: &HashMap<FlowBoxChild, MenuItem<T>>, items: &HashMap<FlowBoxChild, MenuItem<T>>,

View file

@ -191,24 +191,22 @@ impl RunProvider {
.filter_map(Result::ok) .filter_map(Result::ok)
.filter_map(|entry| { .filter_map(|entry| {
let path = entry.path(); let path = entry.path();
if is_executable(&path) { if !is_executable(&path) {
let label = path return None;
.file_name() }
.and_then(|s| s.to_str())
.map(String::from)?; let label = path.file_name()?.to_str()?.to_string();
let sort_score = *self.cache.get(&label).unwrap_or(&0) as f64; let sort_score = *self.cache.get(&label).unwrap_or(&0) as f64;
Some(MenuItem::new( Some(MenuItem::new(
label, label,
None, None,
path.to_str().map(std::string::ToString::to_string), path.to_str().map(ToString::to_string),
vec![], vec![],
None, None,
sort_score, sort_score,
None, None,
)) ))
} else {
None
}
}) })
}) })
.collect(); .collect();
@ -217,15 +215,11 @@ impl RunProvider {
let mut entries: Vec<MenuItem<i32>> = entries let mut entries: Vec<MenuItem<i32>> = entries
.into_iter() .into_iter()
.filter(|entry| { .filter(|entry| {
if let Some(action) = &entry.action { entry
if let Some(cmd) = action.split('/').last() { .action
seen_actions.insert(cmd.to_string()) .as_ref()
} else { .and_then(|action| action.split('/').next_back())
false .is_some_and(|cmd| seen_actions.insert(cmd.to_string()))
}
} else {
false
}
}) })
.collect(); .collect();
@ -262,42 +256,47 @@ impl<T: Clone> FileItemProvider<T> {
} }
fn resolve_icon_for_name(path: &Path) -> String { fn resolve_icon_for_name(path: &Path) -> String {
let result = tree_magic_mini::from_filepath(path); let Some(mime) = tree_magic_mini::from_filepath(path) else {
if let Some(result) = result { return "image-not-found".to_string();
if result.starts_with("image") { };
"image-x-generic".to_owned()
} else if result.starts_with("inode") { if mime.starts_with("image") {
return result.replace('/', "-"); return "image-x-generic".to_string();
} else if result.starts_with("text") {
if result.contains("plain") {
"text-x-generic".to_owned()
} else if result.contains("python") {
"text-x-script".to_owned()
} else if result.contains("html") {
return "text-html".to_owned();
} else {
"text-x-generic".to_owned()
} }
} else if result.starts_with("application") {
if result.contains("octet") { if mime.starts_with("inode") {
"application-x-executable".to_owned() return mime.replace('/', "-");
} else if result.contains("tar") }
|| result.contains("lz")
|| result.contains("zip") if mime.starts_with("text") {
|| result.contains("7z") return if mime.contains("plain") {
|| result.contains("xz") "text-x-generic".to_string()
} else if mime.contains("python") {
"text-x-script".to_string()
} else if mime.contains("html") {
"text-html".to_string()
} else {
"text-x-generic".to_string()
};
}
if mime.starts_with("application") {
return if mime.contains("octet") {
"application-x-executable".to_string()
} else if mime.contains("tar")
|| mime.contains("lz")
|| mime.contains("zip")
|| mime.contains("7z")
|| mime.contains("xz")
{ {
"package-x-generic".to_owned() "package-x-generic".to_string()
} else { } else {
return "text-html".to_owned(); "text-html".to_string()
} };
} else {
log::debug!("unsupported mime type {result}");
return "application-x-generic".to_owned();
}
} else {
"image-not-found".to_string()
} }
log::debug!("unsupported mime type {mime}");
"application-x-generic".to_string()
} }
} }
@ -585,45 +584,28 @@ impl AutoItemProvider {
impl ItemProvider<AutoRunType> for AutoItemProvider { impl ItemProvider<AutoRunType> for AutoItemProvider {
fn get_elements(&mut self, search_opt: Option<&str>) -> (bool, Vec<MenuItem<AutoRunType>>) { fn get_elements(&mut self, search_opt: Option<&str>) -> (bool, Vec<MenuItem<AutoRunType>>) {
if let Some(search) = search_opt { let search = match search_opt {
let trimmed_search = search.trim(); Some(s) if !s.trim().is_empty() => s.trim(),
if trimmed_search.is_empty() { _ => return self.default_auto_elements(search_opt),
let (_changed, items) = self.default_auto_elements(search_opt); };
(true, items)
} else if MathProvider::<AutoRunType>::contains_math_functions_or_starts_with_number( let (mode, (changed, items)) =
trimmed_search, if MathProvider::<AutoRunType>::contains_math_functions_or_starts_with_number(search) {
) { (AutoRunType::Math, self.math.get_elements(search_opt))
// math mode handling } else if search.starts_with('$') || search.starts_with('/') || search.starts_with('~')
let (changed, items) = self.math.get_elements(search_opt);
if self.last_mode == Some(AutoRunType::Math) {
return (changed, items);
}
self.last_mode = Some(AutoRunType::Math);
return (true, items);
} else if trimmed_search.starts_with('$')
|| trimmed_search.starts_with('/')
|| trimmed_search.starts_with('~')
{ {
// file mode handling (AutoRunType::File, self.file.get_elements(search_opt))
let (changed, items) = self.file.get_elements(search_opt); } else if search.starts_with("ssh") {
if self.last_mode == Some(AutoRunType::File) { (AutoRunType::Ssh, self.ssh.get_elements(search_opt))
return (changed, items);
}
self.last_mode = Some(AutoRunType::File);
return (true, items);
} else if trimmed_search.starts_with("ssh") {
// file mode handling
let (changed, items) = self.ssh.get_elements(search_opt);
if self.last_mode == Some(AutoRunType::Ssh) {
return (changed, items);
}
self.last_mode = Some(AutoRunType::Ssh);
return (true, items);
} else { } else {
self.default_auto_elements(search_opt) return self.default_auto_elements(search_opt);
} };
if self.last_mode.as_ref().is_some_and(|m| m == &mode) {
(changed, items)
} else { } else {
self.default_auto_elements(search_opt) self.last_mode = Some(mode);
(true, items)
} }
} }