From 785f820c50f9fa26732cd94a4ada7034827aa570 Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Wed, 21 Aug 2024 02:27:52 +0300 Subject: [PATCH] sort keymap and lang --- src/keyboard_page/mod.rs | 18 ++++++++++++++++-- src/language_page/mod.rs | 24 +++++++++++++++++++----- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/keyboard_page/mod.rs b/src/keyboard_page/mod.rs index 9720b07..80eb09c 100644 --- a/src/keyboard_page/mod.rs +++ b/src/keyboard_page/mod.rs @@ -5,6 +5,11 @@ use gnome_desktop::XkbInfoExt; use gtk::{gio, glib, prelude::*}; use std::{cell::RefCell, fs, path::Path, process::Command, rc::Rc}; +struct PikaKeymap { + name: String, + pretty_name: String +} + pub fn keyboard_page( main_carousel: &adw::Carousel, keymap_base_data_refcell: &Rc>, @@ -69,9 +74,18 @@ pub fn keyboard_page( let keymap_list = gnome_desktop::XkbInfo::all_layouts(&xkbinfo); + let mut sorted_keymap_vec = Vec::new(); for keymap in keymap_list.iter() { - let keymap = keymap.to_string(); - let keymap_name = xkbinfo.layout_info(&keymap).unwrap().0.unwrap().to_string(); + sorted_keymap_vec.push(PikaKeymap{ + 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 = keymap.split("+").map(|s| s.into()).collect(); let keymap_base = keymap_split.get(0).unwrap().clone(); let mut keymap_variant = String::new(); diff --git a/src/language_page/mod.rs b/src/language_page/mod.rs index d992bf0..86f3580 100644 --- a/src/language_page/mod.rs +++ b/src/language_page/mod.rs @@ -4,6 +4,11 @@ use glib::{clone, closure_local}; use gtk::{gio, glib, prelude::*}; use std::{cell::RefCell, env, fs, path::Path, process::Command, rc::Rc}; +struct PikaLocale { + name: String, + pretty_name: String +} + pub fn language_page( main_carousel: &adw::Carousel, lang_data_refcell: &Rc>, @@ -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", ]; + let mut sorted_locale_vec = Vec::new(); for locale in locale_list.iter() { - let locale = locale.to_string(); - let locale_name = gnome_desktop::language_from_locale(&locale, None) + sorted_locale_vec.push(PikaLocale{ + name: locale.to_string(), + pretty_name: gnome_desktop::language_from_locale(&locale, None) .unwrap_or(locale.clone().into()) - .to_string(); - let locale_clone = locale.clone(); + .to_string() + }) + } + 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() .valign(gtk::Align::Center) .can_focus(false) @@ -114,7 +128,7 @@ pub fn language_page( } } )); - if ¤t_locale == &locale_clone + if ¤t_locale == &locale_clone0 && current_locale != "C.UTF-8" && current_locale != "C" && current_locale != "C.utf8"