Skip to content

Commit

Permalink
fix(region): alphabetically sort languages and regions
Browse files Browse the repository at this point in the history
  • Loading branch information
mmstick committed Nov 7, 2024
1 parent 26a3c7e commit f6c6314
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions cosmic-settings/src/pages/time/region.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: GPL-3.0-only

use std::collections::BTreeMap;
use std::collections::{BTreeMap, BTreeSet};
use std::rc::Rc;
use std::str::FromStr;
use std::sync::Arc;
Expand Down Expand Up @@ -64,12 +64,32 @@ pub enum SourceContext {
}

#[derive(Clone, Debug)]
struct SystemLocale {
pub struct SystemLocale {
lang_code: String,
display_name: String,
region_name: String,
}

impl Eq for SystemLocale {}

impl Ord for SystemLocale {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.display_name.cmp(&other.display_name)
}
}

impl PartialOrd for SystemLocale {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.display_name.partial_cmp(&other.display_name)
}
}

impl PartialEq for SystemLocale {
fn eq(&self, other: &Self) -> bool {
self.display_name == other.display_name
}
}

#[derive(Debug)]
pub struct PageRefresh {
config: Option<(cosmic_config::Config, Vec<String>)>,
Expand Down Expand Up @@ -762,7 +782,7 @@ pub async fn page_reload() -> eyre::Result<PageRefresh> {
.or_else(|| system_locales.get("LANG"))
.cloned();

let mut available_languages = SlotMap::new();
let mut available_languages_set = BTreeSet::new();

let output = tokio::process::Command::new("localectl")
.arg("list-locales")
Expand All @@ -777,7 +797,7 @@ pub async fn page_reload() -> eyre::Result<PageRefresh> {
}

if let Some(locale) = registry.locale(line) {
available_languages.insert(SystemLocale {
available_languages_set.insert(SystemLocale {
lang_code: line.to_owned(),
display_name: locale.display_name.clone(),
region_name: format!(
Expand All @@ -788,6 +808,11 @@ pub async fn page_reload() -> eyre::Result<PageRefresh> {
}
}

let mut available_languages = SlotMap::new();
for language in available_languages_set {
available_languages.insert(language);
}

Ok(PageRefresh {
config,
registry: Registry(registry),
Expand Down

0 comments on commit f6c6314

Please sign in to comment.