support no_actions

This commit is contained in:
Alexander Mohr 2025-05-04 12:35:47 +02:00
parent b2cddb02be
commit 99b893c468
2 changed files with 37 additions and 30 deletions

View file

@ -201,7 +201,7 @@ pub struct Config {
term: Option<String>, term: Option<String>,
#[clap(short = 'P', long = "password")] #[clap(short = 'P', long = "password")]
password: Option<String>, // todo support this password: Option<String>,
#[clap(short = 'e', long = "exec-search")] #[clap(short = 'e', long = "exec-search")]
exec_search: Option<bool>, // todo support this exec_search: Option<bool>, // todo support this
@ -230,7 +230,7 @@ pub struct Config {
location: Option<Vec<Anchor>>, location: Option<Vec<Anchor>>,
#[clap(short = 'a', long = "no-actions")] #[clap(short = 'a', long = "no-actions")]
no_actions: Option<bool>, // todo support this no_actions: Option<bool>,
#[clap(short = 'L', long = "lines")] #[clap(short = 'L', long = "lines")]
lines: Option<u32>, // todo support this lines: Option<u32>, // todo support this
@ -493,6 +493,11 @@ impl Config {
pub fn password(&self) -> Option<String> { pub fn password(&self) -> Option<String> {
self.password.clone() self.password.clone()
} }
#[must_use]
pub fn no_actions(&self) -> bool {
self.no_actions.unwrap_or(false)
}
} }
fn default_false() -> bool { fn default_false() -> bool {

View file

@ -29,16 +29,18 @@ struct DRunProvider<T: Clone> {
cache_path: Option<PathBuf>, cache_path: Option<PathBuf>,
cache: HashMap<String, i64>, cache: HashMap<String, i64>,
data: T, data: T,
no_actions: bool,
} }
impl<T: Clone + Send + Sync> DRunProvider<T> { impl<T: Clone + Send + Sync> DRunProvider<T> {
fn new(menu_item_data: T) -> Self { fn new(menu_item_data: T, no_actions: bool) -> Self {
let (cache_path, d_run_cache) = load_d_run_cache(); let (cache_path, d_run_cache) = load_d_run_cache();
DRunProvider { DRunProvider {
items: None, items: None,
cache_path, cache_path,
cache: d_run_cache, cache: d_run_cache,
data: menu_item_data, data: menu_item_data,
no_actions,
} }
} }
@ -100,33 +102,33 @@ impl<T: Clone + Send + Sync> DRunProvider<T> {
sort_score, sort_score,
Some(self.data.clone()), Some(self.data.clone()),
); );
if !self.no_actions {
for action in file.actions.values() { for action in file.actions.values() {
if let Some(action_name) = lookup_name_with_locale( if let Some(action_name) = lookup_name_with_locale(
&locale_variants, &locale_variants,
&action.name.variants, &action.name.variants,
&action.name.default, &action.name.default,
) { ) {
let action_icon = action let action_icon = action
.icon .icon
.as_ref() .as_ref()
.map(|s| s.content.clone()) .map(|s| s.content.clone())
.or(icon.clone()) .or(icon.clone())
.unwrap_or("application-x-executable".to_string()); .unwrap_or("application-x-executable".to_string());
entry.sub_elements.push(MenuItem::new( entry.sub_elements.push(MenuItem::new(
action_name, action_name,
Some(action_icon), Some(action_icon),
action.exec.clone(), action.exec.clone(),
Vec::new(), Vec::new(),
working_dir.clone(), working_dir.clone(),
0.0, 0.0,
Some(self.data.clone()), Some(self.data.clone()),
)); ));
}
} }
} }
Some(entry) Some(entry)
}) })
.collect(); .collect();
@ -626,9 +628,9 @@ struct AutoItemProvider {
} }
impl AutoItemProvider { impl AutoItemProvider {
fn new() -> Self { fn new(config: &Config) -> Self {
AutoItemProvider { AutoItemProvider {
drun: DRunProvider::new(AutoRunType::DRun), drun: DRunProvider::new(AutoRunType::DRun, config.no_actions()),
file: FileItemProvider::new(AutoRunType::File), file: FileItemProvider::new(AutoRunType::File),
math: MathProvider::new(AutoRunType::Math), math: MathProvider::new(AutoRunType::Math),
ssh: SshProvider::new(AutoRunType::Ssh), ssh: SshProvider::new(AutoRunType::Ssh),
@ -696,7 +698,7 @@ impl ItemProvider<AutoRunType> for AutoItemProvider {
/// ///
/// Will return `Err` if it was not able to spawn the process /// Will return `Err` if it was not able to spawn the process
pub fn d_run(config: &Config) -> Result<(), Error> { pub fn d_run(config: &Config) -> Result<(), Error> {
let provider = DRunProvider::new(0); let provider = DRunProvider::new(0, config.no_actions());
let cache_path = provider.cache_path.clone(); let cache_path = provider.cache_path.clone();
let mut cache = provider.cache.clone(); let mut cache = provider.cache.clone();
@ -741,7 +743,7 @@ pub fn run(config: &Config) -> Result<(), Error> {
/// # Panics /// # Panics
/// Panics if an internal static regex cannot be passed anymore, should never happen /// Panics if an internal static regex cannot be passed anymore, should never happen
pub fn auto(config: &Config) -> Result<(), Error> { pub fn auto(config: &Config) -> Result<(), Error> {
let mut provider = AutoItemProvider::new(); let mut provider = AutoItemProvider::new(config);
let cache_path = provider.drun.cache_path.clone(); let cache_path = provider.drun.cache_path.clone();
let mut cache = provider.drun.cache.clone(); let mut cache = provider.drun.cache.clone();