From 753f146d930f42b16637dda0ef9fbc1f3ba89a42 Mon Sep 17 00:00:00 2001 From: Madis Liias Date: Thu, 5 Jan 2023 20:47:02 +0200 Subject: [PATCH] force non-browser apps as first --- src/ui.rs | 64 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index b72a5c8..1f5e66c 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -335,6 +335,10 @@ pub struct UIBrowser { } impl UIBrowser { + pub fn has_priority_ordering(&self) -> bool { + return !self.restricted_domains.is_empty(); + } + /// Returns app name + optionally profile name if app supports multiple profiles pub fn get_full_name(&self) -> String { let mut full_name = self.browser_name.to_string(); @@ -873,7 +877,7 @@ impl FilteredBrowsersLens { .map(|url| url.domain().map(|d| d.to_string())) .flatten(); - let filtered: Vec = data + let mut filtered: Vec = data .1 .iter() .cloned() @@ -891,6 +895,9 @@ impl FilteredBrowsersLens { }) .collect(); + // always show special apps first + filtered.sort_by_key(|b| !b.has_priority_ordering()); + return filtered; } } @@ -1230,38 +1237,39 @@ fn make_context_menu(browser: &UIBrowser) -> Menu { let id = browser.unique_id.clone(); let app_name = browser.browser_name.to_string(); - let is_visible = browser.browser_profile_index > 0; + if !browser.has_priority_ordering() { + let is_visible = browser.browser_profile_index > 0; - let item_name = browser.get_full_name(); - - let move_profile_higher_label = LocalizedString::new("move-profile-higher") - .with_arg("item-name", move |_, _| item_name.clone().into()); + let item_name = browser.get_full_name(); - let this_id = id.clone(); - menu = menu.entry( - MenuItem::new(move_profile_higher_label) - .on_activate(move |ctx, _data: &mut UIState, _env| { - let command = MOVE_PROFILE.with((this_id.clone(), true)); - ctx.submit_command(command); - }) - .enabled_if(move |_, _| is_visible), - ); + let move_profile_higher_label = LocalizedString::new("move-profile-higher") + .with_arg("item-name", move |_, _| item_name.clone().into()); - let is_visible = !browser.is_last; - let item_name = browser.get_full_name(); + let this_id = id.clone(); + menu = menu.entry( + MenuItem::new(move_profile_higher_label) + .on_activate(move |ctx, _data: &mut UIState, _env| { + let command = MOVE_PROFILE.with((this_id.clone(), true)); + ctx.submit_command(command); + }) + .enabled_if(move |_, _| is_visible), + ); - let move_profile_lower_label = LocalizedString::new("move-profile-lower") - .with_arg("item-name", move |_, _| item_name.to_string().into()); + let is_visible = !browser.is_last; + let item_name = browser.get_full_name(); + let move_profile_lower_label = LocalizedString::new("move-profile-lower") + .with_arg("item-name", move |_, _| item_name.to_string().into()); - let this_id = id.clone(); - menu = menu.entry( - MenuItem::new(move_profile_lower_label) - .on_activate(move |ctx, _data: &mut UIState, _env| { - let command = MOVE_PROFILE.with((this_id.clone(), false)); - ctx.submit_command(command); - }) - .enabled_if(move |_, _| is_visible), - ); + let this_id = id.clone(); + menu = menu.entry( + MenuItem::new(move_profile_lower_label) + .on_activate(move |ctx, _data: &mut UIState, _env| { + let command = MOVE_PROFILE.with((this_id.clone(), false)); + ctx.submit_command(command); + }) + .enabled_if(move |_, _| is_visible), + ); + } let item_name = browser.get_full_name();