aboutsummaryrefslogtreecommitdiff
path: root/src/components/preferences_window.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/preferences_window.rs')
-rw-r--r--src/components/preferences_window.rs60
1 files changed, 42 insertions, 18 deletions
diff --git a/src/components/preferences_window.rs b/src/components/preferences_window.rs
index 0fb7d63..29e42fe 100644
--- a/src/components/preferences_window.rs
+++ b/src/components/preferences_window.rs
@@ -146,8 +146,8 @@ impl SimpleComponent for PreferencesWindow {
}
PreferencesAction::ImportFromFile(path) => {
if storage::import_from_file(&mut self.preferences, &path).is_ok() {
- self.sync_ui_from_preferences();
self.save_and_notify(&sender);
+ Self::sync_ui_from_preferences(&sender);
}
}
PreferencesAction::ExportToFile(path) => {
@@ -155,8 +155,8 @@ impl SimpleComponent for PreferencesWindow {
}
PreferencesAction::ResetToDefaults => {
self.preferences = UserPreferences::default();
- self.sync_ui_from_preferences();
self.save_and_notify(&sender);
+ Self::sync_ui_from_preferences(&sender);
}
PreferencesAction::SetShowMapBackground(show_background) => {
self.preferences.show_map_background = show_background;
@@ -207,24 +207,13 @@ impl SimpleComponent for PreferencesWindow {
self.save_and_notify(&sender);
}
PreferencesAction::SetCustomEditorFontName(font_name) => {
- self.preferences
- .custom_editor_font_name
- .clone_from(&font_name);
- self.editor_page
- .emit(preference_pages::EditorAction::SetCustomFont(font_name));
- self.save_and_notify(&sender);
+ self.handle_set_custom_editor_font_name(font_name, &sender);
}
PreferencesAction::SetEditorFontSize(font_size) => {
- self.preferences.editor_font_size = font_size;
- self.editor_page
- .emit(preference_pages::EditorAction::SetFontSize(font_size));
- self.save_and_notify(&sender);
+ self.handle_set_editor_font_size(font_size, &sender);
}
PreferencesAction::SetSoftWrapLines(soft_wrap_lines) => {
- self.preferences.soft_wrap_lines = soft_wrap_lines;
- self.editor_page
- .emit(preference_pages::EditorAction::SetSoftWrap(soft_wrap_lines));
- self.save_and_notify(&sender);
+ self.handle_set_soft_wrap_lines(soft_wrap_lines, &sender);
}
PreferencesAction::AddTemplate(name) => self.handle_add_template(name, &sender),
PreferencesAction::RemoveTemplate(id) => self.handle_remove_template(id, &sender),
@@ -259,8 +248,12 @@ impl PreferencesWindow {
.ok();
}
- // TODO: Figure out how to best do this with messages.
- fn sync_ui_from_preferences(&mut self) {}
+ // This is a lazy placeholder. I'd love if these values were easy
+ // to cascade, maybe they can but I don't know how yet. Anyway,
+ // closing and re-opening the window works just as well.
+ fn sync_ui_from_preferences(sender: &ComponentSender<Self>) {
+ sender.output(Action::ReloadPreferencesWindow).ok();
+ }
fn handle_add_template(&mut self, name: String, sender: &ComponentSender<Self>) {
let template = Template::new(name, String::new(), false);
@@ -391,6 +384,37 @@ impl PreferencesWindow {
}
}
+ fn handle_set_soft_wrap_lines(
+ &mut self,
+ soft_wrap_lines: bool,
+ sender: &ComponentSender<Self>,
+ ) {
+ self.preferences.soft_wrap_lines = soft_wrap_lines;
+ self.editor_page
+ .emit(preference_pages::EditorAction::SetSoftWrap(soft_wrap_lines));
+ self.save_and_notify(sender);
+ }
+
+ fn handle_set_editor_font_size(&mut self, font_size: f64, sender: &ComponentSender<Self>) {
+ self.preferences.editor_font_size = font_size;
+ self.editor_page
+ .emit(preference_pages::EditorAction::SetFontSize(font_size));
+ self.save_and_notify(sender);
+ }
+
+ fn handle_set_custom_editor_font_name(
+ &mut self,
+ font_name: String,
+ sender: &ComponentSender<Self>,
+ ) {
+ self.preferences
+ .custom_editor_font_name
+ .clone_from(&font_name);
+ self.editor_page
+ .emit(preference_pages::EditorAction::SetCustomFont(font_name));
+ self.save_and_notify(sender);
+ }
+
// Initializes the breakpoint logic
fn init_breakpoints(root: &adw::Window, widgets: &PreferencesWindowWidgets) {
let breakpoint = adw::Breakpoint::new(adw::BreakpointCondition::new_length(