aboutsummaryrefslogtreecommitdiff
path: root/src/handlers
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
parent5f5b94474c83f85d95be5c53d148c4205c17d8e1 (diff)
Spin header into its own component
Diffstat (limited to 'src/handlers')
-rw-r--r--src/handlers/mod.rs1
-rw-r--r--src/handlers/preferences.rs70
-rw-r--r--src/handlers/view.rs21
3 files changed, 84 insertions, 8 deletions
diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs
index 235afc2..4e53195 100644
--- a/src/handlers/mod.rs
+++ b/src/handlers/mod.rs
@@ -15,5 +15,6 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pub mod export;
pub mod file;
+pub mod preferences;
pub mod view;
pub mod zoom;
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);
+}
diff --git a/src/handlers/view.rs b/src/handlers/view.rs
index 660f7b9..87c4172 100644
--- a/src/handlers/view.rs
+++ b/src/handlers/view.rs
@@ -13,9 +13,11 @@
// 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::gtk;
+use relm4::prelude::*;
+use crate::components::header::HeaderAction;
use crate::AppModel;
+use wmap_renderer::StageType;
/// Toggles between horizontal and vertical layout orientation.
pub fn change_orientation(model: &mut AppModel) {
@@ -23,14 +25,17 @@ pub fn change_orientation(model: &mut AppModel) {
gtk::Orientation::Horizontal => gtk::Orientation::Vertical,
_ => gtk::Orientation::Horizontal,
};
+ model.header.emit(HeaderAction::SetLayoutOrientation(model.orientation));
}
/// Updates the selected stage type from dropdown selection.
-pub fn stage_type_selected(model: &mut AppModel, index: usize) {
- if index < model.available_stage_types.len()
- && let Some(stage_type) = model.available_stage_types.get(index)
- {
- model.stage_type = stage_type.clone();
- model.update_image();
- }
+pub fn stage_type_selected(model: &mut AppModel, stage_type: StageType) {
+ model.stage_type = stage_type;
+ model.update_image();
+}
+
+/// Updates the selected stage type from dropdown selection.
+pub fn change_horizontal_layout(model: &mut AppModel, is_enabled: bool) {
+ model.horizontal_layout_enabled = is_enabled;
+ model.header.emit(HeaderAction::SetHorizontalLayoutEnabled(is_enabled));
}