diff --git a/src/lib/config.rs b/src/lib/config.rs index 19ad77c..08762a5 100644 --- a/src/lib/config.rs +++ b/src/lib/config.rs @@ -201,7 +201,7 @@ pub struct Config { term: Option, #[clap(short = 'P', long = "password")] - password: Option, // todo support this + password: Option, #[clap(short = 'e', long = "exec-search")] exec_search: Option, // todo support this @@ -230,7 +230,7 @@ pub struct Config { location: Option>, #[clap(short = 'a', long = "no-actions")] - no_actions: Option, // todo support this + no_actions: Option, #[clap(short = 'L', long = "lines")] lines: Option, // todo support this @@ -493,6 +493,11 @@ impl Config { pub fn password(&self) -> Option { self.password.clone() } + + #[must_use] + pub fn no_actions(&self) -> bool { + self.no_actions.unwrap_or(false) + } } fn default_false() -> bool { diff --git a/src/lib/mode.rs b/src/lib/mode.rs index 41ce0f3..e3205aa 100644 --- a/src/lib/mode.rs +++ b/src/lib/mode.rs @@ -29,16 +29,18 @@ struct DRunProvider { cache_path: Option, cache: HashMap, data: T, + no_actions: bool, } impl DRunProvider { - 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(); DRunProvider { items: None, cache_path, cache: d_run_cache, data: menu_item_data, + no_actions, } } @@ -100,33 +102,33 @@ impl DRunProvider { sort_score, Some(self.data.clone()), ); - - for action in file.actions.values() { - if let Some(action_name) = lookup_name_with_locale( - &locale_variants, - &action.name.variants, - &action.name.default, - ) { - let action_icon = action - .icon - .as_ref() - .map(|s| s.content.clone()) - .or(icon.clone()) - .unwrap_or("application-x-executable".to_string()); + if !self.no_actions { + for action in file.actions.values() { + if let Some(action_name) = lookup_name_with_locale( + &locale_variants, + &action.name.variants, + &action.name.default, + ) { + let action_icon = action + .icon + .as_ref() + .map(|s| s.content.clone()) + .or(icon.clone()) + .unwrap_or("application-x-executable".to_string()); - entry.sub_elements.push(MenuItem::new( - action_name, - Some(action_icon), - action.exec.clone(), - Vec::new(), - working_dir.clone(), - 0.0, - Some(self.data.clone()), - )); + entry.sub_elements.push(MenuItem::new( + action_name, + Some(action_icon), + action.exec.clone(), + Vec::new(), + working_dir.clone(), + 0.0, + Some(self.data.clone()), + )); + } } } - Some(entry) }) .collect(); @@ -626,9 +628,9 @@ struct AutoItemProvider { } impl AutoItemProvider { - fn new() -> Self { + fn new(config: &Config) -> Self { AutoItemProvider { - drun: DRunProvider::new(AutoRunType::DRun), + drun: DRunProvider::new(AutoRunType::DRun, config.no_actions()), file: FileItemProvider::new(AutoRunType::File), math: MathProvider::new(AutoRunType::Math), ssh: SshProvider::new(AutoRunType::Ssh), @@ -696,7 +698,7 @@ impl ItemProvider for AutoItemProvider { /// /// Will return `Err` if it was not able to spawn the process 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 mut cache = provider.cache.clone(); @@ -741,7 +743,7 @@ pub fn run(config: &Config) -> Result<(), Error> { /// # Panics /// Panics if an internal static regex cannot be passed anymore, should never happen 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 mut cache = provider.drun.cache.clone();