aboutsummaryrefslogtreecommitdiff
path: root/src/handlers/preferences.rs
diff options
context:
space:
mode:
authorRubén Beltrán del Río <jj@r.bdr.sh>2026-03-26 18:13:49 +0100
committerRubén Beltrán del Río <jj@r.bdr.sh>2026-03-26 23:02:28 +0100
commitc5d45b748d90c79f881c4e054b425d68801dad14 (patch)
treeb39ddf37fb74d761b98d4e0e8f2abdb1a764273e /src/handlers/preferences.rs
parent5f5b94474c83f85d95be5c53d148c4205c17d8e1 (diff)
Spin header into its own component
Diffstat (limited to 'src/handlers/preferences.rs')
-rw-r--r--src/handlers/preferences.rs70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/handlers/preferences.rs b/src/handlers/preferences.rs
new file mode 100644
index 0000000..f915898
--- /dev/null
+++ b/src/handlers/preferences.rs
@@ -0,0 +1,70 @@
+// Map, wardley map editor for linux
+// Copyright (C) 2026 Rubén Beltrán del Río
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+use relm4::prelude::*;
+use adw::prelude::*;
+
+use crate::file_registry;
+use crate::preferences::{PreferencesWindow, UserPreferences, storage, window};
+use crate::actions::Action;
+use crate::components::header::HeaderAction;
+
+use crate::AppModel;
+
+/// Shows the preferences window.
+pub fn show(model: &mut AppModel, sender: &ComponentSender<AppModel>) {
+ if model.preferences_window.is_none() {
+ let controller = PreferencesWindow::builder()
+ .transient_for(&model.window)
+ .launch(model.preferences.clone())
+ .forward(sender.input_sender(), |output| match output {
+ window::PreferencesOutput::PreferencesChanged(preferences) => {
+ Action::PreferencesChanged(preferences)
+ }
+ window::PreferencesOutput::Closed => {
+ Action::PreferencesWindowClosed
+ }
+ });
+ model.preferences_window = Some(controller);
+ }
+ if let Some(ref controller) = model.preferences_window {
+ controller.widget().present();
+ }
+}
+
+/// Closes the preferences window.
+pub fn close(model: &mut AppModel) {
+ model.preferences_window = None;
+}
+
+/// Reloads the preferences.
+pub fn reload(model: &mut AppModel) {
+ model.preferences = storage::load();
+ model.apply_preferences();
+ model.header.emit(HeaderAction::SetCustomStages(model.preferences.custom_stages.clone()));
+ model.header.emit(HeaderAction::SetCustomStages(model.preferences.custom_stages.clone()));
+ model.header.emit(HeaderAction::SetTemplates(model.preferences.map_templates.clone()));
+ model.update_image();
+}
+
+/// Updates preferences after they change.
+pub fn update(model: &mut AppModel, preferences: UserPreferences) {
+ model.preferences = preferences;
+ model.apply_preferences();
+ model.header.emit(HeaderAction::SetCustomStages(model.preferences.custom_stages.clone()));
+ model.header.emit(HeaderAction::SetTemplates(model.preferences.map_templates.clone()));
+ model.update_image();
+ file_registry::broadcast_to_all_windows(&Action::ReloadPreferences);
+}