RR: Add search bars

This commit is contained in:
Ward from fusion-voyager-3 2024-02-20 11:14:18 +03:00
parent a722ef7c04
commit 37c0b5a901
4 changed files with 129 additions and 25 deletions

View File

@ -127,7 +127,7 @@ pub fn keyboard_page(content_stack: &gtk::Stack) {
.build(); .build();
let keyboard_selection_expander_row_viewport = let keyboard_selection_expander_row_viewport =
gtk::ScrolledWindow::builder().height_request(450).build(); gtk::ScrolledWindow::builder().height_request(355).build();
let keyboard_selection_expander_row_viewport_box = gtk::ListBox::builder() let keyboard_selection_expander_row_viewport_box = gtk::ListBox::builder()
.build(); .build();
@ -148,6 +148,16 @@ pub fn keyboard_page(content_stack: &gtk::Stack) {
keyboard_selection_expander_row.add_row(&keyboard_selection_expander_row_viewport); keyboard_selection_expander_row.add_row(&keyboard_selection_expander_row_viewport);
let keyboard_search_bar = gtk::SearchEntry::builder()
.halign(gtk::Align::Center)
.hexpand(true)
.margin_top(15)
.margin_bottom(15)
.margin_start(15)
.margin_end(15)
.search_delay(500)
.build();
let current_keyboard_cli = Command::new("localectl") let current_keyboard_cli = Command::new("localectl")
.arg("status") .arg("status")
.stdin(Stdio::piped()) .stdin(Stdio::piped())
@ -220,6 +230,7 @@ pub fn keyboard_page(content_stack: &gtk::Stack) {
// / keyboard_selection_box appends // / keyboard_selection_box appends
//// add text and and entry to keyboard page selections //// add text and and entry to keyboard page selections
keyboard_selection_box.append(&keyboard_selection_text); keyboard_selection_box.append(&keyboard_selection_text);
keyboard_selection_box.append(&keyboard_search_bar);
keyboard_selection_box.append(&keyboard_selection_expander_row_viewport_listbox); keyboard_selection_box.append(&keyboard_selection_expander_row_viewport_listbox);
// / keyboard_header_box appends // / keyboard_header_box appends
@ -259,6 +270,28 @@ pub fn keyboard_page(content_stack: &gtk::Stack) {
let keyboard_data_buffer_clone = keyboard_data_buffer.clone(); let keyboard_data_buffer_clone = keyboard_data_buffer.clone();
keyboard_search_bar.connect_search_changed(clone!(@weak keyboard_search_bar, @weak keyboard_selection_expander_row_viewport_box => move |_| {
let mut counter = keyboard_selection_expander_row_viewport_box.first_child();
while let Some(row) = counter {
if row.widget_name() == "AdwActionRow" {
if !keyboard_search_bar.text().is_empty() {
if row.property::<String>("subtitle").to_lowercase().contains(&keyboard_search_bar.text().to_string().to_lowercase()) || row.property::<String>("title").to_lowercase().contains(&keyboard_search_bar.text().to_string().to_lowercase()) {
keyboard_selection_expander_row.set_expanded(true);
//row.grab_focus();
//row.add_css_class("highlight-widget");
row.set_property("visible", true);
keyboard_search_bar.grab_focus();
} else {
row.set_property("visible", false);
}
} else {
row.set_property("visible", true);
}
}
counter = row.next_sibling();
}
}));
bottom_next_button.connect_clicked(clone!(@weak content_stack => move |_| { bottom_next_button.connect_clicked(clone!(@weak content_stack => move |_| {
if Path::new("/tmp/pika-installer-gtk4-keyboard.txt").exists() { if Path::new("/tmp/pika-installer-gtk4-keyboard.txt").exists() {
fs::remove_file("/tmp/pika-installer-gtk4-keyboard.txt").expect("Bad permissions on /tmp/pika-installer-gtk4-keyboard.txt"); fs::remove_file("/tmp/pika-installer-gtk4-keyboard.txt").expect("Bad permissions on /tmp/pika-installer-gtk4-keyboard.txt");

View File

@ -125,11 +125,11 @@ pub fn language_page(content_stack: &gtk::Stack) {
.build(); .build();
let language_selection_expander_row_viewport = let language_selection_expander_row_viewport =
gtk::ScrolledWindow::builder().height_request(200).build(); gtk::ScrolledWindow::builder().height_request(420).build();
let language_selection_expander_row_viewport_box = gtk::Box::builder() let language_selection_expander_row_viewport_box = gtk::ListBox::builder()
.orientation(Orientation::Vertical)
.build(); .build();
language_selection_expander_row_viewport_box.add_css_class("boxed-list");
language_selection_expander_row_viewport language_selection_expander_row_viewport
.set_child(Some(&language_selection_expander_row_viewport_box)); .set_child(Some(&language_selection_expander_row_viewport_box));
@ -146,6 +146,16 @@ pub fn language_page(content_stack: &gtk::Stack) {
language_selection_expander_row.add_row(&language_selection_expander_row_viewport); language_selection_expander_row.add_row(&language_selection_expander_row_viewport);
let language_search_bar = gtk::SearchEntry::builder()
.halign(gtk::Align::Center)
.hexpand(true)
.margin_top(15)
.margin_bottom(15)
.margin_start(15)
.margin_end(15)
.search_delay(500)
.build();
let current_locale = match env::var_os("LANG") { let current_locale = match env::var_os("LANG") {
Some(v) => v.into_string().unwrap(), Some(v) => v.into_string().unwrap(),
None => panic!("$LANG is not set"), None => panic!("$LANG is not set"),
@ -202,7 +212,7 @@ pub fn language_page(content_stack: &gtk::Stack) {
lang_data_buffer.set_text(&locale); lang_data_buffer.set_text(&locale);
} }
})); }));
if current_locale.contains(&(locale_clone)) { if current_locale.contains(&(locale_clone)) && current_locale != "C.UTF-8" && current_locale != "C" && current_locale != "C.utf8" && current_locale != "POSIX" {
locale_checkbutton.set_active(true); locale_checkbutton.set_active(true);
} }
} }
@ -210,6 +220,7 @@ pub fn language_page(content_stack: &gtk::Stack) {
// / language_selection_box appends // / language_selection_box appends
//// add text and and entry to language page selections //// add text and and entry to language page selections
language_selection_box.append(&language_selection_text); language_selection_box.append(&language_selection_text);
language_selection_box.append(&language_search_bar);
language_selection_box.append(&language_selection_expander_row_viewport_listbox); language_selection_box.append(&language_selection_expander_row_viewport_listbox);
// / language_header_box appends // / language_header_box appends
@ -235,6 +246,28 @@ pub fn language_page(content_stack: &gtk::Stack) {
let lang_data_buffer_clone = lang_data_buffer.clone(); let lang_data_buffer_clone = lang_data_buffer.clone();
language_search_bar.connect_search_changed(clone!(@weak language_search_bar, @weak language_selection_expander_row_viewport_box => move |_| {
let mut counter = language_selection_expander_row_viewport_box.first_child();
while let Some(row) = counter {
if row.widget_name() == "AdwActionRow" {
if !language_search_bar.text().is_empty() {
if row.property::<String>("subtitle").to_lowercase().contains(&language_search_bar.text().to_string().to_lowercase()) || row.property::<String>("title").to_lowercase().contains(&language_search_bar.text().to_string().to_lowercase()) {
language_selection_expander_row.set_expanded(true);
//row.grab_focus();
//row.add_css_class("highlight-widget");
row.set_property("visible", true);
language_search_bar.grab_focus();
} else {
row.set_property("visible", false);
}
} else {
row.set_property("visible", true);
}
}
counter = row.next_sibling();
}
}));
bottom_next_button.connect_clicked(clone!(@weak content_stack => move |_| { bottom_next_button.connect_clicked(clone!(@weak content_stack => move |_| {
if Path::new("/tmp/pika-installer-gtk4-lang.txt").exists() { if Path::new("/tmp/pika-installer-gtk4-lang.txt").exists() {
fs::remove_file("/tmp/pika-installer-gtk4-lang.txt").expect("Bad permissions on /tmp/pika-installer-gtk4-lang.txt"); fs::remove_file("/tmp/pika-installer-gtk4-lang.txt").expect("Bad permissions on /tmp/pika-installer-gtk4-lang.txt");

View File

@ -30,3 +30,8 @@
background-color:green; background-color:green;
color: white; color: white;
} }
.highlight-widget {
background-color: @success_bg_color;
color: @success_fg_color;
}

View File

@ -125,7 +125,7 @@ pub fn timezone_page(content_stack: &gtk::Stack) {
.build(); .build();
let timezone_selection_expander_row_viewport = let timezone_selection_expander_row_viewport =
gtk::ScrolledWindow::builder().height_request(200).build(); gtk::ScrolledWindow::builder().height_request(420).build();
let timezone_selection_expander_row_viewport_box = gtk::ListBox::builder() let timezone_selection_expander_row_viewport_box = gtk::ListBox::builder()
.build(); .build();
@ -146,6 +146,16 @@ pub fn timezone_page(content_stack: &gtk::Stack) {
timezone_selection_expander_row.add_row(&timezone_selection_expander_row_viewport); timezone_selection_expander_row.add_row(&timezone_selection_expander_row_viewport);
let timezone_search_bar = gtk::SearchEntry::builder()
.halign(gtk::Align::Center)
.hexpand(true)
.margin_top(15)
.margin_bottom(15)
.margin_start(15)
.margin_end(15)
.search_delay(500)
.build();
let current_timezone_cli = Command::new("timedatectl") let current_timezone_cli = Command::new("timedatectl")
.arg("show") .arg("show")
.arg("--va") .arg("--va")
@ -161,47 +171,48 @@ pub fn timezone_page(content_stack: &gtk::Stack) {
.unwrap() .unwrap()
.trim(); .trim();
let timezone_layout_cli = Command::new("timedatectl") let timezone_cli = Command::new("timedatectl")
.arg("list-timezones") .arg("list-timezones")
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.spawn() .spawn()
.unwrap_or_else(|e| panic!("failed {}", e)); .unwrap_or_else(|e| panic!("failed {}", e));
let timezone_layout_stdout = timezone_layout_cli.stdout.expect("could not get stdout"); let timezone_stdout = timezone_cli.stdout.expect("could not get stdout");
let timezone_layout_reader = BufReader::new(timezone_layout_stdout); let timezone_reader = BufReader::new(timezone_stdout);
let timezone_data_buffer = gtk::TextBuffer::builder().build(); let timezone_data_buffer = gtk::TextBuffer::builder().build();
for timezone_layout in timezone_layout_reader.lines() { for timezone in timezone_reader.lines() {
let timezone_layout = timezone_layout.unwrap(); let timezone = timezone.unwrap();
let timezone_layout_clone = timezone_layout.clone(); let timezone_clone = timezone.clone();
let timezone_layout_checkbutton = gtk::CheckButton::builder() let timezone_checkbutton = gtk::CheckButton::builder()
.valign(Align::Center) .valign(Align::Center)
.can_focus(false) .can_focus(false)
.build(); .build();
let timezone_layout_row = adw::ActionRow::builder() let timezone_row = adw::ActionRow::builder()
.activatable_widget(&timezone_layout_checkbutton) .activatable_widget(&timezone_checkbutton)
.title(timezone_layout.clone()) .title(timezone.clone())
.build(); .build();
timezone_layout_row.add_prefix(&timezone_layout_checkbutton); timezone_row.add_prefix(&timezone_checkbutton);
timezone_layout_checkbutton.set_group(Some(&null_checkbutton)); timezone_checkbutton.set_group(Some(&null_checkbutton));
timezone_selection_expander_row_viewport_box.append(&timezone_layout_row); timezone_selection_expander_row_viewport_box.append(&timezone_row);
timezone_layout_checkbutton.connect_toggled(clone!(@weak timezone_layout_checkbutton, @weak timezone_selection_expander_row, @weak bottom_next_button, @weak timezone_data_buffer => move |_| { timezone_checkbutton.connect_toggled(clone!(@weak timezone_checkbutton, @weak timezone_selection_expander_row, @weak bottom_next_button, @weak timezone_data_buffer => move |_| {
if timezone_layout_checkbutton.is_active() == true { if timezone_checkbutton.is_active() == true {
timezone_selection_expander_row.set_title(&timezone_layout); timezone_selection_expander_row.set_title(&timezone);
bottom_next_button.set_sensitive(true); bottom_next_button.set_sensitive(true);
timezone_data_buffer.set_text(&timezone_layout); timezone_data_buffer.set_text(&timezone);
} }
})); }));
if current_timezone.contains(&(timezone_layout_clone)) { if current_timezone.contains(&(timezone_clone)) {
timezone_layout_checkbutton.set_active(true); timezone_checkbutton.set_active(true);
} }
} }
// / timezone_selection_box appends // / timezone_selection_box appends
//// add text and and entry to timezone page selections //// add text and and entry to timezone page selections
timezone_selection_box.append(&timezone_selection_text); timezone_selection_box.append(&timezone_selection_text);
timezone_selection_box.append(&timezone_search_bar);
timezone_selection_box.append(&timezone_selection_expander_row_viewport_listbox); timezone_selection_box.append(&timezone_selection_expander_row_viewport_listbox);
// / timezone_header_box appends // / timezone_header_box appends
@ -227,6 +238,28 @@ pub fn timezone_page(content_stack: &gtk::Stack) {
let timezone_data_buffer_clone = timezone_data_buffer.clone(); let timezone_data_buffer_clone = timezone_data_buffer.clone();
timezone_search_bar.connect_search_changed(clone!(@weak timezone_search_bar, @weak timezone_selection_expander_row_viewport_box => move |_| {
let mut counter = timezone_selection_expander_row_viewport_box.first_child();
while let Some(row) = counter {
if row.widget_name() == "AdwActionRow" {
if !timezone_search_bar.text().is_empty() {
if row.property::<String>("subtitle").to_lowercase().contains(&timezone_search_bar.text().to_string().to_lowercase()) || row.property::<String>("title").to_lowercase().contains(&timezone_search_bar.text().to_string().to_lowercase()) {
timezone_selection_expander_row.set_expanded(true);
//row.grab_focus();
//row.add_css_class("highlight-widget");
row.set_property("visible", true);
timezone_search_bar.grab_focus();
} else {
row.set_property("visible", false);
}
} else {
row.set_property("visible", true);
}
}
counter = row.next_sibling();
}
}));
bottom_next_button.connect_clicked(clone!(@weak content_stack => move |_| { bottom_next_button.connect_clicked(clone!(@weak content_stack => move |_| {
if Path::new("/tmp/pika-installer-gtk4-timezone.txt").exists() { if Path::new("/tmp/pika-installer-gtk4-timezone.txt").exists() {
fs::remove_file("/tmp/pika-installer-gtk4-timezone.txt").expect("Bad permissions on /tmp/pika-installer-gtk4-timezone.txt"); fs::remove_file("/tmp/pika-installer-gtk4-timezone.txt").expect("Bad permissions on /tmp/pika-installer-gtk4-timezone.txt");