| 1 | /* |
| 2 | * Copyright 2020-2024 Andrey Kutejko <[email protected]> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 3 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * For more details see the file COPYING. |
| 18 | */ |
| 19 | |
| 20 | use superrust-analyzer cargo gnome-robots 50.0.0 controls/::editorrust-analyzer cargo gnome-robots 50.0.0 controls/editor/::ControlEditorrust-analyzer cargo gnome-robots 50.0.0 controls/editor/ControlEditor#; |
| 21 | use craterust-analyzer cargo gnome-robots 50.0.0 crate/::{ |
| 22 | propertiesrust-analyzer cargo gnome-robots 50.0.0 properties/::{Propertiesrust-analyzer cargo gnome-robots 50.0.0 properties/Properties#, *}, |
| 23 | utilsrust-analyzer cargo gnome-robots 50.0.0 utils/::settings_aware_widgetrust-analyzer cargo gnome-robots 50.0.0 utils/settings_aware_widget()., |
| 24 | }; |
| 25 | use adwrust-analyzer cargo libadwaita 0.9.1 crate/::preluderust-analyzer cargo libadwaita 0.9.1 prelude/::*; |
| 26 | use gettextrsrust-analyzer cargo gettext-rs 0.7.7 crate/::gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().; |
| 27 | use gtkrust-analyzer cargo gtk4 0.11.1 crate/::{giorust-analyzer cargo gio 0.22.2 crate/, glibrust-analyzer cargo glib 0.22.3 crate/}; |
| 28 | |
| 29 | pub fn create_controls_listrust-analyzer cargo gnome-robots 50.0.0 controls/controls/create_controls_list().(settings: &giorust-analyzer cargo gio 0.22.2 crate/::Settingsrust-analyzer cargo gio 0.22.2 auto/settings/Settings#) -> adwrust-analyzer cargo libadwaita 0.9.1 crate/::PreferencesGrouprust-analyzer cargo libadwaita 0.9.1 auto/preferences_group/PreferencesGroup# { |
| 30 | let pg = adwrust-analyzer cargo libadwaita 0.9.1 crate/::PreferencesGrouprust-analyzer cargo libadwaita 0.9.1 auto/preferences_group/PreferencesGroup#::builderrust-analyzer cargo libadwaita 0.9.1 auto/preferences_group/impl#[PreferencesGroup]builder().() |
| 31 | .titlerust-analyzer cargo libadwaita 0.9.1 auto/preferences_group/impl#[PreferencesGroupBuilder]title().(gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().("Keyboard")) |
| 32 | .buildrust-analyzer cargo libadwaita 0.9.1 auto/preferences_group/impl#[PreferencesGroupBuilder]build().(); |
| 33 | |
| 34 | for (key, label) in [ |
| 35 | (CONTROL_KEY_NWrust-analyzer cargo gnome-robots 50.0.0 properties/CONTROL_KEY_NW., gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().("Key to move NW")), |
| 36 | (CONTROL_KEY_Nrust-analyzer cargo gnome-robots 50.0.0 properties/CONTROL_KEY_N., gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().("Key to move N")), |
| 37 | (CONTROL_KEY_NErust-analyzer cargo gnome-robots 50.0.0 properties/CONTROL_KEY_NE., gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().("Key to move NE")), |
| 38 | (CONTROL_KEY_Wrust-analyzer cargo gnome-robots 50.0.0 properties/CONTROL_KEY_W., gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().("Key to move W")), |
| 39 | (CONTROL_KEY_HOLDrust-analyzer cargo gnome-robots 50.0.0 properties/CONTROL_KEY_HOLD., gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().("Key to hold")), |
| 40 | (CONTROL_KEY_Erust-analyzer cargo gnome-robots 50.0.0 properties/CONTROL_KEY_E., gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().("Key to move E")), |
| 41 | (CONTROL_KEY_SWrust-analyzer cargo gnome-robots 50.0.0 properties/CONTROL_KEY_SW., gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().("Key to move SW")), |
| 42 | (CONTROL_KEY_Srust-analyzer cargo gnome-robots 50.0.0 properties/CONTROL_KEY_S., gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().("Key to move S")), |
| 43 | (CONTROL_KEY_SErust-analyzer cargo gnome-robots 50.0.0 properties/CONTROL_KEY_SE., gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().("Key to move SE")), |
| 44 | ] { |
| 45 | let editor = new_editorrust-analyzer cargo gnome-robots 50.0.0 controls/controls/new_editor().(settings, key); |
| 46 | |
| 47 | let action_row = adwrust-analyzer cargo libadwaita 0.9.1 crate/::ActionRowrust-analyzer cargo libadwaita 0.9.1 auto/action_row/ActionRow#::builderrust-analyzer cargo libadwaita 0.9.1 auto/action_row/impl#[ActionRow]builder().() |
| 48 | .titlerust-analyzer cargo libadwaita 0.9.1 auto/action_row/impl#[ActionRowBuilder]title().(&label) |
| 49 | .activatable_widgetrust-analyzer cargo libadwaita 0.9.1 auto/action_row/impl#[ActionRowBuilder]activatable_widget().(&editor) |
| 50 | .buildrust-analyzer cargo libadwaita 0.9.1 auto/action_row/impl#[ActionRowBuilder]build().(); |
| 51 | action_row.add_suffixrust-analyzer cargo libadwaita 0.9.1 auto/action_row/ActionRowExt#add_suffix().(&editor); |
| 52 | pg.addrust-analyzer cargo libadwaita 0.9.1 auto/preferences_group/PreferencesGroupExt#add().(&action_row); |
| 53 | } |
| 54 | |
| 55 | let dbut = gtkrust-analyzer cargo gtk4 0.11.1 crate/::Buttonrust-analyzer cargo gtk4 0.11.1 auto/button/Button#::builderrust-analyzer cargo gtk4 0.11.1 auto/button/impl#[Button]builder().() |
| 56 | .labelrust-analyzer cargo gtk4 0.11.1 auto/button/impl#[ButtonBuilder]label().(gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().("_Restore Defaults")) |
| 57 | .use_underlinerust-analyzer cargo gtk4 0.11.1 auto/button/impl#[ButtonBuilder]use_underline().(true) |
| 58 | .buildrust-analyzer cargo gtk4 0.11.1 auto/button/impl#[ButtonBuilder]build().(); |
| 59 | dbut.connect_clickedrust-analyzer cargo gtk4 0.11.1 auto/button/ButtonExt#connect_clicked().(glibrust-analyzer cargo glib 0.22.3 crate/::clonerust-analyzer cargo glib-macros 0.22.2 clone!!( |
| 60 | #[weak] |
| 61 | settings, |
| 62 | move |_| { |
| 63 | settings.reset_all_control_keysrust-analyzer cargo gnome-robots 50.0.0 properties/Properties#reset_all_control_keys().(); |
| 64 | } |
| 65 | )); |
| 66 | pg.set_header_suffixrust-analyzer cargo libadwaita 0.9.1 auto/preferences_group/PreferencesGroupExt#set_header_suffix().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&dbut)); |
| 67 | |
| 68 | pg |
| 69 | } |
| 70 | |
| 71 | fn new_editorrust-analyzer cargo gnome-robots 50.0.0 controls/controls/new_editor().(settings: &giorust-analyzer cargo gio 0.22.2 crate/::Settingsrust-analyzer cargo gio 0.22.2 auto/settings/Settings#, control_key: ControlKeyrust-analyzer cargo gnome-robots 50.0.0 properties/ControlKey#) -> ControlEditorrust-analyzer cargo gnome-robots 50.0.0 controls/editor/ControlEditor# { |
| 72 | let editor = ControlEditorrust-analyzer cargo gnome-robots 50.0.0 controls/editor/ControlEditor#::defaultrust-analyzer cargo gnome-robots 50.0.0 controls/editor/impl#[ControlEditor][Default]default().(); |
| 73 | |
| 74 | editor.set_keyrust-analyzer cargo gnome-robots 50.0.0 controls/editor/impl#[ControlEditor]set_key().(settings.get_control_keyrust-analyzer cargo gnome-robots 50.0.0 properties/impl#[`gio::Settings`][Properties]get_control_key().(&control_key)); |
| 75 | |
| 76 | editor.connect_editedrust-analyzer cargo gnome-robots 50.0.0 controls/editor/impl#[ControlEditor]connect_edited().(glibrust-analyzer cargo glib 0.22.3 crate/::clonerust-analyzer cargo glib-macros 0.22.2 clone!!( |
| 77 | #[strong] |
| 78 | settings, |
| 79 | move |keyval| { |
| 80 | settings.set_control_keyrust-analyzer cargo gnome-robots 50.0.0 properties/impl#[`gio::Settings`][Properties]set_control_key().(&control_key, keyval); |
| 81 | } |
| 82 | )); |
| 83 | editor.connect_clearedrust-analyzer cargo gnome-robots 50.0.0 controls/editor/impl#[ControlEditor]connect_cleared().(glibrust-analyzer cargo glib 0.22.3 crate/::clonerust-analyzer cargo glib-macros 0.22.2 clone!!( |
| 84 | #[strong] |
| 85 | settings, |
| 86 | move || { |
| 87 | settings.reset_control_keyrust-analyzer cargo gnome-robots 50.0.0 properties/impl#[`gio::Settings`][Properties]reset_control_key().(&control_key); |
| 88 | settings.get_control_keyrust-analyzer cargo gnome-robots 50.0.0 properties/impl#[`gio::Settings`][Properties]get_control_key().(&control_key) |
| 89 | } |
| 90 | )); |
| 91 | settings_aware_widgetrust-analyzer cargo gnome-robots 50.0.0 utils/settings_aware_widget().( |
| 92 | &editor, |
| 93 | settings, |
| 94 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(control_key.settings_keyrust-analyzer cargo gnome-robots 50.0.0 properties/ControlKey#settings_key.), |
| 95 | move |e, s| { |
| 96 | e.set_keyrust-analyzer cargo gnome-robots 50.0.0 controls/editor/impl#[ControlEditor]set_key().(s.get_control_keyrust-analyzer cargo gnome-robots 50.0.0 properties/impl#[`gio::Settings`][Properties]get_control_key().(&control_key)); |
| 97 | }, |
| 98 | ); |
| 99 | editor |
| 100 | } |