aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRubén Beltrán del Río <jj@r.bdr.sh>2026-01-18 23:16:54 +0100
committerRubén Beltrán del Río <jj@r.bdr.sh>2026-01-18 23:19:25 +0100
commitab544baf9b7fc39d671f922e827a4f2d6179a7f7 (patch)
tree47d4278119c676f7485b41c19b0fbc2497e3c32d /src
parent988e2ef1e8a7075a07a50d64f1e8439ebf8df098 (diff)
Fix bug where focus is lost when editing maps
Diffstat (limited to 'src')
-rw-r--r--src/preferences/pages/templates.rs71
1 files changed, 67 insertions, 4 deletions
diff --git a/src/preferences/pages/templates.rs b/src/preferences/pages/templates.rs
index 1760085..029b3e9 100644
--- a/src/preferences/pages/templates.rs
+++ b/src/preferences/pages/templates.rs
@@ -177,11 +177,37 @@ impl TemplatesPage {
}
pub fn refresh(&self, prefs: &UserPreferences) {
- // Clear existing rows
- while let Some(child) = self.list_box.first_child() {
- self.list_box.remove(&child);
+ // Check if we need to recreate rows (templates added/removed/reordered)
+ let current_row_count = {
+ let mut count = 0;
+ let mut child = self.list_box.first_child();
+ while child.is_some() {
+ count += 1;
+ child = child.and_then(|c| c.next_sibling());
+ }
+ count
+ };
+
+ let needs_recreate = current_row_count != prefs.map_templates.len();
+
+ if needs_recreate {
+ // Clear existing rows
+ while let Some(child) = self.list_box.first_child() {
+ self.list_box.remove(&child);
+ }
+ self.populate_templates(prefs);
+ } else {
+ // Just update existing rows in place
+ let mut child = self.list_box.first_child();
+ let mut index = 0;
+ while let Some(row) = child {
+ if let Some(template) = prefs.map_templates.get(index) {
+ TemplatesPage::update_template_row(&row, template);
+ }
+ child = row.next_sibling();
+ index += 1;
+ }
}
- self.populate_templates(prefs);
// Update editor if selected template still exists
let selected = *self.selected_id.borrow();
@@ -236,6 +262,43 @@ impl TemplatesPage {
}
}
+ fn update_template_row(row: &gtk::Widget, template: &Template) {
+ if let Some(list_row) = row.downcast_ref::<gtk::ListBoxRow>()
+ && let Some(hbox) = list_row.child().and_then(|c| c.downcast::<gtk::Box>().ok())
+ {
+ let mut child = hbox.first_child();
+ let mut widget_index = 0;
+
+ while let Some(widget) = child {
+ if widget_index == 0 {
+ // Update default button
+ if let Some(button) = widget.downcast_ref::<gtk::Button>() {
+ if template.is_default {
+ button.set_icon_name("emblem-default-symbolic");
+ button
+ .set_tooltip_text(Some(&tr!("preferences.templates.help.default")));
+ } else {
+ button.set_icon_name("radio-symbolic");
+ button.set_tooltip_text(Some(&tr!(
+ "preferences.templates.help.set_as_default"
+ )));
+ }
+ }
+ } else if widget_index == 1 {
+ // Update name entry
+ if let Some(entry) = widget.downcast_ref::<gtk::Entry>() {
+ // Only update if different to avoid cursor reset
+ if entry.text() != template.name {
+ entry.set_text(&template.name);
+ }
+ }
+ }
+ child = widget.next_sibling();
+ widget_index += 1;
+ }
+ }
+ }
+
fn create_template_row(&self, template: &Template) -> gtk::ListBoxRow {
let row = gtk::ListBoxRow::new();
let hbox = gtk::Box::new(gtk::Orientation::Horizontal, 10);