1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
use adw::prelude::*;
use relm4::prelude::*;
use crate::settings::Settings;
pub struct PreferencesDialog {
parent_window: adw::ApplicationWindow,
dialog: adw::PreferencesDialog,
}
#[derive(Debug)]
pub enum PreferencesDialogMsg {
Show,
}
#[relm4::component(pub)]
impl SimpleComponent for PreferencesDialog {
type Init = adw::ApplicationWindow;
type Input = PreferencesDialogMsg;
type Output = ();
view! {
#[root]
adw::PreferencesDialog {
set_title: "Preferences",
add: &page,
},
#[name(page)]
adw::PreferencesPage {
adw::PreferencesGroup {
set_title: "Machine Translation",
#[name(deepl_api_key_row)]
adw::EntryRow {
set_title: "DeepL API key",
},
}
}
}
fn init(
parent_window: Self::Init,
root: Self::Root,
_sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let settings = Settings::default();
let model = Self {
parent_window,
dialog: root.clone(),
};
let widgets = view_output!();
settings
.bind_deepl_api_key(&widgets.deepl_api_key_row, "text")
.build();
ComponentParts { model, widgets }
}
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
match msg {
PreferencesDialogMsg::Show => {
self.dialog.present(Some(&self.parent_window));
}
}
}
}
|