monorepo/otg/gtk/src/components/config.rs

53 lines
1.5 KiB
Rust
Raw Normal View History

use crate::CoreApi;
2023-08-25 00:24:41 +00:00
use adw::{prelude::*, subclass::prelude::*};
use glib::Object;
2024-03-22 03:48:48 +00:00
use otg_core::{ui::ConfigurationView, ChangeSettingRequest, CoreRequest};
2023-08-25 00:24:41 +00:00
#[derive(Default)]
pub struct ConfigurationPagePrivate {}
#[glib::object_subclass]
impl ObjectSubclass for ConfigurationPagePrivate {
const NAME: &'static str = "Configuration";
type Type = ConfigurationPage;
type ParentType = adw::PreferencesPage;
}
impl ObjectImpl for ConfigurationPagePrivate {}
impl WidgetImpl for ConfigurationPagePrivate {}
impl PreferencesPageImpl for ConfigurationPagePrivate {}
glib::wrapper! {
pub struct ConfigurationPage(ObjectSubclass<ConfigurationPagePrivate>)
@extends adw::PreferencesPage, gtk::Widget,
@implements gtk::Orientable;
}
impl ConfigurationPage {
pub fn new(api: CoreApi, view: ConfigurationView) -> Self {
2023-08-25 00:24:41 +00:00
let s: Self = Object::builder().build();
let group = adw::PreferencesGroup::builder().build();
let library_entry = &adw::EntryRow::builder()
.name("library-path")
.title(view.library.label)
.show_apply_button(true)
.build();
if let Some(path) = view.library.value {
library_entry.set_text(&path);
}
library_entry.connect_apply(move |entry| {
api.dispatch(CoreRequest::ChangeSetting(
ChangeSettingRequest::LibraryPath(entry.text().into()),
));
2023-08-25 00:24:41 +00:00
});
group.add(library_entry);
s.add(&group);
s
}
}