feat(keyboard): searchable input sources
This commit is contained in:
parent
42989b68a7
commit
4762bdaa59
2 changed files with 21 additions and 3 deletions
|
|
@ -38,6 +38,7 @@ static ALTERNATE_CHARACTER_OPTIONS: &[(&str, &str)] = &[
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
ExpandInputSourcePopover(Option<DefaultKey>),
|
ExpandInputSourcePopover(Option<DefaultKey>),
|
||||||
|
InputSourceSearch(String),
|
||||||
OpenSpecialCharacterContext(SpecialKey),
|
OpenSpecialCharacterContext(SpecialKey),
|
||||||
ShowInputSourcesContext,
|
ShowInputSourcesContext,
|
||||||
SourceAdd(DefaultKey),
|
SourceAdd(DefaultKey),
|
||||||
|
|
@ -61,10 +62,11 @@ pub type Description = String;
|
||||||
pub struct Page {
|
pub struct Page {
|
||||||
config: cosmic_config::Config,
|
config: cosmic_config::Config,
|
||||||
context: Option<Context>,
|
context: Option<Context>,
|
||||||
expanded_source_popover: Option<DefaultKey>,
|
input_source_search: String,
|
||||||
|
xkb: XkbConfig,
|
||||||
keyboard_layouts: SlotMap<DefaultKey, (Locale, Variant, Description)>,
|
keyboard_layouts: SlotMap<DefaultKey, (Locale, Variant, Description)>,
|
||||||
active_layouts: Vec<DefaultKey>,
|
active_layouts: Vec<DefaultKey>,
|
||||||
xkb: XkbConfig,
|
expanded_source_popover: Option<DefaultKey>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Page {
|
impl Default for Page {
|
||||||
|
|
@ -77,6 +79,7 @@ impl Default for Page {
|
||||||
keyboard_layouts: SlotMap::new(),
|
keyboard_layouts: SlotMap::new(),
|
||||||
active_layouts: Vec::new(),
|
active_layouts: Vec::new(),
|
||||||
xkb: XkbConfig::default(),
|
xkb: XkbConfig::default(),
|
||||||
|
input_source_search: String::new(),
|
||||||
config,
|
config,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -303,6 +306,10 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
impl Page {
|
impl Page {
|
||||||
pub fn update(&mut self, message: Message) -> Command<crate::app::Message> {
|
pub fn update(&mut self, message: Message) -> Command<crate::app::Message> {
|
||||||
match message {
|
match message {
|
||||||
|
Message::InputSourceSearch(search) => {
|
||||||
|
self.input_source_search = search;
|
||||||
|
}
|
||||||
|
|
||||||
Message::SourceAdd(id) => {
|
Message::SourceAdd(id) => {
|
||||||
self.context = None;
|
self.context = None;
|
||||||
|
|
||||||
|
|
@ -398,13 +405,23 @@ impl Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_input_source_view(&self) -> Element<'_, crate::pages::Message> {
|
pub fn add_input_source_view(&self) -> Element<'_, crate::pages::Message> {
|
||||||
|
let search = widget::search_input(fl!("type-to-search"), &self.input_source_search)
|
||||||
|
.on_input(Message::InputSourceSearch)
|
||||||
|
.on_clear(Message::InputSourceSearch(String::new()));
|
||||||
|
|
||||||
let mut list = widget::list_column();
|
let mut list = widget::list_column();
|
||||||
|
|
||||||
|
let search_input = self.input_source_search.trim();
|
||||||
|
|
||||||
for (id, (_locale, variant, description)) in &self.keyboard_layouts {
|
for (id, (_locale, variant, description)) in &self.keyboard_layouts {
|
||||||
list = list.add(self.input_source_item(id, description, !variant.is_empty()));
|
if search_input.is_empty() || description.contains(search_input) {
|
||||||
|
list = list.add(self.input_source_item(id, description, !variant.is_empty()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
widget::column()
|
widget::column()
|
||||||
|
.spacing(32)
|
||||||
|
.push(search)
|
||||||
.push(list)
|
.push(list)
|
||||||
.apply(Element::from)
|
.apply(Element::from)
|
||||||
.map(crate::pages::Message::Keyboard)
|
.map(crate::pages::Message::Keyboard)
|
||||||
|
|
|
||||||
|
|
@ -406,6 +406,7 @@ keyboard-special-char = Special Character Entry
|
||||||
.compose = Compose key
|
.compose = Compose key
|
||||||
|
|
||||||
added = Added
|
added = Added
|
||||||
|
type-to-search = Type to search...
|
||||||
|
|
||||||
## Input: Keyboard: Shortcuts
|
## Input: Keyboard: Shortcuts
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue