sort keymap and lang

This commit is contained in:
Ward from fusion-voyager-3 2024-08-21 02:27:52 +03:00
parent 7beeb231ad
commit 785f820c50
2 changed files with 35 additions and 7 deletions

View File

@ -5,6 +5,11 @@ use gnome_desktop::XkbInfoExt;
use gtk::{gio, glib, prelude::*}; use gtk::{gio, glib, prelude::*};
use std::{cell::RefCell, fs, path::Path, process::Command, rc::Rc}; use std::{cell::RefCell, fs, path::Path, process::Command, rc::Rc};
struct PikaKeymap {
name: String,
pretty_name: String
}
pub fn keyboard_page( pub fn keyboard_page(
main_carousel: &adw::Carousel, main_carousel: &adw::Carousel,
keymap_base_data_refcell: &Rc<RefCell<String>>, keymap_base_data_refcell: &Rc<RefCell<String>>,
@ -69,9 +74,18 @@ pub fn keyboard_page(
let keymap_list = gnome_desktop::XkbInfo::all_layouts(&xkbinfo); let keymap_list = gnome_desktop::XkbInfo::all_layouts(&xkbinfo);
let mut sorted_keymap_vec = Vec::new();
for keymap in keymap_list.iter() { for keymap in keymap_list.iter() {
let keymap = keymap.to_string(); sorted_keymap_vec.push(PikaKeymap{
let keymap_name = xkbinfo.layout_info(&keymap).unwrap().0.unwrap().to_string(); name: keymap.to_string(),
pretty_name: xkbinfo.layout_info(&keymap).unwrap().0.unwrap().to_string()
})
}
sorted_keymap_vec.sort_by_key(|k| k.pretty_name.clone());
for pika_keymap in sorted_keymap_vec {
let keymap = pika_keymap.name;
let keymap_name = pika_keymap.pretty_name;
let keymap_split: Vec<String> = keymap.split("+").map(|s| s.into()).collect(); let keymap_split: Vec<String> = keymap.split("+").map(|s| s.into()).collect();
let keymap_base = keymap_split.get(0).unwrap().clone(); let keymap_base = keymap_split.get(0).unwrap().clone();
let mut keymap_variant = String::new(); let mut keymap_variant = String::new();

View File

@ -4,6 +4,11 @@ use glib::{clone, closure_local};
use gtk::{gio, glib, prelude::*}; use gtk::{gio, glib, prelude::*};
use std::{cell::RefCell, env, fs, path::Path, process::Command, rc::Rc}; use std::{cell::RefCell, env, fs, path::Path, process::Command, rc::Rc};
struct PikaLocale {
name: String,
pretty_name: String
}
pub fn language_page( pub fn language_page(
main_carousel: &adw::Carousel, main_carousel: &adw::Carousel,
lang_data_refcell: &Rc<RefCell<String>>, lang_data_refcell: &Rc<RefCell<String>>,
@ -82,12 +87,21 @@ pub fn language_page(
"cy_GB", "wo_SN", "fy_NL", "xh_ZA", "yi_US", "yo_NG", "zu_ZA", "zu_ZA", "pt_BR", "pt_PT", "cy_GB", "wo_SN", "fy_NL", "xh_ZA", "yi_US", "yo_NG", "zu_ZA", "zu_ZA", "pt_BR", "pt_PT",
]; ];
let mut sorted_locale_vec = Vec::new();
for locale in locale_list.iter() { for locale in locale_list.iter() {
let locale = locale.to_string(); sorted_locale_vec.push(PikaLocale{
let locale_name = gnome_desktop::language_from_locale(&locale, None) name: locale.to_string(),
pretty_name: gnome_desktop::language_from_locale(&locale, None)
.unwrap_or(locale.clone().into()) .unwrap_or(locale.clone().into())
.to_string(); .to_string()
let locale_clone = locale.clone(); })
}
sorted_locale_vec.sort_by_key(|k| k.pretty_name.clone());
for pika_locale in sorted_locale_vec {
let locale = pika_locale.name;
let locale_clone0 = locale.clone();
let locale_name = pika_locale.pretty_name;
let locale_checkbutton = gtk::CheckButton::builder() let locale_checkbutton = gtk::CheckButton::builder()
.valign(gtk::Align::Center) .valign(gtk::Align::Center)
.can_focus(false) .can_focus(false)
@ -114,7 +128,7 @@ pub fn language_page(
} }
} }
)); ));
if &current_locale == &locale_clone if &current_locale == &locale_clone0
&& current_locale != "C.UTF-8" && current_locale != "C.UTF-8"
&& current_locale != "C" && current_locale != "C"
&& current_locale != "C.utf8" && current_locale != "C.utf8"