support password
This commit is contained in:
parent
f55e04c219
commit
f625eaacfa
2 changed files with 35 additions and 13 deletions
|
|
@ -488,6 +488,11 @@ impl Config {
|
||||||
pub fn allow_markup(&self) -> bool {
|
pub fn allow_markup(&self) -> bool {
|
||||||
self.allow_markup.unwrap_or(false)
|
self.allow_markup.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn password(&self) -> Option<String> {
|
||||||
|
self.password.clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_false() -> bool {
|
fn default_false() -> bool {
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,7 @@ struct UiElements<T: Clone> {
|
||||||
search: SearchEntry,
|
search: SearchEntry,
|
||||||
main_box: FlowBox,
|
main_box: FlowBox,
|
||||||
menu_rows: ArcMenuMap<T>,
|
menu_rows: ArcMenuMap<T>,
|
||||||
|
search_text: Arc<Mutex<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shows the user interface and **blocks** until the user selected an entry
|
/// Shows the user interface and **blocks** until the user selected an entry
|
||||||
|
|
@ -240,6 +241,7 @@ fn build_ui<T, P>(
|
||||||
search: SearchEntry::new(),
|
search: SearchEntry::new(),
|
||||||
main_box: FlowBox::new(),
|
main_box: FlowBox::new(),
|
||||||
menu_rows: Arc::new(Mutex::new(HashMap::new())),
|
menu_rows: Arc::new(Mutex::new(HashMap::new())),
|
||||||
|
search_text: Arc::new(Mutex::new(String::new())),
|
||||||
});
|
});
|
||||||
|
|
||||||
// handle keys as soon as possible
|
// handle keys as soon as possible
|
||||||
|
|
@ -283,7 +285,7 @@ fn build_ui<T, P>(
|
||||||
outer_box.append(&scroll);
|
outer_box.append(&scroll);
|
||||||
|
|
||||||
build_main_box(config, &ui_elements);
|
build_main_box(config, &ui_elements);
|
||||||
build_search_entry(config, &ui_elements);
|
build_search_entry(config, &ui_elements, &meta);
|
||||||
|
|
||||||
let wrapper_box = gtk4::Box::new(Orientation::Vertical, 0);
|
let wrapper_box = gtk4::Box::new(Orientation::Vertical, 0);
|
||||||
wrapper_box.append(&ui_elements.main_box);
|
wrapper_box.append(&ui_elements.main_box);
|
||||||
|
|
@ -334,7 +336,7 @@ fn build_main_box<T: Clone + 'static>(config: &Config, ui_elements: &Rc<UiElemen
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_search_entry<T: Clone>(config: &Config, ui_elements: &UiElements<T>) {
|
fn build_search_entry<T: Clone>(config: &Config, ui_elements: &UiElements<T>, meta: &MetaData<T>) {
|
||||||
ui_elements.search.set_widget_name("input");
|
ui_elements.search.set_widget_name("input");
|
||||||
ui_elements.search.set_css_classes(&["input"]);
|
ui_elements.search.set_css_classes(&["input"]);
|
||||||
ui_elements
|
ui_elements
|
||||||
|
|
@ -345,7 +347,21 @@ fn build_search_entry<T: Clone>(config: &Config, ui_elements: &UiElements<T>) {
|
||||||
ui_elements.search.set_visible(false);
|
ui_elements.search.set_visible(false);
|
||||||
}
|
}
|
||||||
if let Some(search) = config.search() {
|
if let Some(search) = config.search() {
|
||||||
ui_elements.search.set_text(&search);
|
set_search_text(&search, ui_elements, meta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_search_text<T: Clone>(text: &str, ui: &UiElements<T>, meta: &MetaData<T>) {
|
||||||
|
let mut lock = ui.search_text.lock().unwrap();
|
||||||
|
text.clone_into(&mut lock);
|
||||||
|
if let Some(pw) = meta.config.password() {
|
||||||
|
let mut ui_text = String::new();
|
||||||
|
for _ in 0..text.len() {
|
||||||
|
ui_text += &pw;
|
||||||
|
}
|
||||||
|
ui.search.set_text(&ui_text);
|
||||||
|
} else {
|
||||||
|
ui.search.set_text(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -379,10 +395,10 @@ fn build_ui_from_menu_items<T: Clone + 'static>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let query = ui_clone.search.text();
|
let search_lock = ui_clone.search_text.lock().unwrap();
|
||||||
let menus = &mut *lock;
|
let menus = &mut *lock;
|
||||||
set_menu_visibility_for_search(
|
set_menu_visibility_for_search(
|
||||||
&query,
|
&search_lock,
|
||||||
menus,
|
menus,
|
||||||
&meta_clone.config,
|
&meta_clone.config,
|
||||||
meta_clone.search_ignored_words.as_ref(),
|
meta_clone.search_ignored_words.as_ref(),
|
||||||
|
|
@ -460,17 +476,19 @@ fn handle_key_press<T: Clone + 'static>(
|
||||||
close_gui(ui.app.clone(), ui.window.clone(), &meta.config);
|
close_gui(ui.app.clone(), ui.window.clone(), &meta.config);
|
||||||
}
|
}
|
||||||
Key::Return => {
|
Key::Return => {
|
||||||
let query = ui.search.text().to_string();
|
let search_lock = ui.search_text.lock().unwrap();
|
||||||
if let Err(e) = handle_selected_item(ui, meta, Some(&query), None, meta.new_on_empty) {
|
if let Err(e) =
|
||||||
|
handle_selected_item(ui, meta, Some(&search_lock), None, meta.new_on_empty)
|
||||||
|
{
|
||||||
log::error!("{e}");
|
log::error!("{e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Key::BackSpace => {
|
Key::BackSpace => {
|
||||||
let mut query = ui.search.text().to_string();
|
let mut query = ui.search_text.lock().unwrap().to_string();
|
||||||
if !query.is_empty() {
|
if !query.is_empty() {
|
||||||
query.pop();
|
query.pop();
|
||||||
|
|
||||||
ui.search.set_text(&query);
|
set_search_text(&query, ui, meta);
|
||||||
update_view_from_provider(&query);
|
update_view_from_provider(&query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -502,7 +520,7 @@ fn handle_key_press<T: Clone + 'static>(
|
||||||
}
|
}
|
||||||
|
|
||||||
let query = changed.1;
|
let query = changed.1;
|
||||||
ui.search.set_text(&query);
|
set_search_text(&query, ui, meta);
|
||||||
update_view(&query);
|
update_view(&query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -512,9 +530,8 @@ fn handle_key_press<T: Clone + 'static>(
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if let Some(c) = keyboard_key.to_unicode() {
|
if let Some(c) = keyboard_key.to_unicode() {
|
||||||
let current = ui.search.text().to_string();
|
let query = format!("{}{c}", ui.search_text.lock().unwrap());
|
||||||
let query = format!("{current}{c}");
|
set_search_text(&query, ui, meta);
|
||||||
ui.search.set_text(&query);
|
|
||||||
update_view_from_provider(&query);
|
update_view_from_provider(&query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue